From max at alcyone.com Mon Oct 17 16:13:50 2005 From: max at alcyone.com (Erik Max Francis) Date: Mon, 17 Oct 2005 13:13:50 -0700 Subject: Stripping ASCII codes when parsing In-Reply-To: References: Message-ID: David Pratt wrote: > I am working with a text format that advises to strip any ascii control > characters (0 - 30) as part of parsing data and also the ascii pipe > character (124) from the data. I think many of these characters are > from a different time. Since I have never seen most of these characters > in text I am not sure how these first 30 control characters are all > represented (other than say tab (\t), newline(\n), line return(\r) ) so > what should I do to remove these characters if they are ever > encountered. Many thanks. Use ''.translate. Pass in the identity mapping for the first argument, and for the second parameter, specify the list of all the characters you wish to delete. This would probably be something like: IDENTITY_MAP = ''.join([chr(x) for x in range(256)]) BAD_MAP = ''.join([chr(x) for x in range(32) + [124]) aNewString = aString.translate(IDENTITY_MAP, BAD_MAP) Note that ASCII 31 is also a control character (US). -- 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 believer is happy; the doubter is wise. -- (an Hungarian proverb) From gregm at taming-tech.com Fri Oct 7 13:35:22 2005 From: gregm at taming-tech.com (GregM) Date: 7 Oct 2005 10:35:22 -0700 Subject: Matching zero only once using RE Message-ID: <1128706522.319929.75310@g49g2000cwa.googlegroups.com> Hi, I've looked at a lot of pages on the net and still can't seem to nail this. Would someone more knowledgeable in regular expressions please provide some help to point out what I'm doing wrong? I am trying to see if a web page contains the exact text: You have found 0 matches But instead I seem to be matching all sorts of expected line like You have found matches for example: You have found 34 matches You have found 189 matches You have found 16,734 matches You have found 1,706 matches You have found 300 matches The last 2 I thought I had eliminated but sadly it seems not the examples above actually seem to match my expression below. :( Here is what I'm doing: zeromatch = [] SecondarySearchTerm = 'You found (0){1} matches' primarySearchTerm = 'Looking for Something' primarySearchTerm2 = 'has been an error connecting' # pagetext is all the body text on a web page. # I'm using COM to drive MSIE and pagetext = doc.body.outerText if (re.search(primarySearchTerm, pagetext) or re.search(primarySearchTerm2, pagetext)): failedlinks.append(link) elif (re.search(SecondarySearchTerm, pagetext)): zeromatch.append(link) I've tried other RE's be had even more spectacular failures any help would be greatly appreciated. Thanks in Advance, Greg Moore Software Test Shop.com From mark.delon at gmx.at Wed Oct 19 17:33:05 2005 From: mark.delon at gmx.at (Mark Delon) Date: Wed, 19 Oct 2005 23:33:05 +0200 (MEST) Subject: connect to https unpossible. Please help. Message-ID: <17677.1129757585@www43.gmx.net> Hi, i want to log via python script to https page: 'https://brokerjet.ecetra.com/at/' # But it does not work. I am using following code(see below) Has somebody any ideas? How can I get to this https page? Need I to know some infos from "provider"(certificates, etc)? Thank u very much ! sincerely mark Code: ====== import urllib2 theurl='https://brokerjet.ecetra.com/at/' # username = 'username' password = 'password' passman = urllib2.HTTPPasswordMgrWithDefaultRealm() passman.add_password(None, theurl, username, password) authhandler = urllib2.HTTPBasicAuthHandler(passman) opener = urllib2.build_opener(authhandler) urllib2.install_opener(opener) t = urllib2.urlopen('https://brokerjet.ecetra.com/at/') # Traceback (most recent call last): File "", line 1, in ? File "C:\Program Files\python233\lib\urllib2.py", line 129, in urlopen return _opener.open(url, data) File "C:\Program Files\python233\lib\urllib2.py", line 326, in open '_open', req) File "C:\Program Files\python233\lib\urllib2.py", line 306, in _call_chain result = func(*args) File "C:\Program Files\python233\lib\urllib2.py", line 908, in https_open return self.do_open(httplib.HTTPS, req) File "C:\Program Files\python233\lib\urllib2.py", line 886, in do_open raise URLError(err) urllib2.URLError: -- Highspeed-Freiheit. Bei GMX superg?nstig, z.B. GMX DSL_Cityflat, DSL-Flatrate f?r nur 4,99 Euro/Monat* http://www.gmx.net/de/go/dsl From davids at webmaster.com Tue Oct 25 14:48:13 2005 From: davids at webmaster.com (David Schwartz) Date: Tue, 25 Oct 2005 11:48:13 -0700 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: "John-Paul Stewart" wrote in message news:pjv133-pjn.ln1 at mail.binaryfoundry.ca... > David Schwartz wrote: >> If nobody wants these operating systems, then it doesn't hurt him not to >> be able to sell them. If people want them, then he could have shown >> Microsoft the door. > > If only 5% want another operating system, the vendor has to choose between > selling to those 5% -or- to the 95% who want Microsoft. Had it not been > for the underhanded tactics, he could have sold to *both* groups. > > From a purely economic standpoint, the sensible thing is to accept that > 95% and let the 5% go elsewhere. > > But if *every* vendor has to make that same choice, there is no place for > that other 5% to go to buy another operating system. So the other > operating system(s) die off. And those 5% become customers of Microsoft > since there's no other choice left. And *that* is where the legal > problems start: they gained market share by preventing consumers from > finding competing products. Right, except that's utterly absurd. If every vendor takes their tiny cut of the 95%, a huge cut of the 5% is starting to look *REALLY* good. DS From http Wed Oct 5 04:04:59 2005 From: http (Paul Rubin) Date: 05 Oct 2005 01:04:59 -0700 Subject: "no variable or argument declarations are necessary." References: <434084 3b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99 f9f10238681bf68f@teranews> Message-ID: <7xu0fw75jo.fsf@ruckus.brouhaha.com> Magnus Lycka writes: > It seems you've missed the entire point of using a dynamically > typed language. It's not just about saving typing time and making > your methods take up fewer lines of code. It's about writing generic > code. Just look at C++ with all that mess with complex templates, > silly casting and dangerous void pointers etc that are needed to > achieve a fraction of the genericity that Python provides with no > effort from the programmer. So where are the complex templates and dangerous void pointers in ML? From steve at REMOVETHIScyber.com.au Sun Oct 9 06:21:33 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 09 Oct 2005 20:21:33 +1000 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> Message-ID: On Sat, 08 Oct 2005 20:44:12 +0000, Roedy Green wrote: > On Wed, 05 Oct 2005 09:38:49 +1000, Steven D'Aprano > wrote or quoted : > >>Yes it is. HTML means that after I've specified my email client use my >>favourite font, in the size I like, people send me emails that over-ride >>my choice. Invariably they use a font I don't even have. > > I would suggest then a better solution is to implement CSS in email, > the way you do in browsers to deal with that same problem. Are you volunteering? Good. Let me know when your done, I'd love to see it. In the meantime, I'll continue viewing emails in plain text, and if they contain HTML I'll choose for myself whether to render it, or trash it, or manually read through the code looking for content. -- Steven. From tadmc at augustmail.com Tue Oct 4 23:16:26 2005 From: tadmc at augustmail.com (Tad McClellan) Date: Tue, 4 Oct 2005 22:16:26 -0500 Subject: check html file size References: <1128473042.653989.175990@o13g2000cwo.googlegroups.com> Message-ID: Xah Lee wrote: > would anyone like to translate the following perl script to Python or > Scheme (scsh)? Yes, I would. -- Tad McClellan SGML consulting tadmc at augustmail.com Perl programming Fort Worth, Texas From cowie.rob at gmail.com Fri Oct 7 21:33:24 2005 From: cowie.rob at gmail.com (Rob Cowie) Date: 7 Oct 2005 18:33:24 -0700 Subject: noob question Letters in words? References: Message-ID: <1128735204.407666.193440@g14g2000cwa.googlegroups.com> A string can be thought of as a tuple of characters. Tuples support membership testing thus... choice1 = raw_input("> ") if '1' or 's' or 'S' in choice1: #do something elif '2' or 'e' or E' in choice1: #do something It doesn't seem to me to be a good idea; If the input is 'Start', option1 is executed, likewise if the input is 'Stop', or any other string with 's' in it. Perhaps a better idea is to present the user with a choice that cannot be deviated from, along the lines of... def main(): print "1.\tStart" print "2.\tSomething Else" print "3.\tStop" x = raw_input() if x is '1': print 'Start' elif x is '2': print 'Something else' elif x is '3': print 'End' else: main() From benji at benjiyork.com Mon Oct 10 20:41:44 2005 From: benji at benjiyork.com (Benji York) Date: Mon, 10 Oct 2005 20:41:44 -0400 Subject: read serial data from a barcode reader/scanner using python In-Reply-To: References: Message-ID: <434B0A48.1070506@benjiyork.com> Edgar wrote: > is there a way to program python to read serial data from a barcode > reader/scanner http://pyserial.sourceforge.net/ > and then using the parallel port of the PC to activate an > electromagnetic door lock. http://pyserial.sourceforge.net/pyparallel.html For other options see Google (then here if answers are not forthcoming). -- Benji York From rtconner at gmail.com Fri Oct 7 17:23:49 2005 From: rtconner at gmail.com (Rob Conner) Date: 7 Oct 2005 14:23:49 -0700 Subject: dictionaries/pointers Message-ID: <1128720229.615202.4670@g47g2000cwa.googlegroups.com> I dont know how to do this and can't think of a simple way to. All I want is a dictionary where two keys point to the same object. (to steal the ascii art from http://starship.python.net/crew/mwh/hacks/objectthink.html) I want sometihng like this: ,------. +-------+ | dict |------>|+-----+| +---+ `------' || "a" |+---->| 1 | |+-----+| +---+ | | ^ |+-----+| | || "b" |+-------' |+-----+| +-------+ | | |+-----+| +---+ || "c" |+---->| 2 | |+-----+| +---+ +-------+ Where if I change "a" or "b" to 3 the other one will change? Is this even possible? How would I do it? From mistobaan at gmail.com Wed Oct 19 05:49:16 2005 From: mistobaan at gmail.com (Misto .) Date: Wed, 19 Oct 2005 11:49:16 +0200 Subject: Well written open source Python apps In-Reply-To: References: <1129214592.342917.100090@g43g2000cwa.googlegroups.com> <1129656350.052690.188500@g14g2000cwa.googlegroups.com> Message-ID: I suggest also these: Spark: ----------------- http://pages.cpsc.ucalgary.ca/~aycock/spark/ Few files. I like how doc strings are used for handling the grammar. Twisted: ---------------- http://twistedmatrix.com/ I like everything, from test to comments! (many are funny) Misto From lasse at vkarlsen.no Sat Oct 8 14:35:49 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Sat, 08 Oct 2005 20:35:49 +0200 Subject: Merging sorted lists/iterators/generators into one stream of values... In-Reply-To: <1128795319.09c32ac9943b0580a86b7bcada7facc1@teranews> References: <1128667968.421469.180910@g47g2000cwa.googlegroups.com> <1128691708.c6930b5cb9f3673ed3abe8755178d163@teranews> <1128692196.410209.252100@g14g2000cwa.googlegroups.com> <1128695317.c6a5acb3e62787f011310c96f0c7cc35@teranews> <1h439qe.pz7c451jcec6hN%aleax@mail.comcast.net> <1128795319.09c32ac9943b0580a86b7bcada7facc1@teranews> Message-ID: George Sakkis wrote: > Just added a recipe at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440673. You can try > both and see if there's any significant performance difference for your data. Thanks, will take a look at it later. The sort solution seems to work nicely. Might be a big difference if I have a lot of sources though as I bet the overhead in doing a sort of N items gets higher than doing a manipulation of a heap to place an item in the right spot, but with 4-5 or a few more sources might not make an impact at all. -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From timothy at open-networks.net Wed Oct 5 20:38:07 2005 From: timothy at open-networks.net (Timothy Smith) Date: Thu, 06 Oct 2005 10:38:07 +1000 Subject: catching all tracebacks In-Reply-To: <4344679D.9040902@open-networks.net> References: <4344679D.9040902@open-networks.net> Message-ID: <434471EF.4070009@open-networks.net> Timothy Smith wrote: >iw ant to use a singel try except statment with my main app loop in the >middle and catch all tracebacks and email them to myself as a bug >report. however it seems a little more tricky then i thought > >try: > Main.Main() >except Exception, err_o: > print err_o.__class__.__name__, '//', err_o, '//', err_o.args > >that was suggested to me however it doesn't catch the errors i made in >the program, it just spits out a traceback. > > never mind it works now. From my_email_is_posted_on_my_website at munged.invalid Wed Oct 26 20:17:42 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Thu, 27 Oct 2005 00:17:42 GMT Subject: Microsoft Hatred FAQ References: <3s6l8mFmj3fjU1@individual.net> <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> Message-ID: On Wed, 26 Oct 2005 16:53:07 -0700, "David Schwartz" wrote, quoted or indirectly quoted someone who said : > Umm, it's not a judgment. Microsoft said you can sell Windows and other >operating systems, but there will be a charge for every machine you sell >without Windows -- if you want to be able to buy Windows wholesale. Someone >could comply with this by not selling any other operating systems at all and >never pay the fee. Therefore, this is a lesser restriction than saying you >can only sell Windows wholesale if you don't sell or offer any competing >systems. If I have the right to say you can't use my car at all, I have the >lesser right to impose the lesser restriction that you can only use my car >if you pay me $10. It makes a big difference that MS has a monopoly. If I open an washing machine store and Maytag says, "we only sell wholesale to you if you agree to sell our brand exclusively." What Microsoft did is different for three reasons: 1. the Maytag agreement made up front, not imposed to shut down a business who has never signed a prior exclusivity contract. 2. The appliance store has lots of other brands to sell. In my case, failing to comply with MS's illegal and immoral demand would put me out of busness. They were forcing me into commit criminal acts or lose my business. 3. Maytag makes the machines. In the computer instance, we at CMP custom build the computers. Microsoft have no business telling me what to do when they supplied only one component. I could not even sell a BARE computer. -- Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching. From codecraig at gmail.com Wed Oct 5 10:26:55 2005 From: codecraig at gmail.com (Java and Swing) Date: 5 Oct 2005 07:26:55 -0700 Subject: Call C functions from Python In-Reply-To: References: <1128454231.381256.297280@g47g2000cwa.googlegroups.com> <1128514161.835258.138730@g44g2000cwa.googlegroups.com> Message-ID: <1128522414.964010.65970@g14g2000cwa.googlegroups.com> i tried... >> from ctypes import * >> myapp = cdll.LoadLibrary("c:\\myapp.dll") >> dumpbin /exports myapp.pyd i get, SyntaxError: invalid syntax with it pointing at the first "p" in myapp.pyd. From dashkedar123 at yahoo.co.in Mon Oct 10 02:20:23 2005 From: dashkedar123 at yahoo.co.in (Kedar Dash) Date: Mon, 10 Oct 2005 07:20:23 +0100 (BST) Subject: Python Programmer Urgently Required Message-ID: <20051010062023.31197.qmail@web8607.mail.in.yahoo.com> Job Description: The position holder will supplement the existing pool of application development and programming pool of OWSA technical team. In particular S/he will be responsible for developing Python based overlay application ? to be mounted on existing software tools and solutions. The position will report to Programe Manager, Training & Technical Services. Required Skills: * A degree in Computer Application, Engineering or another numerate subject * 1+ years experience of web application development in Python or PHP * Good understanding of MySQL, PostGreSQL or another RDBMS platform. * Aptitude and experience of technical writing and process documentation * Good oral and written communication abilities; and ability to work in multi-disciplinary team To apply for any of these above positions, please send your latest resume along with details of your current role and how do your propose to contribute in this position. Women candidates with the requisite skills & qualifications are especially encouraged to apply. OneWorld South Asia is an equal opportunity employer. Applications along with a one page write up explaining the suitability to the job may be sent (preferably through email) to: Kedar Dash Team Leader, Web Development OneWorld South Asia, C-5 Qutab Institutional Area New Delhi ? 110016 Tel: 91 11 51689001 Ext 108 Fax: 91 11 51689001 Email : kedar.dash at oneworld.net __________________________________________________________ Yahoo! India Matrimony: Find your partner now. Go to http://yahoo.shaadi.com From http Thu Oct 13 04:15:37 2005 From: http (Paul Rubin) Date: 13 Oct 2005 01:15:37 -0700 Subject: installer for amd64 build of python? References: <1129162224.131305.269060@g49g2000cwa.googlegroups.com> Message-ID: <7xek6poms6.fsf@ruckus.brouhaha.com> magneticlemur at gmail.com writes: > Does anyone know of an available downloader for an amd64 bit > build of (a modern) python? I've gotten a bug report from someone using Python under Linux on an amd64, so compiling for 64 bits definitely is feasible. You could try the Fedora Core 4 amd64 distro (http://fedora.redhat.com). From john at castleamber.com Tue Oct 18 19:41:28 2005 From: john at castleamber.com (John Bokma) Date: 18 Oct 2005 23:41:28 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <867jcbzdw9.fsf@bhuda.mired.org> Message-ID: Steven D'Aprano wrote: > Oh, and if you think I'm saying something shocking by suggesting that > somebody is a psychopath, I'm not. Something like one in five of the > general population are psychopaths, psychopaths according to DSM IV, or just some silly test from a magazine? > With training and/or a good dose of enlightened self-interest, most > psychopaths are perfectly capable of learning to not be selfish Yup, like everybody can become an olympic swimmer, or get a degree. Just work, and you'll make it. > Actually doing that harm is, or at least should be, although sadly > when we allow the psychopaths to make the rules, they tend to make > rules that allow themselves to prosper at our expense. Hmmmm... and probably one in three is paranoid? -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From saint.infidel at gmail.com Thu Oct 6 17:56:07 2005 From: saint.infidel at gmail.com (infidel) Date: 6 Oct 2005 14:56:07 -0700 Subject: Python, alligator kill each other Message-ID: <1128635767.068104.232190@g14g2000cwa.googlegroups.com> By Denise Kalette Associated Press MIAMI - The alligator has some foreign competition at the top of the Everglades food chain, and the results of the struggle are horror-movie messy. A 13-foot Burmese python recently burst after it apparently tried to swallow a live 6-foot alligator whole, authorities said. ... ... It is unknown how many pythons are competing with the thousands of alligators in the Everglades, but at least 150 have been captured in the past two years ... From richard at zync.co.uk Wed Oct 5 16:58:21 2005 From: richard at zync.co.uk (Richard Gration) Date: Wed, 05 Oct 2005 20:58:21 GMT Subject: check html file size References: <1128473042.653989.175990@o13g2000cwo.googlegroups.com> Message-ID: On Tue, 04 Oct 2005 17:44:02 -0700, Xah Lee wrote: > would anyone like to translate the following perl script to Python or > Scheme (scsh)? Are you fucking seriously fucking expecting some fucking moron to translate your tech geeking fucking code moronicity? Fucking try writing it fucking properly in fucking Perl first. -- I guess everybody's the same: Gotta be good at your job before you can enjoy the rest of your life -- Cole Trickle From hauck at gseos.com Wed Oct 26 13:45:39 2005 From: hauck at gseos.com (Tommytrojan) Date: 26 Oct 2005 10:45:39 -0700 Subject: Weird import behavior In-Reply-To: References: <1130260282.027302.49370@g44g2000cwa.googlegroups.com> <1130265049.927710.155050@g44g2000cwa.googlegroups.com> Message-ID: <1130348739.872653.111820@g43g2000cwa.googlegroups.com> Thanks for the clarification. I never ran into this before although I have been working with Python for over 8 years. Good to learn something new. Cheers, Thomas From steve at holdenweb.com Tue Oct 4 15:31:17 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 04 Oct 2005 20:31:17 +0100 Subject: Newbie regular expression ? In-Reply-To: <1128450779.107011.5370@z14g2000cwz.googlegroups.com> References: <1128450779.107011.5370@z14g2000cwz.googlegroups.com> Message-ID: len wrote: > I have the following statement and it works fine; > > list1 = glob.glob('*.dat') > > however I now have an additional requirement the the string must begin > with > any form of "UNQ,Unq,unq,..." > > as an example if I had the following four files in the directory: > > unq123abc.dat > xy4223.dat > myfile.dat > UNQxyc123489-24.dat > > only unq123abc.dat and UNQxyc123489-24.dat would be selected > > I have read through the documentation and I am now sooooo > confussedddddd!! > You don't need regular expressions. You want list1 = glob.glob("[Uu][Nn][Qq]*.dat") regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From nir at digitalpeers.com Thu Oct 13 08:01:12 2005 From: nir at digitalpeers.com (Nir Aides) Date: Thu, 13 Oct 2005 14:01:12 +0200 Subject: Looking for a Python mentor In-Reply-To: <1129167866.253155.157850@g43g2000cwa.googlegroups.com> References: <1129167866.253155.157850@g43g2000cwa.googlegroups.com> Message-ID: <434e4ad2$1@news.bezeqint.net> Hello Len, You should try the #python IRC room. It is always very active and helpful. Nir LenS wrote: > Hello > > Was wandering if there is any place where some one could go to get > mentoring on python coding. I have started coding in python but I am > the only one in the shop using it. So there is no one around to look > over my code give suggestions on improvement, in style, logic, easier > ways of doing things etc. I am not really looking for hand holding as > much mentoring. I have purchased about every python book out and have > a list a mile long on my internet bookmarks. I believe I have a good > grasp of the fundamentals procedurally and I am fighting my way through > OOP. I am more at the stage of trying to pull things together into > programs that perform real world tasks. At one point I thought I saw > some place on one of the web site that did this kind of thing but I > can't find it now. > > Any help or suggestions welcomed > Len Sumnler > From quiteblack at gmail.com Tue Oct 11 21:14:01 2005 From: quiteblack at gmail.com (black) Date: 11 Oct 2005 18:14:01 -0700 Subject: can we save print msg into a file when script running ? Message-ID: <1129079641.137785.320000@g44g2000cwa.googlegroups.com> hi all~ in my .py file there are a few print to trace out some message and i wonder if we can save it into a specified file when that script get running. if so, i may just check that file to c how the script is running. can anyone show me a right direction ? one million tks~ From fredrik at pythonware.com Mon Oct 24 04:06:49 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 24 Oct 2005 10:06:49 +0200 Subject: Syntax across languages References: <1130052687.396109.145420@o13g2000cwo.googlegroups.com> Message-ID: Tom Anderson wrote: > This is taken from the AIEEEEEEEE 754 standard, i take it? :) > > Seriously, that's horrible. Fredrik, you are a bad man, and run a bad > railway. > > However, looking at the page the OP cites, the only mention of that > operator i can find is in Dylan, and in Dylan, it's nothing to do with > approximate FP equality - it means 'not identical', which we can spell "is > not". > > What would approximate FP equality even mean? How approximate? so you don't really know what it is, but you're sure that "looks the same when printed using a well-defined algorithm" can never be the answer ? From ms at cerenity.org Sun Oct 2 18:33:13 2005 From: ms at cerenity.org (Michael) Date: Sun, 02 Oct 2005 23:33:13 +0100 Subject: A Moronicity of Guido van Rossum References: <1128003857.930444.47650@g14g2000cwa.googlegroups.com><1128013745.763757.144280@g44g2000cwa.googlegroups.com><1128176637.146092.314200@o13g2000cwo.googlegroups.com> <434031f6$0$73596$ed2619ec@ptn-nntp-reader03.plus.net> Message-ID: <43405fff$0$15048$ed2619ec@ptn-nntp-reader02.plus.net> Fredrik Lundh wrote: ... > fwiw, they've also been around for ages: > > http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?list+comprehension > > (the name goes back to the early eighties, the construct is older than > that) Ahh... Fair enough. I hadn't come across it as a programming construct until I hit Python. I'd seen the (presumable) precursor of set comprehension it in maths & formal methods before though. To help Xah along, this shows a //more nearly// correct version of his table function (his doesn't do anything like the spec). It works correctly for tables of the form: table("i", ("i",3)) table("i,j", ("i",3), ("j",3)) table("math.cos(i+j)", ("i",3), ("j",-3,3)) It doesn't produce quite the right structure when you have more than 2 iteration rules). Problems with this implementation: * mkrange() is not passed along the existing context. This means tables of the form: table("i,j", ("i",3), ("j",1,"i")) Won't work. This would require changing the mkRange function such that it's passed the most currently built environment. This is a relatively trivial change, which I'll leave for Xah. * The structure is incorrect for more than 2 iteration rules. I think I'm missing a simple/obvious trick in my mkTable._extend_table function. I'm not really fussed though. (It's clearly something dumb :) * It's not really clear which list nests which. It's possible the lists are nested the wrong way round. I'm fairly certain that the evalTable code will work fine when the mkTable code creates the right structure. I'll leave that to Xah to fix. It's somewhat further along than his original attempt though. (actually matches his spec for 1 or 2 iteration rules). def mkRange(listspec): if len(listspec)==2: return xrange(1,listspec[1]+1) elif len(listspec)==3: return xrange(listspec[1],listspec[2]+1) return [] def mkTable(ignore, *listspecs): def _extend_table(listspecs, result): if len(listspecs) == 0: return result else: listspec = listspecs[-1] listspecs = listspecs[:-1] r2 = [] for R_ in result: for R in R_: # SMELLY inner_result = [] for i in mkRange(listspec): inner_env2 = dict(R[1]) inner_env2[listspec[0]] = i inner_result.append( (ignore, inner_env2) ) r2.append(inner_result) result = _extend_table(listspecs, r2) return result return _extend_table(listspecs, [[(ignore,dict(globals()))]]) # SMELLY def evalTable(table): if len(table) ==0: return table else: result = [] for evallist in table: inner_result = [] for eval_args in evallist: try: r = eval(*eval_args) inner_result.append(r) except TypeError: inner_result.append(evalTable(eval_args)) result.append(inner_result) return result def table(ignore, *listspecs): abstract_table = mkTable(ignore, *listspecs) return evalTable(abstract_table) Example: >>> import math >>> table("math.cos(i+j)", ("i",3), ("j",-3,3)) [[-0.41614683654714241, 0.54030230586813977, 1.0], [0.54030230586813977, 1.0, 0.54030230586813977], [1.0, 0.54030230586813977, -0.41614683654714241], [0.54030230586813977, -0.41614683654714241, -0.98999249660044542], [-0.41614683654714241, -0.98999249660044542, -0.65364362086361194], [-0.98999249660044542, -0.65364362086361194, 0.28366218546322625], [-0.65364362086361194, 0.28366218546322625, 0.96017028665036597]] Regards, Michael. From Michael.Coll-Barth at VerizonWireless.com Fri Oct 7 11:36:24 2005 From: Michael.Coll-Barth at VerizonWireless.com (Michael.Coll-Barth at VerizonWireless.com) Date: Fri, 7 Oct 2005 11:36:24 -0400 Subject: users of pycurl here? Message-ID: <20051007153731.4612C1E4005@bag.python.org> How about doing an 'ls -la' once you have connected to the server? That returns a listing of the files with the size in bytes. -----Original Message----- From: Michele Simionato I am having a hard time in finding out how to retrieve information about the *size* of files I want to download from an FTP site. Should I send a QUOTE SIZE command to the ftp server or is there an easier way? ___________________________________________________________________ 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 nyamatongwe+thunder at gmail.com Tue Oct 4 20:10:46 2005 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Wed, 05 Oct 2005 00:10:46 GMT Subject: "no variable or argument declarations are necessary." In-Reply-To: <1128467011.312.15.camel@blackwidow> References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> <434245F5.6060500@REMOVEMEcyber.com.au> <7xr7b14lk0.fsf@ruckus.brouhaha.com> <7xu0fx9l7y.fsf@ruckus.brouhaha.com> <1128467011.312.15.camel@blackwidow> Message-ID: C++ and C# are converging with implicitly typed languages to the extent that many declarations will be able to omit types. In the next C++ standard and in C# 3.0 it may be possible to write, where Fn is a function returning any particular type: auto spam = Fn(); // C++0x var spam = Fn(); // C# 3.0 http://www.research.att.com/~bs/rules.pdf http://msdn.microsoft.com/vcsharp/future/ (most useful is the C# 3.0 language spec Word document) Neil From my_email_is_posted_on_my_website at munged.invalid Wed Oct 12 17:40:34 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 12 Oct 2005 21:40:34 GMT Subject: Jargons of Info Tech industry References: <1124804082_1011@spool6-east.superfeed.net> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <86y853mzmr.fsf@bhuda.mired.org> <86mzlil269.fsf@bhuda.mired.org> Message-ID: On 12 Oct 2005 01:43:32 GMT, John Bokma wrote or quoted : >> So let's say I decide to send an email to Donald Knuth. > >:-) I did write him, snail mail, and he responded giving us permission to rewrite any of the algorithms in his famous set of books in to Java. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From scott.daniels at acm.org Fri Oct 14 16:03:50 2005 From: scott.daniels at acm.org (Scott David Daniels) Date: Fri, 14 Oct 2005 13:03:50 -0700 Subject: Comparing lists In-Reply-To: References: <1128930699.799657.146210@g47g2000cwa.googlegroups.com> <1128952417.0544cc73190bbbd4e683448c137969c8@teranews> <434ba977@nntp0.pdx.net> Message-ID: <43500eb0@nntp0.pdx.net> Let me begin by apologizing to Christian as I was too snippy in my reply, and sounded even snippier than I meant to. Christian Stapfer wrote: > "Scott David Daniels" wrote in message > news:434ba977 at nntp0.pdx.net... >>a "better" set implementation will win if >>it can show better performance without >>related down-sides. > > Is there ever such a thing? I always > thought that, most of the time, there > is no such thing as a free lunch in If you look at the history of Python's sort, it has steadily gotten better. The list implementations has been tweaked to produce better performance appending and popping. There are a number of such cases. In fact, as Python rolls along, code keeps getting improved. Usually the requirement is that the change not degrade current benchmarks and provide a substantial improvement in at least some practical cases. >>As to the "either now, or eventually;" if you _must_ have performance >>now, not in some abstract future, then it behooves you to _test_, >>_test_, _test_! > > Well, I might want to test: but *first* I want > to design, preferably in "armchair style" ... [using] > rough complexity measures to .... >>>>>If the documentation stated the order-of-magnitude >>>>>behavior of those basic operations up front, then >>>>>I (and *anyone* else who ever wanted to use those >>>>>operations on large lists / large sets) could do >>>>>a quick order-of-magnitude estimation of how >>>>>a certain program design will behave, performance >>>>>wise. I think this is where I started over-reacting. There are a number of requests here over time by people who state that things would be so much better for every one if only someone (never themselves) did some more work that they might not otherwise want to do. The people who implement the code often do so on their own time. I find the Python docs surprisingly good for even commercial documentation. For work that is done gratis, it is phenomenal. I hesitate to ask any more of it (although I have pointed out bugs in docs as I've found them). >>And, if the proper documentation is in place, and it >>says "dictionary lookup is O(N)" (and you avoid using >>it for exactly that reason), how surprised will you be >>to discover that the O(N) is only reached if the hash >>values of the keys are all equal? > > It's not that difficult to distinguish > *average* case and *worst* case scenarios. > It might even be a good idea to state, > if that can easily be done, what the > *best* case happens do be... > >>Oh, maybe you expect "O(N)" to really mean "\Theta(N)". >>Then, if you are a dweeb like me, you will respond that >>"This is not possible, a dictionary of size N must take at >>least 'O(lg N)' to read the key, never mind processing it." >>But, it turns out, that given a bound on the size of a >>process, processing an address is "O(1)", not "O(lg N)". >>Is that too practical for you, or not enough? > > I do not expect a developer to expend *inordinate* > amounts of work to figure out the computational > complexity of what he has implemented. But, as I > wrote, he *must* have thought about the matter, and > is thus, by definition, in a rather good position > to provide what he can frequently simply pull from > memory when it comes to documenting the interface > of his module. I talked about Big-O (worst case) or Big-Theta (average case) just to point out that no simple characterization like "O(N)" tells enough of the story to be practically useful. Once you decide that isn't good enough, the burden on creating the documentation is getting substantial, especially given that you've already spent the effort to write the code and tests for it. In fact I'd hesitate to raise the documentation bar any higher -- I'd hate to think someone thought, "Oh, forget it, I'll just use this code myself." >>>>> *Experimenting* is not necessarily as easy to >>>>>do as you seem to believe. No, "experimenting" is not always easy (though often it is easy enough). However, "experimenting" puts the cost on the person who derives the benefit, and is thus likely to not be done in a slipshod way. > I am not at all a lawyer type, as you seem to > imagine. I just want to suggest that some > (to the implementer - but not the average user) > *easily* available information about computational > complexity (especially for the most basic data types) > would be a good thing to have. Nothing more. My point is that simple performance characterization is not good enough to be useful, and fully accurate characterization is an onerous documentation burden. Something in between will be fraught with complaints about "surprising" worst cases. Whether you would approach middle-ground documentation with the spirit of "this is enough to go on" or not, rest assured that a number of people will complain in a "language- lawyer-like" way about any perceived imperfections. >>Would you mind if the quality is proportional to >>the price you paid? Here I was too snippy. Sorry. >>>>You are, of course, either assuming that there's a >>>>single implementation of Python, >>>>or that all implementations have the same behaviour. (Each line denied with "Of course not.") But realistically, most users will learn the performance characteristics once, and continue to use the trade-offs that were characteristics of that version of Python going forward. Now maybe you behave differently, but most programmers I know (and I explicitly include myself) do have that tendency. Lots of python code moves around operating systems and implementations (and the number of implementations is growing). >>>But it is reasonable, anyway, to ask for information >>>about a specific implementation (that one is *forced* >>>to use). >>You are not _forced_ to use any implementation of Python. > What I wanted to say is ... this: *whenever* a Python > program is run, it will run on some specific > implementation of Python. That much should be obvious. If I were still in a snippy mood, I'd point out that you might look at your original statement and see how it might be read by someone who accidentally read what you wrote, rather than what wanted to write. >>You are free to implement your own Python system. > Don't be ridiculous. If Pypy gets going this may not be as unlikely as you think. You will be able to (relatively easily) replace implementations of parts of Python and re-generate a system. > It is you (and only you) here, who is arguing that if > perfection is not attainable (with reasonable effort), > nothing should be done at all. I am trying to say the request you make is substantially larger than you understand (or would appear at first blush). Further it is a request that asks for work from others for your (and other's) benefit, not work that you offer to pitch in and help on. > I am as willing to live with imperfect module inferface > specification as I am willing with imperfect tools more > generally. But that will not stop me from making > *suggestions* for improvement (not arrogant demands, mind you). Try writing something that would fit your standards for all of the basic types, punting where you don't know details. If it is enough to be useful, others will chip in and help fix it where it is broken. > I have seen *many* books on algorithms that specify > computational complexity measures for the algorithms > described. Any really good library of algorithms will > at least try to reach that standard, too. How many "really good libraries of algorithms" do you know of? Could you name a couple that have these characterizations? Practical code is rife with issues of "finite address space," low-order effects swamping the higher-order terms for most practical sizes and such. It is this collection of nasty little details that makes characterizing libraries frustratingly hard. >>>I consider it the job of the implementer to ... >>Am I to take it you provide this to all of your customers? > ...I did not want to pose as the customer who expects nothing > but perfection from *others* (but not himself, of course). > I am not at all like that: you are attacking > a figment of your imagination. Actually, I was not attacking at all. I was trying to suggest that it is a harder task than you imagine. I am assuming you won't take me up on the suggestion of starting a flawed document, but I'd be happy to be proved wrong. If not, try writing a characterization of the performance of a dozen or so of your own programs. Does the result seem useful in proportion to the work it took you to write it? >>>How reasonable is it to ask me, or anyone else >>>for that matter, to extract, experiment-wise >>>(if it can be done at all with reasonable effort) >>>information that properly belongs to the implementer >>>and really should have been exposed in the >>>documentation in the first place? >>Not at all reasonable. How reasonable is it to ask >>me to provide you support information for free? OK, here I was _very_ snippy. Sorry again. I will assert that often the experiment results in a single bit of information: "it is fast enough." Experimenting will get you reliable answers like that, and only when run-time is an issue will you need to go into it much further. --Scott David Daniels scott.daniels at acm.org From pmartin at snakecard.com Fri Oct 21 19:30:23 2005 From: pmartin at snakecard.com (Philippe C. Martin) Date: Fri, 21 Oct 2005 23:30:23 GMT Subject: how to modify text in html form from python References: <0Ra6f.5050$q%.616@newssvr12.news.prodigy.com> <86d5lyu0j8.fsf@bhuda.mired.org> <%Tb6f.5062$q%.3600@newssvr12.news.prodigy.com> <7xbr1ijvy2.fsf@ruckus.brouhaha.com> Message-ID: Paul, That won't cut it: The cards I use/code do not have RSA capabilities but only symmetrical algorithms (AES, 3DES, ....). I use the same type of authentication you would see between a POS and a Smart Card (ex: B0' in France) So I cannot hookup to one of the standards (PKCS11 or CSP). Thanks anyway. Regards, Philippe Paul Rubin wrote: > "Philippe C. Martin" writes: >> ***** HOW (if there's a better way let me know please) ****** >> As I have not found any better solution yet, I am trying to do the >> following (on the server there is an html file and a cgi file) > > If I understand it, you're trying to use a smart card to authenticate > a web site login. The major browsers already have smart card interfaces > (Windows CAPI for MSIE, or PKCS11 for Netscape/Moz*) so you shouldn't > need a plugin. On the other hand, smart cards are very slow. > > The typical approach is as follows (MSIE version). Stop using special > smart card programs and just use a card that implements CAPI with a > from the vendor and that can sign against an X509 certificate. The > CSP will have a special signature that makes it less scary to install > than a browser plugin. You'll have to issue a cert for the smart card > and there's various approaches to that, so I'll skip that part. Set > up a TLS server to require a client cert from the CA that signed the > smart card. The browser should recognize the challenge and select the > right cert. The CSP will have its own interface for the user entering > a PIN along with inserting the card. Once you have the TLS connection > established, set a secure cookie in the client session and then redirect > the browser to another URL that doesn't require the smart card (because > otherwise the card will have to re-authenticate every click, which is > very slow). From then on, use the cookie for authentication (it can > have a timeout or whatever). From max at alcyone.com Fri Oct 7 17:26:57 2005 From: max at alcyone.com (Erik Max Francis) Date: Fri, 07 Oct 2005 14:26:57 -0700 Subject: dictionaries/pointers In-Reply-To: <1128720229.615202.4670@g47g2000cwa.googlegroups.com> References: <1128720229.615202.4670@g47g2000cwa.googlegroups.com> Message-ID: Rob Conner wrote: > I dont know how to do this and can't think of a simple way to. > > All I want is a dictionary where two keys point to the same object. > (to steal the ascii art from > http://starship.python.net/crew/mwh/hacks/objectthink.html) > I want sometihng like this: > > ,------. +-------+ > | dict |------>|+-----+| +---+ > `------' || "a" |+---->| 1 | > |+-----+| +---+ > | | ^ > |+-----+| | > || "b" |+-------' > |+-----+| > +-------+ > | | > |+-----+| +---+ > || "c" |+---->| 2 | > |+-----+| +---+ > +-------+ > > Where if I change "a" or "b" to 3 the other one will change? > Is this even possible? How would I do it? Objects of type int are immutable in Python, so you'll need a helper class to do this. Try something like: >>> class Container: ... def __init__(self, value=None): self.value = value ... def get(self): return self.value ... def set(self, value): self.value = value ... >>> one = Container(1) >>> myDictionary = {} >>> myDictionary['a'] = one >>> myDictionary['b'] = one >>> myDictionary['b'].set(3) >>> print myDictionary['a'].get() 3 -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis Never make a promise or plan / Take a little love where you can -- Florence, _Chess_ From svenn.are at bjerkem.de Thu Oct 27 09:05:37 2005 From: svenn.are at bjerkem.de (Svenn Are Bjerkem) Date: Thu, 27 Oct 2005 15:05:37 +0200 Subject: forum References: <1128272422.987128.295820@g43g2000cwa.googlegroups.com> Message-ID: In article <1128272422.987128.295820 at g43g2000cwa.googlegroups.com>, csheppard91 at gmail.com says... > Forum commuication is easier, and I've just started a new forum and > would like to invite all of you to sign up and post there. I'm still I don't agree. USENET is easier because you can search and post on groups.google.com. You don't have to register, you can use your favourite NNTP reader etc. -- Svenn From steve at holdenweb.com Fri Oct 21 11:24:24 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 21 Oct 2005 16:24:24 +0100 Subject: classmethods, class variables and subclassing In-Reply-To: References: <4357EE59.1000005@bakerjaffe.plus.com> <43588b5c$0$6536$ed2619ec@ptn-nntp-reader01.plus.net> <4358C7A6.1040907@bakerjaffe.plus.com> <4358F492.7000406@imperial.ac.uk> Message-ID: Steve Holden wrote: [...] > > I think so. It's not normal adive, but it sounds like a metaclass might > be what you need here. > ^adive^advice^ spell-me-own-name-wrong-next-ly y'rs - evest -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From chris at angband.org Fri Oct 14 16:27:13 2005 From: chris at angband.org (Operation Latte Thunder) Date: Fri, 14 Oct 2005 20:27:13 +0000 (UTC) Subject: KeyboardInterrupt being lost? Message-ID: I have a simple test proggie that isn't behaving like I expect ( found below ). The script will infinitely run ( as expected ), but seems to completely ignore control-C's. Shouldn't the interpreter pass along KeyboardInterrupts and break out of the while loop, or am I missing something? Using python 2.4.2 on linux ( if it matters ) -- Script Below -- import threading, traceback, time class TestThread ( threading.Thread ): def __init__ ( self ): threading.Thread.__init__ ( self ) def run ( self ): print "Starting..." while True: time.sleep ( 1 ) return if __name__ == '__main__': test = TestThread ( ) test.start() print "Started..." test.join() -- chris From david at jotax.com Wed Oct 26 03:57:44 2005 From: david at jotax.com (David Poundall) Date: 26 Oct 2005 00:57:44 -0700 Subject: How best to reference parameters. In-Reply-To: <*firstname*nlsnews-A70110.21161425102005@news.verizon.net> References: <1130274796.584531.229340@g43g2000cwa.googlegroups.com> <*firstname*nlsnews-A70110.21161425102005@news.verizon.net> Message-ID: <1130313463.973864.287730@z14g2000cwz.googlegroups.com> Nice - I like that Tony. I had seen it around before but I didn't catch on. Thanks for the clear example.. From rdm at rcblue.com Sat Oct 8 20:53:10 2005 From: rdm at rcblue.com (Dick Moores) Date: Sat, 08 Oct 2005 17:53:10 -0700 Subject: Book "Python and Tkinter Programming" In-Reply-To: References: <1128620086.240847.235490@g44g2000cwa.googlegroups.com> Message-ID: <6.2.1.2.2.20051008175005.03f9e310@rcblue.com> DaveInSidney wrote at 15:55 10/8/2005: >Check out BestBookBuys: >http://www.bestwebbuys.com/Python_and_Tkinter_Programming-ISBN_1884777813.html?isrc=b-search Or even better, BestBookDeal.com: Dick Moores From utabintarbo at gmail.com Wed Oct 5 10:43:00 2005 From: utabintarbo at gmail.com (utabintarbo at gmail.com) Date: 5 Oct 2005 07:43:00 -0700 Subject: question about output References: <1128522271.424943.204030@o13g2000cwo.googlegroups.com> Message-ID: <1128523380.618777.10710@g44g2000cwa.googlegroups.com> Given that the format is consistent (and the last char is not part of the number you want), you can probably do something like this: x = int('10944800e'[:-1]) Disclaimer: I am a n00b. YMMV ;-) From davids at webmaster.com Thu Oct 27 03:49:27 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 00:49:27 -0700 Subject: Microsoft Hatred FAQ References: <3s6l8mFmj3fjU1@individual.net> <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> Message-ID: Roedy Green wrote: > On Wed, 26 Oct 2005 19:50:07 -0700, "David Schwartz" > wrote, quoted or indirectly quoted someone who > said : >> The Microsoft agreement is also up front. It's not "imposed" in >> any sense except that it's one of the conditions for buying Windows >> wholesale. > No it was not . It was never on paper. It was not imposed until I > had been in business for at least 5 years. I guess I don't understand what you're saying. Are you saying that Microsoft demanded you pay them per machine you sold under the table in the absence of a written contract that said that? Or are you simply saying that they changed the terms of your agreement when it came up for renewal? DS From kent37 at tds.net Wed Oct 19 11:58:33 2005 From: kent37 at tds.net (Kent Johnson) Date: Wed, 19 Oct 2005 11:58:33 -0400 Subject: parser question In-Reply-To: References: Message-ID: <43566b30_1@newspeer2.tds.net> Micah Elliott wrote: > You might be able to tackle this easily enough with REs if your > structures don't nest arbitrarily. It's hard to tell if this deserves > a formal grammar based on the example. If it does, you could try PLY > (which I've had a pleasant experience > with in the past) or any of the other parsers listed on the PLY site's > "Other Python Parsing Tools". A more complete list is here: http://www.nedbatchelder.com/text/python-parsers.html I have found pyparsing easy to work with. Kent From mytsai at u.washington.edu Fri Oct 14 12:09:25 2005 From: mytsai at u.washington.edu (Mingus Tsai) Date: Fri, 14 Oct 2005 11:09:25 -0500 Subject: Help with cPickle for deserializing datetime.datetime instances In-Reply-To: References: Message-ID: Hans Georg Krauthaeuser wrote: > Mingus Tsai schrieb: > >>Hello- please help with unpickling problem: >> >>I am using Python version 2.3.4 with IDLE version 1.0.3 on a Windows >>XPhome system. >> >>My problem is with using cPickle to deserialize my pickled arrays of >>datetime.datetime instances. The following is the code I have written: >> >> import cPickle, datetime >> import Numeric >> >>#the file below contains a serialized dict with arrays of datetime >>#objects. When these three statements run, the IDLE crashes! >> >> input1 = open('tsm2_outa','r') >> time1 = cPickle.load(input1) >> input1.close() >> >>#the file below contains serialized dict with arrays of built-in objects >>#it unpickles without any problem, when I omit the above unpickling >>#operation. >> >> input2 = open('tsm2_outb','rb') >> data1 = cPickle.load(input2) >> input2.close() >> >>My guess is that I need to somehow tell the pickle.load command that it >>is loading datetime instances, but I have no idea how to do this. Any >>help would be much appreciated. >> >>Thanks, >>Ming > > How did you wrote the pickle-file. If you used mode 2 you have to open > the file with mode "rb", as you did for the other pickle file. > > Hans here's the code from my pickling: #dict of arrays of datetime objects export1 = {'gagetime':gagednt2ar,'gagetime_offset':gagednt2_offsetar, 'tektime_lagb':mdntmar,'tektime':mdntzar,'tektime_lagf':mdntpar} #dict of arrays of built-in objects datamat = {'az':azrowfar,'el':elrowfar,'tekrange_lagb':mtmt, 'tekrange':mtzt,'tekrange_lagf':mtpt,'teksig_lagb':mvmt, 'teksig':mvzt,'teksig_lagf':mvpt,'gagerange':gagerange, 'gagesig':gagesig} time_out = open('tsm2_outa','w') cPickle.dump(export1,time_out) time_out.close() data_out = open('tsm2_outb','wb') cPickle.dump(datamat,data_out,1) data_out.close() ------ So, you can see that the first dict is pickled in ascii (those arrays are pretty small), but the second dict (the one that i have no problem unpickling) is pickled in binary. However, I have tried both ascii and binary for the frist dict, but both crash the IDLE. I don't understand how pickling works with non built-in objects--is it necessary for me to tell it that I have datetime objects and how do i do that? Or perhaps there's something entirely different happening? much obliged, Ming From matthew.garrish at sympatico.ca Sun Oct 23 15:41:28 2005 From: matthew.garrish at sympatico.ca (Matt Garrish) Date: Sun, 23 Oct 2005 15:41:28 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <86k6g59ke6.fsf@bhuda.mired.org> <3EI6f.43974$MF6.5922@fe1.news.blueyonder.co.uk> <86irvo861u.fsf@bhuda.mired.org> Message-ID: "David Schwartz" wrote in message news:djgm8u$k14$1 at nntp.webmaster.com... > > "Mike Meyer" wrote in message > news:86irvo861u.fsf at bhuda.mired.org... > >> David claimed that everyone had a right to do whatever they wanted >> with their property. This is simply false throughout most of the >> civilized world - zoning laws control what kinds of business you can >> run on your property, various laws designed to control the looks of >> the town dictate what you can do to the exterior or lawn, flood and >> earthquake laws state what kinds of structural changes you can make, >> and so on. I took the view of a political extremist to point out that >> he was wrong. David predictably used that to tar me as an extremist >> from the other end of the spectrum. > > Here's a question for you, Mike. Presumably, you have the right not to > be shot for no reason at all. Does that right act as a bulletproof vest > that actually physically prevents me from shooting you? If I argued that a > person had a right not to be shot for no reason at all by a random > stranger, would you point out that such shootings occur throughout the > civilized world as some kind of refutation? > > The way you respond to what I'm saying shows that you really don't have > any clue whatsoever of what the words I'm using *mean*. Do you even know > what a "right" is? (Such that, for example, it's possible for rogue > governments to violate the rights of their citizens even if those > governments don't recognize those rights.) > I'd be interested in hearing what you think a right is? In Florida, for example, you have the right to gun someone down if you think they're a bit too menacing. In Canada, most people find that reprehensible. So does a Floridian visiting Canada have their rights infringed on by our rogue government because they're not allowed to gun down menacing looking Canadians at will? Should they be able to exercise that right regardless and not have to face the consequences of our laws? I think "right", however, was the wrong choice of words in this thread; there is rarely anything codifying a company's "right" to succeed at all costs and at the expense of all competition (except Crown Corporations and the like, which are created (in theory, anyway) in the interest of general population as opposed to it). Your question here appears to be one of ethics. Is MS ethically bankrupt for pursuing business practices that run counter to society's established norms, and should they be punished for doing so? And is their behaviour the more reprehensible because of the contempt they show for the decisions of society's judicial arm. Matt From steve at holdenweb.com Tue Oct 4 11:25:34 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 04 Oct 2005 16:25:34 +0100 Subject: Exception raising, and performance implications. In-Reply-To: <1128435341.708873.244050@g43g2000cwa.googlegroups.com> References: <1128375280.034852.119910@o13g2000cwo.googlegroups.com> <*firstname*nlsnews-B3B8C2.18033703102005@news.verizon.net> <1128435341.708873.244050@g43g2000cwa.googlegroups.com> Message-ID: leo wrote: >>However, I think the functionality you're asking for is available as >>inspect.currentframe(), and if the implementation is in "C" it may have a tiny >>performance advantage over the Python version. > > > You're absolutely right, in fact the code snippet from my OP was taken > directly from inspect.currentframe. We're intending on using this in > production, and I'm trying to gauge what the implications may be. > > >>Python uses exceptions internally, using StopIteration to terminate the >>iterator in a for: loop. > > > Wow, I was unaware of this. If Python internally uses exceptions, maybe > they aren't as detrimental as I thought. > > That said, I will be judiciously profiling my code and measuring as > much as possible, I just wanted to throw this question out to the NG in > case anyone had done this before (and so I can put off learning the > profiler a little bit longer :) ) > > Thanks all for the replies. > Do note, however, that detecting an exception inside the C framework of the interpreter carries less overhead than detecting an exception in Python itself. That said, exceptions are probably rather more "lightweight" than you might imagine, so benchmarking (the profiler may not be best - have you come across "timeit.py"?) is the best way to go. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From g.franzkowiak at onlinehome.de Fri Oct 28 13:12:27 2005 From: g.franzkowiak at onlinehome.de (g.franzkowiak) Date: Fri, 28 Oct 2005 19:12:27 +0200 Subject: popen2 Message-ID: I start a process in my application with popen2.popen3('MyOtherProcess'). That's ok, but what can I do if the other process is running ? Can I fetch some information and start with that ? gerd From iddw at hotmail.com Mon Oct 10 19:17:06 2005 From: iddw at hotmail.com (Dave Hansen) Date: Mon, 10 Oct 2005 23:17:06 GMT Subject: [Info] PEP 308 accepted - new conditional expressions References: <3q4ro9Fd770nU3@individual.net> Message-ID: <1128986126.7aab88bc9d9a2f56ea6d61ec086380ec@teranews> On Mon, 10 Oct 2005 16:42:34 -0500, Terry Hancock wrote: >On Sunday 09 October 2005 07:50 am, phil hunt wrote: >> On Fri, 7 Oct 2005 01:05:12 -0500, Terry Hancock wrote: >> >GvR's syntax has the advantage of making grammatical sense in English (i.e. >> >reading it as written pretty much makes sense). >> >> I know, let's re-write Python to make it more like COBOL! That's >> bound to be a winner! > >Whereas the "natural order" of "condition affirmative negative" is natural >for what reason? That it is so in C? And Basic, and Fortran, and Lisp, and just about any programming language you care to name, including python (if Condition: Affirmative else: Negative). Not to mention that the sequence is identical to execution order. It's just plain goofy to have to scan to the middle of an expression to find out what happens first, then depending on the result of that, skipping back over what you just skipped. > >I don't find that so compelling either, frankly. Why should it really >matter in the end? I've always found C's order (and punctuation) confusing, Confusing how? Perform test, choose branch. Simple. And it's not punctuation. It's an operator, just like + or & or ~. I can understand how you might find the terseness confusing, though. >I have to look it up practically everytime I use it or have to read it >(which correlates to it being used very rarely, with causality in both >directions). FWIW, in over 20 years of C programming, I use it pretty rarely too, though I never had to look it up after I first saw it in K&R. It only very rarely holds any advantage over a simple if/else statement, especially in modern compilers. It's most useful in macros, which python doesn't even have. > >Given that situation, choosing a form which is easy to read is surely >an advantage, and, since it is the way that Python has handled logic >in the past, it makes sense to continue doing so. Easy to read out loud, but complex to understand, with all the back and forth scanning required. > >No doubt, ANY choice of ternary operator for Python will be >criticized, and no doubt, ANY choice would nevertheless be >usable. The whole idea of a ternary operator is somewhat complex. > >OTOH, I think this choice is consistent with the rest of Python's >design. The general choice to use keyword operators for LOGIC >and symbolic operators for MATH is retained, and so long as we're >describing the logic in words, it makes sense for the wording >to sound natural. I guess I agree, thoug I would have preferred to see something like r = c ?then: yes else: no > >Consistency certainly does make it easier for me to remember. I guess I disagree that it's consistent, at least with the way I see python. > >Python's main advantage over other languages, for me, is that >it makes me run to the manual a lot less, and I generally don't >get confused trying to follow other people's code. I'm inexperienced enough to keep Beazley's book at my elbow when writing my own code, though reading other's code is usually simpler. Until things like __metaclass__ and @classmethod start showing up... Regards, -=Dave -- Change is inevitable, progress is not. From fredrik at pythonware.com Fri Oct 7 07:01:14 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 7 Oct 2005 13:01:14 +0200 Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net><1128306351.13c600edac4bfa99f9f10238681bf68f@teranews><3qi8erFf252rU1@uni-berlin.de><3qkdbrFfgga9U1@uni-berlin.de><3qkn7qFffkl6U1@uni-berlin.de><3qkr1hFfgj5uU1@uni-berlin.de><7xr7ax690j.fsf@ruckus.brouhaha.com><1128676408.129888.297840@g <434651f4$0$11145$626a14ce@news.free.fr> Message-ID: "Christophe" wrote: > It's more of a "Nearly too late" type checking I would say. Not that I > complain but it would be great if there were also some automatic type > checking to catch a few errors as soon as possible. use assert as the soonest possible point. implementing "type gates" is trivial, if you think you need them. From m.barenco at gmail.com Tue Oct 11 20:45:12 2005 From: m.barenco at gmail.com (m.barenco at gmail.com) Date: 11 Oct 2005 17:45:12 -0700 Subject: dictionnaries and lookup tables In-Reply-To: References: <1129053992.141269.149840@z14g2000cwz.googlegroups.com> <1129056624.073937.207160@g44g2000cwa.googlegroups.com> Message-ID: <1129077912.846879.140640@f14g2000cwb.googlegroups.com> Ok, Thanks for your answers, that's pretty unambiguous. M. From hancock at anansispaceworks.com Mon Oct 10 16:46:34 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Mon, 10 Oct 2005 15:46:34 -0500 Subject: When someone from Britain speaks, Americans hear a "British accent"... In-Reply-To: References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <200510071643.11162.hancock@anansispaceworks.com> Message-ID: <200510101546.34584.hancock@anansispaceworks.com> On Saturday 08 October 2005 04:35 am, Steve Holden wrote: > I must have been working at NASA at the time; they are well known for > embiggening prices. Not nearly as much as the DoD, from what I hear. Truthfully, I think those stories are bit exaggerated -- I think the real problem is somebody making a bad make/buy decision. They decide to make something that they could easily have bought at the hardware store. Naturally, any time you make a one-off part, it costs something awful. That's the real reason that, say, Apollo was so expensive. Nearly every part was a one-off prototype. If you get used to that almost always being the case, it shouldn't be so surprising that somebody forgets to check to see if the odd part *can* be sourced commercially. Of course, making one-off parts isn't nearly as hard today as it was in 1965, so that's interesting too. Sorry for the digression, but the real story behind things like that is kind of interesting, IMHO. ;-) And I think the original joke is pretty dead by now. ;-) -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From mwm at mired.org Wed Oct 19 16:58:32 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 19 Oct 2005 16:58:32 -0400 Subject: Sequence and/or pattern matching References: <1129710091.400262.139440@g14g2000cwa.googlegroups.com> <1h4ocwa.184dksqmnv1q1N%aleaxit@yahoo.com> <1129712258.200656.202440@g43g2000cwa.googlegroups.com> Message-ID: <86fyqxw7ev.fsf@bhuda.mired.org> "S?b" writes: >> Essentially, if I understand correctly, you want to detect LOOPS given a >> sequence of directed connections A->B. "loop detection" and "graph" >> would then be the keywords to search for, in this case. > > Exactly, but the sequence has to be discovered by the piece of code ! > >> Does this "then" imply you're only interested in loops occurring in this >> *sequence*, i.e., is order of connections important? If the sequence of >> directed connections was, say, in the different order: >> >> B->C >> A->B >> C->A >> >> would you want this detected as a loop, or not? > > Yes, it would be nice to detect it as a loop, with for example a > threshold. Btw, it would be nice to ignore additional connections in > such a way : > > B->C # Normal connection > D->E # Additional connection to ignore > A->B # Normal connection > C->A # Normal connection > > Would it be possible ? As Ben Sizer pointed out, this is a fairly well-known graph algorithm. You just want to add information to add ordering information to each edge, so you can verify that the an edge that is further down the path is "older" than the last edge added. Given your ordering requirement, simply numbering the edges and checking that the "older" edge has a larger number than the previous edge should do. With my admin hat on, I have to wonder - don't you really want to deal with duration? I.e - each connection has a "start" and "end" time, and you're really only interested in paths that happen while all the connections actually exist? Just a wild ass guess, mind you. However, it doesn't radically change the test. You now tag each edge with a start and stop time, and check that all previous edges on the path exist while the one you are adding exists. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From percivall at gmail.com Sun Oct 16 11:38:38 2005 From: percivall at gmail.com (Simon Percivall) Date: 16 Oct 2005 08:38:38 -0700 Subject: subtle side effect of generator/generator expression In-Reply-To: <1129472425.591880.11500@g14g2000cwa.googlegroups.com> References: <1129470158.623786.135010@g14g2000cwa.googlegroups.com> <1129472425.591880.11500@g14g2000cwa.googlegroups.com> Message-ID: <1129477118.700187.17570@g44g2000cwa.googlegroups.com> If you find that you want to iterate over an iterable multiple times, have a look at the solution that the tee() function in the itertools module provides (http://docs.python.org/lib/itertools-functions.html). (Have a look at the rest of the itertools module as well, for that matter.) From sjmaster at gmail.com Thu Oct 6 16:52:06 2005 From: sjmaster at gmail.com (Steve M) Date: 6 Oct 2005 13:52:06 -0700 Subject: Lambda evaluation References: Message-ID: <1128631926.003173.237990@o13g2000cwo.googlegroups.com> Here's another one: >>> d = {} >>> for x in [1,2,3]: ... d[x] = (lambda z: lambda y: y * z) (x) ... >>> d[1](3) 3 >>> d[2](3) 6 From larry.bates at websafe.com Fri Oct 28 14:38:55 2005 From: larry.bates at websafe.com (Larry Bates) Date: Fri, 28 Oct 2005 13:38:55 -0500 Subject: SNMP In-Reply-To: <1130515702.436348.190240@g43g2000cwa.googlegroups.com> References: <1130515702.436348.190240@g43g2000cwa.googlegroups.com> Message-ID: <4362703F.30106@websafe.com> py wrote: >>From what I have seen Python does not come with an snmp module built > in, can anyone suggest some other SNMP module (preferably one you have > used/experienced)..I have googled and seen yapsnmp and pysnmp (which > seem to be the two most active SNMP modules). > > Thanks > Google turns up the following: Yet Another Python SNMP module - http://yapsnmp.sourceforge.net/intro.html Python SNMP framework - http://pysnmp.sourceforge.net/ Larry Bates From steve at REMOVETHIScyber.com.au Sun Oct 16 07:02:34 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 16 Oct 2005 21:02:34 +1000 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <11l48tuqj7m11b5@corp.supernews.com> Message-ID: On Sun, 16 Oct 2005 11:54:20 +0200, Jeroen Wenting wrote: >> What you call "clever marketing" the DOJ calls "monopolistic >> practices". The courts agreed with the DOJ. Having had several large >> PC manufacturers refuse to sell me a system without some form of >> Windows because MS made it impossible for them to compete if they >> didn't agree to do so, I agree with the courts and the DOJ. >> > And were later forced to rescind. False. When the Bush administration took over from Clinton, they didn't follow through with punishing Microsoft for, e.g. perjury, but they didn't "rescind" the judgement. > The judge who wrote that opinion is well > known for his anti-Microsoft activism. Well, that sure answered my previous question. Remember, Microsoft has been found guilty of illegal practices in *many* civil suits, and settled out of court many more, plus TWO American DoJ investigations by two different judges, plus Japan, the EU, and a number of individual European nations. -- Steven. From fredrik at pythonware.com Thu Oct 20 03:27:53 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 20 Oct 2005 09:27:53 +0200 Subject: Extention Woes References: <1129753094.056781.319720@z14g2000cwz.googlegroups.com><1129777857.676019.263340@f14g2000cwb.googlegroups.com><1129780560.288676.177850@f14g2000cwb.googlegroups.com> <1129782119.830390.235540@g47g2000cwa.googlegroups.com> Message-ID: "Tuvas" wrote: > Well, the point of declaring it as a char was to have it as an 8 bit > integer, as is requested later on in the program. since ParseTuple writes an integer to the address you pass in, that's likely to overwrite some random stuff on the stack. like- wise, passing in a character buffer where ParseTuple expects a pointer to a char pointer isn't going to work either (but that only writes garbage into the buffer). > Anyways, I tried making the changes, similar results. post the new code and the output it's giving you. > BTW, it doesn't give me one single warning, so I don't think it's a > casting problem... the C compiler doesn't understand the ParseTuple format string, so that doesn't mean anything. it's up to you to make sure that the format specifiers and the pointers you pass in match. From david.rasmussen at gmx.net Sat Oct 29 18:55:32 2005 From: david.rasmussen at gmx.net (David Rasmussen) Date: Sun, 30 Oct 2005 00:55:32 +0200 Subject: Scanning a file In-Reply-To: References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> Message-ID: <4363fdd4$0$2107$edfadb0f@dtext02.news.tele.dk> Steven D'Aprano wrote: > On Fri, 28 Oct 2005 06:22:11 -0700, pinkfloydhomer at gmail.com wrote: > >>Which is quite fast. The only problems is that the file might be huge. > > What *you* call huge and what *Python* calls huge may be very different > indeed. What are you calling huge? > I'm not saying that it is too big for Python. I am saying that it is too big for the systems it is going to run on. These files can be 22 MB or 5 GB or ..., depending on the situation. It might not be okay to run a tool that claims that much memory, even if it is available. > >>I really have no need for reading the entire file into a string as I am >>doing here. All I want is to count occurences this substring. Can I >>somehow count occurences in a file without reading it into a string >>first? > > Magic? > That would be nice :) But you misunderstand me... > You have to read the file into memory at some stage, otherwise how can you > see what value the bytes are? I haven't said that I would like to scan the file without reading it. I am just saying that the .count() functionality implemented into strings could just as well be applied to some abstraction such as a stream (I come from C++). In C++, the count() functionality would be separated as much as possible from any concrete datatype (such as a string), precisely because it is a concept that is applicable at a more abstract level. I should be able to say "count the substring occurences of this stream" or "using this iterator" or something to that effect. If I could say print file("filename", "rb").count("\x00\x00\x01\x00") (or something like that) instead of the original print file("filename", "rb").read().count("\x00\x00\x01\x00") it would be exactly what I am after. What is the conceptual difference? The first solution should be at least as fast as the second. I have to read and compare the characters anyway. I just don't need to store them in a string. In essence, I should be able to use the "count occurences" functionality on more things, such as a file, or even better, a file read through a buffer with a size specified by me. > > Here is another thought. What are you going to do with the count when you > are done? That sounds to me like a pretty pointless result: "Hi user, the > file XYZ has 27 occurrences of bitpattern \x00\x00\x01\x00. Would you like > to do another file?" > It might sound pointless to you, but it is not pointless for my purposes :) If you must know, the above one-liner actually counts the number of frames in an MPEG2 file. I want to know this number for a number of files for various reasons. I don't want it to take forever. > If you are planning to use this count to do something, perhaps there is a > more efficient way to combine the two steps into one -- especially > valuable if your files really are huge. > Of course, but I don't need to do anything else in this case. /David From savatage4ever at gmail.com Thu Oct 20 05:44:18 2005 From: savatage4ever at gmail.com (savatage4ever at gmail.com) Date: 20 Oct 2005 02:44:18 -0700 Subject: All What You Are Looking For And Mor ... Message-ID: <1129801458.568596.182860@g43g2000cwa.googlegroups.com> Hello Dear friend... Here http://s14.invisionfree.com/SaVaTaGe4eVeR/ you can find all what you are looking for in all the internet to download it like ... Applications Movies PC Games Animes Musics Mobile e-books and many many more So please come and see what we can offer for you at http://s14.invisionfree.com/SaVaTaGe4eVeR/ SaVaTaGe4eVeR forum team From simon.brunning at gmail.com Fri Oct 21 10:57:22 2005 From: simon.brunning at gmail.com (Simon Brunning) Date: Fri, 21 Oct 2005 15:57:22 +0100 Subject: Accessing a dll from Python In-Reply-To: <11lhuqar6sklqa0@corp.supernews.com> References: <1129814361.130127.255990@f14g2000cwb.googlegroups.com> <11lhuqar6sklqa0@corp.supernews.com> Message-ID: <8c7f10c60510210757g200afd65k@mail.gmail.com> On 21/10/05, Grant Edwards wrote: > Sorry, I've no clue about anything VB-related unless it's > Victoria Bitter. +1 QOTW. -- Cheers, Simon B, simon at brunningonline.net, http://www.brunningonline.net/simon/blog/ From apgwoz at gmail.com Mon Oct 3 08:23:12 2005 From: apgwoz at gmail.com (Andrew Gwozdziewycz) Date: Mon, 3 Oct 2005 08:23:12 -0400 Subject: Python based unacceptable language filter In-Reply-To: <11k13a57dtm2u0d@news.supernews.com> References: <11k13a57dtm2u0d@news.supernews.com> Message-ID: On Oct 2, 2005, at 9:45 PM, Nigel Rowe wrote: > David Pratt wrote: > > >> Hi. Is anyone aware of any python based unacceptable language filter >> code to scan and detect bad language in text from uploads etc. >> >> Many thanks. >> David >> > > You might be able to adapt languagetool. > http://www.danielnaber.de/languagetool/features.html > > Later versions have been ported to Java, but the old python version of > languagetool is at http://tkltrans.sourceforge.net/#r03 > > His thesis paper is at > http://www.danielnaber.de/languagetool/download/ > style_and_grammar_checker.pdf > > Mind you, given the poor language skills of many native english > speakers > (not to mention those for whom english is a second language) > relying on > automated filters to enforce 'good' language seems a trifle > extreme. This > post for example would probably not pass. > > Cheers, > Nigel > > PS. For the humour impaired, this g*d d*mm post was a f*cking joke, > OK! :-) > > Mind you, the links are real. > > -- > Nigel Rowe > A pox upon the spammers that make me write my address like.. > rho (snail) swiftdsl (stop) com (stop) au > -- > http://mail.python.org/mailman/listinfo/python-list > I think he may be referring to "bad" words, and 'filthy' language. At least that's what i got from the question. There are many PHP implementations on the web, which could be adapted to python fairly easily. Most of which are probably not the most ideal solution and involve alot of stuff like for n in badwords: texttofilter.replace(n, '') If that's all you need though, maybe it's not so bad. --- Andrew Gwozdziewycz apgwoz at gmail.com http://ihadagreatview.org http://plasticandroid.org From dont at spam.me Wed Oct 5 11:59:52 2005 From: dont at spam.me (Bugs) Date: Wed, 05 Oct 2005 08:59:52 -0700 Subject: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please! In-Reply-To: References: Message-ID: Another page with up to date IronPython information: http://www.gotdotnet.com/workspaces/workspace.aspx?id=ad7acff7-ab1e-4bcb-99c0-57ac5a3a9742 Cameron Laird wrote: > In article , spiffo wrote: > . > . > . > >>I am a corporate developer, working for a single company. Got a new project >>coming up and wondering if I should stay with Python for this new, fairly >>large project, are jump back on the 'safe' M$ bandwagon using a dot net >>language? Cross platform is NOT an issue, but COMPLETE control/compatability > > . > . > . > While I know others in this thread have already mentioned the > fact somewhat obliquely, I'll make it explicit: Python IS "a > dot net language" . From *firstname*nlsnews at georgea*lastname*.com Mon Oct 3 18:03:28 2005 From: *firstname*nlsnews at georgea*lastname*.com (Tony Nelson) Date: Mon, 03 Oct 2005 22:03:28 GMT Subject: Exception raising, and performance implications. References: <1128375280.034852.119910@o13g2000cwo.googlegroups.com> Message-ID: <*firstname*nlsnews-B3B8C2.18033703102005@news.verizon.net> In article <1128375280.034852.119910 at o13g2000cwo.googlegroups.com>, "leo" wrote: > Hello all - > > I was wondering about the performance implications of explicitly > raising exceptions to get information about the current frame. > Something like what the inspect module does, with: Python uses exceptions internally, using StopIteration to terminate the iterator in a for: loop. > --- > def currentframe(): > """Return the frame object for the caller's stack frame.""" > try: > raise 'catch me' > except: > return sys.exc_traceback.tb_frame.f_back > --- This also does a traceback; you might want to measure the cost of that. > I come from a java background, where Exceptions are a big Avoid Me, but > are the performance implications the same in Python? We're expecting a > big load on our app (100,000 users/hour) , so we'd like to be as tuned > as possible. Switching to Python, eh? Remember to measure, measure, measure! ________________________________________________________________________ TonyN.:' *firstname*nlsnews at georgea*lastname*.com ' From jepler at unpythonic.net Wed Oct 5 14:05:18 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Wed, 5 Oct 2005 13:05:18 -0500 Subject: updating local() In-Reply-To: <1128530014.323801.290360@g47g2000cwa.googlegroups.com> References: <1128530014.323801.290360@g47g2000cwa.googlegroups.com> Message-ID: <20051005180518.GG13147@unpythonic.net> I'm surprised you found any example of 'locals().update' that worked. Here's one that doesn't work: def f(y): locals().update({'x': y}) return x print f(3) # prints 3? Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From steve at REMOVETHIScyber.com.au Sun Oct 9 07:01:56 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 09 Oct 2005 21:01:56 +1000 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> Message-ID: On Sat, 08 Oct 2005 23:39:27 +0000, John Bokma wrote: > Rich Teer wrote: > >> On Sat, 8 Oct 2005, Roedy Green wrote: >> >>> Some people use email PRIMARILY for sharing photos. >> >> WHat the hell has that got to do with HTML email? > > The photo doesn't have to be included (as in attached)? with the email? I'll repeat the question: what do attachments have to do with HTML emails? -- Steven. From grig.gheorghiu at gmail.com Mon Oct 10 16:18:29 2005 From: grig.gheorghiu at gmail.com (Grig Gheorghiu) Date: 10 Oct 2005 13:18:29 -0700 Subject: rrdtool? In-Reply-To: References: Message-ID: <1128975509.418396.232840@g14g2000cwa.googlegroups.com> By sheer coincidence I was looking into the same thing today. I just downloaded the latest rrdtool release (rrdtool-1.2.11) and I noticed a /bindings/python subdirectory. I haven't played with it yet, as I still need to install tons of prerequisites before I can build rrdtool. Grig From christian.siegl at gmail.com Mon Oct 17 12:45:18 2005 From: christian.siegl at gmail.com (christian.siegl at gmail.com) Date: 17 Oct 2005 09:45:18 -0700 Subject: How to delete yourself???? In-Reply-To: <1129309450.534478.179670@o13g2000cwo.googlegroups.com> References: <1129299904.130287.287680@g44g2000cwa.googlegroups.com> <1129301105.048023.36430@f14g2000cwb.googlegroups.com> <1129301853.032055.54010@g43g2000cwa.googlegroups.com> <1129309450.534478.179670@o13g2000cwo.googlegroups.com> Message-ID: <1129567518.494824.234040@g44g2000cwa.googlegroups.com> Well, this might be the best way, but my special case is programming a GUI. And a (child) window receives a close event and wants to destroy itself. The main window (parent) will never notice that (or its lots of code and not very nice....). So that is the case and there is no way that the parent deletes the child. By the way, I am aware of the fact that I'm just deleting a reference. But on deleting the last reference (and that's what I wanna do here) the object will be destroyed........ chris From steve at REMOVETHIScyber.com.au Tue Oct 25 08:06:58 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Tue, 25 Oct 2005 22:06:58 +1000 Subject: more than 100 capturing groups in a regex References: <1130160675.270886.208420@z14g2000cwz.googlegroups.com> <1130225565.592108.197670@z14g2000cwz.googlegroups.com> <1130237717.557334.277910@g44g2000cwa.googlegroups.com> Message-ID: On Tue, 25 Oct 2005 03:55:17 -0700, Joerg Schuster wrote: > No limitation at all would be best. If a limitation is necessary, then > the more capturing groups, the better. At the time being, I would be > really happy about having the possibility to use 10000 capturing > groups. Do you really think that the regular expression needed to do that would be maintainable? I'm also curious, what sort of usage case would need ten thousand capturing groups? I'd love to see the performance, especially if all ten thousand of them do backtracking. -- Steven. From iainking at gmail.com Wed Oct 26 04:15:53 2005 From: iainking at gmail.com (Iain King) Date: 26 Oct 2005 01:15:53 -0700 Subject: more than 100 capturing groups in a regex In-Reply-To: References: <1130160675.270886.208420@z14g2000cwz.googlegroups.com> <1130253162.790086.59130@o13g2000cwo.googlegroups.com> Message-ID: <1130314553.112864.233480@g43g2000cwa.googlegroups.com> Fredrik Lundh wrote: > Iain King wrote: > > > Anyway, back to the OP: in this specific case, the cap of 100 groups in > > a RE seems random to me, so I think the rule applies. > > perhaps in the "indistinguishable from magic" sense. > > if you want to know why 100 is a reasonable and non-random choice, I > suggest checking the RE documentation for "99 groups" and the special > meaning of group 0. > > Ah, doh! Of course. Oh well then... still, doesn't python's RE engine support named groups? That would be cumbersome, but would allow you to go above 100... From usenet at DavidFilmer.com Wed Oct 26 03:45:52 2005 From: usenet at DavidFilmer.com (usenet at DavidFilmer.com) Date: 26 Oct 2005 00:45:52 -0700 Subject: a Haskell a Day In-Reply-To: <1130312303.713737.160830@g44g2000cwa.googlegroups.com> References: <1130312303.713737.160830@g44g2000cwa.googlegroups.com> Message-ID: <1130312752.238762.30360@g14g2000cwa.googlegroups.com> Xah Lee wrote: > I hope you will join me in learning Haskell. I think the folks here are more interested in Perl. There's a reason why this newsgroup is called lc("comp.lang.PERL.misc"). From leszczynscyATnospam.yahoo.com.nospam Thu Oct 13 01:25:54 2005 From: leszczynscyATnospam.yahoo.com.nospam (Andy Leszczynski) Date: Thu, 13 Oct 2005 00:25:54 -0500 Subject: TurboGears /.-ed, >new == True< or >new == "True"< In-Reply-To: References: Message-ID: Sybren Stuvel wrote: > Andy Leszczynski enlightened us with: > >>should not it be: >> >>2 def save(self, pagename, data, submit, new): >>3 hub.begin() >>4 if new == True: >>5 page = Page(pagename=pagename, data=data) >>6 else: >>7 page = Page.byPagename(pagename) >>8 page.data = data >> >>instead of: >> >>4 if new == "True": > > > No it should not. The values passed to the function are the strings > passed by the GET request, hence all strings. There are methods of > dealing with this - read the rest of the documentation. > > Sybren So how does it correspond to other piece of the code: 2 def notfound(self, pagename): 3 return dict(pagename=pagename, data="", new=True) new is a boolean here? A. From apardon at forel.vub.ac.be Fri Oct 28 04:44:17 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 28 Oct 2005 08:44:17 GMT Subject: Would there be support for a more general cmp/__cmp__ References: Message-ID: Op 2005-10-26, Ron Adam schreef : > > Adding complexity to cmp may not break code, but it could probably slow > down sorting in general. So I would think what ever improvements or > alternatives needs to be careful not to slow down existing sorting cases. As a result of Bengt's post, I rewrote my test program, this is the program now. from random import shuffle from time import time class UnequalValues(Exception): pass __metaclass__ = type class cla: def __init__(self, i): self.value = int(i) def __cmp__(self, other): return self.value - other.value class clb: def __init__(self, i): self.value = int(i) def __lt__(self, other): return self.value < other.value class clc: def __init__(self, i): self.value = int(i) def __gt__(self, other): return self.value > other.value class cld: def __init__(self, i): self.value = int(i) def __comp__(self, other): return self.value - other.value def __lt__(self, other): return self.__comp__(other) < 0 class cle: def __init__(self, i): self.value = int(i) def __comp__(self, other): return self.value - other.value def __lt__(self, other): try: return self.__comp__(other) < 0 except UnequalValues: return False def test(lng, rep): for cl in cla, clb, clc, cld, cle: total = 0.0 for _ in xrange(rep): lst = [cl(i) for i in xrange(lng)] shuffle(lst) start = time() lst.sort() stop = time() total += stop - start for i in xrange(1,rep): assert lst[i - 1] < lst[i] print "%s: %d repeats, %d long, %9.6f secs" % (cl, rep, lng, total) test(1000,1000) --- These are the results. : 1000 repeats, 1000 long, 10.061425 secs : 1000 repeats, 1000 long, 9.544035 secs : 1000 repeats, 1000 long, 10.450864 secs : 1000 repeats, 1000 long, 15.566061 secs : 1000 repeats, 1000 long, 15.776443 secs Results on a longer sequence were: : 1000 repeats, 10000 long, 146.722443 secs : 1000 repeats, 10000 long, 139.480863 secs : 1000 repeats, 10000 long, 152.623424 secs : 1000 repeats, 10000 long, 224.630926 secs : 1000 repeats, 10000 long, 228.663825 secs The most interesting result of this test is the difference between cld and cle. IMO this difference is an indication of the cost that my idea would have on sorting, should it be implemented. That would be around 2%. I think that is bearable. Especially since this were very simple routines. The moment the comparison calculation become heavier, the relative contribution of the try: except will diminuish. If you are concerned about sorting times, I think you should be more concerned about Guido's idea of doing away with __cmp__. Sure __lt__ is faster. But in a number of cases writing __cmp__ is of the same complexity as writing __lt__. So if you then need a __lt__, __le__, __eq__, __ne__, __gt__ and __ge__ it would be a lot easier to write a __cmp__ and have all rich comparisons methods call this instead of duplicating the code about six times. So you would be more or less forced to write your class as class cld or cle. This would have a bigger impact on sorting times than my suggestion. -- Antoon Pardon From postmaster at ristretto4u.f9.co.uk Mon Oct 10 07:36:12 2005 From: postmaster at ristretto4u.f9.co.uk (David Welch) Date: Mon, 10 Oct 2005 12:36:12 +0100 Subject: Expression templates for arithmetic operations in python Message-ID: Hi, I am new to python so I thought I would write a quick and simple vector/matrix multiplication class in c++ and use it in python. Is it possible to overload the operators in python such a way that a tree of calculations is built which I can then pass to an evaluator written in c++ to calculate the tree with max efficiency. My thought train is that the args are passed to c++ only once and so there is less overhead in unpacking them. Is there are an existing implementation in python which does this? What is the best way to implement this? Thanks for your help. David From jepler at unpythonic.net Thu Oct 20 08:18:57 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Thu, 20 Oct 2005 07:18:57 -0500 Subject: Set an environment variable In-Reply-To: <43573022$0$155$edfadb0f@dread16.news.tele.dk> References: <43573022$0$155$edfadb0f@dread16.news.tele.dk> Message-ID: <20051020121857.GA17409@unpythonic.net> In Unix, you generally can't affect the environment of your parent program (in a broad sense, which includes environment variables, current working directory, opened files, effective user ID, etc). You have two basic choices to achieve an effect like this. First, you can start a subshell with the desired environment, something like (untested) os.environ['VARIABLE'] = 'value' os.system(os.environ['shell']) (commands like 'su' work in this way) Second, you can produce shell commands that have the effect of changing a shell's environment when they are executed. Something like: print "VARIABLE=value" To use this, the user must write something like eval `myscript.py` instead of just myscript.py this can typically be encapsulated in a shell alias or function. (commands like 'resize' (which sets the shell's idea of a terminal's size) work this way) Finally, you might be able to use an OS-specific interface like linux' ptrace to change the actual contents of a calling process's memory. I didn't immediately find an example of this, but on Linux it would consist of using PTRACE_PEEKDATA and PTRACE_POKEDATA to locate the environment in another process and modify it. The ptrace interface is not available from any standard Python module, and isn't portable anyway. (though my manpage actually says 'CONFORMING TO SVr4, ..., X/OPEN, BSD 4.3' so maybe ptrace is more portable than I believed) Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From db3l at fitlinxx.com Wed Oct 5 17:51:06 2005 From: db3l at fitlinxx.com (David Bolen) Date: 05 Oct 2005 17:51:06 -0400 Subject: Replacing utf-8 characters References: <1128522921.72009@nntp.acecape.com> <1128538344.802444@nntp.acecape.com> <1128541211.632803@nntp.acecape.com> Message-ID: Mike writes: > What you and I typed was ascii. The value of link came from importing > that utf-8 web page into that variable. That is why I think it is not > working. But not sure what the solution is. Are you sure you're asking what you think you are asking? Both the ampersand character (&) and the characters within the ampersand entity character reference (&) are ASCII. As it turns out they are also legal UTF-8, but I would not call a web page UTF-8 just because I saw the sequence of characters "&" within the stream. (That's not to say it isn't UTF-8 encoded, just that I don't think that's the issue) I'm just guessing, but you do realize that legal HTML should quote all uses of the ampersand character with an entity reference, since the ampersand itself is reserved for use in such references. This includes URL references whether inside attributes or in the body of the text. So when you see something in a browser in a web page that shows a URL that includes "&" such as for separating parameters, internally that page is (or should be) stored with "&" for that character. Thus if you retrieve the page in code, that's what you'll find. It's the browser processing that entity reference that turns it back into the "&" for presentation. Note that whether or not the page in question is encoded as UTF-8 is a completely distinct question - whatever encoding the page is in would be used to encode the characters in the entity reference (namely "&"). I'm assuming that in scraping the page you want to reverse the process (e.g., perform the interpretation of the entity references much as a browser would) before using that URL for other purposes. If so, the string replacement you tried should handle the replacement just fine, at least within the value of the URL as managed by your code. You then mention it being the same when you view the contents of the link, which isn't quite clear to me, but if that means retrieving another copy of the link as embedded in an HTML page then yes, it'll get quoted again since as initially, you have to quote an ampersand as an entity reference within HTML. What did you mean by "view the contents link"? -- David From gandalf at designaproduct.biz Wed Oct 12 09:39:29 2005 From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy) Date: Wed, 12 Oct 2005 15:39:29 +0200 Subject: Very dumb question Message-ID: <434D1211.6010903@designaproduct.biz> I have a program with this code fragment: print len(data) print data[:50] raise SystemExit This prints: 20381 References: <1d987df30510240602j4916a088s63f4fe34857943d1@mail.gmail.com> Message-ID: Shi Mu wrote: > Is there any difference if I remove the '/' \ > from the following statement? > intMatrix2 = [[1,1,2,4,1,7,1,7,6,9],\ > [1,2,5,3,9,1,1,1,9,1],\ > [0,0,5,1,1,1,9,7,7,7]] > print intMatrix2 > I removed one '\' and it still works. > So what is the use of '\'? You only need line continuations if you aren't inside brackets, braces or parentheses. Inside these paired delimiters Python assumes you know what you are doing and will continue the statement or expression on the next line. >>> print "This is a continued"\ ... " statement" This is a continued statement >>> Note that Python *knew* the statement was complete at the end of the second line. Inside an extended string literal (""" or ''') it has the effect of removing the newline that would otherwise appear in the string. >>> print repr("""This string has a ... newline in it""") 'This string has a\nnewline in it' >>> print repr("""There is no \ ... newline in this string""") 'There is no newline in this string' >>> regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From maksim.kasimov at gmail.com Thu Oct 27 07:10:18 2005 From: maksim.kasimov at gmail.com (Maksim Kasimov) Date: Thu, 27 Oct 2005 14:10:18 +0300 Subject: select.select() on windows In-Reply-To: References: <1130249197.810665.272520@g47g2000cwa.googlegroups.com> Message-ID: yes, i missed, sorry Dennis Lee Bieber wrote: > On Wed, 26 Oct 2005 11:29:17 +0300, Maksim Kasimov > declaimed the following in comp.lang.python: > > >>you have to use non-block readining. >> >>http://docs.python.org/lib/module-select.html: >>A time-out value of zero specifies a poll and never blocks. >> > > Did you miss the subject line... "... on windows"? select() only > works with sockets on windows, not on regular file streams. -- Best regards, Maksim Kasimov mailto: maksim.kasimov at gmail.com From http Tue Oct 4 14:47:17 2005 From: http (Paul Rubin) Date: 04 Oct 2005 11:47:17 -0700 Subject: cgi relay for python cgi script References: <1128411305.541560.90790@g44g2000cwa.googlegroups.com> Message-ID: <7xpsql9l1m.fsf@ruckus.brouhaha.com> "Amir Michail" writes: > Is there an easy way to execute a python cgi script on a different > machine from the cgi server? What exactly do you mean by that? You can set a form target to another machine, if that's what you mean. From lbolognini at gmail.com Fri Oct 28 18:49:12 2005 From: lbolognini at gmail.com (lbolognini at gmail.com) Date: 28 Oct 2005 15:49:12 -0700 Subject: Automatic binding of **kwargs to variables Message-ID: <1130539752.667045.183460@g14g2000cwa.googlegroups.com> Hi all, I have a very long list of parameters coming from a web form to my method foo(self, **kwargs) I would like to avoid manually binding the variables to the values coming through the **kwargs dictionary, just to keep the code cleaner, I'd like to bind them automatically I was adviced against doing it by adding stuff to locals such as: locals()["x"] = 5 since the Python Docs say: Warning: The contents of this dictionary should not be modified; changes may not affect the values of local variables used by the interpreter. Is there a way to do this? Maybe object.__setattr__() or something that involves metaclasses? As I might go touching something that I shouldn't (like locals()) I'd like some advice from you before deciding which way to go. Thanks, Lorenzo From gerrit at nl.linux.org Sat Oct 1 04:02:16 2005 From: gerrit at nl.linux.org (Gerrit Holl) Date: Sat, 1 Oct 2005 10:02:16 +0200 Subject: A Moronicity of Guido van Rossum In-Reply-To: <6CF2AADA-3E79-4535-B61A-9FE06AC1B6E1@ihug.co.nz> References: <2773CAC687FD5F4689F526998C7E4E5F4DB681@au3010avexu1.global.avaya.com> <77498FFE-AEC3-4148-A113-E434EE4A4E52@ihug.co.nz> <200509292042.36051.jstroud@mbi.ucla.edu> <43D1E0B3-6A3B-442E-9BDE-6DBC1A2466A7@ihug.co.nz> <20050930105646.GA17540@topjaklont.student.utwente.nl> <6CF2AADA-3E79-4535-B61A-9FE06AC1B6E1@ihug.co.nz> Message-ID: <20051001080216.GA2379@topjaklont.student.utwente.nl> Tony Meyer wrote: > X-Spambayes-Classification: ham; 0.008 > > On 30/09/2005, at 10:56 PM, Gerrit Holl wrote: > > Tony Meyer wrote: > >> X-Spambayes-Classification: ham; 0.048 > > Unless I'm misreading things, that's *my* message that scored 0.048 > (the "from:addr:ihug.co.nz", "from:name:tony meyer", and "spambayes" > tokens make it seem that way)... It is, and that's very surprising, but apparantly it was not really hammy enough. But don't worry, by ham_cutoff is 0.2, and out of the 10 'unsure' messages per week, 2 are spam, 2 are ham, and 6 are, well, unsure. Note that with all my mailinglists, the number of messages handled is more than 2500 per week, so I'm very, very happy with spambayes... Gerrit. -- Temperature in Lule?, Norrbotten, Sweden: | Current temperature 05-10-01 09:49:52 9.7 degrees Celsius ( 49.5F) | -- Det finns inte d?ligt v?der, bara d?liga kl?der. From fredrik at pythonware.com Sat Oct 22 09:24:40 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 22 Oct 2005 15:24:40 +0200 Subject: Help with language, dev tool selection References: <1129915422.693950.97000@g43g2000cwa.googlegroups.com> Message-ID: vasilijepetkovic at yahoo.com wrote: > I have a flat text file, 30000 records, each record has two columns, > the columns are tab separated. > > The file looks like this (approximately) > > Sarajevo 431104-133111 (when did they move sarajevo to italy?) > Mostar 441242-133421 > Zagreb 432322-134423 here's a straightforward Python solution: HEADER = "This page displays longitude-latitude information" SUBHEADER = "Grad" for line in open("datafile.txt"): town, latlong = line.split() lat, long = latlong.split("-") f = open(town + ".html", "w") f.write(HEADER + "\n") f.write(SUBHEADER + "\n") f.write(town + "\n") f.write(long + " " + lat + "\n") f.close() # end tweak as necessary. see the Python tutorial for help: http://docs.python.org/tut/tut.html From rrr at ronadam.com Sat Oct 22 23:59:10 2005 From: rrr at ronadam.com (Ron Adam) Date: Sun, 23 Oct 2005 03:59:10 GMT Subject: best way to replace first word in string? In-Reply-To: References: <1129822003.246170.303920@f14g2000cwb.googlegroups.com> Message-ID: Steven D'Aprano wrote: > On Sat, 22 Oct 2005 21:41:58 +0000, Ron Adam wrote: > > >>Don't forget a string can be sliced. In this case testing before you >>leap is a win. ;-) > > > Not much of a win: only a factor of two, and unlikely to hold in all > cases. Imagine trying it on *really long* strings with the first space > close to the far end: the split-and-join algorithm has to walk the string > once, while your test-then-index algorithm has to walk it twice. > > So for a mere factor of two benefit on short strings, I'd vote for the > less complex split-and-join version, although it is just a matter of > personal preference. > Guess again... Is this the results below what you were expecting? Notice the join adds a space to the end if the source string is a single word. But I allowed for that by adding one in the same case for the index method. The big win I was talking about was when no spaces are in the string. The index can then just return the replacement. These are relative percentages of time to each other. Smaller is better. Type 1 = no spaces Type 2 = space at 10% of length Type 3 = space at 90% of length Type: Length Type 1: 10 split/join: 317.38% index: 31.51% Type 2: 10 split/join: 212.02% index: 47.17% Type 3: 10 split/join: 186.33% index: 53.67% Type 1: 100 split/join: 581.75% index: 17.19% Type 2: 100 split/join: 306.25% index: 32.65% Type 3: 100 split/join: 238.81% index: 41.87% Type 1: 1000 split/join: 1909.40% index: 5.24% Type 2: 1000 split/join: 892.02% index: 11.21% Type 3: 1000 split/join: 515.44% index: 19.40% Type 1: 10000 split/join: 3390.22% index: 2.95% Type 2: 10000 split/join: 2263.21% index: 4.42% Type 3: 10000 split/join: 650.30% index: 15.38% Type 1: 100000 split/join: 3342.08% index: 2.99% Type 2: 100000 split/join: 1175.51% index: 8.51% Type 3: 100000 split/join: 677.77% index: 14.75% Type 1: 1000000 split/join: 3159.27% index: 3.17% Type 2: 1000000 split/join: 867.39% index: 11.53% Type 3: 1000000 split/join: 679.47% index: 14.72% import time def test(func, source): t = time.clock() n = 6000000/len(source) s = '' for i in xrange(n): s = func(source, "replace") tt = time.clock()-t return s, tt def replace_word1(source, newword): """Replace the first word of source with newword.""" return newword + " " + " ".join(source.split(None, 1)[1:]) def replace_word2(source, newword): """Replace the first word of source with newword.""" if ' ' in source: return newword + source[source.index(' '):] return newword + ' ' # space needed to match join results def makestrings(n): s1 = 'abcdefghij' * (n//10) i, j = n//10, n-n//10 s2 = s1[:i] + ' ' + s1[i:] + 'd.' # space near front s3 = s1[:j] + ' ' + s1[j:] + 'd.' # space near end return [s1,s2,s3] for n in [10,100,1000,10000,100000,1000000]: for sn,s in enumerate(makestrings(n)): r1, t1 = test(replace_word1, s) r2, t2 = test(replace_word2, s) assert r1 == r2 print "Type %i: %-8i split/join: %.2f%% index: %.2f%%" \ % (sn+1, n, t1/t2*100.0, t2/t1*100.0) From davids at webmaster.com Sat Oct 22 19:10:24 2005 From: davids at webmaster.com (David Schwartz) Date: Sat, 22 Oct 2005 16:10:24 -0700 Subject: Microsoft Hatred FAQ References: <86ll0vs1sw.fsf@bhuda.mired.org> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> Message-ID: "Roedy Green" wrote in message news:70njl1t0gu91o2redeptktvsjp8lprao02 at 4ax.com... > On Fri, 21 Oct 2005 21:47:27 -0700, "David Schwartz" > wrote or quoted : >> There is no way Microsoft could have expected the >>market to be defined in this way and no way to argue that Microsoft had >>any >>reason to believe their conduct was illegal. > If what they did to me in the 90s was not illegal it damn well should > have been. If the deal didn't give you more than it cost you, all you had to do was say 'no'. I understand the frustration at being forced to pay for something what it is worth. DS From larry.bates at websafe.com Wed Oct 5 16:53:14 2005 From: larry.bates at websafe.com (Larry Bates) Date: Wed, 05 Oct 2005 15:53:14 -0500 Subject: Using command line args on Windows In-Reply-To: <1128544715.139551.15960@g43g2000cwa.googlegroups.com> References: <1128544715.139551.15960@g43g2000cwa.googlegroups.com> Message-ID: <43443D3A.4040704@websafe.com> 1) Start a command prompt window (Start-Programs-Accessories-Command Prompt) 2) Change to directory where the python program is stored (cd \) 3) Type python myscript.py myarg -Larry Bates k8 wrote: > Hello- > > I'm stuck on a Windows machine today and would love to fully play with > and test a simple python script. I want to be able to type "python > myscript myarg" somewhere. Is there anything out there to help me? My > main concern is playing with the myarg in the sys.argv list. I've been > mucking around with IDLE without much success. > From *firstname*nlsnews at georgea*lastname*.com Sun Oct 30 20:37:18 2005 From: *firstname*nlsnews at georgea*lastname*.com (Tony Nelson) Date: Mon, 31 Oct 2005 01:37:18 GMT Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <1130614532.765771.288960@g43g2000cwa.googlegroups.com> <1130637600.659212.66140@g43g2000cwa.googlegroups.com> Message-ID: <*firstname*nlsnews-6B0995.20371830102005@news.verizon.net> In article <1130637600.659212.66140 at g43g2000cwa.googlegroups.com>, netvaibhav at gmail.com wrote: > Steve Holden wrote: > > Indeed, but reading one byte at a time is about the slowest way to > > process a file, in Python or any other language, because it fails to > > amortize the overhead cost of function calls over many characters. > > > > Buffering wasn't invented because early programmers had nothing better > > to occupy their minds, remember :-) > > Buffer, and then read one byte at a time from the buffer. Have you mesured it? #!/usr/bin/python '''Time some file scanning. ''' import sys, time f = open(sys.argv[1]) t = time.time() while True: b = f.read(256*1024) if not b: break print 'initial read', time.time() - t f.close() f = open(sys.argv[1]) t = time.time() while True: b = f.read(256*1024) if not b: break print 'second read', time.time() - t f.close() if 1: f = open(sys.argv[1]) t = time.time() while True: b = f.read(256*1024) if not b: break for c in b: pass print 'third chars', time.time() - t f.close() f = open(sys.argv[1]) t = time.time() n = 0 srch = '\x00\x00\x01\x00' laplen = len(srch)-1 lap = '' while True: b = f.read(256*1024) if not b: break n += (lap+b[:laplen]).count(srch) n += b.count(srch) lap = b[-laplen:] print 'fourth scan', time.time() - t, n f.close() On my (old) system, with a 512 MB file so it won't all buffer, the second time I get: initial read 14.513395071 second read 14.8771388531 third chars 178.250257969 fourth scan 26.1602909565 1 ________________________________________________________________________ TonyN.:' *firstname*nlsnews at georgea*lastname*.com ' From samrobertsmith at gmail.com Mon Oct 24 08:30:24 2005 From: samrobertsmith at gmail.com (Shi Mu) Date: Mon, 24 Oct 2005 05:30:24 -0700 Subject: Print in PythonWin Message-ID: <1d987df30510240530nfd07d47mf3ec2831891ac9e7@mail.gmail.com> In the PythonWin's interactive window, why sometimes I need type the command two times to make it work? for example, I execute "print testList" two times to make it work. Why? >>> print testList >>> print testList ['w', 'e', ' ', 'w', 'a', 'n', 't', ' ', 't', 'o', ' ', 'l', 'e', 'a', 'r', 'n', ' ', 'p', 'y', 't', 'h', 'o', 'n'] From tim at vegeta.ath.cx Sat Oct 15 00:03:59 2005 From: tim at vegeta.ath.cx (Tim Hammerquist) Date: Sat, 15 Oct 2005 04:03:59 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> Message-ID: ["Followup-To:" header set to comp.lang.perl.misc.] Roedy Green wrote: > "Xah Lee" wrote or quoted : > > Q: Microsoft's Operating System is used over 90% of PCs. > > If that's not monopoly, i don't know what is. > > They got where they are by CHEATING. That is why they are > evil, not because they have a large market share. Mr. Lee is a troll. And an increasingly obscene one. I think his mother didn't pay him enough attention. Perhaps she locked him in the basement... and he never left? IAC, I've had enough. I don't killfile many people... but Mr. Lee seems to have gone above and beyond. His arguments are nothing but incendiary, and he doesn't even know Perl well enough to bash it as he does. *plonk* Tim From lycka at carmen.se Mon Oct 17 09:45:12 2005 From: lycka at carmen.se (Magnus Lycka) Date: Mon, 17 Oct 2005 15:45:12 +0200 Subject: Profiling results In-Reply-To: References: Message-ID: Dave wrote: > I'm trying to profile a Python program using gprof, I don't think you will learn anything meaningful about a Python program from gprof. Use the profiling tools in Python. http://docs.python.org/lib/profile.html From Casper.Dik at Sun.COM Wed Oct 12 05:21:05 2005 From: Casper.Dik at Sun.COM (Casper H.S. Dik) Date: 12 Oct 2005 09:21:05 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <86y853mzmr.fsf@bhuda.mired.org> <86mzlil269.fsf@bhuda.mired.org> Message-ID: <434cd581$0$11068$e4fe514c@news.xs4all.nl> Steven D'Aprano writes: >On Tue, 11 Oct 2005 14:27:30 +0000, axel wrote: >> I don't know how much spam other people receive but on one account I >> hardly receive any as I reserve it for friends and business. On another >> I had about 40 spam messages which took all of ten seconds to delete. >> Hardly a serious matter. >Can I remind you that spam is approximately 70% of all email traffic these >days? Most of that is blocked by the ISPs, but even so you are obviously >one of the lucky few. 95% - 99% of all email, not 70% (just ask your ISP). A large percentage of the cost of email is the cost of getting rid of SPAM; and that cannot happen without colleteral damage in the form of lost valid email, not just because of improper filtering but also because the more layers are there to touch the email the bigger the chances that it does not arrive. >My work email address, on the other hand, is another story. We run a two >layer defence: blocking blacklisted addresses at our mail server, and spam >assassin at the individual user level. Even with that, I get about 100 >spams a day delivered into my inbox, although many of those are addressed >to generic email addresses which are automatically forwarded to me. Same here: Sun probably tosses 99% of the email directed at me, yet I get well over 100 spams/day. Casper -- Expressed in this posting are my opinions. They are in no way related to opinions held by my employer, Sun Microsystems. Statements on Sun products included here are not gospel and may be fiction rather than truth. From bokr at oz.net Thu Oct 27 22:31:03 2005 From: bokr at oz.net (Bengt Richter) Date: Fri, 28 Oct 2005 02:31:03 GMT Subject: How to replace all None values with the string "Null" in a dictionary References: <1130444785.353905.85380@g47g2000cwa.googlegroups.com> <867jbyit7b.fsf@bhuda.mired.org> Message-ID: <43618c43.1143739260@news.oz.net> On Thu, 27 Oct 2005 16:46:32 -0400, Mike Meyer wrote: >"dcrespo" writes: > >> Hi all, >> >> How can I replace all None values with the string 'Null' in a >> dictionary? > >Iterate over everything in the dictionary: > >for key, item in mydict.items(): > if item is None: > mydict[key] = 'Null' > Which is probably more efficient than one-liner updating the dict with mydict.update((k,'Null') for k,v in mydict.items() if v is None) as in >>> mydict = dict(a=1, b=None, c=3, d=None, e=5) >>> mydict {'a': 1, 'c': 3, 'b': None, 'e': 5, 'd': None} >>> mydict.update((k,'Null') for k,v in mydict.items() if v is None) >>> mydict {'a': 1, 'c': 3, 'b': 'Null', 'e': 5, 'd': 'Null'} (too lazy to measure ;-) Regards, Bengt Richter From davids at webmaster.com Mon Oct 31 18:16:51 2005 From: davids at webmaster.com (David Schwartz) Date: Mon, 31 Oct 2005 15:16:51 -0800 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <7xbr1aewtq.fsf@ruckus.brouhaha.com> <86acgulv5z.fsf@localhost.localdomain> <7xvezi8ypy.fsf@ruckus.brouhaha.com> <86y84ehd3j.fsf@bhuda.mired.org> <86hdb2h750.fsf@bhuda.mired.org> <86zmoufiww.fsf@bhuda.mired.org> <86oe59e57v.fsf@bhuda.mired.org> <868xwcevke.fsf@bhuda.mired.org> <86br1530w7.fsf@bhuda.mired.org> <867jbt2xyb.fsf@bhuda.mired.org> <863bmh2t7x.fsf@bhuda.mired.org> Message-ID: "Mike Meyer" wrote in message news:863bmh2t7x.fsf at bhuda.mired.org... > "David Schwartz" writes: >>> I'm trying to find out why you regularly ignore that difference for >>> everyone but MS. >> To substantiate that claim, you'd have to point to some cases where I >> talk about something other than MS. > You do that *every time* someone compares MS with other criminals - > you immediately refer to "criminals with guns" and refuse to discuss > the issue further. And yes, you've already claimed that you only do > that when the other reference is to "actual use of force", and I've > already disproved that. You have not disproved that. The closest you've come to a disproof is one case where the word "theft" was used (while earlier in the thread, actual physical force had been used, but not in that specific spot) where the context strongly suggested that it meant theft by force. You are correct that it is possible to steal something without actually using physical force. But that's not an important difference. The hugely important difference, and the one that you and others *are* seeking to obliterate, is the difference between inherently unjust actions such as force and fraud and actions that are neither forceful nor fraudulent. >> But if you do a little research, you'll find I'm completely >> consistent and have said similar things about numerour other >> entities. > Not in this thread, you haven't. Well duh, this thread is about Microsoft. > The only consistency here has been > trying to treat MS's crimes as somehow different from other peoples > crimes. That's because the only crimes that have come up in this thread are Microsoft's crimes (that don't involve force or fraud) and other crimes (such as theft, threats of force, and the like) which do. Duh. > I'm still waiting for you to quit trying to lie (or, as you > would say, "argue") your way out of it, and come up with a reason for > this behavior other than doing so at MS's orders. The reason is that there is a huge difference between crimes that involve force or fraud and crimes that don't involve any force or fraud. Theft, threats of force, and the like are in a totally different category from purely consensual crimes such as the ones Microsoft was accused of. There were a few narrow cases where Microsoft was actually accused of actions that I do consider force or fraud. And had Microsoft been convicted for *those* actions (rather than metaphorical use of "market force"), then I would not be defending them. I don't defend them of those charges, which would have been (and is) equally wrong for a monopolist or a non-monopolist. DS From grante at visi.com Wed Oct 26 10:55:19 2005 From: grante at visi.com (Grant Edwards) Date: Wed, 26 Oct 2005 14:55:19 -0000 Subject: Top-quoting defined [was: namespace dictionaries ok?] References: Message-ID: <11lv66njrkkln8b@corp.supernews.com> On 2005-10-26, Duncan Booth wrote: > James Stroud wrote: >> On Tuesday 25 October 2005 00:31, Duncan Booth wrote: >>> P.S. James, *please* could you avoid top-quoting >> >> Were it not for Steve Holden's providing me with a link off the list, >> I would have never known to what it is you are referring. I have read >> some relevant literature to find that this is more widely known as >> "top-posting". I'll go with majority rules here, but I would like to >> say that my lack of "netiquette" in this matter comes from >> practicality and not malice. > > No, I didn't think it was malice which is why I just added what I > considered to be a polite request at the end of my message. I assumed that > most people either knew the phrase or could find out in a few seconds using > Google so there wasn't much point in rehashing the arguments. Probably I > should have equally lambasted Ron for the heinous crime of bottom-quoting. > > In general, there are three ways to quote a message: top-quoting, which > forces people to read the message out of order; Uh, no. Isn't what we're doing here top-quoting? The quoted stuff is at the top. Everything is in chronological order. I think what you're referring to is "top-posting". -- Grant Edwards grante Yow! ... If I had heart at failure right now, visi.com I couldn't be a more fortunate man!! From scott.daniels at acm.org Mon Oct 10 12:23:39 2005 From: scott.daniels at acm.org (Scott David Daniels) Date: Mon, 10 Oct 2005 09:23:39 -0700 Subject: Python reliability In-Reply-To: References: Message-ID: <434a9531$1@nntp0.pdx.net> You might try a "take over" mode -- starting another copy gets to the point it looks to listen for UDP, the (if the listening fails), tells the other process to die over UDP, taking over then. This scheme would would reduce your "time-to-switch" to a much shorter window. Whenever given the shutdown signal, you could turn on the "watcher sleeping" light. The remaining issue, replacing hardware or OS (possibly due to failure) probably changes the UDP address. That might be trickier. I certainly feel happier when I can do a hand-off to another box, but it sounds like you might need the instruments to broadcast or multicast to get to that happy place. --Scott David Daniels scott.daniels at acm.org From spe.stani.be at gmail.com Fri Oct 28 22:28:21 2005 From: spe.stani.be at gmail.com (SPE - Stani's Python Editor) Date: 28 Oct 2005 19:28:21 -0700 Subject: Print to printer References: <1130528702.908172.189990@g47g2000cwa.googlegroups.com> Message-ID: <1130552901.655182.203330@g44g2000cwa.googlegroups.com> You should be more specific. What do you want to print? Text, images, ... If you want a cross platform solution you could use wxPython: http://wiki.wxwidgets.org/docbrowse.cgi/wxwin_printingoverview.html#printingoverview For text you could use wxHtmlEasyPrinting: http://wiki.wxpython.org/index.cgi/Printing For mac solutions, you better post this on the pythonmac mailing list. Stani -- http://pythonide.stani.be http://pythonide.stani.be/manual/html/manual.html From nicopernetty at nowhere.fr Fri Oct 7 16:55:40 2005 From: nicopernetty at nowhere.fr (Nicolas Pernetty) Date: Fri, 7 Oct 2005 22:55:40 +0200 Subject: Continuous system simulation in Python References: <20051007011222.1aeab426@linuxcestcomplique.fr> <1128643441.765008.264750@g14g2000cwa.googlegroups.com> Message-ID: <20051007225540.7fadb903@linuxcestcomplique.fr> Thanks, but what is really difficult is not to understand how to design the program which solve a specific problem but to design a generic framework for solving all these kinds of problem. And in a simple enough way for basic programmers (but good scientists !) to handle it. *********** REPLY SEPARATOR *********** On 6 Oct 2005 17:04:01 -0700, "hrh1818" wrote : > A good starting point is the book "Python Scripting for Computational > Science" by Hans Petter Langtangen. The book covers topics that go > from simulating second order mechanical systems to solving partial > differentail equations. > > Howard > > Nicolas Pernetty wrote: > > Hello, > > > > I'm looking for any work/paper/ressource about continuous system > > simulation using Python or any similar object oriented languages (or > > even UML theory !). > > > > I'm aware of SimPy for discrete event simulation, but I haven't > > found any work about continuous system. > > I would like to develop a generic continous system simulator, and so > > would be eager to join any open source effort on the subject. > > > > For instance, it would be useful for modelling an airplane with all > > the dynamics (flight simulator). > > > > Python is my language of choice because of the keyword 'generic'. > > Being an object oriented dynamic language, it's perfect for such a > > task. Unfortunately I'm a novice when it comes to object oriented > > design and development, so I would prefer to start from something > > already existent instead of starting from scratch. > > > > If you had any idea on the subject, I would be really glad to > > discuss it with you. > > > > Thanks in advance, > > > > P.S. : for email, replace nowhere by yahoo > From jelleferinga at gmail.com Fri Oct 21 04:46:10 2005 From: jelleferinga at gmail.com (jelle) Date: 21 Oct 2005 01:46:10 -0700 Subject: Should i pick up Numeric, Numarray or SciPy.core? Message-ID: <1129884370.881194.20420@g47g2000cwa.googlegroups.com> #No rant intended I'm not at all confused wether I should learn an one of the advanced array modules, I'm slightly confused over which I should pick up. I'm impressed with the efforts of SciPy and Scientific, but since I'm fairly new to programming & OO, choosing Numarray over Numeric hasnt been that satisfactory at all, which is not a problem of the quality of Numarray, but the fact that a lot of modules still heavily realy on Numeric. Which, with my fragile knowledge in programming is rather confusing sometimes. Since its seems its far from pragmatic to opt solely for either one of them. So Scipy.core looks like the ticket for me here, doesnt it? Before putting an effort into it, I'd like to know whether this would make sense, certainly since scipy.core is in its early stages, and documentation isnt available yet (for free that is... its not clear to me why I should pay for software in its early stages, when it extents on efforts freely available) Curious for your opinions, I definitely think the Scipy.core effort is terrific, but right now I'm wondering whether its a pragmatic choice. -Jelle From iddw at hotmail.com Thu Oct 13 17:02:19 2005 From: iddw at hotmail.com (Dave Hansen) Date: Thu, 13 Oct 2005 21:02:19 GMT Subject: [Info] PEP 308 accepted - new conditional expressions References: <3q4ro9Fd770nU3@individual.net> <3q6oo1Fddg7eU3@individual.net> <7xr7b5zq31.fsf@ruckus.brouhaha.com> <1129129852.92dc41cf1bd445c448e00bd42ec59500@teranews> Message-ID: <1129237343.f9f0866203b462304281d6e31bb39067@teranews> On Thu, 13 Oct 2005 21:49:15 +0200, Piet van Oostrum wrote: >>>>>> iddw at hotmail.com (Dave Hansen) (DH) wrote: > >>DH> So lose the "if." > >>DH> R = C then A else B > >>DH> I don't think python uses the question mark for anything. Throw that >>DH> in, if it makes parsing easier: > >>DH> R = C ? then A else B > >We have already had this discussion several times. I don't think it is >going to add anything new to it. Besides after the BDFL has decided it is >useless. Oh, agreed, most assuredly (except that "we" didn't include "me," not that that would have made any difference, but I missed most of the discussion). I was merely responding to your assertion that using "if C then A else B" could cause parsing problems. I'm not convinced python even needs a ternary operator. I just wish the syntax chosen by the BDFL made more sense. Even if I don't use it, I'll likely have to read it... Regards, -=Dave -- Change is inevitable, progress is not. From felix at keyremovethisghost.com Wed Oct 19 22:43:58 2005 From: felix at keyremovethisghost.com (Felix Collins) Date: Thu, 20 Oct 2005 15:43:58 +1300 Subject: Trouble with win32com and MS Project Message-ID: Hi, I'm trying to assign a resource to a task in MS Project by using the example from MSDN for VB... "Use the Add method to add an Assignment object to the Assignments collection. The following example adds a resource identified by the number of 212 as a new assignment for the specified task. ActiveProject.Tasks(1).Assignments.Add ResourceID:=212" My code fragment for Python... proj.Tasks(3).Assignments.Add(ResourceID=2) but this doesn't work. I get... Error (-2147352567, 'Exception occurred.', (0, None, 'The argument value is not valid.', 'D:\\Program Files\\Microsoft Office\\OFFICE11\\VBAPJ.CHM', 131074, -2146827187), None) Anyone got any ideas about how to attack this? Cheers, Felix From steve at REMOVETHIScyber.com.au Mon Oct 10 11:00:42 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Tue, 11 Oct 2005 01:00:42 +1000 Subject: Comparing lists References: <1128930699.799657.146210@g47g2000cwa.googlegroups.com> Message-ID: On Mon, 10 Oct 2005 14:34:35 +0200, Christian Stapfer wrote: > Sorting the two lists and then extracting > A-B, B-A, A|B, A & B and A ^ B in one single > pass seems to me very likely to be much faster > for large lists. Unless you are running a Python compiler in your head, chances are your intuition has no connection to the actual performance of Python except by pure coincidence. Write some code, and time it in action. In fact, here is some code I've written for you, complete with timer. Do yourself a favour, and run it and see for yourself which is faster. Then, if you think you can write a list version that is more efficient than my (admittedly very inefficient) version, please do so. Then time the difference again. Then think about how much time it took you to write, test and debug your list version, compared to my four lines using sets. from sets import Set import time def compare_and_separate(A, B): only_A = [] only_B = [] both_AB = [] for item in A: # ignore items we've already seen before if item in only_A or item in both_AB: continue if item in B: both_AB.append(item) else: only_A.append(item) for item in B: # ignore items we've already seen before if item in only_B or item in both_AB: continue only_B.append(item) return (only_A, only_B, both_AB) def compare_and_separate_with_sets(A, B): only_A = list(Set(A)-Set(B)) only_B = list(Set(B)-Set(A)) both_AB = list(Set(A+B) - Set(only_A+only_B)) return (only_A, only_B, both_AB) A = range(199) + range(44, 300, 3) + range(250, 500) + range(2000, 2100) B = range(1000) + range(3000, 4000) def tester(): # confirm that the two functions give the same results r1 = compare_and_separate(range(5), range(3,8)) r2 = compare_and_separate_with_sets(range(5), range(3,8)) print r1 print r2 if r1 == r2: print " Same." else: print " Warning: results are different." loopit = range(20) # repeat the test 20 times for timing purposes t1 = time.time() for i in loopit: results = compare_and_separate(A, B) t1 = time.time() - t1 t2 = time.time() for i in loopit: results = compare_and_separate_with_sets(A, B) t2 = time.time() - t2 print "Time with loops:", t1 print "Time with sets:", t2 -- Steven. From xah at xahlee.org Wed Oct 19 01:00:50 2005 From: xah at xahlee.org (Xah Lee) Date: 18 Oct 2005 22:00:50 -0700 Subject: Jargons of Info Tech industry In-Reply-To: <1129685728.880635.128930@g44g2000cwa.googlegroups.com> References: <1129685728.880635.128930@g44g2000cwa.googlegroups.com> Message-ID: <1129698050.381751.81240@o13g2000cwo.googlegroups.com> > Xah Lee, on Aug 22, 2:43 pm wrote: > Unix, RFC, and Line Truncation > http://xahlee.org/UnixResource_dir/writ/truncate_line.html Steve wrote: > I've seen this argument before. There's at least one VERY good reason > to hard-code linebreaks in text: to preserve a covert channel. It's > really easy to structure plain text in such a way to include super > sekret messages that can only be properly decoded when the original > formatting of the text is preserved. Assuming that all of us are > agreed that plain text is the correct lowest-common denominator in > email and Usenet communications, it makes sense to allow for additional > personal expression by way of enabling users to encode additional > information in the formatting of their messages. Rethink what you are saying. You'll see that what you propose as reasons for one, is actually for the other. Xah xah at xahlee.org ? http://xahlee.org/ From simon.brunning at gmail.com Tue Oct 11 10:19:52 2005 From: simon.brunning at gmail.com (Simon Brunning) Date: Tue, 11 Oct 2005 15:19:52 +0100 Subject: how to(can we ?) pass argument to .py script ? In-Reply-To: <1129039664.425406.265670@f14g2000cwb.googlegroups.com> References: <1129039664.425406.265670@f14g2000cwb.googlegroups.com> Message-ID: <8c7f10c60510110719k55e8994fr@mail.gmail.com> On 11 Oct 2005 07:07:44 -0700, quiteblack at gmail.com wrote: > i wrote a .py file and it works fine, my goal is to pass argument to > that py file when it get executed, and accept that argument within py > file, eg. i prefer a command like below: > > python test.py -t > > and then, i may get "-t" within test.py for later use. > > i have no ideas how to do and i'm really stuck, can anyone help ? Short answer: import sys print sys.argv You might also want to take to butchers at the optparse module. -- Cheers, Simon B, simon at brunningonline.net, http://www.brunningonline.net/simon/blog/ From steve at REMOVETHIScyber.com.au Fri Oct 7 07:04:20 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Fri, 07 Oct 2005 21:04:20 +1000 Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <3qi8erFf252rU1@uni-berlin.de> <3qkdbrFfgga9U1@uni-berlin.de> <3qkn7qFffkl6U1@uni-berlin.de> <3qkr1hFfgj5uU1@uni-berlin.de> <7xr7ax690j.fsf@ruckus.brouhaha.com> <1128676408.129888.297840@g14g2000cwa.googlegroups.com> Message-ID: On Fri, 07 Oct 2005 06:01:00 -0400, Roy Smith wrote: > There's more to it than just that. Python's type checking is not just not > done at compile time, it's done as late in run time as possible. One might > call it just-in-time type checking. Well there you go then. Instead of pulling our hair out that Python has no type checking ("that's a bug in the language design, woe woe woe!!!") we can just say that Python does JIT type checking, which not only is a feature, but also satisfies the Pointy Haired Bosses who demand buzzwords they can't understand. -- Steven. From mwm at mired.org Sat Oct 8 23:08:04 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 08 Oct 2005 23:08:04 -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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> <7xvf07a1ro.fsf@ruckus.brouhaha.com> Message-ID: <86ll13mlpn.fsf@bhuda.mired.org> Paul Rubin writes: > I read mail over an ssh connection to a Unix shell. I have no easy > way to read html email with a graphics browser. You don't need a grahics browser - you just need a browser. I read mail in emacs, and use emacs-w3m to view html in the mailer. Works for most things, and doesn't have the nasty side effect of letting the sender know I read it by fetching images from their web site. > I occasionally get html email that I want to read. I save it in a > file and read it with lynx, which so far works perfectly well. I > find html email to be a PITA and as someone else said, html in email > is an almost sure sign that it's a message that I want to trash > without reading it. Unfortunately, I've found that HTML email comes in two flavors: That which sets content-type to text/html in the headers, and that which sets it to some form of multipart in the headers. I used to bounce all mail of either form. Then I discovered that the AOL client - used by my relatives - could *not* be set to not send HTML email. At least it sends text/plain as well. On investigation, most legit email does sends multipart/mixed, so I only reject mail whose sole content is text/html. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From fredrik at pythonware.com Mon Oct 17 04:09:49 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 17 Oct 2005 10:09:49 +0200 Subject: graphic memory & animation References: <009d01c5d2f0$3c634590$0a01a8c0@NEWLAT> Message-ID: "Peres" wrote: > Slow means more than 20ms to erase the screen. After double buffering it > improved a lot , of course (16 ms) but I'll need a faster speed. are you measuring the time it takes to go from a populated screen to a blank screen? if so, you're probably seeing the screen refresh time (16 ms = 60 fps) rather than the time it takes to draw things. try disabling vertical sync in your display driver to see if that fixes the problem (if you do things the right way, you shouldn't have to do that: you should clear/copy and draw the new screen before you flip the buffers) From joerg.schuster at gmail.com Wed Oct 26 04:44:23 2005 From: joerg.schuster at gmail.com (Joerg Schuster) Date: 26 Oct 2005 01:44:23 -0700 Subject: more than 100 capturing groups in a regex In-Reply-To: <1130231775.770582.199690@g43g2000cwa.googlegroups.com> References: <1130160675.270886.208420@z14g2000cwz.googlegroups.com> <1130231775.770582.199690@g43g2000cwa.googlegroups.com> Message-ID: <1130316263.790812.13440@g14g2000cwa.googlegroups.com> My first test program was far too naive. Evil things do happen. Simply removing the code that restricts the number of capturing groups to 100 is not a solitution. From apardon at forel.vub.ac.be Mon Oct 3 03:15:15 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 3 Oct 2005 07:15:15 GMT Subject: Will python never intend to support private, protected and public? References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xll1gvk7w.fsf@ruckus.brouhaha.com> <1128001308.905398.321670@g44g2000cwa.googlegroups.com> <311b5ce105092908332c12164c@mail.gmail.com> Message-ID: Op 2005-09-30, Steve Holden schreef : > Antoon Pardon wrote: >> Op 2005-09-30, Steve Holden schreef : >> >>>Antoon Pardon wrote: >>> >>>>Op 2005-09-29, Bill Mill schreef : >>>> >>>> >>>>>But, if your users can't figure out that they shouldn't be changing >>>>>the variable called t._test__i without expecting side effects, what do >>>>>you think of the users of your class? >>>>> >>>>>Python is for consenting adults. >>>> >>>> >>>>No it is not. Consenting means you had the choice. Python doesn't >>>>give you the choice not to consent. Unless of course you write >>>>it as a C-extension, then you can hide all you want. >>>> >>> >>>Good grief, the ultimate choice is to use Python because you like it, or >>>not to use it because you don't. Enough with the picking every available >>>nit, please. Consent or stop complaining :-) >> >> >> This is IMO not a nit. IMO people are redefining words. We are also >> talking within a certain context. When people use this slogan, they >> don't mean that people have the choice to not use python. >> > Quite true, but people do none the less have that choice. Some days I > wish a few more would exercise it. Yes they have that choice and the problem is that if too many make that choice, python wouldn't evolve. A lot of progress python made, is because people who didn't like some aspects of it, discussed them and either implemeted a change themselves or got someone else interested enough to implement a change. -- Antoon Pardon From codecraig at gmail.com Thu Oct 13 09:47:06 2005 From: codecraig at gmail.com (Java and Swing) Date: 13 Oct 2005 06:47:06 -0700 Subject: When to free memory for C wrapper? In-Reply-To: <1129210809.038807.122340@z14g2000cwz.googlegroups.com> References: <1129210809.038807.122340@z14g2000cwz.googlegroups.com> Message-ID: <1129211226.780676.294760@g49g2000cwa.googlegroups.com> One other thing, I was reading about Py_DECREF...and I see it says "A safe approach is to always use the generic operations (functions whose name begins with "PyObject_", "PyNumber_", "PySequence_" or "PyMapping_"). These operations always increment the reference count of the object they return. This leaves the caller with the responsibility to call Py_DECREF() when they are done with the result; this soon becomes second nature." URL: http://www.python.org/doc/api/refcounts.html So does that mean before my C wrapper function exits, or returns I should Py_DECREF any PyObject's I have? For example, in my previous post in this thread..I would have to Py_DECREF(data) right? What if in my wrapper I had static PyObject *wrap_doStuff(...) { PyObject *pyResult; ... pyResult = PyString_FromString(...); return pyResult; } Is PyResult going to be de-referenced or handled automaticlly by python in some way? Or, do I need to somehow call Py_DECREF(pyResult) somewhere..if so, where/when? Thanks! Java and Swing wrote: > I have been posting lately about writing a C wrapper so Python can > access my C functions. > > In my wrapper function I have something like... > > static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { > PyObject *data; > char *result; > long *d; > > PyArg_ParseTuple(args, "O:wrap_doStuff", &data); > > d = get_long_array(data); > > result = doStuff(d); > > return PyString_FromString(result); > } > > Now, do I need to use PyMem_Free to free up the "PyObject *data"? > > Thanks. From jbo at cannedham.ee.ed.ac.uk Fri Oct 14 08:46:58 2005 From: jbo at cannedham.ee.ed.ac.uk (Jim O'D) Date: Fri, 14 Oct 2005 13:46:58 +0100 Subject: my array subset method could be improved? Message-ID: Hi all I have an array a=array([2,3,1]). I want to extract an array with all the elements of a that are less than 0. Method 1. new = array([i for i in a if i < 0]) Method 2. new = a[nonzero(a<0)] I'm using Numeric arrays but can't seem to find a function that does this. Am I missing a more obvious way to do it quickly? Thanks Jim From steve at holdenweb.com Sun Oct 30 20:36:31 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 31 Oct 2005 01:36:31 +0000 Subject: learning emacs lisp In-Reply-To: <1130698078.823822.223300@g43g2000cwa.googlegroups.com> References: <1130241817.688203.320540@g44g2000cwa.googlegroups.com> <85br1dydvn.fsf@lola.goethe.zz> <1130246810.318934.123570@g44g2000cwa.googlegroups.com> <1130267274.057695.116050@o13g2000cwo.googlegroups.com> <1130698078.823822.223300@g43g2000cwa.googlegroups.com> Message-ID: [To new readers: please ignore the rantings of this unbalanced person, who is well known for posing inappropriate and inflammatory material on news groups and mailing lists of all kinds.] Xah Lee wrote: > well, in the past couple of days i started my own: > http://xahlee.org/emacs/notes.html > > but i'm sure something like it exists. > > Btw, the elisp intro by > Robert J Chassell. At: > http://www.gnu.org/software/emacs/emacs-lisp-intro/ > is extremely well written. > (and so is the elisp reference) > > Bravo to GNU & Freesoftware Foundation once again. Thank you. > > PS Fuck unix and unix fuckheads. Fuck asshole Larry Wall. Fuck Python > documenation community and their fucking ass lying thru their teeth > ignorance fucking shit. (See: > http://xahlee.org/UnixResource_dir/writ/gubni_papri.html) > > Disclaimer: all mention of real person are opinion only. > > Xah > xah at xahlee.org > ? http://xahlee.org/ > > rgb wrote: > >>>i'm looking for something example based... for senior professional >>>programers who may want to pickup some elisp for practical macro. >> >>Unfortunately the path from any given language to Elisp varies vastly. >>For example a Prolog programmer would need far fewer tips than a Cobol >>or even a C programmer. It's unlikely you will find something >>tailored to your specific experience. >> >>I'd already written programs in well over 100 languages in the 20 >>years before learning Elisp yet I didn't find the intro terribly >>tedious until around section 13 (Counting). At that point it switches >>focus toward examples of creating functions rather than introducing >>syntax and available features. Perhaps starting at section 12 would >>suit your learning style better. >> >>As you probably realize, the language itself is just syntax and the >>hard part is learning about all the facilities at your disposal once >>you decide to write something. There are a lot of features available >>and, although daunting, I think the reference is the best resource >>for discovering them. >> >>This group has also been indispensable to me. > > -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From timb at tbitc.com Mon Oct 17 03:24:45 2005 From: timb at tbitc.com (Tim) Date: Mon, 17 Oct 2005 16:54:45 +0930 Subject: How do you draw this layout with wxpython? In-Reply-To: <1129531620.723991.53140@g14g2000cwa.googlegroups.com> References: <1129531620.723991.53140@g14g2000cwa.googlegroups.com> Message-ID: <435351b1@duster.adelaide.on.net> Young H. Rhiu wrote: > See: http://hilug.org/img/app_layout.GIF > > I'm implementing an album-like application with wxpython but I'm new to > wxPython though I know how to program with python. The problem is that > it's not easy for me to deal with drawing layout stuff with wxpython. > What layout I'm thinking of looks like the gif image above. > > The application is about saving some comments for each pictures on the > filesystem. There are two windows. The above one is a window for > loading some images and the below one is a TextCtrl for writing > comments and if img1, for instance, is clicked, the first notebook(?) > folder should be active. > > Below is the program I tried but I don't know how to attach a notebook > window under the image window. > Any help is greatly appreciated. > > Thanks in Advance, Rhiu > > My Code: > from wxPython.wx import * > > class smallAppFrame(wxFrame): > def __init__(self, parent, id, title): > wxFrame.__init__(self, parent = None, id = -1, > title = "MySmallApp", pos = wxPoint(200, 200), > size = wxSize(460, 200), style = > wxDEFAULT_FRAME_STYLE) > > self.bitmap01 = wxStaticBitmap(self, -1, > wxEmptyBitmap(100,100)) > self.bitmap02 = wxStaticBitmap(self, -1, > wxEmptyBitmap(100,100)) > self.bitmap03 = wxStaticBitmap(self, -1, > wxEmptyBitmap(100,100)) > self.bitmap04 = wxStaticBitmap(self, -1, > wxEmptyBitmap(100,100)) > > box = wxBoxSizer(wxHORIZONTAL) > > box.Add((10,10)) > box.Add(self.bitmap01, 0, wxALIGN_CENTER) > box.Add((10,10)) > box.Add(self.bitmap02, 0, wxALIGN_CENTER) > box.Add((10,10)) > box.Add(self.bitmap03, 0, wxALIGN_CENTER) > box.Add((10,10)) > box.Add(self.bitmap04, 0, wxALIGN_CENTER) > box.Add((10,10)) > > self.SetAutoLayout(True) > self.SetSizer(box) > > class MySmallApp(wxApp): > def OnInit(self): > frame = smallAppFrame(None, -1, "MySmallApp") > frame.Show(true) > self.SetTopWindow(frame) > return true > > app = MySmallApp(0) > app.MainLoop() > Hi Take a LONG look at Boa Constructor. Boa is young, imperfect, and a little emotional at times. BUT after spending a few hours with it - I think I could create your screen layout in a matter of minutes. Really is worth the steep learning curve and the frustration. timb From mwm at mired.org Wed Oct 19 23:35:16 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 19 Oct 2005 23:35:16 -0400 Subject: destroy your self???? References: <1129776816.148308.210460@g44g2000cwa.googlegroups.com> <1129778080.444432.115690@g14g2000cwa.googlegroups.com> Message-ID: <863bmwx3m3.fsf@bhuda.mired.org> "KraftDiner" writes: > Well I guess what I'm trying to achive is the invalidate the instance > of the object. > I have been using None to denote an invalide or uninitialized instance > of an object. > > There is a degenerate case in my code where a polygon has less than 3 > points and > I want to class to flag this instance of the object as invalid. > > so.. like super.self = None :) You're running headlong into the fact that Python's variables are just ways to reference objects - "names" if you will - and not objects themselves. Whe you write "foo = some_obj", all you're doing is making tha name "foo" refer to some_obj instead of to whatever it was referring to before. Neither some_obj nor the object previously known as "foo" are changed in anyway. To make a change in the object, you have to make a change in the object proper, not just a name that refers to it. Adding a flag that clients can test to see if the object is still valid would do it. Changing the operations that clients do on the object so they raise exceptions will also work, and might be considered more Pythonic. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From istvan.albert at gmail.com Tue Oct 4 14:18:33 2005 From: istvan.albert at gmail.com (Istvan Albert) Date: 4 Oct 2005 11:18:33 -0700 Subject: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please! In-Reply-To: <1128447970.707787.50050@g47g2000cwa.googlegroups.com> References: <1128428885.390019.304730@g43g2000cwa.googlegroups.com> <1128432576.708995.19060@f14g2000cwb.googlegroups.com> <1128436552.877409.296480@g47g2000cwa.googlegroups.com> <1128446202.858491.240700@o13g2000cwo.googlegroups.com> <1128447970.707787.50050@g47g2000cwa.googlegroups.com> Message-ID: <1128449913.744150.300430@f14g2000cwb.googlegroups.com> > It has many similarities, but also some fundamental differences, > considered "almost" a static python lol, if that is your definition of 'almost' then your statement is correct From fredrik at pythonware.com Thu Oct 6 02:53:55 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 6 Oct 2005 08:53:55 +0200 Subject: bug or feature? References: <1128508770.727391.313300@f14g2000cwb.googlegroups.com> Message-ID: Steven D'Aprano wrote: > I suppose someone might be able to come up with code that deliberately > uses this feature for good use argument binding is commonly used for optimization, and to give simple functions persistent storage (e.g. memoization caches). more importantly, it's the standard pydiom for passing object *values* (of any kind) into an inner scope: x = something def myfunc(arg, x=x): # myfunc needs the current value, not whatever x # happens to be when the function is called here's a typical gotcha: for i in range(10): def cb(): print "slot", i, "fired" register_callback(slot=i, callback=cb) to make this work as expected, you have to do for i in range(10): def cb(i=i): print "slot", i, "fired" register_callback(slot=i, callback=cb) From no at spam Wed Oct 5 10:35:36 2005 From: no at spam (Mike) Date: Wed, 05 Oct 2005 10:35:36 -0400 Subject: Replacing utf-8 characters Message-ID: <1128522921.72009@nntp.acecape.com> Hi, I am using Python to scrape web pages and I do not have problem unless I run into a site that is utf-8. It seems & is changed to & when the site is utf-8. If I try to replace it with .replace('&','&') it for some reason does not replace it. For example: http://today.reuters.co.uk/news/default.aspx The url in the page looks like this http://today.reuters.co.uk/news/NewsArticle.aspx?type=topNews&storyID=2005-10-05T140937Z_01_MCC423599_RTRUKOC_0_UK-BRITAIN-CONSERVATIVES.xml However when I pull it into python the URL ends up looking like this (notice the & instead of just & in the URL) http://today.reuters.co.uk/news/newsArticle.aspx?type=businessNews&storyID=2005-10-05T094354Z_01_MOL530411_RTRUKOC_0_UK-CONSTRUCTION-BPB-STGOBAIN.xml Any ideas? From my_email_is_posted_on_my_website at munged.invalid Wed Oct 19 04:45:45 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 19 Oct 2005 08:45:45 GMT Subject: Microsoft Hatred FAQ References: <867jcbzdw9.fsf@bhuda.mired.org> <48jbl1honbc8ccfnkuo0bjatmqi5bqfks4@4ax.com> Message-ID: On Tue, 18 Oct 2005 23:18:31 -0700, "David Schwartz" wrote or quoted : > Perhaps you aren't following the thread, but I was talking about the >obligations a company has, not the obligations any individual has. And I was >talking about obligations *to* individuals. To me that makes no sense. Microsoft is an abstraction. It can't do anything. It can't make decisions. Only the individuals to work for it or on the board can, though they may do it in Microsoft's name. If you want to talk about moral action, obligation etc. you can't divorce that from the people who do the actions. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From pmartin at snakecard.com Tue Oct 18 10:38:37 2005 From: pmartin at snakecard.com (Philippe C. Martin) Date: Tue, 18 Oct 2005 14:38:37 GMT Subject: wxPython + pyPlot References: Message-ID: I think wxWidget comes with a sample Philippe Robert wrote: > Maebe, does anyone have some examples with wxPython and pyplot? > > Thanks again, > Robert From aleaxit at yahoo.com Sun Oct 30 01:22:14 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 29 Oct 2005 22:22:14 -0700 Subject: Automatic binding of **kwargs to variables References: <1130539752.667045.183460@g14g2000cwa.googlegroups.com> <1130638902.048806.183580@g43g2000cwa.googlegroups.com> <1130647542.669549.300360@g43g2000cwa.googlegroups.com> Message-ID: <1h57spy.bpig8y1g0rvzfN%aleaxit@yahoo.com> lbolognini at gmail.com wrote: ... > def foo(**kwargs): > expected_form1_kwargs = ["arg1", "arg2"] > > for name in expected_form1_kwargs: > if name not in kwargs: > kwargs[name]=None > > for name in kwargs: > if name in kwargs and name not in expected_form1_kwargs: > raise ValueError, "Unrecognized keyword: " + name > > print kwargs I find this style of coding repulsive when compared to: def foo(arg1=None, arg2=None): print dict(arg1=arg1, arg2=arg2) I don't understand what added value all of those extra, contorted lines are supposed to bring to the party. Alex From tuvas21 at gmail.com Mon Oct 24 14:28:23 2005 From: tuvas21 at gmail.com (Tuvas) Date: 24 Oct 2005 11:28:23 -0700 Subject: Extention String returning Message-ID: <1130178503.498003.175810@f14g2000cwb.googlegroups.com> I have been writing a program that is designed to return an 8 byte string from C to Python. Occasionally one or more of these bytes will be null, but the size of it will always be known. How can I write an extention module that will return the correct bytes, and not just until the null? I would think there would be a fairly easy way to do this, but, well... Thanks! From my_email_is_posted_on_my_website at munged.invalid Sun Oct 9 03:23:26 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sun, 09 Oct 2005 07:23:26 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> Message-ID: On Sun, 09 Oct 2005 04:44:25 -0000, gordonb.7vhwj at burditt.org (Gordon Burditt) wrote or quoted : >And how do you fix the problem of unsolicited USENET articles? >(*ALL* of them are unsolicited to someone). Or unsolicited >email? Read my essay. http://mindprod.com/projects.html/mailreadernewsreader.html I talk around those problems. It requires a fresh start. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From davids at webmaster.com Mon Oct 31 14:25:39 2005 From: davids at webmaster.com (David Schwartz) Date: Mon, 31 Oct 2005 11:25:39 -0800 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <66u633-etj.ln1@news.it.uc3m.es> <7xbr1aewtq.fsf@ruckus.brouhaha.com> <86acgulv5z.fsf@localhost.localdomain> <7xvezi8ypy.fsf@ruckus.brouhaha.com> <86y84ehd3j.fsf@bhuda.mired.org> <86hdb2h750.fsf@bhuda.mired.org> <86zmoufiww.fsf@bhuda.mired.org> <86oe59e57v.fsf@bhuda.mired.org> <868xwcevke.fsf@bhuda.mired.org> Message-ID: "Mike Meyer" wrote in message news:868xwcevke.fsf at bhuda.mired.org... >> Microsoft's behavior consisted of arguments, that is, did not >> involve force, the threat of force, fraud, or the threat of >> fraud. This is perhaps the most vital distinction that there is. > Wrong. Either your definition of force is to narrow, or you're wrong > that it's the distinction is even vaguely vital. If I convince > everyone who might make food available to you not to do so - for > example, by paying them more than their interaction with you is worth > to them, I can starve you to death. I'd say I've used force against > you - an economic force. Right, you would say that, because you don't see the difference between guns and arguments. > This is the kind of force that MS wields > illegally. I'm willing to admit this isn't a usual definition of > force, and won't argue if you want to say that it isn't force. But in > that case, the fact that I didn't use "force" against you is > irrelevant to you - you're just as dead. No, it is completely relevant. You are trying to say the means don't matter if the same end is achieved. But if you're going to say that, you might as well say there's no difference between shooting someone and letting them die of natural causes. But you are completely and utterly wrong. Civilized interactions between men consist of prohibiting certain *means*, not prohibiting certain ends. DS From free.condiments at gmail.com Sun Oct 30 19:46:24 2005 From: free.condiments at gmail.com (Sam Pointon) Date: 30 Oct 2005 16:46:24 -0800 Subject: Pickling and unpickling inherited attributes In-Reply-To: <1130714629.049424.237250@z14g2000cwz.googlegroups.com> References: <1130713951.953157.270130@g14g2000cwa.googlegroups.com> <1130714629.049424.237250@z14g2000cwz.googlegroups.com> Message-ID: <1130719584.505020.118800@g14g2000cwa.googlegroups.com> Of course, in __setstate__, there should be a tup = list(tup) as well - sheer forgetfulness and a confusing name in one. From saint.infidel at gmail.com Wed Oct 19 17:44:12 2005 From: saint.infidel at gmail.com (infidel) Date: 19 Oct 2005 14:44:12 -0700 Subject: infinite cherrypy autoreloader loop In-Reply-To: <1129751081.407613.289710@g14g2000cwa.googlegroups.com> References: <1129751081.407613.289710@g14g2000cwa.googlegroups.com> Message-ID: <1129758252.410765.142210@z14g2000cwz.googlegroups.com> Ok, the problem seems to be with my cherrypy importing Kid. If I import the kid module or any of my compiled kid template modules, then I get the autoreloader infinite loop. Is anyone else experiencing this effect? From mirandacascade at yahoo.com Thu Oct 27 00:15:20 2005 From: mirandacascade at yahoo.com (mirandacascade at yahoo.com) Date: 26 Oct 2005 21:15:20 -0700 Subject: handling ExpatError exception raised from ElementTree.XML() method Message-ID: <1130386520.772048.117530@o13g2000cwo.googlegroups.com> Verion of Python: 2.4 O/S: Windows XP ElementTree resides in the c:\python24\lib\site-packages\elementtree\ folder When a string that does not contain well-formed XML is passed as an argument to the XML() method in ElementTree.py, an ExpatError exception is raised. I can trap the exception with a try/except where the except does not specify a specific exception, but I cannot figure out how to construct the except clause in a try/except statement to catch the ExpatError exception. Interactive window illustrates >>> import elementtree.ElementTree as ElemTree >>> badxml = 'abc' >>> root = ElemTree.XML(badxml) Traceback (most recent call last): File "", line 1, in ? File "C:\Python24\Lib\site-packages\elementtree\ElementTree.py", line 960, in XML parser.feed(text) File "C:\Python24\Lib\site-packages\elementtree\ElementTree.py", line 1242, in feed self._parser.Parse(data, 0) ExpatError: mismatched tag: line 1, column 15 >>> try: ... root = ElemTree.XML(badxml) ... except: ... print 'some exception raised' ... some exception raised >>> try: ... root = ElemTree.XML(badxml) ... except ExpatError: ... print 'ExpatError exception raised' ... Traceback (most recent call last): File "", line 3, in ? NameError: name 'ExpatError' is not defined I'm guessing that I need to define/describe the ExpatError exception class and then refer to that defined exception class after the keyword 'except' and before the ':', but I cannot figure out how to do that. From Slattery_T at bls.gov Thu Oct 20 16:17:21 2005 From: Slattery_T at bls.gov (Tim Slattery) Date: Thu, 20 Oct 2005 16:17:21 -0400 Subject: Microsoft Hatred FAQ References: <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> Message-ID: <0mufl1588t4sj6jcptbb727mquie9fu12r@4ax.com> "Peter T. Breuer" wrote: >No - they got the deal with IBM when they were a garage startup. Not quite a garage startup. They had initial success in Albuquerque, NM, writing a Basic interpreter for the MITS Altair machine. By the time IBM came to them, they had moved to Seattle and were having more success writing compilers for several languages for microcomputers. So no longer a garage startup, but still very small, and definitely not a monopoly. -- Tim Slattery Slattery_T at bls.gov From mwm at mired.org Wed Oct 12 19:43:56 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 12 Oct 2005 19:43:56 -0400 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <868xx3m2ve.fsf@bhuda.mired.org> <86achikzg5.fsf@bhuda.mired.org> Message-ID: <86d5mawbb7.fsf@bhuda.mired.org> Roedy Green writes: > On Sun, 09 Oct 2005 20:06:34 -0400, Mike Meyer wrote > or quoted : >>Nah, I've just know people who spend a lot of time - and money - >>dealing with spam, and we've discussed these issues at great >>length. You haven't proposed anything that hasn't been proposed >>before, and rejected for various reasons. > As if what we are living with now were preferable to what I propose. Nope. Any of the rejected proposals would be better than what we have now. > It is inertia. It is herd mentality that dare not leap out of the > current rut. It is not a particularly difficult technical problem. It > is figuring out how to get people to switch over. Yup, you solved an easy problem - designing a spam-proof email system. That's been done any number of times. The hard part is a deployment strategy that will actually get the world to transition to such a system. That's why earlier nearly identical proposals got rejected - nobody could come up with a workable transition plan. Without a transition plan, a better email system is only of academic interest - and not even much of that at this late date. And yes, it's just inertia. Sort of like why the world stays in it's orbit is just inertia. If you could get enough people to agree on a solution and switch to it at the same time, you'd be done. But "enough" is everyone who uses email, so realistically you need a plan - and a system - that lets things interoperate during the transition. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From my_email_is_posted_on_my_website at munged.invalid Tue Oct 4 13:16:17 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Tue, 04 Oct 2005 17:16:17 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: On Thu, 25 Aug 2005 08:15:25 GMT, CBFalconer wrote or quoted : > It also >interferes with the use of AsciiArt, second only in irritation to spam. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From peter at engcorp.com Tue Oct 18 08:49:47 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 18 Oct 2005 08:49:47 -0400 Subject: unittest of file-reading function In-Reply-To: References: Message-ID: Helge Stenstroem wrote: > Say I have a function > > def f(filename): > result = openFileAndProcessContents(filename) > return result > > Can that function be unit tested without having a real file as input? > Something along the lines of > > import unittest > class tests(unittest.TestCase): > def test1(self): > fileContents = "bla bla bla\nmore bla bla bla" > ??? # make f read this string instead of opening a file > expected = expectedResult > result = f(filename) > self.assertEqual(result, expected) > > One possibility would be to make the unit test write to a temporary > file. Are there better alternatives? The simplest approach is to use a StringIO. Often that will require passing a "file" object to the routine instead of a file *name*, but often that's better anyway (decouples file management and parsing). Another approach is to create a "mock file" object. Depending on your needs, this can be a very simple or a very complex thing to do. I can offer more detail/suggestions here if you need. -Peter From lasse at vkarlsen.no Wed Oct 12 05:40:54 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Wed, 12 Oct 2005 11:40:54 +0200 Subject: crosswords helper program References: <434cd0b3$0$5378$8fcfb975@news.wanadoo.fr> Message-ID: gg wrote: > I plan to write a program in Python in order to help me doing > crosswords, I was wondering if such a program already existed. > > Basically it will get the number of letters of the word (5, 10, 12...) > then the letters known (B in second letter, E in 5th letter...) and then > search in a dictionary the words matching this criteria > > Regards > > Gerard Pretty straightforward with a regular expression: import re words = ["BULLETIN", "BALLPARK", "BUSINESS"] r = re.compile("^BU..N..S$", re.IGNORECASE) for word in words: if r.match(word): print word You would probably want to allow the user to input both some basic format for your program and convert it to a regular expression as well as input a full pattern, because then the user can have words that have a U or a E in the second letter, simply because he doesn't know which one is right yet. -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From contact at ljbsoftware.com Mon Oct 24 22:33:13 2005 From: contact at ljbsoftware.com (contact at ljbsoftware.com) Date: Mon, 24 Oct 2005 22:33:13 -0400 Subject: wxPython import error Message-ID: I have tried several times to install wxPython on Fedora Core 2. The installation seems to go fine (from sources), but when I try to import the wx module I keep getting the following error: ============================================================================= Python 2.4.2 (#1, Sep 29 2005, 13:42:11) [GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import wx Traceback (most recent call last): File "", line 1, in ? File "/usr/local/lib/python2.4/site-packages/wx-2.6-gtk2-unicode/wx/__init__.py", line 42, in ? from wx._core import * File "/usr/local/lib/python2.4/site-packages/wx-2.6-gtk2-unicode/wx/_core.py", line 4, in ? import _core_ ImportError: /usr/local/lib/libwx_gtk2ud_core-2.6.so.0: undefined symbol: pango_x_get_context ============================================================================= Any help or explanation would be greatly appreciated. From rrr at ronadam.com Mon Oct 17 13:51:16 2005 From: rrr at ronadam.com (Ron Adam) Date: Mon, 17 Oct 2005 17:51:16 GMT Subject: ordered keywords? Message-ID: Is there a way to preserve or capture the order which keywords are given? >>> def foo(**kwds): ... print kwds ... >>> foo(one=1, two=2, three=3) {'three': 3, 'two': 2, 'one': 1} I would love to reverse the *args, and **kwds as well so I can use kwds to set defaults and initiate values and args to set the order of expressions. def foo(**__dict__, *args): print args print foo(x=10, y=20, x, y, x+y) [10, 20, 30] Ok, I know there is a lot of problems with that. The reason I would like it is because I think there might be a use case for it where a function iterates over *args in order, but uses kwds to set values. def drawshapes(**inits, *args): for obj in args: obj.draw() drawshapes( triangle=3, square=4, color=red, polygon(triangle, color), polygon(square, color) ) This comes close to the same pattern used in SVG and other formats where you have definitions before expressions. If I use keywords only, It won't keep the order, and if I use args before keywords, I have to pre-assign temporary 'None' values to the arguments in the parent or global scope. Any ideas? Cheers, Ron From http Tue Oct 4 06:35:11 2005 From: http (Paul Rubin) Date: 04 Oct 2005 03:35:11 -0700 Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> <434245F5.6060500@REMOVEMEcyber.com.au> Message-ID: <7xr7b14lk0.fsf@ruckus.brouhaha.com> Antoon Pardon writes: > > Or you just code without declaring, intending to go > > back and do it later, and invariably forget. > > What's the problem, the compilor will allert you > to your forgetfullness and you can then correct > them all at once. Thiat in fact happens to me all the time and is an annoying aspect of Python. If I forget to declare several variables in C, the compiler gives me several warning messages and I fix them in one edit. If I forget to initialize several variables in Python, I need a separate test-edit cycle to hit the runtime error for each one. From rbt at athop1.ath.vt.edu Mon Oct 10 08:59:46 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Mon, 10 Oct 2005 08:59:46 -0400 Subject: One last thing about SocketServer Message-ID: <1128949186.15247.11.camel@athop1.ath.vt.edu> I've read more about sockets and now, I have a better understanding of them. However, I still have a few SocketServer module questions: When used with SocketServer how exactly does socket.setdefaulttimeout() work? Does it timeout the initial connect request to the socket server or does it timeout the session between the connecting client socket and the client socket the server generated to handle the incoming request? Also, since the *only* thing a 'socket server' does is to create 'client sockets' to handle requests, how do I use socket object features on these generated clients to manage and/or monitor them? The SocketServer module is great, but it seems to hide too many details of what it's up to! Thanks, rbt From dave at pythonapocrypha.com Sun Oct 23 07:24:33 2005 From: dave at pythonapocrypha.com (Dave Brueck) Date: Sun, 23 Oct 2005 05:24:33 -0600 Subject: System tray Icon In-Reply-To: References: Message-ID: <435B72F1.3090607@pythonapocrypha.com> Mike Pippin wrote: > How would I have an app run with just a system tray Icon??? any help > would be greatly appreciated. I have no clue where to start. Choose a GUI toolkit, e.g. wxPython. From matthew.garrish at sympatico.ca Sun Oct 23 18:12:54 2005 From: matthew.garrish at sympatico.ca (Matt Garrish) Date: Sun, 23 Oct 2005 18:12:54 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <86k6g59ke6.fsf@bhuda.mired.org> <3EI6f.43974$MF6.5922@fe1.news.blueyonder.co.uk> <86irvo861u.fsf@bhuda.mired.org> Message-ID: "David Schwartz" wrote in message news:djgt6m$mj7$1 at nntp.webmaster.com... > > "Matt Garrish" wrote in message > news:GHR6f.1428$ki7.48975 at news20.bellglobal.com... > >> I'd be interested in hearing what you think a right is? > > A right is a scope of authority. That is, a sphere within which one's > decision is sovereign. > Then why were you claiming that a government can infringe on a person's rights if those rights are not codified or even accepted by those people? The idea of inalienable rights for anyone in a Western society only exists if you believe that the rights of Western societies are inalienable and should be respected everywhere. There is a huge arrogance in that assumption, though, and once you enter a jurisdiction that does not hold your rights to be inalienable they are no longer your rights. You can have generally agreed upon rights, but as you note, those rights can only be hoped for if the systems exist to enforce them. Once those systems erode, you no longer have rights only hopes. The more you allow those systems to be eroded, the less you can expect your rights to exist. In the end, the slippery slope theory would suggest that if you allow MS to get away with bad business practices you are in effect giving all companies the right to leverage whatever means are at their disposal to do the same, to the detriment of society. >> In Florida, for example, you have the right to gun someone down if you >> think they're a bit too menacing. In Canada, most people find that >> reprehensible. So does a Floridian visiting Canada have their rights >> infringed on by our rogue government because they're not allowed to gun >> down menacing looking Canadians at will? > > That's obviously a complicated question but totally unrelated to the > issue at hand, which was one's sovereignty over one's own property. > Obviously issues where a person has to use force against another are going > to be complicated. The existence of complicated questions doesn't make the > simple ones complicated. > I brought it up as an example of why rights are difficult in all cases. You can't claim that anyone has a right to the land they live on. Your only legitimacy to ownership comes through goverment and its ability to enforce that legitimacy for you. And if you really want to get contentious, in Canada and the US your only legitimacy comes from an artificial transaction between a landowner and your government at some time in the past to legitimize its sovereignty over Native American land. Your only real right when it comes to land ownership is to receive some kind of compensation if it is taken away. Your government could decide at any time to expropriate your property to build a new highway (for example), and you'd be out in the cold. You can try to fight the government in court but more often than not you'll lose because the greater good of society outweighs your right to own the land (and the assumption is always that governments work for the greater good of society). And add to that all the covenants and municipal laws you have to obey when purchasing property and the notion that you have sovereignty over your land becomes even less tenable. Matt From http Fri Oct 28 16:46:45 2005 From: http (Paul Rubin) Date: 28 Oct 2005 13:46:45 -0700 Subject: How do I sort these? References: <1130524906.918612.38540@g49g2000cwa.googlegroups.com> <1130531874.710810.39050@g43g2000cwa.googlegroups.com> Message-ID: <7x8xwdid3e.fsf@ruckus.brouhaha.com> "KraftDiner" writes: > In C++ you can specify a comparision method, how can I do this with > python... Yes, see the docs. Just pass a comparison func to the sort method. From mark.engelberg at gmail.com Sun Oct 16 13:58:42 2005 From: mark.engelberg at gmail.com (mark.engelberg at gmail.com) Date: 16 Oct 2005 10:58:42 -0700 Subject: Need advice on finding memory leak Message-ID: <1129485522.439259.211480@o13g2000cwo.googlegroups.com> I am having trouble identifying the source of a memory leak in a Windows Python program. The basic gist is as follows: 1. Generate a directed graph (approx. 1000 nodes). 2. Write the graph to a file. 3. Use the os.system command to invoke another program which processes the graph file (graphViz), and generates a gif image of the graph. 4. Use another os.system command to delete the intermediate file, which is no longer needed. 5. Append to a global list variable some summary information about the graph (a few floats, a few ints, and a couple of short strings). 6. Repeat the above steps several thousand times. 7. Sort the global summary list. 8. Write the summary information out to a file. When running this program, Python consumes all memory after about a thousand graphs. I have confirmed the following: 1. I am closing all files that I open. 2. Although within the directed graph, nodes refer back and forth to each other, the main object which manages the directed graph is not part of anything cyclical. It's reference count is in fact going to zero when the graph goes out of scope. 3. After running gc.collect(), I have confirmed that the nodes are not in the garbage list. I interpret this to mean that although their may be cyclical references among them, the collector was able to determine that they were unreachable as a group, and successfully collected them. 4. I am generating all these graphs in a for loop (using xrange), not through a recursive process that would cause the stack to grow. So really the only thing that should be growing here is the global list that maintains summary information, and since I'm only adding little bits of data, it's hard to imagine how this could be exhausting 2GB of memory after just a thousand iterations. Can anyone help me think of other possible sources of a leak? Are there any classic "python-gotchas" I'm missing here, such as something leaking from calling os.system so many times? Any other suggestions as to what strategies I could employ to track down the leak? Thanks, Mark From jfdoyon at methane.ca Sun Oct 2 17:11:13 2005 From: jfdoyon at methane.ca (=?ISO-8859-1?Q?Jean-Fran=E7ois_Doyon?=) Date: Sun, 02 Oct 2005 17:11:13 -0400 Subject: "no variable or argument declarations are necessary." In-Reply-To: References: Message-ID: Wow, never even occured ot me someone would have a problem with this! But, this might help: http://www.logilab.org/projects/pylint In more detail: > Surely that means that if I misspell a variable name, my program will > mysteriously fail to work with no error message. No, the error message will be pretty clear actually :) You are attempting to use a variable that doesn't exist! This would be the same type of message you would get from a compiled language, just at a different point in time (runtime vs. compile time). > If you don't declare variables, you can inadvertently re-use an > variable used in an enclosing context when you don't intend to, Possible, though good design should always keep anysuch situation at bay. Python is OO, hence scoping should rarely be a problem ... globals are mostly evil, so the context at any given time should be the method, you'd need a fairly big and complex method to start loosing track of what you called what ... Also, a good naming convention should keep this at bay. Also, because things are interpreted, you don't (normally) need to put extensive forthought into things as you do with compiled languages. You can run things quickyl and easily on demand, a misnamed variable will be clearly indicated and easily solved in a matter of minutes. Using a smart IDE might also help prevent such problems before they occur? Hope you enjoy python :) J.F. James A. Donald wrote: > I am contemplating getting into Python, which is used by engineers I > admire - google and Bram Cohen, but was horrified to read > > "no variable or argument declarations are necessary." > > Surely that means that if I misspell a variable name, my program will > mysteriously fail to work with no error message. > > If you don't declare variables, you can inadvertently re-use an > variable used in an enclosing context when you don't intend to, or > inadvertently reference a new variable (a typo) when you intended to > reference an existing variable. > > What can one do to swiftly detect this type of bug? > > > -- > http://www.jim.com From the.theorist at gmail.com Tue Oct 25 14:09:34 2005 From: the.theorist at gmail.com (the.theorist) Date: 25 Oct 2005 11:09:34 -0700 Subject: Setting Class Attributes Message-ID: <1130263774.719830.6230@f14g2000cwb.googlegroups.com> I have a small, simple class which contains a dictionary (and some other stuff, not shown). I then have a container class (Big) that holds some instances of the simple class. When I try to edit the elements of the dictionary, all instances obtain those changes; I want each instance to hold separate entries. #----------Begin module test.py class ex: def __init__(self, val={}): self.value = val def __str__(self): return str(self.value) class Big: def __init__(self): self.A = ex() self.B = ex() def __str__(self) return "A=%s, B=%s"%(self.A, self.B) def changea(self): a = self.A.value a['x'] = 1 a['y'] = 10 print "x = Big()" x = Big() print x print "x.changea()" x.changea() print x print "x.B.value = 30" x.B.value = 30 print x #----------End module test.py #----------Begin actual output x = Big() A={}, B={} x.changea() A={'x':1, 'y':10}, B={'x':1, 'y':10} x.B.value = 30 A={'x':1, 'y':10}, B=30 #----------End actual output #----------Begin Desired output x = Big() A={}, B={} x.changea() A={'x':1, 'y':10}, B={} x.B.value = 30 A={'x':1, 'y':10}, B=30 #----------End Desired output I'm never actually planning on changing the dictionary into something else, I just included that test to see wether both A and B would be set to 30. I'm clearly missing something here: Why do both dictionaries appear to get the same data when they are clearly separate instances? From nnorwitz at gmail.com Wed Oct 5 00:01:19 2005 From: nnorwitz at gmail.com (Neal Norwitz) Date: 4 Oct 2005 21:01:19 -0700 Subject: isatty() for file-like objects: Implement or not? In-Reply-To: References: Message-ID: <1128484879.240338.128730@z14g2000cwz.googlegroups.com> HOWARD GOLDEN wrote: > The standard documentation for isatty() says: > > "Return True if the file is connected to a tty(-like) device, else > False. Note: If a file-like object is not associated with a real file, > this method should not be implemented." > > In his book, "Text Processing in Python," David Mertz says: "... > implementing it to always return 0 is probably a better approach." > > My reaction is to agree with Mertz. I agree, I think the doc is wrong, e.g. StringIO has isatty() which returns False. I think the doc was probably a thinko (or things have changed) since Guido checked it in over 3 years ago. It would be great if you can provide a patch or at least a bug report on SourceForge. Thanks, n From andrea_gavana at tin.it Fri Oct 14 15:16:17 2005 From: andrea_gavana at tin.it (Andrea Gavana) Date: Fri, 14 Oct 2005 21:16:17 +0200 Subject: [PIL]: Question On Changing Colour References: <00fe01c5cf7c$410750e0$69820257@Gavana> Message-ID: <434eb32d$0$29544$4fafbaef@reader1.news.tin.it> I have tried your solution, Terry: > new_hue # your 'basic color', just the hue part > rgb_base # color from the basic button image > rgb_new # the new color you want to replace rgb_base with > > rgb_new = hsv_to_rgb( (new_hue,) + rgb_to_hsv(rgb_base)[1:]) thanks a lot for your suggestion! However, either I did not understand it correctly or I am doing something stupid in my code. Here is a small example: from colorsys import * # that is the old colour --> GREY rgb_old = (0.7, 0.7, 0.7) # Transform the new colour in HSV hsv_old = rgb_to_hsv(rgb_old[0], rgb_old[1], rgb_old[2]) # this is the new colour --> BLUE rgb_new = (0.0, 0.0, 1.0) # Transform the new colour in HSV hsv_new = rgb_to_hsv(rgb_new[0], rgb_new[1], rgb_new[2]) # I take only the Hue part of the new colour new_hue = hsv_new[0] # Get the new colour rgb_new = hsv_to_rgb(new_hue, hsv_old[1], hsv_old[2]) print rgb_old print rgb_new print rgb_old == rgb_new This prints: (0.69999999999999996, 0.69999999999999996, 0.69999999999999996) (0.69999999999999996, 0.69999999999999996, 0.69999999999999996) True So, no matter what colour I choose as a "new" colour, the Hue part of the new colour doesn't change in RGB. In other words, leaving the old value for "Saturation" and "Value" makes the presence of the "Hue" part useless. But why in the world does this happen? If a colour is defined by 3 values, changes in every single value should change the colour too... Ah, thanks God for the existence of RGB ;-) Thanks a lot for every suggestion. Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.virgilio.it/infinity77 From leszczynscyATnospam.yahoo.com.nospam Wed Oct 26 23:25:05 2005 From: leszczynscyATnospam.yahoo.com.nospam (Andy Leszczynski) Date: Wed, 26 Oct 2005 22:25:05 -0500 Subject: creating/altering the OpenOffice spredsheet docs Message-ID: Any idea how to do that the way ActiveX would be used on M$? A. From rrr at ronadam.com Mon Oct 24 22:06:34 2005 From: rrr at ronadam.com (Ron Adam) Date: Tue, 25 Oct 2005 02:06:34 GMT Subject: namespace dictionaries ok? Message-ID: Hi, I found the following to be a useful way to access arguments after they are passed to a function that collects them with **kwds. class namespace(dict): def __getattr__(self, name): return self.__getitem__(name) def __setattr__(self, name, value): self.__setitem__(name, value) def __delattr__(self, name): self.__delitem__(name) def foo(**kwds): kwds = namespace(kwds) print kwds.color, kwds.size, kwds.shape etc.... foo( color='red', size='large', shape='ball', .... etc..) It just seems awkward to have to use "string keys" in this situation. This is easy and still retains the dictionary so it can be modified and passed to another function or method as kwds again. Any thoughts? Any better way to do this? Cheers, Ron From rrr at ronadam.com Sun Oct 23 01:27:44 2005 From: rrr at ronadam.com (Ron Adam) Date: Sun, 23 Oct 2005 05:27:44 GMT Subject: best way to replace first word in string? In-Reply-To: <1130043938.837369.255270@g44g2000cwa.googlegroups.com> References: <1129822003.246170.303920@f14g2000cwb.googlegroups.com> <1130043938.837369.255270@g44g2000cwa.googlegroups.com> Message-ID: bonono at gmail.com wrote: > interesting. seems that "if ' ' in source:" is a highly optimized code > as it is even faster than "if str.find(' ') != -1:' when I assume they > end up in the same C loops ? The 'in' version doesn't call a function and has a simpler compare. I would think both of those results in it being somewhat faster if it indeed calls the same C loop. >>> import dis >>> def foo(a): ... if ' ' in a: ... pass ... >>> dis.dis(foo) 2 0 LOAD_CONST 1 (' ') 3 LOAD_FAST 0 (a) 6 COMPARE_OP 6 (in) 9 JUMP_IF_FALSE 4 (to 16) 12 POP_TOP 3 13 JUMP_FORWARD 1 (to 17) >> 16 POP_TOP >> 17 LOAD_CONST 0 (None) 20 RETURN_VALUE >>> >>> def bar(a): ... if str.find(' ') != -1: ... pass ... >>> dis.dis(bar) 2 0 LOAD_GLOBAL 0 (str) 3 LOAD_ATTR 1 (find) 6 LOAD_CONST 1 (' ') 9 CALL_FUNCTION 1 12 LOAD_CONST 2 (-1) 15 COMPARE_OP 3 (!=) 18 JUMP_IF_FALSE 4 (to 25) 21 POP_TOP 3 22 JUMP_FORWARD 1 (to 26) >> 25 POP_TOP >> 26 LOAD_CONST 0 (None) 29 RETURN_VALUE >>> From aisaac0 at verizon.net Tue Oct 25 02:45:01 2005 From: aisaac0 at verizon.net (David Isaac) Date: Tue, 25 Oct 2005 06:45:01 GMT Subject: grep Message-ID: What's the standard replacement for the obsolete grep module? Thanks, Alan Isaac From jason at pengale.com Mon Oct 17 15:23:21 2005 From: jason at pengale.com (Jason Stitt) Date: Mon, 17 Oct 2005 14:23:21 -0500 Subject: UI toolkits for Python In-Reply-To: References: <7xslv56ud1.fsf@ruckus.brouhaha.com> <3ras6oFit2djU1@individual.net> <4350dd34$0$6774$9b4e6d93@newsread4.arcor-online.net> <863bn12k6i.fsf@bhuda.mired.org> Message-ID: <98CEBC3D-1D24-4DB8-9962-386E48A4C17D@pengale.com> On Oct 17, 2005, at 12:19 PM, Kenneth McDonald wrote: > Web interfaces are missing a lot more than this. Here are just a > few things that cannot be done with web-based interfaces (correct > me where I'm wrong): > > 1) A real word processor. > 2) Keybindings in a web application > 3) Drag and drop > 4) Resizable windows (i.e. not the browser window) within the > application. > 5) Anything other than absolutely trivial graphical programs. > > State is a very small part of the whole thing. Progress is being > made, but web interfaces are still basically forms that can contain > buttons, checkboxes, text fields, and a few other basic controls. I > wish it were otherwise. Drag-and-drop within a page can be done. Drag-and-drop between pages is the only thing on that list I think is outright impossible. Everything else is a matter of overcoming difficulty (well, 5 might be close enough to qualify as impossible, if you're thinking Photoshop.) Thing is, as Web applications continue to increase in complexity, they're going to resemble desktop apps more and more, not just on the front end but in back as well. So the "advantage" of Web apps being simpler to program will probably go away. Right now, they're only simpler because people are doing simpler things with them (and browsers only let you do so much.) The extra complexity you get with desktop app toolkits is overkill for many purposes. HTML is often "good enough" in a lot less time. But if we get to the point where browsers are implementing inter-page drag-and-drop (probably differently!) and so forth, some of us might well decide it's simpler to go back to wxPython, etc. Then again, maybe we'll live to see the W3C standardize the desktop environment... -Jason From aasava at gmail.com Sun Oct 23 19:54:11 2005 From: aasava at gmail.com (aasava at gmail.com) Date: 23 Oct 2005 16:54:11 -0700 Subject: All kind of download just here Message-ID: <1130111651.817492.94170@g43g2000cwa.googlegroups.com> All What You Are Looking For And More.... Hello Dear friend... Here http://s14.invisionfree.com/SaVaTaGe4eVeR/ you can find all what you are looking for in all the internet to download it like ... New Applications just here http://s14.invisionfree.com/SaVaTaGe4eVeR/index.php?showtopic=94 New Movies just here http://s14.invisionfree.com/SaVaTaGe4eVeR/index.php?showtopic=96 New PC Games just here http://s14.invisionfree.com/SaVaTaGe4eVeR/index.php?showtopic=95 New Animes just here http://s14.invisionfree.com/SaVaTaGe4eVeR/index.php?showtopic=104 New Musics just here http://s14.invisionfree.com/SaVaTaGe4eVeR/index.php?showtopic=104 New Mobile just here http://s14.invisionfree.com/SaVaTaGe4eVeR/ New e-books just here http://s14.invisionfree.com/SaVaTaGe4eVeR/ and many many more So please come and see what we can offer for you at http://s14.invisionfree.com/SaVaTaGe4eVeR/ SaVaTaGe4eVeR forum team From codecraig at gmail.com Tue Oct 25 08:22:20 2005 From: codecraig at gmail.com (jas) Date: 25 Oct 2005 05:22:20 -0700 Subject: Read/Write from/to a process In-Reply-To: References: <1130163642.868252.148070@g44g2000cwa.googlegroups.com> <1130174259.472124.114790@f14g2000cwb.googlegroups.com> Message-ID: <1130242940.918480.65020@f14g2000cwb.googlegroups.com> So it seems there is no good way to handle "interactive" processes on windows using python. By interactive I mean processes/commands that require user interaction, such as telnet or del (to delete a file or directory sometimes you need to confirm with a yes or no), date, etc. os.system gives the exact behavior, but you can't redirec the output. pexpect isn't supported on windows. Even with subprocess you can't handle all/most cases..since you have to do things like look for he prompt. I modified the original suggestion so it would update the prompt, in case the user did a "cd.." ..which works fine now. However, if a user tries to do, "del tmp123" ...windows prompts for a "are you sure you want to delete... Y/N?" ...so the code hangs. I can't believe no one else has done this yet..or if they have, it hasn't been widely discussed. Any other suggestions? From chris.atlee at gmail.com Sat Oct 29 14:01:02 2005 From: chris.atlee at gmail.com (chris.atlee at gmail.com) Date: 29 Oct 2005 11:01:02 -0700 Subject: Automatic binding of **kwargs to variables References: <1130539752.667045.183460@g14g2000cwa.googlegroups.com> <86d5lpdwg3.fsf@bhuda.mired.org> Message-ID: <1130608862.858527.124330@g14g2000cwa.googlegroups.com> Mike Meyer wrote: [snip] > for name, value in kwargs.items(): > if name in ('a', 'list', 'of', 'valid', 'keywords'): > exec "%s = %s" % (name, value) > else: > raise ValueError, "Unrecognized keyword " + name > > Others will probably tell you that you really shouldn't be using exec. What about using setattr? for name, value in kwargs.items(): if name in ('a', 'list', 'of', 'valid', 'keywords'): setattr(self, name, value) else: raise ValueError, "Unrecognized keyword " + name I'd probably turn the list of valid keywords into another dictionary to make it easy to specify default values for all the parameters as well. Cheers, Chris From mekstran at scl.ameslab.gov Thu Oct 6 22:56:14 2005 From: mekstran at scl.ameslab.gov (Michael Ekstrand) Date: Thu, 6 Oct 2005 21:56:14 -0500 Subject: So far (about editing tools) In-Reply-To: <20051006204548.GH32363@kitchen.client.attbi.com> References: <48D17FEA-3E2D-46CA-AEB4-86EA1CFACCB1@sbcglobal.net> <20051006204548.GH32363@kitchen.client.attbi.com> Message-ID: <200510062156.14442.mekstran@scl.ameslab.gov> On Thursday 06 October 2005 15:45, Micah Elliott wrote: > On Oct 06, Kenneth McDonald wrote: > > The only _real_ problem is the eclipse learning curve. > > The only real *advantage* of Eclipse (over other suggested tools) is > its highly hyped automatic refactoring. Admittedly, I have not used > it for Python development, but I'm skeptical of the feasibility of > auto-refactoring in general, and therefore acknowledge *no* > advantage. Furthermore, Eclipse requires java and is thusly not > provided on any linux distro I'm familiar with, which I consider a > huge roadblock. And as mentioned, it's bloated. Eclipse is massively bloated. We're using it for a class I'm taking where we have to program in Java... when I start Eclipse on my 1.7GHz laptop w/ 256 MB ram, Eclipse is very slow and KDE takes forever to switch desktops or applications... Eclipse running brings my entire laptop to a near-standstill. And refactoring: Eclipse has incredible Java refactoring, which works beautifully due to Java's highly static nature. Eclipse is by far the best tool I've ever seen for browsing and manipulating Java projects. But Python's highly dynamic nature makes automatic refactoring difficult, and I find Bicycle Repair Man has difficulty with even some highly trivial refactoring things (renaming the variable in a for loop in one place I tried to use it...). > I would suspect that the majority of Python programmers write in one > of vim or emacs. Anyone got stats? +1 Vim. But no stats. Perhaps a survey of Python source files found on the Internet for prevailing modelines would be revealing? - Michael From http Thu Oct 6 05:10:15 2005 From: http (Paul Rubin) Date: 06 Oct 2005 02:10:15 -0700 Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> <434245F5.6060500@REMOVEMEcyber.com.au> <7xr7b14lk0.fsf@ruckus.brouhaha.com> <7xu0fx9l7y.fsf@ruckus.brouhaha.com> <7xwtks2tnw.fsf@ruckus.brouhaha.com> <7xek70xhzz.fsf@ruckus.brouhaha.com> <7xirwbn1kl.fsf@ruckus.brouhaha.com> Message-ID: <7xslvf105k.fsf@ruckus.brouhaha.com> Brian Quinlan writes: > I'm not trying to be silly. I am trying to get a handle on the > semantics that you are proposing. So we now have two requirements for > the new declaration syntax (please let me know if I'm wrong): > > o the variable must be declared > o the variable must be assigned These would both be errors that the compiler could and should check for, if declaration checking is enabled. However, they would not be syntax errors. > I would assume that you would make it so that assignment and > delaration happen as part of the same statement? Sure, why not. > Right now, the compiler DOES NOT examine the contents of the other > modules. All it does is generate an IMPORT_NAME instruction which is > evaluation during runtime. In that case the other module gets compiled when the IMPORT_NAME instruction is executed. That says that compile time and runtime are really the same thing in the current system. > So are you proposing that the compiler now scan other modules during > compilation? Yeah, maybe some optimization is possible. From http Sat Oct 15 02:56:14 2005 From: http (Paul Rubin) Date: 14 Oct 2005 23:56:14 -0700 Subject: MD5 module Pythonicity References: <6815022a0510142223q3b6ae449ja0483f2f25ebb263@mail.gmail.com> Message-ID: <7xoe5r1d69.fsf@ruckus.brouhaha.com> "Fredrik Lundh" writes: > > Forcing every digest module to add code to cater for just one of many > > use cases is most likely a waste of time. > here's the hash API specification, btw: > http://www.python.org/peps/pep-0247.html I agree with you and Mike that a file checksum function isn't that important. I use the hash modules all the time and can't think of a single time I've ever used one to hash an entire file. However, PEP 247 shows that the modules are supposed to have a common API. So if there was some actual reason to have a file-hashing operation, it would be done by implementing it once and having it call a hash module that's passed as a parameter, similar to the HMAC module, rather than implementing the file operation in every different hash module. From rrr at ronadam.com Mon Oct 17 22:45:01 2005 From: rrr at ronadam.com (Ron Adam) Date: Tue, 18 Oct 2005 02:45:01 GMT Subject: ordered keywords? In-Reply-To: <435443e9$1_3@newspeer2.tds.net> References: <435443e9$1_3@newspeer2.tds.net> Message-ID: Kent Johnson wrote: > Ron Adam wrote: > >> drawshapes( triangle=3, square=4, color=red, >> polygon(triangle, color), >> polygon(square, color) ) >> >> This comes close to the same pattern used in SVG and other formats >> where you have definitions before expressions. > > > Why is this better than the obvious > triangle=3 > square=4 > color=red > drawshapes(polygon(triangle, color), > polygon(square, color) ) > > or even > drawshapes(polygon(3, red), > polygon(4, red) ) > > which is concise and readable IMO...? > > Kent That example was over simplified quite a bit. :-) The reason I'm trying to get named attributes is so I can change colors or the text items later without having to recreate the object. The objects I'm using are capable inheriting from other predefined objects so you only have to add or modify it a tiny bit. For example the following creates shapes that build on each other and they all have a .draw() method to draw on a Tk canvas. In addition they can be scaled, stretched and rotated. Well, the ones based on polygons and lines can be rotated and stretched. I'm still working on how to do that with arcs and text items. ## These are the most basic shape elements which use the ## Tkinter canvas items specified by the 'obj' attribute. # base shapes. text = Shape( obj='text', text='', fill='black', size=1, font='', style='', pos=(0,0), points=(0,0) ) line = Shape( obj='line', arrow='none', fill='black', smooth='false', pos=(0,0), width=.1, points=(-.5,0,.5,0), size=1, rotate=0, center=(0,0) ) polygon = Shape( obj='polygon', fill='grey', outline='', size=1, smooth='false', pos=(0,0), width=0, points=(0,0), rotate=0, center=(0,0), ratio=(1,1) ) arc = Shape( obj='arc', fill='grey', outline='', pos=(0,0), width=0, size=1, style='arc', start='0', extent='90', points=(-.5,-.5,.5,.5) ) ## This next group inherits from the shapes above and only ## needs to change what's different. # shape variations chord = arc(style='chord') pie = arc(style='pieslice') rectangle = polygon(points=[-.5,-.5,.5,-.5,.5,.5,-.5,.5]) triangle = polygon(points=getpolygon(3)) square = polygon(points=getpolygon(4)) octagon = polygon(points=getpolygon(8)) circle = polygon(smooth='true', points=getpolygon(16)) # The oval is stretched circle, which is a smoothed polygon. # this can be rotated, the Tkinter oval can't. oval = circle(ratio=(1,.7)) ## Grouping combines the shapes together. Again only what is ## different needs to be changed, such as color or size and ## relative position. Any previously defined ## shapes can be combined to create complex new ones. # CAUTION ICON caution = Group( triangle(pos=(6,5), size=75), triangle(fill='yellow', size=75), txt = text( text='!', font='times', style='bold', pos=(0,-3), size=30,) ) # ERROR ICON error = Group( octagon(pos=(6,5), size=55), octagon(fill='red', size=55), circle(fill='white', size=37), circle(fill='red', size=25), line(fill='white', width=.2, rotate=45, size=28) ) ## For this next group it would be nice if the bubbletip ## shape could be in the argument list, but it would need ## to be after the other refernces to it, and they ## would not find it. I did it this way to try out ## the idea of reusing objects, it would be no trouble ## just to duplicate the bubbletip in this case. # QUESTION & INFO ICONS bubbletip = polygon(points=[-5,10, 20,10, 30,30]) question = Group( bubbletip(pos=(6,5)), oval(pos=(6,5), size=60), bubbletip(fill='lightblue'), oval(fill='lightblue', size=60), txt = text( text='?', font='times', style='bold', size=25 ) ) ## Here I just need to change the text element to 'i' to get ## the Info icon. Since it has a name we can do that. info = question() # get a copy of question info.txt.text = 'i' # change the '?' mark to 'i' These can all be in a file ready to import and then you can use them anywhere in Tkinter that accepts a normal canvas commands. caution.draw(c, pos=(70,50), scale=.5) # small caution icon error.draw(c, pos=(150,48), scale=3) # triple sized error icon Now this all works wonderfully, but I can only have one named attribute because I can't depend on the order a dictionary has. So I'm going to probaby need to have a layer attribute. Thus the need for either ordered keyword arguments, or a way to specify keywords as a variable for the arguments list. Eventually I will be able to mix groups and shapes together in other groups by using them exactly like any other shape. So I can take a image of a guy, add a hat, tilt the hat, and few other props, put some text on it, and I have a nice illustration with very little effort. There are still a lot of small details that still need to be worked out before it's suitable for real use. It works now, but too much will change as I add too it at this stage. ;-) Cheers, Ron From samrobertsmith at gmail.com Wed Oct 19 08:22:11 2005 From: samrobertsmith at gmail.com (Shi Mu) Date: Wed, 19 Oct 2005 05:22:11 -0700 Subject: path Message-ID: <1d987df30510190522m6b5fbd20n2fddd311e34ed7b1@mail.gmail.com> I have installed Python 2.3 and I type "help()" and then "Keywords". I get a list of words. And it says that I can enter any of the words to get more help. I enter "and" and I get the following error message: "Sorry, topic and keyword documentation is not available because the Python HTML documentation files could not be found. If you have installed them, please set the environment variable PYTHONDOCS to indicate their location." but I have set both the environment variable, with the path to be C:\Python23\Doc which includes python23.chm Why I still got the above error message? From rrr at ronadam.com Sun Oct 16 05:33:49 2005 From: rrr at ronadam.com (Ron Adam) Date: Sun, 16 Oct 2005 09:33:49 GMT Subject: dis.dis question In-Reply-To: <4351affc.104308027@news.oz.net> References: <4351affc.104308027@news.oz.net> Message-ID: <18p4f.151667$xl6.58345@tornado.tampabay.rr.com> Bengt Richter wrote: > On Sun, 09 Oct 2005 12:10:46 GMT, Ron Adam wrote: >>Ron Adam wrote: >>It seems I've found a bug in dis.py, or maybe a expected non feature. >>When running dis from a program it fails to find the last traceback >>because sys.last_traceback doesn't get set. (a bug in sys?) It works >>ok from the shell, but not from the program. >> >>Changing it to to get sys.exc_info()[2], fix's it in a program, but then >>it doesn't work in the shell. So I replaced it with the following which >>works in both. >> >> try: >> if hasattr(sys,'last_traceback'): >> tb = sys.last_traceback >> else: >> tb = sys.exc_info()[2] >> except AttributeError: >> raise RuntimeError, "no last traceback to disassemble" I guess I should do a bug report on this part so you can do the following in a program. try: (something that fails) except: dis.dis() # print a dissasembled traceback. >>I'm still looking for info on how to use disassemble_string(). >> > > > One way to get dis output without modufying dis is to capture stdout: > (ancient thing I cobbled together, no guarantees ;-) > > >>> class SOCapture: > ... """class to capture stdout between calls to start & end methods, q.v.""" > ... import sys > ... def __init__(self): > ... self.so = self.sys.stdout > ... self.text = [] > ... def start(self, starttext=None): > ... """Overrides sys.stdout to capture writes. > ... Optional starttext is immediately appended as if written to stdout.""" > ... self.sys.stdout = self > ... if starttext is None: return > ... self.text.append(starttext) > ... def end(self, endtext=None): > ... """Restores stdout to value seen at contruction time. > ... Optional endtext is appended as if written to stdout before that.""" > ... self.sys.stdout = self.so > ... if endtext is None: return > ... self.text.append(endtext) > ... def gettext(self): > ... """Returns captured text as single string.""" > ... return ''.join(self.text) > ... def clear(self): > ... """Clears captured text list.""" > ... self.text = [] > ... def write(self, s): > ... """Appends written string to captured text list. > ... This method is what allows an instance to stand in for stdout.""" > ... self.text.append(s) This is useful. But I've already rewritten it. ;-) I tried to keep it's output as close to the original as possible. For example replacing the the call "dis.dis(func)" in test_dis.py with "print dis.dis(func)" is all that's needed to get it to pass the test. s = StringIO.StringIO() save_stdout = sys.stdout sys.stdout = s dis.dis(func) #<- "print dis.dis(func)" passes sys.stdout = save_stdout got = s.getvalue() The above could be replaced with... got = dis.dis(func) The same minor change needs to be made in test_peepholer.py. It uses dis to check the bytecodes. I havn't found any other dependancies yet. > >>> diss(foo) > ' 1 0 LOAD_FAST 0 (x)\n 3 LOAD_CONST 1 (1)\ > n 6 BINARY_ADD \n 7 LOAD_CONST 2 (2)\n > 10 BINARY_POWER \n 11 RETURN_VALUE \n' > >>> print diss(foo) > 1 0 LOAD_FAST 0 (x) > 3 LOAD_CONST 1 (1) > 6 BINARY_ADD > 7 LOAD_CONST 2 (2) > 10 BINARY_POWER > 11 RETURN_VALUE This is something I fixed (or added) so it displays the same from print, the terminal, and the command line. I'm not sure if it can replace dis module. It may be different enough that it can't. I suspect some might not like the table class. I'm thinking of making a bug report for the traceback not being found when distb() is used inline, and attach the altered file for consideration and feedback. One possibility is to dispense with keeping it like dis and rename it to something different and then additional functions and capabilities can be added to it without worrying about breaking anything. ;-) BTW do you know how to read the time and version stamp of the beginning of .pyo and .pyc files? I added that (just too easy not to) and would like to put the time and version stamp at the top of the output for those. It's easy to take stuff out if needed. ;-) I can send it to you as an attached file if you'd like to take a look. Cheers, Ron From my_email_is_posted_on_my_website at munged.invalid Mon Oct 17 20:47:31 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Tue, 18 Oct 2005 00:47:31 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: On Sun, 16 Oct 2005 22:36:53 -0700, "David Schwartz" wrote or quoted : > As for it being illegal, it was illegal only because if was Microsoft >doing it. There's nothing illegal about a car dealer not selling a car >without an engine. But that is not what was happening. It was not Microsoft selling computers with MS OSs. MS was arm-twisting retailers like me to bundle a copy of Windows with every sale whether the customer wanted it or not. I think some imagine a computer is worthless without Windows. That gave their OS a grossly unfair price advantage. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From eternalsquire at comcast.net Sat Oct 29 18:46:37 2005 From: eternalsquire at comcast.net (The Eternal Squire) Date: 29 Oct 2005 15:46:37 -0700 Subject: dreaming in Python Message-ID: <1130625997.428653.28080@g49g2000cwa.googlegroups.com> All, I have to tell all of you this, at least for some laughs. Honestly, I had the silliest dream involving the language last night. I dreamt that it was a decade into the future and that Grand Central Station in NYC was installing a cement and steel "computer core" for directing its trains and station elevators... and for some reason I was supervising a technician on the project. I asked the technician, what version of Python was being used, and he said 2.1... I said better install 2.4! So he loaded a chip into the 15 ton cylindrical core, then the core was lowered by winch into a manhole cover. The lights in the station lit, and I shouted: One Python to Rule Them All And In The Darkness Bind Them! Then I took an elevator downstairs to log into the terminal. Who did I meet on a neighboring terminal other than the BDFL? He was doing something esoteric and strange on the terminal but I was just having trouble logging in. End of dream. Anyone ever have a wierd engineering dream sometime in thier career? The Eternal Squire From sidanko at scientist.com Wed Oct 26 12:52:24 2005 From: sidanko at scientist.com (sidanko) Date: 26 Oct 2005 09:52:24 -0700 Subject: WinXP vs. Win98 In-Reply-To: References: <1130331088.292656.213430@g47g2000cwa.googlegroups.com> Message-ID: <1130345544.813854.64850@g49g2000cwa.googlegroups.com> Thanks a lot! I have set the environment variable and now it runs just fine! AS From codecraig at gmail.com Mon Oct 24 09:35:44 2005 From: codecraig at gmail.com (jas) Date: 24 Oct 2005 06:35:44 -0700 Subject: Redirect os.system output In-Reply-To: References: <1129927486.854143.169670@g49g2000cwa.googlegroups.com> <43596c70$1_3@newspeer2.tds.net> <1130154552.795209.25830@g43g2000cwa.googlegroups.com> <435cd10c$1_2@newspeer2.tds.net> <1130157195.954433.131650@g49g2000cwa.googlegroups.com> <1130159194.833666.250820@g47g2000cwa.googlegroups.com> Message-ID: <1130160944.738377.42810@g14g2000cwa.googlegroups.com> doesn't sound to encouraging :) How about something with os.popen? in = os.popen("cmd", "w") in.write("hostname") I tried this, and I get "IOError: [Errno 22] Invalid Argument" I am not sure why this isnt working. Steve Holden wrote: > jas wrote: > > Ok, I tried this... > > > > C:\>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 subprocess as sp > >>>>p = sp.Popen("cmd", stdout=sp.PIPE) > >>>> > >>>>result = p.communicate("ipconfig") > > > > 'result' is not recognized as an internal or external command, > > operable program or batch file. > > > > > > > > basically I was opening to send the "ipconfig" command to cmd.exe and > > store the result in the "result" variable. But you can see there was > > an error with result. > > > It looks to me like the line you thought you were typing at the Python > command interpreter actually got snagged by the command processor you > just ran, which presumably is taking its input from the console just > like Python is. > > > Ideas? > > > Haven't used subprocess much yet, but I will just mention that this kind > of thing always looks easy in principle and turns out to be surprisingly > gnarly and difficult in practice. > > I'm not suggesting you shouldn't continue, but you are going to learn a > *lot* as you proceed. Good luck. > > regards > Steve > [...] > -- > Steve Holden +44 150 684 7255 +1 800 494 3119 > Holden Web LLC www.holdenweb.com > PyCon TX 2006 www.python.org/pycon/ From fredrik at pythonware.com Tue Oct 4 10:05:05 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 4 Oct 2005 16:05:05 +0200 Subject: ssh or other python editor References: <1128430526.531749.68600@g47g2000cwa.googlegroups.com><1128431721.153846.236930@g43g2000cwa.googlegroups.com> <1128433683.342113.32060@g47g2000cwa.googlegroups.com> Message-ID: martijn at gamecreators.nl wrote: >- I'm a newbie at freeBSD so I think there is , but I don't know where. I just complained when someone included the entire message thread in their replies, but not including anything at all is pretty annoying too. > And i'm using putty on a windows OS what don't understand the syntax > coloring. Putty isn't doing any syntax coloring; it just draws things in the color specified by your editor. If you don't get any colors, it's probably because your editor isn't properly configured. Explicitly setting the TERM variable to "xterm" might help: http://www.chiark.greenend.org.uk/~sgtatham/putty/faq.html#faq-term (but I'm pretty sure ssh does this for you, so it's probably an editor configuration issue. checking the FAQ for your editor might be a good idea) From bonono at gmail.com Wed Oct 19 04:24:00 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 19 Oct 2005 01:24:00 -0700 Subject: write a loopin one line; process file paths In-Reply-To: <1129708210.963305.43270@g49g2000cwa.googlegroups.com> References: <1129672592.328278.41490@g14g2000cwa.googlegroups.com> <1129696357.539158.233870@g47g2000cwa.googlegroups.com> <1129699998.324180.56530@f14g2000cwb.googlegroups.com> <1129701270.792327.168620@z14g2000cwz.googlegroups.com> <1129708210.963305.43270@g49g2000cwa.googlegroups.com> Message-ID: <1129710240.173768.151950@g14g2000cwa.googlegroups.com> Xah Lee wrote: > besides syntactical issues, another thing with doing functional > programing in imperative languages is that they become very inefficent. > Functional languages are optimized by various means of functional > programings styles. Doing them in imperative languages usually comes > with a order of execution penalty because imperative language compilers > are usually dumb. The itertools module and the new generator feature tries to make this better as it is lazily evaluated, in a sense. But its side effect is nasty. Usable though need to twist my mind a bit, not like when I do it in haskell. But the occasion imperative dip makes some of my programs easier to code. > > though, one can't totally blame for Python's lack of ability to do > functional programing. Its language's syntax of using indentations for > blocks by design, pretty much is in odds with functional programing's > sequencing of functions and other ways. (such as generic mechanism for > prefix/postfix syntax, or macros or other transformations and patterns, > or heavy reliance on the free flow of expressions/values) That I am not sure. haskell also use this indentation but I don't see a problem about it. One thing I find it odd though is the @decorator construct. I just don't understand why it is viewed as simple. It becomes very ugly IMO when there is a number of it, I am doing some web apps which requres varies decorators(one over the other). @format @login_block @validate @something def my_func(): I find it easier to read and under stand in the form of format(login_block(validate(something(my_func))))) though haskell's $ and . is even better. format.login_block.validate.somethin.my_func > > I don't blame Python that it doesn't cater to functional programing BY > DESIGN. But i do hate the mother fucking fuckheads Pythoners for one > thing that they don't know what functional programing really is, and on > the other hand fucking trumpet their righteousness and lies thru their > teeth of their ignorance. (that Guido guy with his Python 3000 article > on his blog is one example, possibly forgivable in that particular > instance. (http://xahlee.org/perl-python/python_3000.html)) That seems to be the case, I mean the design. For fairness, list comphrehension sometimes looks cleaner, though becomes ugly when you do the pipe/chain like programming in FP(multiple for). This again is an odd choice. It seems to be a flattening of multiple line for loop, yet at the same time python seems to be moving towards being more explicit(no map/filter/etc as they can be done in for loop). But I believe Python is designed for easy to code and read and maintain in mind. One has to admit that without some training, FP is not very intuitive, my head spin when I see haskell code. A for loop is easier to understand. Well, if you want clean FP, you can always try haskell which is getting better and better in terms of real world module support(file system, network etc). > > (excuse me for lashing out) > > Xah > xah at xahlee.org > ? http://xahlee.org/ From enleverlesO.OmcO at OmclaveauO.com Sun Oct 30 17:24:46 2005 From: enleverlesO.OmcO at OmclaveauO.com (Do Re Mi chel La Si Do) Date: Sun, 30 Oct 2005 23:24:46 +0100 Subject: Using graphviz to visualize trace.py output, anybody? References: <1130710534.618559.40680@g43g2000cwa.googlegroups.com> Message-ID: <4365487c$0$31846$636a15ce@news.free.fr> Hi! Under Windows, I call graphwiz from Python via COM, with win32all (PyWin). Sorry, I don't know the Mac. @-salutations Michel Claveau From enrico.sirola_NOSPAM at gmail.com Mon Oct 17 05:31:46 2005 From: enrico.sirola_NOSPAM at gmail.com (enrico.sirola_NOSPAM at gmail.com) Date: 17 Oct 2005 11:31:46 +0200 Subject: [newbie]Is there a module for print object in a readable format? References: Message-ID: >>>>> "James" == James Gan writes: James> I want the object printed in a readable format. For [...] James> I tried pickled, marshel. They do different work. Is there James> another module which do this kind of job? from pprint import pprint pprint(object) bye, e. -- Enrico Sirola From davids at webmaster.com Mon Oct 24 16:03:19 2005 From: davids at webmaster.com (David Schwartz) Date: Mon, 24 Oct 2005 13:03:19 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <86k6g59ke6.fsf@bhuda.mired.org> <3EI6f.43974$MF6.5922@fe1.news.blueyonder.co.uk> Message-ID: wrote in message news:xO47f.174444$RW.76779 at fe2.news.blueyonder.co.uk... >> His comments are not applicable to America. They are applicable to a >> country where the government owns the economy. >> No reply is needed to his comments except to point out that they only >> apply to a communist or totalitarian state. We don't have one here, so >> his >> argument doesn't apply. > The last time I looked, property taxes were enforced in many states of > the USA. Do you deny this? What do property taxes have to do with Microsoft? >> I am not saying "because you are a communist, your argument is wrong". >> I >> am saying, "because your argument is based upon communist or totalitarian >> premises about the relationship between the government and the economy, >> it >> does not apply to the United States, and we were talking about the United >> States." > Then you are sadly deluded if you think that the US government does not > make decisions on the economy. That's true. Of course, I do think the US government makes decisions on the economy. DS From steve at rueb.com Tue Oct 4 13:22:42 2005 From: steve at rueb.com (Steve Bergman) Date: Tue, 04 Oct 2005 12:22:42 -0500 Subject: Which SQL module to use? In-Reply-To: <1128433394.470896.89770@g44g2000cwa.googlegroups.com> References: <1128433394.470896.89770@g44g2000cwa.googlegroups.com> Message-ID: <4342BA62.5070109@rueb.com> mrstephengross wrote: >I'd like to do some basic SQL stuff in Python. It seems like there are >a heck of a lot of SQL modules for Python. What's the simplest and >easiest one to use? > > The suggestion to use sqllite is probably a good one to get started. I'm a PostgreSQL fan and use pygresql. It has 2 modes: "Classic" and "DBAPI 2.0". The DPAPI 2.0 interface makes your SQL portable between RDBMs. But you can't beat the classic interface for simplicity, elegance, and convenience. With classic, just pass a dictionary and say insert this or update this and its done. With selects, its easy to get your results as a dictionary. -Steve Bergman From cs at totallybogus.com.invalid Sat Oct 15 10:05:49 2005 From: cs at totallybogus.com.invalid (Cousin Stanley) Date: Sat, 15 Oct 2005 09:05:49 -0500 Subject: [ANN] XPN 0.5.5 released References: <20051013194207.1700.5269.XPN@orion.homeinvalid> <1129300207_2667@spool6-east.superfeed.net> <20051014170644.1803.75237.XPN@orion.homeinvalid> <1129316814_3173@spool6-east.superfeed.net> <20051015094021.2058.55430.XPN@orion.homeinvalid> Message-ID: <1129385149_1570@spool6-east.superfeed.net> > I'd add also config.txt ;-) I did but failed to include it in the list I posted .... One small config problem that I haven't figured out how to deal with .... I use a dark background with white foreground text .... When posting a reply in the compose/edit window the cursor is NOT visible .... Is there an incantation I can add to the config file that might render the cursor visible on a dark background ? -- Stanley C. Kitching Human Being Phoenix, Arizona ----== 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 steve at REMOVETHIScyber.com.au Mon Oct 3 13:38:47 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Tue, 04 Oct 2005 03:38:47 +1000 Subject: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please! References: Message-ID: On Mon, 03 Oct 2005 09:01:37 -0500, spiffo wrote: > The Main Issue in a nutshell > > I am a corporate developer, working for a single company. Got a new project > coming up and wondering if I should stay with Python for this new, fairly > large project, are jump back on the 'safe' M$ bandwagon using a dot net > language? What makes you think dot net will be any safer than the last half dozen "bet the farm" technologies Microsoft used? http://lwn.net/Articles/85797/?format=printable (Disclaimer: the author is my boss.) > Cross platform is NOT an issue, but COMPLETE control/compatability > with MsSql Server (current and future versions) certainly is. How can you have COMPLETE (your emphasis) control over software when you don't have access to the source code? [snip] > Ok, I LOVE python, so that is not the issue, but, I am getting very worried > about it's growth. I recently re-visted the web looking at alot of projects > I assumed would be up and running by now from over a year ago, such as Boa > Constructor, Iron Python etc... it seems all these projects get started, but > never finished. I'm not sure what you are trying to say here. Why do you care if "a lot of projects" are not finished? Do you need them? Why waste time worrying about projects that don't interest you? What do you mean by "finished"? To my mind, a finished project is an obsolete project that nobody is working on any more. Is that a good thing? Is MS SQL "finished"? > Also, more and more I need *complete* control of ms sql from my apps, which > is simply not available from the adodbapi module I got off the internet... > also, ms sql 2005 is getting ready to come out... what if the guy that wrote > adodbapi.py does not feel like upgrading it so it even works with MS SQL > SERVER 2005? Yeesh... you get the picture... Then you could offer him some money to support it. Or, if it is Open Source software, you could support it yourself, or hire a consultant to do it. How much is it worth to you? What would it cost you to *not* use Python? If it would cost you $100,000 to develop your app in Python, and $200,000 to develop it in the alternatives, then that gives you a war-chest of $100,000 you can spend. (Disclaimer: the company I work for does that sort of consulting and development work.) How much money will you save by dropping MS SQL licence fees by migrating to MySQL or Postgres? Will that money saved be enough to hire a full-time developer to keep adodbapi updated? -- Steven. From steve at REMOVETHIScyber.com.au Thu Oct 27 08:12:49 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Thu, 27 Oct 2005 22:12:49 +1000 Subject: Python vs Ruby References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> <1129883505.814349.306860@g44g2000cwa.googlegroups.com> Message-ID: On Wed, 26 Oct 2005 22:35:33 -0500, Andy Leszczynski wrote: > Steven D'Aprano wrote: > >> >> Every line = more labour for the developer = more cost and time. >> Every line = more places for bugs to exist = more cost and time. >> > > The place I work at the creation rate is not a problem - we could crank > out in the team 1000s lines a week. Good on you. I assume those thousands of lines are good ones, and not just churning out quantity instead of quality. In any case, no matter how fast you are, you will be faster if you have fewer lines to write. > Most time we spend is on maintanance > . This is where Pyton shines over Java/C++/Perl. It is easy to read thus > maintane. Yes. Now imagine how much less maintenance you'd have to do with fewer lines. Of course, it is easy to take this to extremes. One thing which is a red rag to me is when folks have written perfectly good, efficient, fast, readable code in four lines, and then obsess "how can I write this as a one-liner?". That way to the Dark Side goes: unreadable, cryptic, unmaintainable, buggy code. In any case, lines of code is a very poor metric for measuring programmer productivity. I'm not even so sure it is better than nothing -- in some cases, it is *worse* than nothing. -- Steven. From my_email_is_posted_on_my_website at munged.invalid Thu Oct 27 04:09:29 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Thu, 27 Oct 2005 08:09:29 GMT Subject: Microsoft Hatred FAQ References: <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> Message-ID: On Thu, 27 Oct 2005 07:58:42 GMT, Roedy Green wrote, quoted or indirectly quoted someone who said : >> I guess I don't understand what you're saying. Are you saying that >>Microsoft demanded you pay them per machine you sold under the table in the >>absence of a written contract that said that? Or are you simply saying that >>they changed the terms of your agreement when it came up for renewal? > >This was all under the table. The other thing to understand is almost no one buys straight from Microsoft. One wholesale side there are levels of distributors. The threat is if you don't comply and they catch you, they will see to it none of your wholesalers will sell to you. No contracts involved anywhere. -- Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching. From mail at eikepreuss.de Tue Oct 18 06:02:37 2005 From: mail at eikepreuss.de (Eike Preuss) Date: Tue, 18 Oct 2005 12:02:37 +0200 Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <1129491006.021102.43920@g14g2000cwa.googlegroups.com> <86zmp8zsjk.fsf@bhuda.mired.org> Message-ID: <3rjvdaFk0l1sU1@individual.net> John Bokma wrote: [snip] > > I see little difference with other big companies. You're right that there > is no excuse for such behaviour, but if MS isn't doing it, another company > will take their place. > And if companies are allowed to behave this way (because of your 'nice,fatalistic' argument), this will never change. Showing companies that you don't excuse such behavior would include not buying there products, using other products, whatever. To say that they are just playing the evil part that somebody *has* to play, is to excuse their behavior, IMO. ++ Eike From steve at REMOVEMEcyber.com.au Tue Oct 25 03:06:26 2005 From: steve at REMOVEMEcyber.com.au (Steven D'Aprano) Date: Tue, 25 Oct 2005 17:06:26 +1000 Subject: namespace dictionaries ok? References: <1130207021.408597.322950@g14g2000cwa.googlegroups.com> Message-ID: <435DD972.2040005@REMOVEMEcyber.com.au> Simon Burton wrote: > Yes! > > I do this a lot when i have deeply nested function calls > a->b->c->d->e > and need to pass args to the deep function without changing the > middle functions. If you find yourself passing arguments to functions just so they can in turn pass them on to other functions, you probably shouldn't be using deeply nested function calls and should be looking for another program structure. -- Steven. From onurb at xiludom.gro Wed Oct 12 09:53:26 2005 From: onurb at xiludom.gro (bruno modulix) Date: Wed, 12 Oct 2005 15:53:26 +0200 Subject: Very dumb question In-Reply-To: References: Message-ID: <434d1558$0$21685$626a54ce@news.free.fr> Laszlo Zsolt Nagy wrote: > I have a program with this code fragment: > > print len(data) > print data[:50] > raise SystemExit > > This prints: > > 20381 > > But if I change 50 to 51 > > print len(data) > print data[:51] > raise SystemExit > > then it prints > > 20381 > !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" > > After all, only the last 50 bytes are printed. The string is the same > (length 20381) in both cases. (snip > I'm sure it is my mistake, but I don't know what am I doing wrong. Do > you have an idea? I assume the code snippets are exact copy/paste so this is not a typo (like print data[51:] ...) - and I can't reproduce it here... even with a string of 20381 characters. mmm... type(data) ??? -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From samrobertsmith at gmail.com Mon Oct 10 01:20:44 2005 From: samrobertsmith at gmail.com (Shi Mu) Date: Sun, 9 Oct 2005 22:20:44 -0700 Subject: line Message-ID: <1d987df30510092220x2ab85939rd1a895718b619685@mail.gmail.com> There are four points with coordinates: 2,3;4,9;1,6;3,10. How to use Python to draw one perpendicular bisector between (2,3) and (4,9); the other perpendicular bisector between (1,6)?(3,10); then, makes the output like: l1 a b c l2 a b c (Note: l indicates the perpendicular bisector with equation ax + by = c.) Plus the intersection coordinates of the two perpendicular bisectors: x,y From prasad.c.iyer at capgemini.com Mon Oct 3 01:32:37 2005 From: prasad.c.iyer at capgemini.com (Iyer, Prasad C) Date: Mon, 3 Oct 2005 11:02:37 +0530 Subject: Python CGI Script Message-ID: I guess your python script isn't getting executed. a. I guess you might have to tweak the server if the script is not getting executed. b. Maybe your script is getting executed but you are not setting the "Content-type" parameter which is essential for browser that it is an html page. Note :- Set "Content-type" to "text/html" I guess this should work regards prasad chandrasekaran --- Cancer cures smoking -----Original Message----- From: Efrat Regev [mailto:efrat_regev at yahoo.com] Sent: Friday, September 30, 2005 4:20 PM To: python-list at python.org Subject: Python CGI Script Hello, I'm a data-structures course TA trying to write a python CGI script for automatically compiling and testing students' projects. Unfortunately, I've run into some questions while writing this, which I couldn't solve with the various (and helpful) python-CGI documentation. (It's possible that I'm posting to the wrong group; if so, I'd appreciate suggestions for the appropriate group.) 1. In my HTML page, I have the following:
....
In the above, submission_processor.py is the python CGI script. I didn't write a URL in the action field, since I'm first testing everyting on a local machine (running FC4). The first line of submission_processor.py is #!/usr/bin/python and I've done chmod +x submission_processor.py When I hit the "submit" button, my browser (Firefox on FC4) doesn't run the script; it asks me whether it should open submission_processor.py or save it to disk. I couldn't figure out why. 2. My HTML page has the option for an instructor to list the various submissions and scores. Obviously, this should be inaccessible to students. The instructor has a password for doing this, therefore. Suppose I place the password inside a python script, and give this script only +x permission for others. Is this adequate as far as security? Thanks in advance for answering these questions. Efrat This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. From steve at REMOVEMEcyber.com.au Tue Oct 4 03:50:56 2005 From: steve at REMOVEMEcyber.com.au (Steven D'Aprano) Date: Tue, 04 Oct 2005 17:50:56 +1000 Subject: Python TNEF (winmail.dat attachment access) library? References: Message-ID: <43423460.9000201@REMOVEMEcyber.com.au> Larry Bates wrote: > Why not write Python class that uses CTypes and make it > available as a recipe? From a performance standpoint it > is unlikely you can do better than to call the .dll and > have it do the work for you. Just a suggestion. A pure Python solution will be cross-platform, while calling a Windows DLL will only work under Windows. The optimal solution will be to call the DLL when it is available, and fall back on pure Python if it is not. -- Steven. From codecraig at gmail.com Wed Oct 5 15:52:56 2005 From: codecraig at gmail.com (Java and Swing) Date: 5 Oct 2005 12:52:56 -0700 Subject: Swig and pointers Message-ID: <1128541976.495441.46140@f14g2000cwb.googlegroups.com> I've tried sending a email to the swig mailing list 3 times...but it never seems to get it...not sure what is going on, still looking into it. Until then... I now have a C function such as... int doIt(char *a, MY_DIGIT **digit) { ... } so I am trying to figure out how to pass in that "digit" pointer. My SWIG interface file looks like... extern int doIt(char *a, MY_DIGIT **digit); %include cpointer.i %pointer_functions(MY_DIGIT, md_prt); %typemap(in) (char *a, MY_DIGIT **argv) { /* Check if is a list */ if (PyList_Check($input)) { int i; $1 = PyList_Size($input); $2 = (MY_DIGIT **) malloc(($1+1)*sizeof(long *)); for (i = 0; i < $1; i++) { PyObject *o = PyList_GetItem($input,i); if (PyString_Check(o)) $2[i] = PyString_AsString(PyList_GetItem($input,i)); else { PyErr_SetString(PyExc_TypeError,"list must contain strings"); free($2); return NULL; } } $2[i] = 0; } else { PyErr_SetString(PyExc_TypeError,"not a list"); return NULL; } } %typemap(freearg) (char *a, MY_DIGIT **argv) { free((MY_DIGIT *) $2); } ..from Python I am trying >> ptr = [] >> doIt("blah", ptr) I thought this was the correct approach as described here: http://www.swig.org/Doc1.3/SWIGDocumentation.html#Python_nn59 However, python comes back and says "TypeError: argument number 2: a 'MY_DIGIT **' is expected, 'list([])' is received" ..any ideas? Thanks for all the help. The python community has been great. From steve at REMOVETHIScyber.com.au Sun Oct 9 07:27:37 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 09 Oct 2005 21:27:37 +1000 Subject: Function decorator that caches function results References: <7x4q7rt3yl.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 09 Oct 2005 02:49:38 -0700, Paul Rubin wrote: >> I'm curious... where does cache live after you use cache_function to >> memoize some function? It doesn't appear to be an attribute of the newly >> memoized function, nor does it look like a global variable. > > It's in the closure returned by cache_function. What's a closure? Googling on define:closure isn't very useful. There are a *lot* of different meanings for closure, none of them to do with programming. No, wait, I tell a lie -- Wikipedia to the rescue again: http://en.wikipedia.org/wiki/Closure_(programming) I notice that type(some_closure) and type(ordinary_function) both return the same result, . I also notice that both the closure and ordinary functions have an attribute "func_closure". Is there a way to tell which is a closure and which is not? In my tests, the ordinary function has func_closure == None, but I don't know if that will always be the case of just for my tests. If I wanted to inspect the value of cache, where would I find it? In other words, if I say some_closure.SOMETHING I would get cache... what should SOMETHING be set to? That assumes that cache can be seen in this way. If it can't, is this a way to create "really private" variables in Python? -- Steven. From deets at nospam.web.de Wed Oct 26 12:56:40 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 26 Oct 2005 18:56:40 +0200 Subject: Windows vs Linux [was: p2exe using wine/cxoffice] In-Reply-To: References: Message-ID: <3s9qqaFn6solU1@uni-berlin.de> > Thanks to both of you. But that much I already knew. It's not > that I have *no* knowledge about readline: I did at least > read the manuals when I got stuck! But as far as I can tell > from my experience and from the docs -- and I'm not near a > Linux box at the mo -- having used ctrl-r to recall line x > in the history, you can't just down-arrow to recall x+1, x+2 etc. > Or can you? Subsequent pressing of C-r will show you items further down the history that contain the same substring. Use C-s to search the other direction. Diez From http Fri Oct 14 20:47:41 2005 From: http (Paul Rubin) Date: 14 Oct 2005 17:47:41 -0700 Subject: deleting a parameter's name as it is passed to a function References: <1129336848.353805.176360@o13g2000cwo.googlegroups.com> Message-ID: <7xfyr3mwr6.fsf@ruckus.brouhaha.com> "Amir Michail" writes: > The idea is to garbage collect the object as soon as possible, and this > may be sooner than when dosomestuff returns. If it's a parameter to dosomestuff, then there's still a reference until dosomestuff returns. Simply getting rid of the name only frees a dictionary entry. From bonono at gmail.com Wed Oct 26 07:13:35 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 26 Oct 2005 04:13:35 -0700 Subject: Windows vs Linux [was: p2exe using wine/cxoffice] In-Reply-To: References: Message-ID: <1130325215.569388.34720@o13g2000cwo.googlegroups.com> Tim Golden wrote: > As it happens, (and I suspect I'll have to don my flameproof suit here), > I prefer the Windows command line to bash/readline for day-to-day use, > including in Python. Why? Because it does what I can't for the life of > me get readline to do: you can type the first few letters of a > previously-entered command and press F8. This brings up (going backwards > > with further presses) the last command which starts like that. And > *then* > you can just down-arrow to retrieve the commands which followed it. > If someone can tell me how to do this with bash/readline I will be > indebted to them and it will increase my chances of switching to Linux > a bit! (Although not at work where I have no choice!) I use XP as my main desktop(because of many fine details) then VNC/X into my linux box. But command line in Windows is in no way in the same league as *nix shell. Use for command completion and up/down arrow or to search for history. _____________________________________________________________________ From martin.witte at gmail.com Sun Oct 2 18:10:40 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 2 Oct 2005 15:10:40 -0700 Subject: Python for search engine development In-Reply-To: <1128288465.580210.35460@g49g2000cwa.googlegroups.com> References: <1128288465.580210.35460@g49g2000cwa.googlegroups.com> Message-ID: <1128291039.914526.68840@o13g2000cwo.googlegroups.com> Well, Google applies some Python in their implementation, see http://www-db.stanford.edu/~backrub/google.html From g.franzkowiak at onlinehome.de Fri Oct 28 16:16:56 2005 From: g.franzkowiak at onlinehome.de (g.franzkowiak) Date: Fri, 28 Oct 2005 22:16:56 +0200 Subject: popen2 In-Reply-To: <1130524659.070912.256550@o13g2000cwo.googlegroups.com> References: <1130524659.070912.256550@o13g2000cwo.googlegroups.com> Message-ID: David Wahler schrieb: > g.franzkowiak wrote: > >>I start a process in my application with popen2.popen3('MyOtherProcess'). >>That's ok, but what can I do if the other process is running ? >>Can I fetch some information and start with that ? >> >>gerd > > > It's not clear what you're asking for. Could you please clarify? > > -- David > If starts a process with popen2.popen3('myprogram') and myprogram.exe is running before, I've a connection to the second process, not to the first. I can find the process by name before I start a process with popen2..., but how bcan I connect t this process with a pipe ? gerd From mde at micah.elliott.name Wed Oct 19 16:14:18 2005 From: mde at micah.elliott.name (Micah Elliott) Date: Wed, 19 Oct 2005 13:14:18 -0700 Subject: How to organize Python files in a (relatively) big project In-Reply-To: References: Message-ID: <20051019201418.GB27602@kitchen.client.attbi.com> On Oct 19, Jarek Zgoda wrote: > How to install this structure eg. on Linux? What layout do you > recommend? It's tempting to use /opt hierarchy for installation > target (as it gives relatively much freedom within application > directory), but many administrators are reluctant to use this > hierarchy and prefer more standarized targets, such as /usr or > /usr/local. Read about (and use) the Python-provided distutils, and let it do the work for you. In particular, discusses installation location. The file name is a misnomer; it's equally applicable to linux. It allows users to easily specify the installation prefix. The default should be the value of "sys.prefix". Note that your modules/packages will be installed within your python installation under its site-packages/ directory. -- _ _ ___ |V|icah |- lliott http://micah.elliott.name mde at micah.elliott.name " " """ From no at spam Wed Oct 5 14:52:41 2005 From: no at spam (Mike) Date: Wed, 05 Oct 2005 14:52:41 -0400 Subject: Replacing utf-8 characters In-Reply-To: References: <1128522921.72009@nntp.acecape.com> Message-ID: <1128538344.802444@nntp.acecape.com> For example this is what I am trying to do that is not working. The contents of link is the reuters web page, containing "/news/newsArticle.aspx?type=businessNews&amp;storyID=2005-10-05T151245Z_01_HO548006_RTRUKOC_0_UK-AIRLINES-BA.xml" link = link.replace('&amp;','&') But if I now view the the contents link it shows it the same as when it was assigned. Richard Brodie wrote: > "Mike" wrote in message news:1128522921.72009 at nntp.acecape.com... > > >>However when I pull it into python the URL ends up looking like this >>(notice the & instead of just & in the URL) >> >>Any ideas? > > > Some code would be helpful: the "&" is in the page source to start > with (which is as it ought to be). What are you using to parse the HTML? > > From michael+USENET at www.heiming.de Sat Oct 15 14:27:15 2005 From: michael+USENET at www.heiming.de (Michael Heiming) Date: Sat, 15 Oct 2005 20:27:15 +0200 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: <39u723-ldp.ln1@news.heiming.de> In comp.os.linux.misc John Bokma : > Michael Heiming wrote: >> The only thing positive about M$ entering the market, probably >> due to their ineffective programming style they pushed Intel into >> producing pretty fast while cheapo CPUs. > Amazing, I thought Xah Lee was the only one able to fit so much BS in one > sentence. You them to have a talent to piss-off people with just a single terse contribution. ;-) >> Ironically exactly this >> is the key to Linux/*BSD success in the unix server market. ;) > Yeah, right. Good riddance! -- Michael Heiming (X-PGP-Sig > GPG-Key ID: EDD27B94) mail: echo zvpunry at urvzvat.qr | perl -pe 'y/a-z/n-za-m/' #bofh excuse 146: Communications satellite used by the military for star wars. From claudio.grondi at freenet.de Wed Oct 12 19:05:59 2005 From: claudio.grondi at freenet.de (Claudio Grondi) Date: Wed, 12 Oct 2005 23:05:59 -0000 Subject: Python source code for direct access to raw sectors of harddrives (MFT, boot sector, etc.) in Linux/Windows References: <3r04p5Fh4lshU1@individual.net> Message-ID: <3r5e1rFhts3qU1@individual.net> Python code for direct access to raw sectors of harddrives (MFT, boot sector, etc.) in Linux/Windows: http://people.freenet.de/AiTI-IT/Python/HowTo_AccessRawSectorsOfPhysicalDrives_onLinux.py and http://people.freenet.de/AiTI-IT/Python/HowTo_AccessRawSectorsOfPhysicalDrives_onWindows.py Claudio http://wiki.python.org/moin/ClaudioGrondi From my_email_is_posted_on_my_website at munged.invalid Wed Oct 12 18:08:24 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 12 Oct 2005 22:08:24 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <868xx3m2ve.fsf@bhuda.mired.org> <86achikzg5.fsf@bhuda.mired.org> Message-ID: On Sun, 09 Oct 2005 20:06:34 -0400, Mike Meyer wrote or quoted : >Nah, I've just know people who spend a lot of time - and money - >dealing with spam, and we've discussed these issues at great >length. You haven't proposed anything that hasn't been proposed >before, and rejected for various reasons. As if what we are living with now were preferable to what I propose. It is inertia. It is herd mentality that dare not leap out of the current rut. It is not a particularly difficult technical problem. It is figuring out how to get people to switch over. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From fredrik at pythonware.com Tue Oct 25 06:13:24 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 25 Oct 2005 12:13:24 +0200 Subject: Upgrading 2.4.1 to 2.4.2 References: <20051017192011.28785.qmail@web50206.mail.yahoo.com><1129690538.026623.28230@o13g2000cwo.googlegroups.com><1129712636.124150.248200@g44g2000cwa.googlegroups.com> Message-ID: >> Hi, I'm new to python and just upgraded python on my system from 2.3 to 2.4. >> My platform is Linux-2.6.9-1.667smp-i686-with-redhat-3-Heidelberg. >> >> Is there any way to inherit (share?) all extensions and additional modules >> the my 2.3 have? (of course, beside re-installing everything) > > binary extensions should, in general, be recompiled for each new X.Y release, > so it's usually best to reinstall them. just noted that your subject doesn't match the rest of your message; if you're doing a minor upgrade (X.Y.Z), it should be safe to install the new version over the old one, and all existing extensions should continue to work. (I say "should", but 2.4 => 2.4.1 did break a lot of things for me; 2.3 => 2.4 was a much cleaner upgrade. most of the 2.4.1 issues are fixed in 2.4.2, so it was probably just a temporary glitch) From auch-ich-m at g-kein-spam.com Tue Oct 18 18:02:44 2005 From: auch-ich-m at g-kein-spam.com (=?UTF-8?B?QW5kcsOp?= Malo) Date: Wed, 19 Oct 2005 00:02:44 +0200 Subject: unittest of file-reading function References: Message-ID: <3655446.HhvzFuQM1f@news.perlig.de> * Helge Stenstroem wrote: > Say I have a function > > def f(filename): > result = openFileAndProcessContents(filename) > return result > > Can that function be unit tested without having a real file as input? > Something along the lines of > > import unittest > class tests(unittest.TestCase): > def test1(self): > fileContents = "bla bla bla\nmore bla bla bla" > ??? # make f read this string instead of opening a file > expected = expectedResult > result = f(filename) > self.assertEqual(result, expected) > > One possibility would be to make the unit test write to a temporary > file. Are there better alternatives? You can also just replace or shadow the file/open builtin (that's what I'm doing). Something like: def test1(self): import StringIO fileContents = "bla bla bla\nmore bla bla bla" def myfile(name, mode, buffering): return StringIO.StringIO(fileContents) testedmodule.file = myfile try: expected = expectedResult result = f(filename) finally: del testedmodule.file self.assertEqual(result, expected) (if you're using open, replace .file with .open) (testedmodule is of course the module where the file call happens) nd -- die (eval q-qq[Just Another Perl Hacker ] ;-) # Andr? Malo, # From deets at nospam.web.de Mon Oct 17 13:28:01 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 17 Oct 2005 19:28:01 +0200 Subject: Installing Python at Work In-Reply-To: <1129561955.452114.53290@g44g2000cwa.googlegroups.com> References: <1129561955.452114.53290@g44g2000cwa.googlegroups.com> Message-ID: <3ri592Fj8j0tU1@uni-berlin.de> Nikola wrote: > I'm currently learning Python for my own use. > I'm considering installing it on a work laptop, knowing that it is > non-licensed, distributable software. Here comes a little bit nitpicking: Python is not "non-licensed" - it has a license, which makes it available for you free and without any costs and some other benefist (like the ability to create commercial programs with it) The difference doesn't matter for you practically (for your current endeavours), but an enormous one in legalese... Diez From mambuhl at earthlink.net Wed Oct 26 04:20:27 2005 From: mambuhl at earthlink.net (Martin Ambuhl) Date: Wed, 26 Oct 2005 08:20:27 GMT Subject: a Haskell a Day In-Reply-To: <1130312303.713737.160830@g44g2000cwa.googlegroups.com> References: <1130312303.713737.160830@g44g2000cwa.googlegroups.com> Message-ID: Xah Lee wrote: > This is my learning notes on Haskell. I call it a-Haskell-a-day. No one in any of comp.lang.perl.misc, comp.lang.python, comp.lang.c, comp.lang.java.programmer, comp.unix.programmer gives a damn about your adventures in Haskell. If you must mastubate, please do so in private. From kevin.bell at slcgov.com Thu Oct 6 12:39:21 2005 From: kevin.bell at slcgov.com (Bell, Kevin) Date: Thu, 6 Oct 2005 10:39:21 -0600 Subject: So far Message-ID: <2387F0EED10A4545A840B231BBAAC722607F16@slcimail1.slcgov.com> I like pythonWin other than the white background where you write your scripts, because after awhile it's bad on the eyes. Does anyone know of a free IDE that will allow control of this, as well as the coloring of keywords, etc? -----Original Message----- From: python-list-bounces+kevin.bell=slcgov.com at python.org [mailto:python-list-bounces+kevin.bell=slcgov.com at python.org] On Behalf Of Christophe Sent: Thursday, October 06, 2005 9:50 AM To: python-list at python.org Subject: Re: So far CppNewB a ?crit : > I am absolutely loving my experience with Python. Even vs. Ruby, the syntax > feels very clean with an emphasis on simplification. > > My only complaint is that there doesn't appear to be a great commercial IDE > for the language. I've tried Komodo, etc and they are nice applications, > but they don't feel like they give me the "power" like a Visual Studio or > Delphi (I wish I could articulate better the differences). Finding a > descent GUI builder has been a challenge as well. Most of them have support > for Dialogs, but what about more complex UI's? I may need a resizable frame > within a resizable frame? I haven''t found a GUI builder with a great feel > yet. > > Other than that, my experience has been wonderful. Even after my > complaints, I plan on sticking with Python for a while. Try PyQT with eric3 as an IDE. http://www.die-offenbachs.de/detlev/eric3.html -- http://mail.python.org/mailman/listinfo/python-list From nyamatongwe+thunder at gmail.com Mon Oct 17 20:14:24 2005 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Tue, 18 Oct 2005 00:14:24 GMT Subject: win32api.FindFiles Win2003, problem with Short Name In-Reply-To: <1129560250.458465.175810@f14g2000cwb.googlegroups.com> References: <1129245942.185252.171220@o13g2000cwo.googlegroups.com> <1129315861.886705.116980@g44g2000cwa.googlegroups.com> <1129560250.458465.175810@f14g2000cwb.googlegroups.com> Message-ID: Frank Borell: > My initial issue was trying to rename/move files on a SAN that were > written from Mac's. I've never used a SAN. It is possible that it has its own name system and what you are seeing is the result of different views of that. > While the easier messed up files names were easy to > convert and move, I quickly came across a few types that were not. > Files with spaces at the end seemed to only be solved with the > win32api.FindFiles(fullpath + '*'). Does performing a dir /X from the command line show the short names from the 2003 system? If so it means that there are APIs capable of finding the information so I'd be trying to use ctypes to call the underlying wide character FindFirstFileExW function. > ^2aCOSBY SON PROFILE^2fNYT18|A^2ACOSB.1A7 This was hex escaped from *COSBY SON PROFILE/NYT18. Neil From hancock at anansispaceworks.com Tue Oct 11 21:34:48 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Tue, 11 Oct 2005 20:34:48 -0500 Subject: [PIL]: Question On Changing Colour In-Reply-To: <00fe01c5cf7c$410750e0$69820257@Gavana> References: <00fe01c5cf7c$410750e0$69820257@Gavana> Message-ID: <200510112034.48195.hancock@anansispaceworks.com> On Wednesday 12 October 2005 05:28 pm, Andrea Gavana wrote: > Now my question: is it possible to transform the pixels colours in order to have another basic colour (say blue)? In other words, the predominant colour will become the blue, with other pixels in a brighter or darker blue to give the same 3D effects. Have a look at the colorsys module. This will allow you to define colors in HSV space, then convert to RGB for image generation. What you want to do sounds like changing only the Hue (H) of the colors. PIL will provide means for efficiently mapping base colors to target colors (IIRC, you'll probably use the 'point' method of Image objects, but check the manual). Once you have that, you can just decide on hues for each button, then do an individual replacement like this: new_hue # your 'basic color', just the hue part rgb_base # color from the basic button image rgb_new # the new color you want to replace rgb_base with rgb_new = hsv_to_rgb( (new_hue,) + rgb_to_hsv(rgb_base)[1:]) Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From mwm at mired.org Sat Oct 29 18:36:47 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 29 Oct 2005 18:36:47 -0400 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <3sf070Fo0klqU1@individual.net> <3sg8hiFmvbo7U1@individual.net> <864q70evci.fsf@bhuda.mired.org> <3si036Fofks2U1@individual.net> Message-ID: <86k6fwc5mo.fsf@bhuda.mired.org> "Paul Watson" writes: > "Mike Meyer" wrote in message > news:864q70evci.fsf at bhuda.mired.org... >> "Paul Watson" writes: > ... >> Did you do timings on it vs. mmap? Having to copy the data multiple >> times to deal with the overlap - thanks to strings being immutable - >> would seem to be a lose, and makes me wonder how it could be faster >> than mmap in general. > > The only thing copied is a string one byte less than the search string for > each block. Um - you removed the code, but I could have *sworn* that it did something like: buf = buf[testlen:] + f.read(bufsize - testlen) which should cause the the creation of three strings: the last few bytes of the old buffer, a new bufferfull from the read, then the sum of those two - created by copying the first two into a new string. So you wind up copying all the data. Which, as you showed, doesn't take nearly as much time as using mmap. Thanks, http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From john at castleamber.com Mon Oct 17 18:41:36 2005 From: john at castleamber.com (John Bokma) Date: 17 Oct 2005 22:41:36 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <43518dc6.95550404@news.oz.net> <4352899f.160023952@news.oz.net> Message-ID: bokr at oz.net (Bengt Richter) wrote: > On 16 Oct 2005 00:31:38 GMT, John Bokma wrote: > >>bokr at oz.net (Bengt Richter) wrote: >> >>> On Tue, 04 Oct 2005 17:14:45 GMT, Roedy Green >>> wrote: >>> >>>>On Tue, 23 Aug 2005 08:32:09 -0500, l v wrote or quoted >>>>: >>>> >>>>>I think e-mail should be text only. >>> I think that is a useful base standard, which allows easy creation >>> of ad-hoc tools to search and extract data from your archives, etc. >>>> >>>>I disagree. Your problem is spam, not HTML. Spam is associated >>>>with HTML and people have in Pavlovian fashion come to hate HTML. >>>> >>>>But HTML is not the problem! >>> Right, it's what the HTML-interpreting engines might do that is >>> the problem. >> >>You mean the same problem as for example using a very long header in >>your email to cause a buffer overflow? That is possible with plain >>ASCII, and has been done. > Are you trolling? No, I don't mean the same problem. > What an HTML interpreter does by _design_ is not in the same category > as an implementation error enabling a root exploit. Ok, what do you think are the bad things in HTML design? (For email that is). I can name only two: 1 - remote loading of objects 2 - when a user clicks on a link, this can be seen as a confirmation. The latter is also possible in the email clients I have used when plain text is used. Ok, you can say that in HTML you can hide somewhat the destination, e.g.
Check out this . OTOH, you are not forced not to read the status bar. [ ... ] > Don't get me wrong, I said "all good stuff," as far as control of > presentation is concerned. And I would be happy to have nice graphic > email if I could get it as a self-contained file from my ISP's mail > server, and I had a presentation engine involved that I knew was > guaranteed to stick to presentation work without communicating over > the web or doing anything else without my knowledge. > > I don't see any technical obstacle to that, but HTML is not designed > to be the solution to that. Of course: I can compose an HTML file which has the graphics embedded in HTML which works in the client I am using. Another option is to include the graphics as attachements (this works). I am convinced this also works for stylesheets and any other object. So in short, it's possible to get a self-contained email. [ pdf ] >>Ah, and that's exploit free? > That's not the issue. All programs can have the kind of exploit > possibilities that you are talking about. A program with the single > purpose of interpreting a page description and presenting it > graphically is easier to eliminate exploitable vulnerabilities from > than a program that involves a lot of additional stuff. I thought it was possible to add a remote link to PDF (but I couldn't make one with OOo -> export pdf). But I am afraid that as soon as PDF is taking over the role of HTML in email, it will certainly going to support things you consider harmfull (and are in some occasions, I mean, I agree that tracking of images in spam is a bad thing). >>>>Program listings are much more readable on my website. >>> IMO FOSS pdf could provide all the layout benefits while >>> avoiding (allowing for bugs) all the downsides of X/HTML in emails. >> >>Amazing, so one data format that's open is better compared to another >>open data format based on what? > I take it you don't understand the difference between pdf and html? > > A primary thing is the monitorable data-moving activity that is > involved. A pdf can have links, but they are not followed (not > counting what closed source proprietary softare might risk a PR black > eye doing) in the process of opening and presenting the document to > you. And a link in an HTML file is? (Ok, there are so called caching systems that do this with browsers). > The whole file comes as a single unit normally As I stated, this is possible with HTML, at least Firefox does support inline images (data scheme). CSS can already be included in the file itself. > (though I could see the > temptation to implement automatic font downloads and enable font-bugs > like web-bugs based on that, though in a FOSS implementation, such > [mal]features could easily be made optional). > > You could say features can be optional re HTML CSS and JS and all the > other automatic web-accessing and other features of HTML, but by the > time you made them all optional and turned them off, you wouldn't see > the HTML-author's intended presentation. That is not the case with > pdf. Also, a single pdf file would be coming from one place. There is > not an on-the-fly gathering of elements that you have to use a special > tool to determine for sure where all the requests to get them went, or > to prevent them from going, and having the activity logged, not to > mention what the interpretation of unknown elements might do. If it's not possible to remote link to an image in PDF, I wouldn't be amazed that if it is replacing HTML in email, such a thing will be added. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From desparn at wtf.com Mon Oct 10 14:46:19 2005 From: desparn at wtf.com (Rick Wotnaz) Date: Mon, 10 Oct 2005 14:46:19 -0400 Subject: convert char to byte representation References: <434ab2f6$1@nntp0.pdx.net> Message-ID: Scott David Daniels wrote in news:434ab2f6$1 at nntp0.pdx.net: > Philipp H. Mohr wrote: >> I am trying to xor the byte representation of every char in a >> string with its predecessor. But I don't know how to convert a >> char into its byte representation. > ord('a') == 97; chr(97) == 'a'; "ord" gives you the value of the > byte. > >> e.g. everything between $ and * needs to be xor: >> $GPGSV,3,1,10,06,79,187,39,30,59,098,40,25,51,287,00,05,25, >> 103,44* >> to get the checksum. > > Probably you want a byte-array here, rather than going > char-by-char. Try: > import array > base = ('$GPGSV,3,1,10,06,79,187,39,30,59,098,' > '40,25,51,287,00,05,25,103,44*') > bytes = array.array('b', base[1 : -1]) > for i in reversed(range(len(bytes))): > bytes[i] ^= bytes[i-1] > result = bytes.tostring() > > --Scott David Daniels > scott.daniels at acm.org > What is the byte representation of 287? -- rzed From jabel at plus.net Wed Oct 12 03:56:41 2005 From: jabel at plus.net (John Abel) Date: Wed, 12 Oct 2005 08:56:41 +0100 Subject: Make SimpleXMLRPCServer Require Auth? Message-ID: <434CC1B9.2030005@plus.net> Hi, I implemented a SimpleXMLRPCServer, modified it slightly to restrict clients based on their IP, but I need to take it a stage further, and add user authentication. I would appreciate any pointers as to how I might go about this, or any packages which already provide this. I'm guessing that I'll need to make changes to BaseHTTPServer. Thanks J From duncan.booth at invalid.invalid Wed Oct 5 07:16:47 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Oct 2005 11:16:47 GMT Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> <434245F5.6060500@REMOVEMEcyber.com.au> <7xr7b14lk0.fsf@ruckus.brouhaha.com> <7xu0fx9l7y.fsf@ruckus.brouhaha.com> Message-ID: Antoon Pardon wrote: > As far as I understand people don't like global very much so I don't > expect that a second keyword with the same kind of behaviour has > any chance. That's why the behaviour I suggest is different than the current behaviour of global. Arguments against global (it is the only non-executable statement in Python & it is confusing because people don't understand the declaration goes inside the function instead of at global scope) don't apply. > >> The >> 'global' keyword itself would be much improved if it appeared on the >> same line as the assignment rather than as a separate declaration. >> >> e.g. something like: >> >> var1 = 0 >> >> def f(): >> var2 = 0 >> >> def g(): >> outer var2 = 1 # Assign to outer variable >> global var1 = 1 # Assign to global > > And what would the following do: > > def f(): > > var = 0 > > def g(): > > var = 1 > > def h(): > > outer var = 2 * var + 1 > > h() > print var > > g() > print var > > f() > It would follow the principle of least surprise and set the value of var in g() of course. The variable in f is hidden, and if you didn't mean to hide it you didn't need to give the two variables the same name. So the output would be: 3 0 (output verified by using my hack for setting scoped variables:) ------------------------------- from hack import * def f(): var = 0 def g(): var = 1 def h(): assign(lambda: var, 2 * var + 1) h() print var g() print var f() ------------------------------- From yuxi at ece.gatech.edu Mon Oct 31 04:36:37 2005 From: yuxi at ece.gatech.edu (Yu-Xi Lim) Date: Mon, 31 Oct 2005 04:36:37 -0500 Subject: Why the nonsense number appears? In-Reply-To: <1130749726.707175.293040@g43g2000cwa.googlegroups.com> References: <1130749726.707175.293040@g43g2000cwa.googlegroups.com> Message-ID: Johnny Lee wrote: > Why are there so many nonsense tails? thanks for your help. I guess you were expecting 0.039? You first need to understand floating point numbers: http://docs.python.org/tut/node16.html What you see are the effects of representation errors. The solution is presented here: http://www.python.org/peps/pep-0327.html But briefly, it means your code should read: from decimal import * t1 = "1130748744" t2 = "461" t3 = "1130748744" t4 = "500" time1 = t1+"."+t2 time2 = t3+"."+t4 print time1, time2 Decimal(time2) - Decimal(time1) From fredrik at pythonware.com Sat Oct 15 17:06:14 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 15 Oct 2005 23:06:14 +0200 Subject: Some set operators References: <1129408019.100885.323870@g47g2000cwa.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > Sometimes I suggest to add things to the language (like adding some set > methods to dicts), but I've seen that I tend to forget the meaning of > six set/frozenset operators: > > s & t s &= t > s | t s |= t > s ^ t s ^= t > > My suggestion is to remove them, and keep them only as explicit > non-operator versions (.symmetric_difference(), .update(), > .intersection_update(), etc). But maybe now it's too much late to > remove them... Maybe someone gentle can explain me the advantage > of having/keeping them. &, |, and ^ are Python's standard operators for AND, OR, and XOR. they make as much sense for sets as they do for bitpatterns... From aleax at mail.comcast.net Thu Oct 13 09:12:06 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Thu, 13 Oct 2005 15:12:06 +0200 Subject: Adding a __filename__ predefined attribute to 2.5? References: <1129098667.336115.303060@g47g2000cwa.googlegroups.com> <1129103007.870187.101790@g44g2000cwa.googlegroups.com> <1129150883.303899.259570@g43g2000cwa.googlegroups.com> <1h4ce9x.v65tbpm7xivfN%aleax@mail.comcast.net> <1129154738.455062.140750@f14g2000cwb.googlegroups.com> Message-ID: <1h4dm1w.3l3ch2p04dd4N%aleax@mail.comcast.net> Rune Strand wrote: > Ok, Alex. I know a good explanation when I see one. Thanks! You're welcome! I've tried to give good (but shorter!-) explanations in the Nutshell, too, but of course it's easier to aim a specific explanation to a specific questioner than to try and clarify "everything" for "everybody" (particularly because, when posting, I'm not forced to be concise as I am when writing books or articles, so I can aim more relentlessly for completeness and precision...). Alex From dalloliogm at gmail.com Wed Oct 26 09:05:31 2005 From: dalloliogm at gmail.com (Giovanni Dall'Olio) Date: 26 Oct 2005 06:05:31 -0700 Subject: Windows vs Linux [was: p2exe using wine/cxoffice] In-Reply-To: References: Message-ID: <1130331931.391249.96680@g49g2000cwa.googlegroups.com> Tim Golden ha scritto: > As it happens, (and I suspect I'll have to don my flameproof suit here), > I prefer the Windows command line to bash/readline for day-to-day use, > including in Python. Why? Because it does what I can't for the life of > me get readline to do: you can type the first few letters of a > previously-entered command and press F8. This brings up (going backwards > > with further presses) the last command which starts like that. And > *then* Argh!! ;) How about reading a simple tutorial on bash? You can use even '!' to recall other commands in history. For example, you can type '!p' and it will call the last command starting with 'p', without having to search for it (and if you want, you can use CTRL+r) You can use '!!' to recall the last command, or '!-#' for the other ones. You can define single arguments, like !-#:2, to call only parts of a old command. With bash, you can repeat instructions (using 'for', 'while', and so on) and use some basic logic to determine if launching them. You can call easily any program installed in the computer, or in other ones, too. Really, are you joking? ;) Do you know that you can use the '' key to auto-fill a command? isn't this useful? I tried to use the windows command line sometimes, but I found it so slow and uncorfortable, that I thought that noone can use it. I really don't understand what you want to say with this topic! p.s. if you want a tip, leave using desktop manager and begin using the command line. You will like it. From OurLab at gmail.com Fri Oct 28 23:54:04 2005 From: OurLab at gmail.com (Alex) Date: 28 Oct 2005 20:54:04 -0700 Subject: pickling class instances with __slots__ Message-ID: <1130558044.085887.104400@g43g2000cwa.googlegroups.com> I would greatly appreciate an advice on the following matter that was very much discussed circa 2002 but in all this discussion I could not find the final answer with a code example. Neither I can find it in Python documentation. I have a series of new classes with child-parent relationship and each has unique __slots__. They don't have __dict__ . I need to be able to pickle and unpickle them. As far as I could understand, I need to provide __getstate__ and __setstate__ methods for each class. Is there a universally accepted code for each method? If so, what is it? If there is no standard, what works? TIA Alex From steve at holdenweb.com Thu Oct 20 06:48:37 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 20 Oct 2005 11:48:37 +0100 Subject: Minimizing Connection reset by peer exceptions In-Reply-To: <1129804084.245716.242040@g47g2000cwa.googlegroups.com> References: <1129777447.614500.232050@z14g2000cwz.googlegroups.com> <1129804084.245716.242040@g47g2000cwa.googlegroups.com> Message-ID: Ben Sizer wrote: > mirandacascade at yahoo.com wrote: > > >>Occasionally (perhaps 5% of the time) the following exception gets >>raised: >> >>(10054, 'Connection reset by peer') > > > Generally this just means the connection has closed through some > unusual means, perhaps by being turned off, or a network cable being > unplugged, or a timeout along the way, etc. 5% is a high figure, but > perhaps you connect to hosts that are unreliable for some reason. > > You don't have control over this really; just make sure you handle the > exception. Such is life, when dealing with networking. > Do note, though, that if you aren't using some means (threading, forking, etc) of handling the connections asynchronously then your server will normally only queue a very limited number of connections (usually 5 at most). So if your service takes a while to run then it's possible that connection requests will be rejected when the queue is full, which might *possibly* result in the error you are seeing. Feel free to ignore this if you only have one client at a time. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From apardon at forel.vub.ac.be Mon Oct 24 06:24:16 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 24 Oct 2005 10:24:16 GMT Subject: Microsoft Hatred FAQ References: <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> Message-ID: Op 2005-10-23, David Schwartz schreef : > > "Roedy Green" wrote in > message news:s3oll1tbve3t5h4c8eghbqihsuuusj72nc at 4ax.com... > >> On Sat, 22 Oct 2005 16:10:24 -0700, "David Schwartz" >> wrote or quoted : > >>> If the deal didn't give you more than it cost you, all you had to do >>> was >>>say 'no'. I understand the frustration at being forced to pay for >>>something >>>what it is worth. > >> The choice was go along with MS arm twisting or go out of business. > > Only because the product they were providing you was so important you > were unable to do business without it. > >> I call that extortion. > > Microsoft had something you need so badly that you could not go into > business without it. So they demanded from you that you pay them what their > software was actually worth to you. That is not extortion. Everyone who > sells something tries to get the maximum possible value for it. If a company wants to be paid for things it didn't deliver, then I think that is extortion. Microsoft want te be paid a license on windows for P.C.'s that were sold without windows. -- Antoon Pardon From lassevk at gmail.com Fri Oct 7 02:52:48 2005 From: lassevk at gmail.com (=?iso-8859-1?q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: 6 Oct 2005 23:52:48 -0700 Subject: Merging sorted lists/iterators/generators into one stream of values... In-Reply-To: References: Message-ID: <1128667968.421469.180910@g47g2000cwa.googlegroups.com> Ok, that one looks more sleak than what I came up with. Couple of things I learn from your solution, please correct me if I misunderstood something: 1. list containing other lists will sort itself based on first element on lists inside ? 2. sort(), pop() is not costly operations Other than that you seem to not use the cmp operator but that's easily fixed. This one looks much better than mine, here's what I came up with: def merge_sorted(iterables, comparer=None): """ Generator that will take a list of iterables/generators that is individually sorted, and then produce values in a sorted order by taking the lowest value from each source each call. @param iterables: List of iterables/generators to retrieve values from @type iterables: List of iterables/generators @param comparer: Optional fn(v1, v2) function that can compare two values, should return <0 if v10 if v1>v2 and ==0 if v1==v2. @type comparer: function-object, example: lambda x, y: x-y @note: The "list of iterables" can actually be anything that produces a list of iterables, so you can use a function that yields lists for instance. """ # First convert whatever we're given into a list of sources iterables = [iterable for iterable in iterables] # This series of if-statements will determine how many sources we have and work out sub-problems # that are manageable. if len(iterables) != 2: if len(iterables) == 0: # List, but no sources pass elif len(iterables) == 1: # Only 1 source, just return its contents for value in iterables[0]: yield value elif len(iterables) == 3: # 3 sources, sub-divide into 0 <--> (1, 2) left_iterable = iterables[0] right_iterable = merge_sorted([iterables[1], iterables[2]], comparer) for value in merge_sorted([left_iterable, right_iterable], comparer): yield value elif len(iterables) == 4: # 4 sources, sub-divide into (0, 1) <--> (2, 3) left_iterable = merge_sorted([iterables[0], iterables[1]], comparer) right_iterable = merge_sorted([iterables[2], iterables[3]], comparer) for value in merge_sorted((left_iterable, right_iterable), comparer): yield value elif len(iterables) > 4: # >4 sources, sub-divide into (0, 1) <--> (2, ...) left_iterable = merge_sorted([iterables[0], iterables[1]], comparer) right_iterable = merge_sorted(iterables[2:], comparer) for value in merge_sorted((left_iterable, right_iterable), comparer): yield value raise StopIteration # The method will only get here if there is only two sources, which is an easy case to handle i1 = iter(iterables[0]) i2 = iter(iterables[1]) # Grab the first two values from the two sources, if possible try: v1 = i1.next() has_v1 = True except StopIteration: has_v1 = False try: v2 = i2.next() has_v2 = True except StopIteration: has_v2 = False # As long as we got values from both generates/iterators/whatever, compare and yield the lowest of the # two, and then get the next value from the corresponding source while has_v1 and has_v2: # Work out which of v1 and v2 comes first if comparer is not None: comp = comparer(v1, v2) if comp <= 0: yield_v1 = True else: yield_v1 = False else: if v1 <= v2: yield_v1 = True else: yield_v1 = False # Yield the next value, then grab a new value from the corresponding source if yield_v1: yield v1 try: v1 = i1.next() except StopIteration: has_v1 = False else: yield v2 try: v2 = i2.next() except StopIteration: has_v2 = False # When we get here, we got 3 possibilities: # 1. has_v1 == True, has_v2 == False --> yield rest of v1/i1 and just exit on StopIteration exception # 2. has_v1 == False, has_v1 == True --> yield rest of v2/i2 and just exit on StopIteration exception # 3. has_v1 == has_v2 == False --> while-loops will skip, function falls off the end while has_v1: yield v1 v1 = i1.next() while has_v2: yield v2 v2 = i2.next() From istvan.albert at gmail.com Tue Oct 4 09:23:08 2005 From: istvan.albert at gmail.com (Istvan Albert) Date: 4 Oct 2005 06:23:08 -0700 Subject: Controlling who can run an executable In-Reply-To: <1128395422.904212.318930@g44g2000cwa.googlegroups.com> References: <1128395422.904212.318930@g44g2000cwa.googlegroups.com> Message-ID: <1128432188.408503.309280@f14g2000cwb.googlegroups.com> >was using to track clients and transactions. He couldn't demonstrate >the program for one reason or another because it was protected in a way >that neither could circumvent. (She didn't remember how it was >protected, she had hired this person a long time ago.) I'd venture to guess that neither of the people above knew much about programming. So do the same, create a security measure that protects against this level of 'threat'. As others have pointed out the simplest way would be to detect the presence of a hidden file, or some hardcoded system value, mac address etc. Obscure this step even more by encrypting some of the information so that one can't just simply view it in a hex editor. Istvan. From mhamilt at sandia.gov Tue Oct 18 14:59:06 2005 From: mhamilt at sandia.gov (Mark E. Hamilton) Date: Tue, 18 Oct 2005 12:59:06 -0600 Subject: Python script produces "sem_trywait: Permission denied" Message-ID: <435545FA.6010606@sandia.gov> Hi, I've seen this question posted many places arount the Internet, but I've not seen any answers. We've been seeing this same error for some time, probably as long as Hudson has (given that it's now mid-October 2005); we just ignored it, since it didn't seem to cause problems. However, if anyone does have a solution to it I'd like to see it. I hate having unresolved wierdnesses in our code. -- ---------------- Mark E. Hamilton Orion International Technologies, Inc. Sandia National Laboratory, NM. 505-844-7666 From steve at aol.com Thu Oct 27 17:19:32 2005 From: steve at aol.com (steve) Date: Fri, 28 Oct 2005 05:19:32 +0800 Subject: a Haskell a Day References: <1130312303.713737.160830@g44g2000cwa.googlegroups.com> <3vmul1hli2t3cuquab99fnlg2g9abqkj3o@4ax.com> Message-ID: On Wed, 26 Oct 2005 18:35:49 +0800, Roedy Green wrote (in article <3vmul1hli2t3cuquab99fnlg2g9abqkj3o at 4ax.com>): > On 26 Oct 2005 00:38:23 -0700, "Xah Lee" wrote, > quoted or indirectly quoted someone who said : > >> A Haskell A Day: Manifesto > This is the wrong newsgroup. Had you done the same for Java, > comp.lang.java.help would be the place to post it. > Stupid newbi wants $1 if you spend more than 30 minutes on his webshite, looking at it you would be hard pressed to spend 30 seconds. Anyway at least we know where to find him. From aleaxit at yahoo.com Fri Oct 28 22:50:04 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 28 Oct 2005 19:50:04 -0700 Subject: Generic utility class for passing data References: <1u-dnSkSzdnsfP_enZ2dnUVZ_tGdnZ2d@comcast.com> Message-ID: <1h55r01.ovyr63zw37r6N%aleaxit@yahoo.com> Gordon Airporte wrote: > I'm wondering if this is might be bad practice. Sometimes when I need to I hope not, 'cuz I suggested that years ago on the Cookbook (under the name of Bunch) with several successive refinements. > class Dummy: > pass > > Then when I need to pass some related data, Python lets me do this: > > prefill = Dummy() > prefill.foreground = 'blue' #"foreground" is made up on the fly > prefill.background = 'red' > prefill.pattern = mypattern > return prefill Sure, but you can do even better: class Dummy(object): def __init__(self, **kwds): self.__dict__ = kwds prefill = Dummy(foreground='blue', background='red', pattern=mypattern) return prefill Alex From fredrik at pythonware.com Wed Oct 19 17:30:11 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 19 Oct 2005 23:30:11 +0200 Subject: Yes, this is a python question, and a serious one at that (moving to Win XP) References: <1129748724.890082.70380@g14g2000cwa.googlegroups.com> Message-ID: robinsiebler at gmail.com wrote: > Try 4NT (http://www.jpsoft.com). It is like cmd on steroids. I've > been using it for years and it is the *only* thing that makes powerful > batch files possible on Windows. why bother with "powerful batch files" when you can use a real programming language ? From http Thu Oct 13 04:04:17 2005 From: http (Paul Rubin) Date: 13 Oct 2005 01:04:17 -0700 Subject: Jargons of Info Tech industry References: <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <868xx3m2ve.fsf@bhuda.mired.org> <86irw6l1mc.fsf@bhuda.mired.org> <86r7aqugmk.fsf@bhuda.mired.org> Message-ID: <7xk6ghkflq.fsf@ruckus.brouhaha.com> Roedy Green writes: > Next Mr. Phish had to present his passport etc when he got his Thawte > ID. Now Interpol has a much better handle on putting him in jail. > He can't repudiate his phishing attempt. Any underage drinker in a college town can tell you a hundred ways to get sufficient fake ID to get around that. See also: http://www.ahbl.org/funny/response1.php I'll let others here fill in the blanks. From bearophileHUGS at lycos.com Wed Oct 12 20:10:53 2005 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 12 Oct 2005 17:10:53 -0700 Subject: Multiple assignments simplification Message-ID: <1129162253.273873.277050@g14g2000cwa.googlegroups.com> The current version of ShedSkin (http://shedskin.sourceforge.net/ experimental Python to C++ compiler) is rather alpha, and the development work is focused on debugging and implementing some more basic Python functionality. But hopefully in future versions more work will be spent to make the resulting C++ programs as fast as possible. One of the many possible details that may be improved, is the compiling to C++ of the Python "parallel" assignments. There are complex situations like this one: | a = 1 | b = 2 | c = 3 | def fun(a): | global b | return c, b ** (b+a) | (a, b), c = fun(a), a | print a, b, c # prints 3 8 1 Probably it isn't necessary to find an optimal solution for complex situations like this one, ShedSkin (SS) uses a basic and simple algorithm to translate all the complex cases. But maybe for simpler and more regular situations it can be useful to find better/optimal solution, like with a swap: a = 1 b = 2 a, b = b, a At the moment SS translates it as something like: int __0, __1, a, b; int __main() { a = 1; b = 2; __0 = b; __1 = a; a = __0; b = __1; SS just copies all the variables before the assignment. If such swap is inside a very long loop, then maybe a simplification can speed up a program a little (I don't know if C++ compilers can do such optimizations). This is another example of such "regular" situations: a, b, c, d, e, f = range(6) a, b, c, d, e = b, d, e, f, c print a, b, c, d, e, f At the moment SS translates its central part just as: __1 = b; __2 = d; __3 = e; __4 = f; __5 = c; a = __1; b = __2; c = __3; d = __4; e = __5; The two sides of the assignment aren't just permutations, because some variables can be different (like f), and some variables can be present two or more times (duplication), some other can be absent. A code like this can be faster (and hopefully still correct): a = b aux_1 = c c = e e = aux_1 b = d d = f That assignment line of code can be represented as: [0, 1, 2, 3, 4], [1, 3, 4, 5, 2] (Numbers represent variables. The first list is always sorted, equivalent to range(n) ). Do you know some algorithm (or you can give some suggestions) to minimize the number of simple assignments needed for a "regular" situation like that? Note that in most situations the number of variables is quite small (but it can be big). (Also note that in the "regular" situation I've ignored the problem of mixed variable types, this is something SS has to take care too). Bye and thank you, bearophile From rrr at ronadam.com Sat Oct 1 19:15:57 2005 From: rrr at ronadam.com (Ron Adam) Date: Sat, 01 Oct 2005 23:15:57 GMT Subject: Class Help In-Reply-To: <1KE%e.162132$p_1.55983@tornado.tampabay.rr.com> References: <1KE%e.162132$p_1.55983@tornado.tampabay.rr.com> Message-ID: Ron Adam wrote: > Also, > > In your example 'q' is assigned the value 2, but as soon as the method > 'y' exits, it is lost. To keep it around you want to assign it to self.y. Ooops, That should say ... "To keep it around you want to assign it to self.q." <---self.q Cheers, Ron From larry.bates at websafe.com Fri Oct 14 14:02:44 2005 From: larry.bates at websafe.com (Larry Bates) Date: Fri, 14 Oct 2005 13:02:44 -0500 Subject: Searching files in directories In-Reply-To: <1129311080.579292.112990@g47g2000cwa.googlegroups.com> References: <1129311080.579292.112990@g47g2000cwa.googlegroups.com> Message-ID: <434FF2C4.3040307@websafe.com> Not tested but should be close: import os import shutil files = ['file1.txt'] source_directory = '/tmp/source/' destination_directory = '/tmp/destination/' for file in files: src=os.path.join(source_directory, file dst=os.path.join(destination_directory, file if os.path.exists(os.path.join(source_directory, file): shutil.copy(src, dst) -Larry Bates pkilambi at gmail.com wrote: > can anyone help me with this... > > I want to search for a list for files in a given directory and if it > exists copy them to destination directory > > so what i am looking for is : > > file = 'file1.txt' > source_directory = '/tmp/source/' > destination_directory = '/tmp/destination/' > > so If the file exists in source_directory cp that file to the > destination_directory.. > > hope I am clear > From dcrespo at gmail.com Fri Oct 28 08:54:35 2005 From: dcrespo at gmail.com (dcrespo) Date: 28 Oct 2005 05:54:35 -0700 Subject: xml-rpc - adodb - None type - DateTime type Message-ID: <1130504075.327403.236240@o13g2000cwo.googlegroups.com> Hi to all, I have functions defined in an xml-rpc server. Some functions query to a Postgres database (using adodb) and return its recordset. So, if some xml-rpc client runs the mentioned function, it will retrieve the recordset. The problem is that if a retrieved field has the Null value or the Date value (DateTime Database format), then, the retrieved recordset in the python program will have the 'None' value or the DateTime type object value. xml-rpc isn't able to accept any type of value, so I have to solve it. I can replace all None values with the string 'Null', there's no problem, but I can't detect the DateTime type object I retrieve from the database. I have something like this: def xmlrpc_function(): conn = adodb.NewADOConnection('postgres') conn.Connect(host,user,password,database) rs = conn.Exec("select * from table") result = [] i = 0 while not rs.EOF: row = rs.GetRowAssoc(False) for key, value in row.items(): if value==None: row[key]='Null' result.append(row) i = i + 1 rs.MoveNext() rs.Close() print result return result The problem here is that if row[key] == , then I don't know what to do for detect it and make the appropriate change to string. Console output: [{'name': 'Null', 'date': }] If you consult the python manual, you'll see that there's no 'DateTime' type object, so I can't do something like: if value==DateTimeType: ... I only need to know which type of data is a field for make the change according to what can I pass through the xml-rpc. Any help? Thanks From aahz at pythoncraft.com Wed Oct 19 20:12:49 2005 From: aahz at pythoncraft.com (Aahz) Date: 19 Oct 2005 17:12:49 -0700 Subject: Python variables are bound to types when used? References: <1129751462.061785.124830@g49g2000cwa.googlegroups.com> <11ld9qtgvead8d0@corp.supernews.com> Message-ID: In article , Steven D'Aprano wrote: >On Wed, 19 Oct 2005 20:06:53 +0000, Grant Edwards wrote: >> >> Python doesn't have variables. >> >> Python has objects of various types. You can bind 0 or more >> names an object. > >I frequently use "variable" as a synonym for "name" when talking about >Python code. Do people think I am wrong to do so? Wrong? No. Bad idea? Possibly, depending on context. I'm often using "variable" in casual conversation -- it's hard to break the habit of thirty years of programming! But I try very hard to stick with "name" when I'm doing formal instruction. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." --Red Adair From en.karpachov at ospaz.ru Tue Oct 11 03:48:13 2005 From: en.karpachov at ospaz.ru (en.karpachov at ospaz.ru) Date: Tue, 11 Oct 2005 11:48:13 +0400 Subject: Let My Terminal Go In-Reply-To: <1129010288.251817.147690@z14g2000cwz.googlegroups.com> References: <1129010288.251817.147690@z14g2000cwz.googlegroups.com> Message-ID: <20051011114813.7c9ad3fd.jk@ospaz.ru> On 10 Oct 2005 22:58:08 -0700 mystilleef at gmail.com wrote: > How do I implement this in my application written in python? Google for "python daemonize". -- jk From apardon at forel.vub.ac.be Mon Oct 17 06:24:27 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 17 Oct 2005 10:24:27 GMT Subject: How to get a raised exception from other thread References: <1129326320.914350.171460@o13g2000cwo.googlegroups.com> <1129434185.879062.61600@o13g2000cwo.googlegroups.com> <1129434873.307336.112030@g47g2000cwa.googlegroups.com> <1129438147.182266.196790@g44g2000cwa.googlegroups.com> <1h4knsn.1tihnpm15d5y4lN%aleaxit@yahoo.com> Message-ID: Op 2005-10-17, Alex Martelli schreef : > wrote: > >> Nevermind. I found a better solution. I used shared memory to create >> a keep-alive flag. I then use the select function with a specified >> timeout, and recheck the keep-alive flag after each timeout. > > Definitely a better architecture. Anyway, one supported way for a > thread to raise an exception in a different thread is function > thread.interrupt_main(), which raises a KeyboardInterrupt in the *main* > thread (the one thread that's running at the beginning of your program). > > There's also a supported, documented function to raise any given > exception in any existing thread, but it's deliberately NOT directly > exposed to Python code -- you need a few lines of C-coded extension (or > pyrex, ctypes, etc, etc) to get at the functionality. This small but > non-null amount of "attrition" was deliberately put there to avoid > casual overuse of a facility intended only to help in very peculiar > cases (essentially in debuggers &c, where the thread's code may be buggy > and fail to check a keep-alive flag correctly...!-). I find this rather arrogant. It is not up to the developers of python to decide how the users of python will use the language. If someone has use of specific functionality he shouldn't be stopped because his use is outside the intentions of the developers. Just suppose you are writing a chess program. You let the program "think" while it is the users move, but this thinking has to be interrupted and some cleanup has to be made after the users move has made a lot of this thinking obsolete by his move. Such code could be mixture of loops and recursion that makes use of a simple flag to end it all, unpractical. Use of an exception raised from somewhere else would IMO in this case be an acceptable choice. Why should the coder of this software have to go through this deliberate set up attrition, to get at this functionality, just because it wasn't intented to be used in such a way by the developers? As far as I know, pyrex and ctypes weren't intended to get at the Python/C api. But they didn't create extra hurdles for those who could use it that way. -- Antoon Pardon From frithiof.jensen at die_spammer_die.ericsson.com Mon Oct 3 06:59:37 2005 From: frithiof.jensen at die_spammer_die.ericsson.com (Frithiof Andreas Jensen) Date: Mon, 3 Oct 2005 12:59:37 +0200 Subject: Python based unacceptable language filter References: Message-ID: "David Pratt" wrote in message news:mailman.1357.1128292457.509.python-list at python.org... > Hi. Is anyone aware of any python based unacceptable language filter > code to scan and detect bad language in text from uploads etc. > > Many thanks. > David Look up Spambayes - if you can filter on terms like "dear friend" you can filter on the inverse too, no? It needs samples to work with. From twic at urchin.earth.li Sat Oct 29 08:46:55 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Sat, 29 Oct 2005 13:46:55 +0100 Subject: Oh what a twisted thread we weave.... In-Reply-To: <1130545786.627404.102940@g47g2000cwa.googlegroups.com> References: <1130545786.627404.102940@g47g2000cwa.googlegroups.com> Message-ID: On Sat, 28 Oct 2005, GregM wrote: > ST_zeroMatch = 'You found 0 products' > ST_zeroMatch2 = 'There are no products matching your selection' > > # why does this always drop through even though the If should be true. > if (ST_zeroMatch or ST_zeroMatch2) in self.webpg: This code - i do not think it means what you think it means. Specifically, it doesn't mean "is either of ST_zeroMatch or ST_zeroMatch2 in self.webpg"; what it means is "apply the 'or' opereator to ST_zeroMatch and ST_zeroMatch2, then check if the result is in self.webpg". The result of applying the or operator to two nonempty strings is the left-hand string; your code is thus equivalent to if ST_zeroMatch in self.webpg: Which will work in cases where your page says 'You found 0 products', but not in cases where it says 'There are no products matching your selection'. What you want is: if (ST_zeroMatch in self.webpg) or (ST_zeroMatch2 in self.webpg): Or something like that. You say that you have a single-threaded version of this that works; presumably, you have a working version of this logic in there. Did you write the threaded version from scratch? Often a bad move! tom -- It's the 21st century, man - we rue _minutes_. -- Benjamin Rosenbaum From nestleNOSPAM12 at comcast.net Fri Oct 21 19:27:01 2005 From: nestleNOSPAM12 at comcast.net (Bryan) Date: Fri, 21 Oct 2005 17:27:01 -0600 Subject: python -m pdb questions Message-ID: So I am new to the whole python thing, be nice. So I do a b /foo/foo.py :10 (if I do a foo.py:10 it says not in sys.path) Then a continue... my breakpoint isn't hit. but if I am in main.py and do a b /foo/main.py:10 I hit the breakpoint. also I can't get b fooMethod to ever take, always get not in sys.path What am I missing? Or is pdb fubar? Suse93 btw. thanks, Bryan From apardon at forel.vub.ac.be Tue Oct 4 03:52:29 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 4 Oct 2005 07:52:29 GMT Subject: Will python never intend to support private, protected and public? References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xd5mstqab.fsf@ruckus.brouhaha.com> Message-ID: Op 2005-10-03, Steven D'Aprano schreef : > On Mon, 03 Oct 2005 09:14:34 +0000, Antoon Pardon wrote: > >> If you are in a project with >> multiple authors, your usage of private variables can break code >> that other people rely on. > > If you are in a project with multiple authors, your usage of PUBLIC > variables can break code that other people rely on. Maybe then those shouldn't have been public variables in the first. > That's why you have testing. You do test, don't you? You do seem to think that testing will solve everything and that any extra protection to get code correct is thus a waste of time. I don't share that view. -- Antoon Pardon From deets at nospam.web.de Mon Oct 17 15:57:27 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 17 Oct 2005 21:57:27 +0200 Subject: Repost: Text not showing up In-Reply-To: <3ridbuFjsoctU1@uni-berlin.de> References: <434FADFA.8050302@gmail.com> <3ridbuFjsoctU1@uni-berlin.de> Message-ID: <3rie18Fjrq1oU1@uni-berlin.de> > The problem is that the changes take effect after gtk has reentered its > event-loop. Which won't happen until your programs terminate. With programs I mean of course the burning commandos. Diez From steve at REMOVETHIScyber.com.au Sun Oct 2 19:08:57 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 03 Oct 2005 09:08:57 +1000 Subject: Program help References: <1128283048.975696.101760@g44g2000cwa.googlegroups.com> Message-ID: On Sun, 02 Oct 2005 12:57:29 -0700, FX wrote: > can anybody write a code for a program that reads from a > /location/file & according to file contents, it execute script. e.g. if > file contains "mp" it runs media player. > I hope the code is small .. plz help me out! There are lots of people who can do that. Are you asking them to do it for free, or are you looking to hire a Python developer to design, build and test your program? -- Steven. From timr at probo.com Fri Oct 21 02:20:12 2005 From: timr at probo.com (Tim Roberts) Date: Fri, 21 Oct 2005 06:20:12 GMT Subject: Cursor Location References: Message-ID: "Samantha" wrote: > >Is there any code that would allow a person to click a location on the >screen and have that location saved for a future use? For example to imbed a >watermark on an image or text, etc. Getting the point is easy. If you are using wxPython, your EVT_LEFT_UP handler gets a mouse event as a parameter: def OnClick( self, evt ): print evt.GetPositionTuple() Once you have the tuple, it's up to you to save it somewhere. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From steve at holdenweb.com Tue Oct 25 19:33:17 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 26 Oct 2005 00:33:17 +0100 Subject: textwidget.tag_bind("name", "", self.donothing) not working In-Reply-To: <1130266889.246361.268610@g47g2000cwa.googlegroups.com> References: <1130266889.246361.268610@g47g2000cwa.googlegroups.com> Message-ID: shannonl wrote: > Hi all, > > For some reason this bind is calling the donothing function, like it > should, but is then allowing the text to be inserted into the Text > widget. > > Here is the code: > > self.framebody.tag_config("name", underline=1) > self.framebody.tag_bind("name", "", self.donothing) > > line = '\t%s' % ('sometext') > self.framebody.insert(END, line, "name") > > def donothing(self): > return 'break' > > This donothing function should keep the tcl bind from inserting the > text...at least so I thought. > > This bind does work on the text widget as a whole, but on a individual > tag, it does not. > > Can anyone help me out with this? > > Thanks in advance, > Shannon > Have you tried capturing the KeyRelease events as well? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From rrr at ronadam.com Tue Oct 4 14:11:02 2005 From: rrr at ronadam.com (Ron Adam) Date: Tue, 04 Oct 2005 18:11:02 GMT Subject: "no variable or argument declarations are necessary." In-Reply-To: References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> Message-ID: Antoon Pardon wrote: > Op 2005-10-03, Steven D'Aprano schreef : > >>On Mon, 03 Oct 2005 06:59:04 +0000, Antoon Pardon wrote: >> >> >>>Well I'm a bit getting sick of those references to standard idioms. >>>There are moments those standard idioms don't work, while the >>>gist of the OP's remark still stands like: >>> >>> egold = 0: >>> while egold < 10: >>> if test(): >>> ego1d = egold + 1 >> >>for item in [x for x in xrange(10) if test()]: >> >>But it isn't about the idioms. It is about the trade-offs. Python allows >>you to do things that you can't do in other languages because you >>have much more flexibility than is possible with languages that >>require you to declare variables before using them. The cost is, some >>tiny subset of possible errors will not be caught by the compiler. But >>since the compiler can't catch all errors anyway, you need to test for >>errors and not rely on the compiler. No compiler will catch this error: >> >>x = 12.0 # feet >># three pages of code >>y = 15.0 # metres >># three more pages of code >>distance = x + y >>if distance < 27: >> fire_retro_rockets() >> >>And lo, one multi-billion dollar Mars lander starts braking either too >>early or too late. Result: a new crater on Mars, named after the NASA >>employee who thought the compiler would catch errors. > > > Using (unit)tests will not guarantee that your programs is error free. > > So if sooner or later a (unit)tested program causes a problem, will you > then argue that we should abondon tests, because tests won't catch > all errors. Maybe you need to specify what kind of errors you want to catch. Different types of errors require different approaches. * Errors that interrupt program execution. These are Type errors and/or illegal instruction errors such as divide by zero. Try-excepts and checking attributes where these are possible to handle them should be used. * Human 'user' input errors. Value testing is what is needed for these. * Programming errors... Nothing will replace testing here. I think what you want is optional name and object locking in order to prevent certain types of errors and increase reliability and dependability. Name locking - This will allow you to be able to depend that a specific name refers to a specific object. But that object can still be modified if it's mutable. Object locking - This would make a non mutable object from a mutable object. A function could work here for lists. This probably isn't possible with many complex objects. Names need to be rebound in many objects for them to work. I think this may be much harder to do than it seems. An example, (but probably not possible to do). Const = {} Const['pi'] = 3.1415926535897931 ... add more keys/value pairs ... lockobject Const # prevent object from being changed lockname Const # prevent name 'Const' from being rebound ... many pages of code ... print Const['pi'] # dependable result? Is this the type of control you want? Would it make your programs more dependable or reliable? Name locking might be implemented with additional name spaces, but they would need to be checked prior to other name spaces, so it could slow everything down. And there would probably be ways to unlock objects. But maybe that's not a problem as I think what you want to prevent is erroneous results due to unintentional name changes or object changes. I think both of these would have unexpected side effects in many cases, so their use would be limited. Cheers, Ron From rrr at ronadam.com Sun Oct 16 05:40:57 2005 From: rrr at ronadam.com (Ron Adam) Date: Sun, 16 Oct 2005 09:40:57 GMT Subject: dis.dis question In-Reply-To: References: <4351affc.104308027@news.oz.net> Message-ID: skip at pobox.com wrote: > >> I'm still looking for info on how to use disassemble_string(). > > How about this? > > >>> import dis > >>> def f(): > ... print "hello world" > ... > >>> f.func_code.co_code > 'd\x01\x00GHd\x00\x00S' > >>> dis.disassemble_string(f.func_code.co_code) > 0 LOAD_CONST 1 (1) > 3 PRINT_ITEM > 4 PRINT_NEWLINE > 5 LOAD_CONST 0 (0) > 8 RETURN_VALUE > > Skip Thanks Skip, I had figured it out, but I like your example. >>> import dis >>> dis.dis('d\x01\x00GHd\x00\x00S') 0 LOAD_CONST 1 (1) 3 PRINT_ITEM 4 PRINT_NEWLINE 5 LOAD_CONST 0 (0) 8 RETURN_VALUE It works! :-) Cheers, Ron From grante at visi.com Fri Oct 21 15:19:04 2005 From: grante at visi.com (Grant Edwards) Date: Fri, 21 Oct 2005 19:19:04 -0000 Subject: Set an environment variable References: <43573022$0$155$edfadb0f@dread16.news.tele.dk> <1129798724.366618.194650@g44g2000cwa.googlegroups.com> <43589205$0$125$edfadb0f@dread16.news.tele.dk> <11lhv31li8sgm0c@corp.supernews.com> <86ll0mu6px.fsf@bhuda.mired.org> Message-ID: <11lifp8r4kipi5c@corp.supernews.com> On 2005-10-21, Mike Meyer wrote: >>>> The closest thing you can do is that: >>>> >>>> -myScript.py-------------------------------------- >>>> print 'export MY_VARIABLE=value' >>>> -------------------------------------------------- >>>> >>>> -myScript.sh-------------------------------------- >>>> python myScript.py > /tmp/chgvars.sh >>>> . /tmp/chgvars.sh >>>> -------------------------------------------------- >> >> Bullshit. Are people being intentionally misleading?? > > No. Are you being intentionally - never mind. Well, yes, probably. >> And even Google knows the correct answer >> >> http://www.google.com/search?hl=en&lr=&q=python+set+environment+variable >> >> Follow the first hit. My bad. I got links mixed up -- it wasn't the first one, it was this one: http://www.faqts.com/knowledge_base/view.phtml/aid/3298 There are two almost-equivalent tirival answers: os.environment['foo'] = 'bar' os.putenv('foo','bar') I don't get why people seem to be obfuscating things with multiple layers of shells or writing shell commands to to a file and executing them. > Maybe the results order has changed since you looked? No, I mixed them up. My point: the OP wanted to know how to export an environment variable to a child process. Either of the lines of code above will do that, so what's with all the shellular shenanigans? -- Grant Edwards grante Yow! Youth of today! Join at me in a mass rally visi.com for traditional mental attitudes! From http Thu Oct 6 16:24:19 2005 From: http (Paul Rubin) Date: 06 Oct 2005 13:24:19 -0700 Subject: So far (about editing tools) References: <48D17FEA-3E2D-46CA-AEB4-86EA1CFACCB1@sbcglobal.net> Message-ID: <7xr7aypf64.fsf@ruckus.brouhaha.com> Micah Elliott writes: > Furthermore, Eclipse requires java and is thusly not provided on any > linux distro I'm familiar with, which I consider a huge roadblock. And > as mentioned, it's bloated. It comes with Fedora Core 4 and is compiled with gcj. > I would suspect that the majority of Python programmers write in one of > vim or emacs. Anyone got stats? I'm a long time emacs bigot but lately I've been editing Python with IDLE. IDLE leaves a lot to be desired but its integration is very convenient. From skromta at gmail.com Fri Oct 14 12:27:34 2005 From: skromta at gmail.com (Kalle Anke) Date: Fri, 14 Oct 2005 18:27:34 +0200 Subject: getting the path in a cgi script References: <0001HW.BF759D88004280C3F0284550@news.individual.de> Message-ID: <0001HW.BF75A91600453623F0488550@news.individual.de> On Fri, 14 Oct 2005 18:20:10 +0200, Fredrik Lundh wrote (in article ): > import os > path_info = os.environ.get("PATH_INFO") Tackar ... det var n?t enkelt det mindes jag :-) From email at christoph-haas.de Fri Oct 14 16:11:48 2005 From: email at christoph-haas.de (Christoph Haas) Date: Fri, 14 Oct 2005 22:11:48 +0200 Subject: Looking for a Python mentor In-Reply-To: References: <1129167866.253155.157850@g43g2000cwa.googlegroups.com> <434e4ad2$1@news.bezeqint.net> Message-ID: <200510142211.49067.email@christoph-haas.de> On Friday 14 October 2005 21:35, billie wrote: > "Nir Aides" wrote > > > Hello Len, > > > > You should try the #python IRC room. > > It is always very active and helpful. > > > > Nir > > Do you mean efnet #Python chan? > It's not too much active... I believe he meant irc.freenode.net :) Christoph -- ~ ~ ".signature" [Modified] 1 line --100%-- 1,48 All From steve at REMOVETHIScyber.com.au Mon Oct 17 09:12:02 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 17 Oct 2005 23:12:02 +1000 Subject: [newbie]Is there a module for print object in a readable format? References: Message-ID: On Mon, 17 Oct 2005 17:25:35 +0800, James Gan wrote: > I want the object printed in a readable format. For example, > x =[a, b, c, [d e]] will be printed as: > x--a > |_b > |_c > |___d > |_e I think you missed an "un-" in your first sentence. :-) In general, if you want special/fancy/bizarre printing, you should either write your own custom functions, or sub-class the objects in question. E.g. def multiline_print(L, indent=""): """Multi-line printing of lists. WARNING: Untested and probably full of bugs. """ for item in L: if type(item) == list: multiline_print(item, indent + " ") else: print indent + "|_" + str(item) Hope this helps. -- Steven. From derek.perriero at gmail.com Sat Oct 15 09:08:07 2005 From: derek.perriero at gmail.com (Derek Perriero) Date: Sat, 15 Oct 2005 09:08:07 -0400 Subject: Best way to handle cgi sessions In-Reply-To: <17fc20160510150605l7cde5386jdf0dd9de84fe363c@mail.gmail.com> References: <17fc20160510141222g65b11873y28ca495874a64156@mail.gmail.com> <200510150028.32610.email@christoph-haas.de> <17fc20160510150605l7cde5386jdf0dd9de84fe363c@mail.gmail.com> Message-ID: <17fc20160510150608h1739db30x2638fdf59b9519bf@mail.gmail.com> Christoph, I really appreciate the effort. I've been searching for something of this magnitude for awhile. See, I would normally use CGI::Session for the equivalent in Perl. That is what I am trying to achieve. I'll give that script a go and see what I can come up with. Luckily, the data I store is kept in MySQL, so that's even better. Regards to your efforts to the community! Cheers, Derek P.S. Sorry for the repeat, this e-mail was never sent to the list, Thanks! On 10/15/05, Derek Perriero wrote: > > Christoph, > > I really appreciate the effort. I've been searching for something of this > magnitude for awhile. See, I would normally use CGI::Session for the > equivalent in Perl. That is what I am trying to achieve. I'll give that > script a go and see what I can come up with. Luckily, the data I store is > kept in MySQL, so that's even better. Regards to your efforts to the > community! > > Cheers, > Derek > > On 10/14/05, Christoph Haas wrote: > > > > On Friday 14 October 2005 21:22, Derek Perriero wrote: > > > What would be the best way to create a cgi session that contains the > > > basic elements of a cookie and can also hold secure data, such as a > > > username/password. [...] > > > > Said. Done. I just tidied up a module we will be using for a web site > > here. It uses the promised session-cookie handling (with a lot of > > security > > checks) and a MySQL database backend. I tried to document as well as > > possible > > so I hope it will even help you if you use it or not. To try it out just > > grab the two files from http://workaround.org/pysessions/ and copy them > > into a > > cgi-bin/ directory. Create a database and the two tables following the > > scheme described on top of the MySessions.py module. Then access the > > /cgi-bin/mypage CGI. Hope to have helped. > > > > Everyone: > > This is my first "bigger" Python script. I would really like to hear > > comments > > on it. If it's deemed to be decent I could use some help making it a > > package > > that can be used by others as well. There is probably a bit of > > perlishness > > that I'd like to get rid of to make it look more snake-like. > > > > Regards > > Christoph > > -- > > ~ > > ~ > > ".signature" [Modified] 1 line --100%-- 1,48 All > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > > -- > Perriero, Derek > derek.perriero at gmail.com > -- Perriero, Derek derek.perriero at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jack at performancedrivers.com Fri Oct 7 20:31:27 2005 From: jack at performancedrivers.com (Jack Diederich) Date: Fri, 7 Oct 2005 20:31:27 -0400 Subject: When someone from Britain speaks, Americans hear a "British accent"... In-Reply-To: <11kdtk2t4kksp25@corp.supernews.com> References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kdpab4l7i7ecb@corp.supernews.com> <11kdtk2t4kksp25@corp.supernews.com> Message-ID: <20051008003127.GN6255@performancedrivers.com> On Fri, Oct 07, 2005 at 10:28:18PM -0000, Grant Edwards wrote: > On 2005-10-07, Jack Diederich wrote: > > > > It is a bit odd that You'uns, yins, and yous are confined to Pennsylvania > > and very distinct east-west regions inside PA at that (Pittsburgh vs > > Philly orbits). > > Eastern and Western Pennsylvania are practically different > countries when it comes to language and culture. > I'll buy that, I'm from Eastern PA (half PA Dutch) and I've only been to Pittsburgh once. There is a very good reason for this, the six hour drive is the same as from Philly to Boston (through NJ, NY, CT and into MA). Alternatively you can drive from Philly to DC to Philly or Philly to New York to Philly to New York in the same amount of time. -jack From http Tue Oct 11 22:05:15 2005 From: http (Paul Rubin) Date: 11 Oct 2005 19:05:15 -0700 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <86y853mzmr.fsf@bhuda.mired.org> <86mzlil269.fsf@bhuda.mired.org> Message-ID: <7xd5mbcwx0.fsf@ruckus.brouhaha.com> Roedy Green writes: > So let's say I decide to send an email to Donald Knuth. Good luck. Prof. Knuth stopped reading email years before there was a big spam problem. He uses his own version of hashcash to cut down on unimportant mail: if you want to write to him, you have to send him snail mail, which means buying and using an actual postage stamp. I do something like that, sort of. I no longer publish an email address, including on business cards and so forth. I have a contact url that I give out instead, which keeps me off mailing lists. From anenem at gmail.com Mon Oct 31 20:01:28 2005 From: anenem at gmail.com (robert) Date: Tue, 1 Nov 2005 02:01:28 +0100 Subject: MySQLdb and cgi In-Reply-To: References: Message-ID: I am sending it again, since it didn't appear on the mailing list. Dear group, > > I have a problem with importing MySQLdb in a cgi-script. > The code fragment at the beginning: > > 1 #!/usr/bin/env python > 2 > 3 print "Content-Type: text/html\n\n" > 4 > 5 import re > 6 import cgi > 7 import MySQLdb > 8 print "something" > > but the print statement in line 8 will never be executed. The Apache error > log says: > "No module named MySQLdb, referer: http://localhost/sqlForm.html" > > But when executing the import statement outside of an cgi-script, for > example at the command line, the import works fine. > I assume, it has something to do with the apache. Why does the python > interpreter not find the MySQLdb module when executed in > apache context? > > thanks, roebi > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark at markroseman.com Tue Oct 18 12:34:12 2005 From: mark at markroseman.com (Mark Roseman) Date: Tue, 18 Oct 2005 12:34:12 -0400 Subject: UI toolkits for Python References: <7xslv56ud1.fsf@ruckus.brouhaha.com> <3ras6oFit2djU1@individual.net> <4350dd34$0$6774$9b4e6d93@newsread4.arcor-online.net> <863bn12k6i.fsf@bhuda.mired.org> <7xslv02aoj.fsf@ruckus.brouhaha.com> <87psq39aur.fsf@wilson.rwth-aachen.de> <7xwtkbud5q.fsf@ruckus.brouhaha.com> <1h4mhm2.1rmv4fh1czi843N%aleaxit@yahoo.com> <86r7aiyg4g.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > aleaxit at yahoo.com (Alex Martelli) writes: > > Maybe that's the key difference between the mindset of a > > mathematician and that of an engineer -- I consider reaching over > > 95% of visitors to be _quite good indeed_, >> What surprises me is that marketing types will accept turning away - > what's the current internet user base? 200 million? - 10 million > potential customers without a complaint. Or maybe they just don't get > told that that's what's going on. Obviously we all agree the effort to support both is significant. The question is not so much "do we turn away 5%" as "do we use the effort we do have to provide a better experience for the 95%, or to provide a slightly worse experience for the 95%, and an ok experience for the 5%". If you're a business, the question then becomes, does the incrementally better experience produce a higher conversion rate (i.e. more sales), in which case it may well be a better investment to focus there and ignore the 5%. It's but one perspective, but depending on your goals, can be a reasonable choice to make. Mark From davids at webmaster.com Sun Oct 23 16:52:38 2005 From: davids at webmaster.com (David Schwartz) Date: Sun, 23 Oct 2005 13:52:38 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <86k6g59ke6.fsf@bhuda.mired.org> <3EI6f.43974$MF6.5922@fe1.news.blueyonder.co.uk> <86irvo861u.fsf@bhuda.mired.org> Message-ID: "Matt Garrish" wrote in message news:GHR6f.1428$ki7.48975 at news20.bellglobal.com... > I'd be interested in hearing what you think a right is? A right is a scope of authority. That is, a sphere within which one's decision is sovereign. > In Florida, for example, you have the right to gun someone down if you > think they're a bit too menacing. In Canada, most people find that > reprehensible. So does a Floridian visiting Canada have their rights > infringed on by our rogue government because they're not allowed to gun > down menacing looking Canadians at will? That's obviously a complicated question but totally unrelated to the issue at hand, which was one's sovereignty over one's own property. Obviously issues where a person has to use force against another are going to be complicated. The existence of complicated questions doesn't make the simple ones complicated. > Should they be able to exercise that right regardless and not have to face > the consequences of our laws? I think there are objective criteria in which the use of force is justified regardless of the laws. However, the strategic decision of whether to use objectively justifiable force when one may not be able to justify it to non-objective observers who may use force against you is going to be a complicated one. > I think "right", however, was the wrong choice of words in this thread; > there is rarely anything codifying a company's "right" to succeed at all > costs and at the expense of all competition (except Crown Corporations and > the like, which are created (in theory, anyway) in the interest of general > population as opposed to it). My point was that the Microsoft corporation was not an impersonal entity. It is an entity that is supposed to embody the will and rights of its shareholders and exists to allow them to act together for their own benefit. > Your question here appears to be one of ethics. Is MS ethically bankrupt > for pursuing business practices that run counter to society's established > norms, and should they be punished for doing so? And is their behaviour > the more reprehensible because of the contempt they show for the decisions > of society's judicial arm. It is only proper to show contempt for bad decisions. MS obligation was to comply with the law and not perform actions that the law put them on clear notice were prohibited. The court's determination of the relevent market, on wich all of their other decisions were predicated, was arbitrary and bizarre, and the law did not provide any notice of how the market would be determined. In the sense of interchangeability, almost all operating systems are monopolies. And if you go by application, Windows, Linux, and FreeBSD are all interchangeable -- there is nothing significant you can do on one that you can't do on the other. DS From usenet at marduk.letterboxes.org Sat Oct 1 19:14:54 2005 From: usenet at marduk.letterboxes.org (marduk) Date: Sat, 01 Oct 2005 18:14:54 -0500 Subject: Class Help In-Reply-To: References: Message-ID: <1128208495.10009.10.camel@blackwidow> On Sat, 2005-10-01 at 18:58 -0400, Ivan Shevanski wrote: > To continue with my previous problems, now I'm trying out classes. But I > have a problem (which I bet is easily solveable) that I really don't get. > The numerous tutorials I've looked at just confsed me.For intance: > > >>>class Xyz: > ... def y(self): > ... q = 2 > ... > >>>Xyz.y() > Traceback (most recent call last): > File "", line 1, in ? > TypeError: unbound method y() must be called with Xyz instance as first > argument > (got nothing instead) > > > So. . .What do I have to do? I know this is an extremley noob question but I > think maybe if a person explained it to me I would finally get it =/ When you define a class, say Xyz, your are defining your own type. Say that Person is a class. And person has a method walk(): class Person: def walk(self): ... now to use the Person class, you need to create an instance of it. You can't just say Person.walk() because Person is a "class"ification, not a real object. You need an instance of person. jane = Person() This creates a new person called "jane". "jane" is an instance of the class Person. >>> jane <__main__.Person instance at 0x2aaaac723710> Now we can tell jane to walk: jane.walk() So what the error is telling you (in a bit confusing way if you're a newbie) is that you are calling a method y() but you have not created an instance of your Xyz class to do y(). Or, to use my analogy, you are telling Person to walk, but you can't make Person walk, you have to create a person, jane, and have jane walk. Hope this helps, but I recommend you read a good intro to object-oriented programming. -a From netvaibhav at gmail.com Mon Oct 10 10:50:12 2005 From: netvaibhav at gmail.com (netvaibhav at gmail.com) Date: 10 Oct 2005 07:50:12 -0700 Subject: Default argument to __init__ Message-ID: <1128955812.913224.150760@z14g2000cwz.googlegroups.com> Hi All: Here's a piece of Python code and it's output. The output that Python shows is not as per my expectation. Hope someone can explain to me this behaviour: [code] class MyClass: def __init__(self, myarr=[]): self.myarr = myarr myobj1 = MyClass() myobj2 = MyClass() myobj1.myarr += [1,2,3] myobj2.myarr += [4,5,6] print myobj1.myarr print myobj2.myarr [/code] The output is: [1, 2, 3, 4, 5, 6] [1, 2, 3, 4, 5, 6] Why do myobj1.myarr and myobj2.myarr point to the same list? The default value to __init__ for the myarr argument is [], so I expect that every time an object of MyClass is created, a new empty list is created and assigned to myarr, but it seems that the same empty list object is assigned to myarr on every invocation of MyClass.__init__ It this behaviour by design? If so, what is the reason, as the behaviour I expect seems pretty logical. Thanks. Vaibhav From pclinch at internet-glue.co.uk Tue Oct 18 06:30:41 2005 From: pclinch at internet-glue.co.uk (pclinch at internet-glue.co.uk) Date: 18 Oct 2005 03:30:41 -0700 Subject: How to make command history persistent? In-Reply-To: <1129627265.021498.146390@g14g2000cwa.googlegroups.com> References: <1129627265.021498.146390@g14g2000cwa.googlegroups.com> Message-ID: <1129631441.629180.191200@g14g2000cwa.googlegroups.com> If using unix, you should have readline available. See the tutotial appendix:- http://www.python.org/doc/current/tut/node15.html Regards, Paul Clinch From http Sun Oct 2 20:46:23 2005 From: http (Paul Rubin) Date: 02 Oct 2005 17:46:23 -0700 Subject: Automating, Building, Testing and Deploying to Production Server References: <1128288243.694287.134210@o13g2000cwo.googlegroups.com> Message-ID: <7xd5mnig0w.fsf@ruckus.brouhaha.com> "yoda" writes: > I realize I'm losing so much time I could spend more productively. I'd > therefore like to know the different approaches you guys employ to > deploy builds from your staging servers (or laptops:) to the production > server in an automated repeatable safe manner. This is really a wide-ranging question and clpy maybe is not the best place for it. Basically every installation does it differently depending on its requirements. You could google some phrases like "continuous integration" and "configuration management" to see some approaches. The general outline is: 1) QA dept. has a server configured as identically as possible to the production server. 2) Engineering releases a sw version by making a source control branch. QA checks out the branch and tests it against pre-agreed release criteria. If there's differences of opinion about criteria, QA manager and engineering manager meet to resolve differences. 3) when QA manager and engineering manager agree to release, code is pushed out to production server (same process as release to QA: someone logs onto the production server and does an svn update or whatever). How that's done depends on how the server works. I worked at one serious web site which worked as follows. We had a primary server and hot backup (secondary) server, so we did pushes by taking the backup server offline, checking out the new build on the backup server and running some sanity tests, then launching the service on the backup server and taking down the primary, so there would be an automatic failover to the backup which was now running the new code. We'd then upgrade the primary the same way, and fail over again if desired. Smaller sites with no hot secondary will typically go briefly offline for version upgrade. Larger sites with multiple primaries could have a more gradual process where primaries are upgraded one by one, or whatever. 4) Some high availability services (e.g. telecom) need hot upgrade (code replacement without stopping the application or interrupting connections). This needs to be built into the app architecture at a deep level and I don't think it's what you were asking, but some languages like Erlang make provisions for it. Generally, a release cycle for an online service isn't that much different than that for a shrink-wrapped software package. From uuuuuu at me.com Sat Oct 1 16:10:55 2005 From: uuuuuu at me.com (Rob) Date: Sun, 2 Oct 2005 09:10:55 +1300 Subject: Not defined References: Message-ID: Thanks for the replies gives me something to chew on. Regards Gramps From sutram at gmail.com Mon Oct 17 22:58:33 2005 From: sutram at gmail.com (Mahesh Padmanabhan) Date: Mon, 17 Oct 2005 20:58:33 -0600 Subject: ANN: Leo 4.4a1 released References: Message-ID: In article , "Edward K. Ream" wrote: [Edward's announcement] Thanks for adding Emacs functionality. I really like the idea of literate programming and have tried to get into Leo but believe it or not, I haven't been able to get into it due to my muscle memory for Emacs keystrokes! I would keep installing Leo only to uninstall it afterwards because I would get frustrated. Another welcome change is complete keyboard control. Cheers, Mahesh From grante at visi.com Fri Oct 7 17:14:51 2005 From: grante at visi.com (Grant Edwards) Date: Fri, 07 Oct 2005 21:14:51 -0000 Subject: When someone from Britain speaks, Americans hear a "British accent"... References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> Message-ID: <11kdpab4l7i7ecb@corp.supernews.com> On 2005-10-07, Terry Hancock wrote: > Of course, just to keep y'all on your toes, we Texans have not only > construed "their" to singular, but also "you", and added a new > plural "y'all". AFAICT, in many parts of "The South", y'all is now used in the singular (e.g. "y'all" is used when addressing a single person), and "all y'all" is the plural form used when addressing a group of people collectively. -- Grant Edwards grante Yow! If elected, Zippy at pledges to each and every visi.com American a 55-year-old houseboy... From rpdooling at gmail.com Wed Oct 26 11:29:13 2005 From: rpdooling at gmail.com (rpdooling at gmail.com) Date: 26 Oct 2005 08:29:13 -0700 Subject: suggestions between these two books In-Reply-To: References: Message-ID: <1130340553.001869.67000@f14g2000cwb.googlegroups.com> Many different opinions on books. But if you are learning programming and learning Python, you can't beat the online book: How To Think Like A Computer Scientist: Learning Pythong http://www.ibiblio.org/obp/thinkCSpy/ It's concise and well-written. rd From usenet at marduk.letterboxes.org Wed Oct 12 01:37:48 2005 From: usenet at marduk.letterboxes.org (marduk) Date: Wed, 12 Oct 2005 05:37:48 GMT Subject: piping out binaries properly In-Reply-To: <86u0fnwes2.fsf@bhuda.mired.org> References: <86u0fnwes2.fsf@bhuda.mired.org> Message-ID: <1129095467.30697.10.camel@blackwidow> On Wed, 2005-10-12 at 00:16 -0400, Mike Meyer wrote: [...] > It's not normal to write binary content to stdout - you normally write > it to a file. Open the file with open(name, 'wb') to write binaries. > It is interesting that as a "Unix consultant" you should make that claim. Especially since >>> sys.stdout ', mode 'w' at 0x2aaaaaac9198> ^^^^ Indeed there would be a lot of broken Unix systems out there if that were not the case. As for the OP, you may want to check how stdout is opened on your system. In Windows there are two "write" modes for files, 'w', and 'wb' where apparently 'w' is text mode and 'wb' is binary. You may want to check what mode your stdout is in. I don't have a Windows box handy right now to verify. > There doesn't appear to be any way to retroactively change the mode on > a file. Which is probably a good thing. > > Mike Meyer http://www.mired.org/home/mwm/ > Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From jpablo.romero at gmail.com Thu Oct 20 23:15:16 2005 From: jpablo.romero at gmail.com (Juan Pablo Romero) Date: Thu, 20 Oct 2005 22:15:16 -0500 Subject: fun with lambdas Message-ID: Hello! given the definition def f(a,b): return a+b With this code: fs = [ lambda x: f(x,o) for o in [0,1,2]] or this fs = [] for o in [0,1,2]: fs.append( lambda x: f(x,o) ) I'd expect that fs contains partial evaluated functions, i.e. fs[0](0) == 0 fs[1](0) == 1 fs[2](0) == 2 But this is not the case :( What is happening here? Nevertheless, this code does work fs = [ eval("lambda x: f(x,%d)" % o) for o in [0,1,2,3]] Thanks. Juan Pablo From csubich.spam.block at spam.subich.block.com Fri Oct 7 11:48:23 2005 From: csubich.spam.block at spam.subich.block.com (Christopher Subich) Date: Fri, 07 Oct 2005 11:48:23 -0400 Subject: Python interpreter bug In-Reply-To: <1128699338.667416.56250@o13g2000cwo.googlegroups.com> References: <1128686833.994339.295780@f14g2000cwb.googlegroups.com> <1128695602.718637.144720@g43g2000cwa.googlegroups.com> <1128699338.667416.56250@o13g2000cwo.googlegroups.com> Message-ID: alainpoint at yahoo.fr wrote: > No doubt you're right but common sense dictates that membership testing > would test identity not equality. > This is one of the rare occasions where Python defeats my common sense But object identity is almost always a fairly ill-defined concept. Consider this (Python 2.2, 'cuz that's what I have right now): Python 2.2.3 (#1, Nov 12 2004, 13:02:04) [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-42)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> al = "ab" >>> alp = al+"c" >>> alphabet = "abc" >>> al 'ab' >>> alp 'abc' >>> alphabet 'abc' >>> alp is alphabet 0 >>> alp == alphabet 1 # True on Py2.4 The only reliable thing that object identity tells you is "these two foos occupy the same memory location." Even for identical, immutable objects, this may not be true (see case above) -- some immutables do end up occupying the same memory location (try i=1;j=2;k=j-1;i is k), but this is by no means guraranteed, and indeed only happens sometimes because of optimizations. From __peter__ at web.de Fri Oct 14 06:53:39 2005 From: __peter__ at web.de (Peter Otten) Date: Fri, 14 Oct 2005 12:53:39 +0200 Subject: get_payload problem with large mail attachments References: <1129286221.172200.217160@o13g2000cwo.googlegroups.com> Message-ID: hungryblank at gmail.com wrote: > I'm having troubles with a script that uses the get_payload function. > My script just works perfectly if I use it with attachment up to 8 Mb. > If the attachment are more than 8 Mb large, the script exits with a > TypeError exception. > IMHO when get_payload try to convert the attachment in a single string > it occours in some size limit. > How can I fix it? > Traceback (most recent call last): > File?"/usr/local/sbin/mailbox2home.py",?line?44,?in?? > fp.write(part.get_payload(decode=1)) > TypeError: argument 1 must be string or read-only buffer, not None None seems to be the expected result of get_payload(decode=1) for multipart parts. > if part.get_content_maintype() == 'multipart': > continue Could it be that your test for multipart isn't correct? I would try if part.is_multipart(): continue Peter From nephish at xit.net Mon Oct 3 15:09:27 2005 From: nephish at xit.net (nephish at xit.net) Date: 3 Oct 2005 12:09:27 -0700 Subject: question about smtplib Message-ID: <1128366567.887891.267520@g43g2000cwa.googlegroups.com> Hey there, i am using the smtplib module in python 2.3 my question is, this works: server = smtplib.SMTP(localhost) then server.sendmail(to address, from address, message) what i want to know is, how does the connection work? when i do server.sendmail, does it connect then ? or did it connect when i made the object ? the reason i need to know is i need to send several emails out at once and would be best to only connect once, i think. i know that i can call server.close(), i just dont know when it was opened. thanks From gsakkis at rutgers.edu Fri Oct 7 10:16:16 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Fri, 7 Oct 2005 10:16:16 -0400 Subject: Merging sorted lists/iterators/generators into one stream of values... References: <1128667968.421469.180910@g47g2000cwa.googlegroups.com> <1128691708.c6930b5cb9f3673ed3abe8755178d163@teranews> <1128692196.410209.252100@g14g2000cwa.googlegroups.com> Message-ID: <1128695317.c6a5acb3e62787f011310c96f0c7cc35@teranews> "Lasse V?gs?ther Karlsen" wrote: > Thanks, that looks like Mike's solution except that it uses the > built-in heapq module. This make a big difference for the algorithmic complexity; replacing an item in a heap is much more efficient than sorting the whole list. > While this one contains less code than Mike's solution it seems to lack > the ability to control the comparison operation, which means it won't > work in my case. I need to both be able to sort on an arbitrary field > name (could be done using a list where I place the field first), and > also to be able to sort in a different order than smallest-first. > > Perhaps by adjusting the data that is returned through each source > would do that. I'll look into it. Yes, it's a little inconvenient that the builtin heap doesn't take a comparison operation but you can easily roll your own heap by transforming each item to a (key,item) tuple. Now that I'm thinking about it, it might be a good addition to the cookbook. George From gh at ghaering.de Tue Oct 25 08:20:35 2005 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Tue, 25 Oct 2005 14:20:35 +0200 Subject: PDO and database abstraction In-Reply-To: <1130240852.794081.158320@g47g2000cwa.googlegroups.com> References: <1130240852.794081.158320@g47g2000cwa.googlegroups.com> Message-ID: <435E2313.3090504@ghaering.de> Luiz Geron wrote: > Hi all, > I'm testing the PDO wrapper to database modules [1] and I'm wondering > how few things like this there are around. Actually there are several Object-Relation Mappers (ORM) for Python, and also a few other attempts to provide a more convenient layer on top of DB-API modules. This wiki page has links: http://wiki.python.org/moin/HigherLevelDatabaseProgramming > My problem, actually, is the paramstyle of modules. That problem exactly what these solutions try to solve, this and multiple SQL dialects and handling types like date etc. for multiple backends. > I want to use kinterbasdb in the same code I use > cx_oracle, for example, but paramstyle changes from one to other, than > I searched for things like this and found nothing really usefull. The > problem with PDO is that it was so dificult to find, since a few people > seems to use it, and I haven't yet figured how to change the paramstyle > on it, so I want to ask: Do you use a thing like this that you would > recommend to me? I always wrote my own thin layer on top of DB-API modules and used it to implement a *specific* database interface for my applications. This would then have one or more database backends. Actually never more than two so far. If you want to go for a more popular ORM, you can try out SqlObject. But it doesn't have Oracle support, yet. There were patches and there are apparently again new attempts to integrate Oracle support, but nothing official/finished yet apparently. Personally, I recently checked out different ORMs for Python one afternoon. Only superficially, but here's my biased uninformed opinion. - SqlObject (1) has an active community, and its use in Subway and TurboGears will create even more momentum for it. By looking at its code (for hacking in Oracle support, which I managed to do for a one-table test case), I found it to have *a lot* features, including caching and others. I don't particularly like that, I'd prefer a thin-to-medium layer myself. - There was something to Modeling (2) I didn't like. It's just a gut feeling that it tries to do too much for my taste. - PyDO2 did work with Oracle out of the box, the SQLite and PostgreSQL adapters looked reasonable too from a quick code inspection. It does seem to do one thing and do it right, which is a philosophy I like in libraries and wrappers. If I'm to use a ORM for a future project, I'd first go with PyDO2. HTH, -- Gehard (1) http://sqlobject.org/ (2) http://modeling.sourceforge.net/ (3) http://skunkweb.sourceforge.net/PyDO2/manual.html From aleaxit at yahoo.com Fri Oct 28 22:56:37 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 28 Oct 2005 19:56:37 -0700 Subject: Newbie question: string replace References: <1130258229.662596.228630@g49g2000cwa.googlegroups.com> <3s7620FlqdmnU1@uni-berlin.de> <1130264859.869054.291760@g14g2000cwa.googlegroups.com> <86u0f52uh2.fsf@bhuda.mired.org> Message-ID: <1h55rbb.14ucuuz1ho4jalN%aleaxit@yahoo.com> Mike Meyer wrote: > "usgog at yahoo.com" writes: > > > So how to overwrite the config file directly in script.py instead of > > running script.py with two params? > > Don't overwrite the file directly. Save a copy, then rename it. That See module fileinput in the standard library, it does this for you automatically when used in the right way -- much better than rolling your own and having to debug it and maintain it forever! Alex From alanmk at hotmail.com Thu Oct 27 13:37:06 2005 From: alanmk at hotmail.com (Alan Kennedy) Date: Thu, 27 Oct 2005 18:37:06 +0100 Subject: help with concurrency control (threads/processes & signals) In-Reply-To: References: Message-ID: <9f88f.17902$R5.1736@news.indigo.ie> [Sori Schwimmer] > I am working on an application which involves > interprocess communication. More to the point, > processes should be able to notify other processes > about certain situations, so the "notifyees" would be > able to act in certain ways. > > As processes are distributed on several machines, in > different physical locations, my thinking was: > a) set a message manager (MM) > b) all the participants will register with MM, so MM > will have their host address and their pid on host > c) when someone needs to send a notification, it is > sent to MM, and MM it's doing the job [snip] > Life is a struggle. Programming in Python shouldn't > be. Ergo, I'm doing something wrong. > > Any advice? Rather than rolling your own, have you considered using the spread module: robust, tested, efficient and no infrastructure development required. http://www.zope.org/Members/tim_one/spread/ http://www.python.org/other/spread/ The latter page has links to the original C spread module, which has documentation, FAQs, etc. -- alan kennedy ------------------------------------------------------ email alan: http://xhaus.com/contact/alan From brakjoller at gmail.com Sat Oct 22 21:02:43 2005 From: brakjoller at gmail.com (Mathias Dahl) Date: Sun, 23 Oct 2005 03:02:43 +0200 Subject: Listening for keypress in the background References: Message-ID: Mathias Dahl writes: > Peter Hansen writes: > >>> How can I make it listen for a certain keypress (say, Windows-key + >>> space) in a controlled fashion even when it is not the program having >>> focus? >>> >>> I need to do this running under GNOME in Mandrake GN/Linux 10. >> >> Search Google for "python keylogger". > > Thanks, good idea! The relevant pages I found only link to > Windows-specific keyloggers though. > > I just got another idea on a solution for my main problem (invoking my > sleeping app) and that would be to let my window manager execute a > small "invoker" program that would communicate with the sleeping > app. The question is, which is the easiest way to communicate with a > running Python program? Signals? TCP/IP (not really, right?) Pipes? I solved it using named pipes (mkfifo, open and read) plus a simple echo x > pipe to invoke. From davids at webmaster.com Thu Oct 27 08:30:04 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 05:30:04 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: Lasse V?gs?ther Karlsen wrote: > David Schwartz wrote: >> Roedy Green wrote: > >> competing products. (Just as Burger King corporate will not you sell >> Big Macs in the same store in which you sell Whoppers.) > Rather odd comparison don't you think ? No, it's dead on. > A better comparison would be if Burger King purchases the fries from a > factory that says that Burger King has to give out a pack of fries > with all meals, regardless of the type of meal, or they are going to > raise the price. In other words, you'll be forced to take a pack of > fries with your ice cream, salad or what not. Considering that > McDonalds have been selling meals with "potato-boats" (don't know the > correct english term for it, carved potato pieces fried), they'd have > to give you a pack of fries with your meal regardless, even if you > want to replace the fries with "potato-boats". The reason this is a much worse comparison is that the fries don't determine the nature, to the consumer, of the meal. On the other hand, there is a sense in which all PCs running, say Windows 98, are alike to the consumer. That is, what Microsoft provided is what put the product in its class to the consumer, and to the typical consumer, the meal is a unit. > Also, in this case Burger King "won't sell you" is not the same as > "can't sell you", which seems to be the case with this whole Microsoft > discussion. I'm pretty sure you wouldn't be able to easily buy a > computer from Microsoft with OS/2 installed or vice versa either and > I'm not sure they would be obliged to do so either. However, > controlling what an independant outlet is doing, that's different. I'm talking about Burger King corporate, the wholesale distributor and franchise licensor. They control what any entity that wants to sell their branded products can do, and do so very strictly. The term "independent outlet" is hiding the entire point. Microsoft has no more obligation to sell Windows through independent outlets than Burger Kind corporate has an obligation to sell Whoppers through indepedent outlets, which is none at all. Microsoft elected only to allow Windows to be purchased wholesale through a franchisee like arrangement, so you were no longer a fully independent outlet. I think the history shows that Microsoft opted for a franchisee-type arrangement for much the same reason Burger King does. They want their company name to have value and bring in customers. To do this, they have to prevent their company name from being associated with products that don't provide the experience they want associated with their name and they have to prevent companies that draw based on the popularity of Windows but then switch people to other products. Because Burger King corporate doesn't want a person to see the golden arches, walk in, and get a crappy burger or be told that a competing burger is cheaper and better, they only allow their branded products to be sold at any business that can draw using their name and products. Microsoft, for much the same reasons, resticted people's ability to modify Windows or sell both Windows and competing products. DS From vinay_sajip at yahoo.co.uk Wed Oct 5 18:46:40 2005 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: 5 Oct 2005 15:46:40 -0700 Subject: How to prevent logging warning? In-Reply-To: <1128551304.960549.235420@f14g2000cwb.googlegroups.com> References: <1128551304.960549.235420@f14g2000cwb.googlegroups.com> Message-ID: <1128552400.004933.29180@g49g2000cwa.googlegroups.com> s/without/with/ From gordonb.tt59b at burditt.org Wed Oct 12 21:23:40 2005 From: gordonb.tt59b at burditt.org (Gordon Burditt) Date: Thu, 13 Oct 2005 01:23:40 -0000 Subject: Jargons of Info Tech industry References: <1124804082_1011@spool6-east.superfeed.net> <8q0rk1tiktr86ksdu55mgsqffpkf2uus1c@4ax.com> <11kr5p3hstor935@corp.supernews.com> Message-ID: <11krdosli1jgla7@corp.supernews.com> >> Links >> Javascript >> Forms >> References to other files > >the only piece of that particularly dangerous is JavaScript. So long >as you have a scheme to unmask where links are really going links are >no more dangerous than they are in browser. Browsers don't read unsolicited web sites. Email readers do, however, read unsolicited email, and email from downright hostile correspondents. And I consider "web bugs" and similar tracking methods to be a danger for something that's supposed to be ONLY "formatted text". >Even a form is not dangerous. You have to fill it in and hit submit. So where does the submitted data GO? And there's all kind of information in there about what software I'm running. Gordon L. Burditt From the.theorist at gmail.com Tue Oct 25 18:57:41 2005 From: the.theorist at gmail.com (the.theorist) Date: 25 Oct 2005 15:57:41 -0700 Subject: Setting Class Attributes In-Reply-To: <435e91b1$0$21322$626a54ce@news.free.fr> References: <1130263774.719830.6230@f14g2000cwb.googlegroups.com> <435e91b1$0$21322$626a54ce@news.free.fr> Message-ID: <1130281061.552882.134540@g14g2000cwa.googlegroups.com> Bruno Desthuilliers wrote: > the.theorist a ?crit : > > I have a small, simple class which contains a dictionary (and some > > other stuff, not shown). I then have a container class (Big) that holds > > some instances of the simple class. When I try to edit the elements of > > the dictionary, all instances obtain those changes; I want each > > instance to hold separate entries. > > > > #----------Begin module test.py > > class ex: > > class ex(object): # oldstyle classes are deprecated > > > def __init__(self, val={}): > > self.value = val > > You didn't search very long. This is one of the most (in)famous Python > gotchas: default args are evaluated *only once*, when the function > definition is evaluated (at load time). This is also a dirty trick to > have a 'static' (as in C) like variable. > > The solution is quite simple: > class ex(object): > def __init__(self, val=None): > if val is None: val = {} > self.value = val > > (snip) Hey, that was extremely helpful. I suspect that the default args evaluation is optimized for speed. So it makes sense to use the None assignment, and a test condition later. Worked like a charm, Thanks! From john at hazen.net Tue Oct 4 15:40:27 2005 From: john at hazen.net (John Hazen) Date: Tue, 4 Oct 2005 12:40:27 -0700 Subject: Background process for ssh port forwarding In-Reply-To: References: Message-ID: <20051004194027.GB31364@gate2.hazen.net> Hi Jesse- > def hostforward(): > #This is based on the assumption that the passfile is the gnus > #authinfo file, or has a similar format... > f = open(PASS_FILE, "r") > f_list = f.read().split(' ') > f.close() > #Now, we get the entry after "password" (be slicker to make it a > #dictionary, but maybe wouldn't work as well). > pass_index = f_list.index('password') + 1 > forwardpass = f_list[pass_index] > #now we connect > command = 'ssh -l %s -L 2022:%s:22 %s' % \ > (login, my_server, forwarding_server) > connection = pexpect.spawn(command) > connection.expect('.*assword:') > connection.sendline(forwardpass) > > If I end this with 'connection.interact()', I will end up logged in to the > forwarding server. But what I really want is to go on and run rsync to > localhost port 2022, which will forward to my_server port 22. So, how can > I put the ssh connection I set up in hostforward() in the background? > I need to make sure that connection is made before I can run the rsync > command. I think what's happening is that when you return from 'hostforward', the connection is being closed because of garbage collection. Python uses (among other stuff) reference counting to tell it when to delete objects. After hostforward returns from execution, there are no longer any references to 'connection', so it gets deleted, which cleans up the connection. You probably want to add: return connection at the end of hostforward, and call it like: connection = hostforward() my_rsync_function() connection.close() # or whatever the approved pexpect cleanup is Hope that helps- John From jadedgamer at hotmail.com Sun Oct 16 04:11:07 2005 From: jadedgamer at hotmail.com (Tor Iver Wilhelmsen) Date: 16 Oct 2005 10:11:07 +0200 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: "David Schwartz" writes: > How is that better? Nothing in your car depends upon what tires you have > on. But all of the rest of the software on your computer is dependent upon > your choice of OS. Which cars let you install another engine as easily as you can install a new operating system? Admit the analogy sucks, like all car-computer analogies invariably do. > I don't really know why and I don't particularly care. I think it has a > lot to do with support costs and may also have to do with the type of deals > Microsoft offers. Microsoft apologists always assume that training cost for Windows users are zero, that people "know" Windows from the start. If that was true, there would not be a multi-million market in Windows user support. > The point is, they do. And there's nothing unusual, immoral, or > problemmatic about it. If you don't think the total package is worth the > total package price, buy elsewhere. But when Microsoft were doing their illegal arm-wringing of dealers, there was no "elsewhere" to go. From scott.daniels at acm.org Thu Oct 13 14:10:37 2005 From: scott.daniels at acm.org (Scott David Daniels) Date: Thu, 13 Oct 2005 11:10:37 -0700 Subject: Python's garbage collection was Re: Python reliability In-Reply-To: <7xr7apqw1y.fsf@ruckus.brouhaha.com> References: <3r6i0uFi3qb8U2@uni-berlin.de> <7xfyr5kfgm.fsf@ruckus.brouhaha.com> <3r6osdFhsfjgU1@uni-berlin.de> <7xvf0168nq.fsf@ruckus.brouhaha.com> <434e7967$1@nntp0.pdx.net> <7xr7apqw1y.fsf@ruckus.brouhaha.com> Message-ID: <434ea2ad$1@nntp0.pdx.net> Paul Rubin wrote: > Scott David Daniels writes: > >>Current speeds are due to deep pipelines, and a conditional in the >>INCREF code would blow a pipeline. > > > I think most of the time, branch prediction will prevent the cache > flush. But, branch prediction is usually a compiler thing, based on code that is, in this case, a spot in the interpreter that is actually taking both sides of the branch quite often. If you split the interpreter to have a "presumed int" side, you might do OK, but that is not how the code works at the moment. > Some implementations use the low order bits as tags with a tag==0 > meaning an integer. That means if you have two tagged integers, > you can add and subtract them without having to twiddle the tags. You can do so only once you discover you have two tagged integers. The test for tagged integers (rather, the subsequent branch) is the thing that blows the pipe. > The alternative (tag==1 means integer) means you don't have to mask > off the tag bits to dereference pointers, and you can still add a > constant to a tagged int by simply adjusting the constant > appropriately. And this presumes an architecture which byte-addresses and only uses "aligned" addresses. --Scott David Daniels scott.daniels at acm.org From fredrik at pythonware.com Fri Oct 7 11:52:21 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 7 Oct 2005 17:52:21 +0200 Subject: [Info] PEP 308 accepted - new conditional expressions References: <3q4ro9Fd770nU3@individual.net> <200510070105.12846.hancock@anansispaceworks.com> Message-ID: Terry Hancock wrote: > GvR's syntax has the advantage of making grammatical sense in English (i.e. > reading it as written pretty much makes sense). as a native Python speaker, I find that argument being remarkably weak. things I write in Python should make sense in Python, not in some other language. (besides, we already have way too many languages designed by self-proclaimed linguists) From http Mon Oct 10 00:44:31 2005 From: http (Paul Rubin) Date: 09 Oct 2005 21:44:31 -0700 Subject: best Pythonic way to do this sort: Python newb References: Message-ID: <7xbr1y9e1c.fsf@ruckus.brouhaha.com> "Sean Berry" writes: > myList = [[value1, value2, value3],[value1, value2, value3], ...] > > I have a function which takes value3 from the lists above and returns > another value. I want to use this returned value to sort the lists. > > So, my resultant list would be ordered by the return value of the > function with value3 as its argument. > > From a relative Python newb, what is the best way to do this? def get_key(x): return x[2] sorted_list = sorted(myList, key=get_key) From pnau at sjm.com Tue Oct 4 01:42:52 2005 From: pnau at sjm.com (pnau at sjm.com) Date: 3 Oct 2005 22:42:52 -0700 Subject: semi-newbie module namespace confusion Message-ID: <1128404572.837225.41870@g47g2000cwa.googlegroups.com> I've stuck my neck out and am in the integration stage of a rather important project at my company, which wears dot net blinders. The program is not too big: I've cranked out 3K lines of code, quite a bit of which is unit tested, but my eyes are starting to glaze, and now I'm stuck (and not just my neck :-). If I can get the show back on the road and bring it to a conclusion, I'll be able to persuade a lot of people to look closely at Python (not to mention the job retention aspect :-). The main jist of the problem is that I'm trying add data from one module to a list and a dictionary in another module, and it doesn't seem to stick over there. The programs below seem to illustrate the issue. (The results follow the programs). Why are the results different from runs of the two programs? The output of nameSpaceTestB.py makes sense to me, but I just don't get why nameSpaceTestA.py does what it does. I'm sure the reason is very simple, but I just don't see it. Please, can someone shed some light on the issue for me? Thanks! ~Peter --------------------------------- nameSpaceTestA.py: import nameSpaceTestB as NSB normalQ = [ 37] abc = 25 def indirect( ) : normalQ.append( 44) print "printing from NSA:" print normalQ NSB.updateNSA( ) print "printing from NSA:" print normalQ print "abc = %d" % abc if __name__ == '__main__' : indirect() --------------------------------- nameSpaceTestB.py: import nameSpaceTestA as NSA def updateNSA( ) : print "printing from NSB:" print NSA.normalQ NSA.normalQ.append( "gotcha") print NSA.normalQ print NSA.abc NSA.abc = 666 print NSA.abc if __name__ == '__main__' : NSA.indirect() --------------------------------- > py24 nameSpaceTestA.py printing from NSA: [37, 44] printing from NSB: [37] [37, 'gotcha'] 25 666 printing from NSA: [37, 44] abc = 25 > --------------------------------- > py24 nameSpaceTestB.py printing from NSA: [37, 44] printing from NSB: [37, 44] [37, 44, 'gotcha'] 25 666 printing from NSA: [37, 44, 'gotcha'] abc = 666 From email at christoph-haas.de Sat Oct 1 19:35:14 2005 From: email at christoph-haas.de (Christoph Haas) Date: Sun, 2 Oct 2005 01:35:14 +0200 Subject: Printing and prompting adds a mysterious extra space In-Reply-To: <20051001220948.GA3403@unpythonic.net> References: <1128197861.418869.221640@g43g2000cwa.googlegroups.com> <20051001214428.GA22491@torf.workaround.org> <20051001220948.GA3403@unpythonic.net> Message-ID: <20051001233514.GA30404@torf.workaround.org> On Sat, Oct 01, 2005 at 05:09:48PM -0500, jepler at unpythonic.net wrote: > Use sys.stdout.write instead of print. It will solve these problems you are > having. > > If you really want to know what's going on, read the language manual, > http://docs.python.org/ref/print.html It explains the behavior of this extra > space, which is output by a successive 'print' statement. The implementation > uses an attribute called 'softspace', which is described in > http://docs.python.org/lib/bltin-file-objects.html Thank you for the technical explanation. "print a,b" is nice to read in simple Python programs. But when you need to get more control of I/O it's better to know what's really happening inside. So the "softspace" is always added after a "print a," statement but only printed if Python thinks it is not at the beginning of a terminal line. Interesting. Again, thanks. I'll rest my case. Christoph -- I'm still confused - just on a higher level now. ~ ~ ".signature" [Modified] 1 line --100%-- 1,48 All From rschroev_nospam_ml at fastmail.fm Wed Oct 5 04:52:17 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Wed, 05 Oct 2005 08:52:17 GMT Subject: Confused with module and .py files In-Reply-To: References: Message-ID: <5vM0f.13069$RZ.594052@phobos.telenet-ops.be> Iyer, Prasad C wrote: > Actually I am bit confused between the modules and .py file > How do I differentiate between the 2. > > For example > I have a file import1.py, import2.py file > Which has few functions and classes > And if I have a class with same name "BaseClass" in both the file > > How would I use it if I declare it as given below in my 3rd class > > from import1.py import * > from import2.py import * Name conflicts like that are a good reason not to use from ... import *, but instead: import import1 import import2 bc1 = import1.BaseClass() bc2 = import2.BaseClass() (Note: don't include the extension .py in the import statements) Namespaces are great for preventing name conflicts; don't circumtvent them by blindly importing everything into the same namespace. As the Zen of Python says: "Namespaces are one honking great idea -- let's do more of those!" -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From timr at probo.com Wed Oct 5 23:36:32 2005 From: timr at probo.com (Tim Roberts) Date: Thu, 06 Oct 2005 03:36:32 GMT Subject: question about smtplib References: <1128366567.887891.267520@g43g2000cwa.googlegroups.com> <1128380307.865252.289510@f14g2000cwb.googlegroups.com> <1494k1pvqvo9lg21q8bhi9qrgmc2ftl5kn@4ax.com> Message-ID: Piet van Oostrum wrote: >>>>>> Tim Roberts (TR) wrote: > >>TR> nephish at xit.net wrote: >>>> cool. so this line >>>> server = smtplib.SMTP(localhost) >>>> is when i connect ? > >>TR> Use the source, Luke. Source code for every standard module is included on >>TR> your hard disk. If you look in the __init__ for "class SMTP", your >>TR> question will be answered. > >The documentation should be the ultimate reference for the API. The source >is just implementation detail which may change in the future. I won't argue with that, but the question of "exactly when does the connection occur" is in itself an implementation detail. I wouldn't expect it to be answered in the documentation. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From steve at REMOVETHIScyber.com.au Sat Oct 22 07:05:43 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sat, 22 Oct 2005 21:05:43 +1000 Subject: best way to replace first word in string? References: <1129822003.246170.303920@f14g2000cwb.googlegroups.com> Message-ID: On Thu, 20 Oct 2005 10:25:27 -0700, Micah Elliott wrote: > I thought that string concatenation was rather > expensive, so its being faster than %-formatting surprised me a bit: Think about what string concatenation actually does: s = "hello " + "world" In pseudo-code, it does something like this: - Count chars in "hello" (six chars). - Count chars in "world" (five chars). - Allocate eleven bytes. - Copy six chars from "hello " and five from "world" into the newly allocated bit of memory. (This should not be thought of as the exact process that Python uses, but simply illustrating the general procedure.) Now think of what str-formatting would do: s = "hello %s" % "world" In pseudo-code, it might do something like this: - Allocate a chunk of bytes, hopefully not too big or too small. - Repeat until done: - Copy chars from the original string into the new string, until it hits a %s placeholder. - Grab the next string from the args, and copy chars from that into the new string. If the new string is too small, reallocate memory to make it bigger, potentially moving chunks of bytes around. The string formatting pseudo-code is a lot more complicated and has to do more work than just blindly copying bytes. It has to analyse the bytes it is copying, looking for placeholders. So string concatenation is more efficient, right? No. The thing is, a *single* string concatenation is almost certainly more efficient than a single string concatenation. But now look what happens when you repeat it: s = "h" + "e" + "l" + "l" + "o" + " " + "w" + "o" + "r" + "l" + "d" This ends up doing something like this: - Allocate two bytes, copying "h" and "e" into them. - Allocate three bytes, copying "he" and "l" into them. - Allocate four bytes, copying "hel" and "l" into them. ... - Allocate eleven bytes, copying "hello worl" and "d" into them. The problem is that string concatenation doesn't scale efficiently. String formatting, on the other hand, does more work to get started, but scales better. See, for example, this test code: py> def tester(n): ... s1 = "" ... s2 = "%s" * n ... bytes = tuple([chr(i % 256) for i in range(n)]) ... t1 = time.time() ... for i in range(n): ... s1 = s1 + chr(i % 256) ... t1 = time.time() - t1 ... t2 = time.time() ... s2 = s2 % bytes ... t2 = time.time() - t2 ... assert s1 == s2 ... print t1, t2 ... py> x = 100000 py> tester(x) 3.24212408066 0.01252317428 py> tester(x) 2.58376598358 0.01238489151 py> tester(x) 2.76262307167 0.01474809646 The string formatting is two orders of magnitude faster than the concatenation. The speed difference becomes even more obvious when you increase the number of strings being concatenated: py> tester(x*10) 2888.56399703 0.13130998611 Almost fifty minutes, versus less than a quarter of a second. -- Steven. From juho.schultz at helsinki.fi Fri Oct 28 03:42:05 2005 From: juho.schultz at helsinki.fi (Juho Schultz) Date: Fri, 28 Oct 2005 10:42:05 +0300 Subject: Jpg In-Reply-To: <1130349223.948333.83230@g49g2000cwa.googlegroups.com> References: <1130349223.948333.83230@g49g2000cwa.googlegroups.com> Message-ID: Tuvas wrote: > I am building a GUI interface at the moment, and would like to have > support for displaying a jpg file, and a FITS file if possible. Is > there any way to do this? My interface has been written in Tkinter at > the moment, especially because of it's great portability, I wouldn't > have to install the other interface software on every computer that I > use (At the moment it is 3, and will signifigantly increase). I'd > prefer to only use built-in functions, but if it can't be done, I'm > willing to look for something else. Is there any way I can do this? > Thanks! > For FITS file reading, an alternative to pCFITSIO is PyFITS (http://www.stsci.edu/resources/software_hardware/pyfits). I guess both need numarray... gifImage = Tkinter.PhotoImage(file="file.gif") ima = yourCanvas.create_image(xpos,ypos,image=gifImage) is the quickest way to display gifs. My version of Tkinter (1.177) does not directly support jpg, but with PIL that should be possible. Ugly but quick solution (for Linux): produce gifs from FITS/jpg files with os.system("convert") and feed them to Tkinter. From news at NOwillmcguganSPAM.com Tue Oct 18 15:13:53 2005 From: news at NOwillmcguganSPAM.com (Will McGugan) Date: Tue, 18 Oct 2005 20:13:53 +0100 Subject: wxPython question In-Reply-To: <1129625587.831829.277820@g47g2000cwa.googlegroups.com> References: <1129207833.953525.266880@f14g2000cwb.googlegroups.com> <434e5dac$0$25428$db0fefd9@news.zen.co.uk> <1129625587.831829.277820@g47g2000cwa.googlegroups.com> Message-ID: <43554972$0$21365$db0fefd9@news.zen.co.uk> vpr wrote: > I've had some problems, it seems that they dont render well in Linux. I > tried it with Ubuntu Breezy. I suspect that the animation may cause problems because of all the refreshes. Perhaps you can render the window first then save it as a bitmap. A simple blit should be better for the animation. HTH, Will McGugan -- http://www.willmcgugan.com "".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in "jvyy*jvyyzpthtna^pbz") From tim.golden at viacom-outdoor.co.uk Wed Oct 26 05:45:16 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Wed, 26 Oct 2005 10:45:16 +0100 Subject: p2exe using wine/cxoffice Message-ID: <9A28C052FF32734DACB0A288A3533991044D22A0@vogbs009.gb.vo.local> > James Stroud wrote: >> "better". The only reason I want this functionality is to make my software >> available to windoze users--despite their unfortunate ignorance, they are >> people too. That's what I always say. Jon Perez writes: > Actually, I think it's many unix/linux users who are ignorant of just > how nice, stable and productive Windows can be as a desktop environment. > > ... and I really mean that. ;-). > Thomas Heller: > I was waiting for someone to say that. > +1. Well, I'm with you. I'm sure a lot of people will chime in to point out just how flexible and useful and productive Linux is as a workstation, but every time I try to use it -- and I make an honest effort -- I end up back in Windows where I've been at home for 10 years and more. I don't claim that Windows has some overall superiority; I merely claim that -- as a professional programmer -- I find Windows at least as easy and comfortable and productive for my tasks as Linux. 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 steve at holdenweb.com Tue Oct 18 03:30:59 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 18 Oct 2005 08:30:59 +0100 Subject: bug in os.system? In-Reply-To: <1129619331.578069.97430@g14g2000cwa.googlegroups.com> References: <1129617198.528491.125830@g44g2000cwa.googlegroups.com> <1129619331.578069.97430@g14g2000cwa.googlegroups.com> Message-ID: wjzrules at gmail.com wrote: > What happens when you try it without the single quotes? > result = os.system("pythonbugtest.exe" "test") > That would be equivalent to result = os.system("pythonbugtest.exetest") which almost certainly won't do anything useful. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From noway at sorry.com Tue Oct 11 05:53:49 2005 From: noway at sorry.com (Giovanni Bajo) Date: Tue, 11 Oct 2005 09:53:49 GMT Subject: A faster shutil.rmtree or maybe a command. References: <1129024138.029854.80350@g47g2000cwa.googlegroups.com> Message-ID: martijn at gamecreators.nl wrote: > Sometimes I must delete 2 very big directory's. > The directory's have a very large tree with much small file's in it. > > So I use shutil.rmtree() > But its to slow. > > Is there a faster method ? Is os.system("rm -rf %s" % directory_name) much faster? -- Giovanni Bajo From rich.teer at rite-group.com Sun Oct 9 12:34:58 2005 From: rich.teer at rite-group.com (Rich Teer) Date: Sun, 09 Oct 2005 16:34:58 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> Message-ID: On Sun, 9 Oct 2005, Roedy Green wrote: > This is pulling a King Canute. There is not even a mechanism in email > protocols to warn your correspondents of your demand. I have been Yes there is: the message my server sends someone sending me HTML says so quite plainly. That Outhouse (and presumably other WIndoze email clients) choses to not display the real message and put up some other generic, "user friendly" (but totally techie useless) message besides the point. > There is nothing wrong with formatted text. You are confusing > formatted text with spam. > > You think you hated formatted text, but you really hate spam. Please don't presume to think for me. I've been using email and the Internet for over 10 years, and I think I can differentiate between spam and formatted text. I hate spam, that's a given. But I hate spam that's in plain text as well as formatted text. I hate HTML email for several reasons, including: 1. it's wasteful of bandwidth 2. it enourages people to put form over content 3. it doesn't display properly on my email client of choice, which, BTW, I've been using in various versions for 10+ years. There are probably others, but you get my drift. You'll also notice that I deliberately didn't list the security issues. HTML is for web sites, not email. > If your lover sent you a message with photo, and even musical > accompaniment, I doubt you would feel offended. It is the CONTENT > bugging you, not the HTML. No it isn't. And my wife knows better than to do that. When she sends me virtual boquets, she does so in the correctmanner: she sends me a plain text link to a web site that does all the fancy stuff, including background music. That is how it should be. > You imagine that the two are inexplicably linked. That is just because No I don't. > Eudora warns you of deceptive links in HTML. There are many more such I am fortuanate enough to not use Windoze. > unfair to blame formatting for the foolish practice off allowing > untrusted code to run without even an ok. They have nothing to do > with each other. Agreed. But as I said above, I have many other issues with HTML emails, over and above the security concerns. -- Rich Teer, SCNA, SCSA, OpenSolaris CAB member President, Rite Online Inc. Voice: +1 (250) 979-1638 URL: http://www.rite-group.com/rich From john at castleamber.com Mon Oct 17 17:46:32 2005 From: john at castleamber.com (John Bokma) Date: 17 Oct 2005 21:46:32 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: Roedy Green wrote: > On 16 Oct 2005 00:47:09 GMT, John Bokma wrote > or quoted : > >>Ok, let me spell it out for you: If all your applications are web based, >>and the OS shouldn't matter, why do Linux distributions matter? > > The point is you make your choice based on quality of the OS and > distribution, not whether it can run a given piece of software. But some clients will work better with web based software, or make the users believe so. If this idea was correct, why aren't all browsers equal in usage and performance? Instead of quality, people seem to pick a browser based on zealotism, look and feel, how well it can be extended, or if a major player is behind it. > Web apps, Java and other multiplatform tools force OSes to compete on > quality, not on proprietary lockin. Nah, they compete on gadgets, and the ignorance of the majority of users. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From sean_mcilroy at yahoo.com Sat Oct 29 00:19:00 2005 From: sean_mcilroy at yahoo.com (Sean McIlroy) Date: 28 Oct 2005 21:19:00 -0700 Subject: tkinter blues (greens, reds, ...) In-Reply-To: References: <1130519159.921821.164420@z14g2000cwz.googlegroups.com> <1130534916.236147.314810@g43g2000cwa.googlegroups.com> Message-ID: <1130559540.711828.26960@g47g2000cwa.googlegroups.com> hi ron changing from english words to hexadecimal numerals did the trick for me, so everything's cool now. thanks for looking at it. peace From peter at engcorp.com Mon Oct 17 20:02:48 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 17 Oct 2005 20:02:48 -0400 Subject: How to get a raised exception from other thread In-Reply-To: <1129571521.699077.224300@f14g2000cwb.googlegroups.com> References: <1129326320.914350.171460@o13g2000cwo.googlegroups.com> <1129571521.699077.224300@f14g2000cwb.googlegroups.com> Message-ID: dcrespo wrote: >>Define what "get" means for your purposes. It appears that you mean you >>want to catch the exception, but in the thread which launched the other >>thread in the first place. If that's true, please show where you would >>expect to catch this exception, given that when you start the thread, >>the main thread continues running and might even finish before the other >>thread finishes. > > In my above example, I want to catch in ProgramA the raised exception > in ProgramB. Better not to call them "programs" since they're not separate programs, just separate modules, one of which starts a thread using methods in the other module. And you haven't really answered the questions I asked. Please show exactly where you expect to catch the exception, given the points I note above. Before, after, or during the .start() call, or somewhere else? > Please, look at my example one more time. Done. It didn't really help looking at it a third time. It's still unclear what you want. Maybe explaining the use case would help you help us help you. :-) Your example seems contrived. In the real code you want to write, why do you expect an exception to occur? Will it be raised deliberately, as you show in the example, or is it unexpected (and unhandled by any try/except at the top level of the thread's run() method)? Or do you really need to use an exception here? I'm quite sure the problem you are trying to solve can be solved, but you are still describing part of the solution you believe you need, rather than explaining why you want to do this (which may let us show you other, simpler or cleaner ways to accomplish your goals). -Peter From andreas.zwinkau at googlemail.com Fri Oct 7 12:09:10 2005 From: andreas.zwinkau at googlemail.com (beza1e1) Date: 7 Oct 2005 09:09:10 -0700 Subject: How to run python scripts with IDLE In-Reply-To: <1128690531.661166.102690@g14g2000cwa.googlegroups.com> References: <1128690531.661166.102690@g14g2000cwa.googlegroups.com> Message-ID: <1128701350.660096.244310@g47g2000cwa.googlegroups.com> What are you developing for? You could write another small python scripts, which calls your script. os.system("python yours.py --param ?nic?de") From erchamion.beren at gmail.com Wed Oct 12 04:06:05 2005 From: erchamion.beren at gmail.com (Sinan Nalkaya) Date: Wed, 12 Oct 2005 11:06:05 +0300 Subject: button design in curses library Message-ID: <434CC3ED.7010109@gmail.com> hi, im using curses library in my program, i need a button. but i cannot find anything about it. should i do the button via newwin function with bold characters ? any help will be appreciated thanks. From nil at dev.nul Tue Oct 11 01:05:53 2005 From: nil at dev.nul (Christian Stapfer) Date: Tue, 11 Oct 2005 07:05:53 +0200 Subject: Comparing lists References: <1128930699.799657.146210@g47g2000cwa.googlegroups.com> <1128952417.0544cc73190bbbd4e683448c137969c8@teranews> Message-ID: "Steve Holden" wrote in message news:mailman.1843.1128959845.509.python-list at python.org... > Christian Stapfer wrote: >> "George Sakkis" wrote in message >> news:1128952417.0544cc73190bbbd4e683448c137969c8 at teranews... >> >>>"Christian Stapfer" wrote: >>>> wrote: >>>> >>>>>try to use set. >>>> >>>> Sorting the two lists and then extracting >>>>A-B, B-A, A|B, A & B and A ^ B in one single >>>>pass seems to me very likely to be much faster >>>>for large lists. >>> >>>Why don't you implement it, test it and time it >>>to be more convincing about your intuition ? >> >> The problem is in the generation of the test data. >> Even merely generating a set of (suitably "average", >> "random", and suitably "worst case") datasets might >> turn out to be a major undertaking. >> If the documentation stated the order-of-magnitude >> behavior of those basic operations up front, then >> I (and *anyone* else who ever wanted to use those >> operations on large lists / large sets) could do >> a quick order-of-magnitude estimation of how >> a certain program design will behave, performance >> wise. >> *Experimenting* is not necessarily as easy to >> do as you seem to believe. How do you, for example, >> hit upon the worst-case behavior with your test >> data? - Without knowing *anything* about the >> implementation it might a matter sheer luck. >> If you *know* something about the implementation >> then, of course, you might be able to figure it >> out. (But note that if you know *that* much about >> the implementation, you usually have an order-of- >> magnitude estimate anyway and don't need to do >> *any* experimenting in order to answer my question.) >> > You are, of course, either assuming that there's a > single implementation of Python, Of course not! > or that all implementations have the same behaviour. Of course not! But it is reasonable, anyway, to ask for information about a specific implementation (that one is *forced* to use). Performance *will* depend on it, whether we like it or not, whether that information is given by the implementer or not. And if the implementer wants to complain that giving such information would break his wonderful abstraction then I can only answer: It is *reality* that *will* break your abstraction as regards performance! It is, therefore, absolutely *no* use to *pretend* you *can* avoid this form of "breaking the abstraction" by simply avoiding to mention it in the documentation... > Or alternatively you are asking all implementers > to do what you seem to consider so difficult > (i.e. identify worst-case scenarios and then estimate order-of-magnitude > behaviour for them). I consider it the job of the implementer to know about the trade-offs that he has been making in choosing one particular implementation, and to know what computational complexity therefore attaches to the various operations exposed in its interface. Why should *every* user of his module be forced to either read the source code of his implementation or try to figure it out experiment-wise on his own? > Test results with known test data are relatively > easy to extrapolate from, and if your test data > are reasonably representative of live data then so will your performance > estimates. How reasonable is it to ask me, or anyone else for that matter, to extract, experiment-wise (if it can be done at all with reasonable effort) information that properly belongs to the implementer and really should have been exposed in the documentation in the first place? > Anyway, aren't you more interested in average > behaviour than worst-case? Most people are. It depends. *I* am NOT the OP of this thread. *The*OP* had asked for an "efficient" way to do what he needed to do. There are many measures of efficiency. Even "programmer efficiency" may be one of them. But I assumed that, since the OP took the time to ask his question in this NG, that it really was about "computational efficiency". Then he was offered solutions - but they were offered just matter-of-factly. *Surely* those who had posted those solutions would be able to answer my question *why* it was, that they *assumed* conversion into sets to be more efficient than operating on the lists in the first place. I was *not* at all criticizing anyone (except, perhaps, the Python documentation for its lack of *insightful* information): I was just asking for a *small* clarification that I *assumed* (mistakenly it now appears) others could *easily* provide. Regards, Christian -- "Those who cannot remember the past are condemned to repeat it." - George Santayana From sybrenUSE at YOURthirdtower.com.imagination Wed Oct 26 08:58:23 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Wed, 26 Oct 2005 14:58:23 +0200 Subject: Windows vs Linux [was: p2exe using wine/cxoffice] References: Message-ID: Tim Golden enlightened us with: > But as far as I can tell from my experience and from the docs -- and > I'm not near a Linux box at the mo -- having used ctrl-r to recall > line x in the history, you can't just down-arrow to recall x+1, x+2 > etc. Or can you? With bash as well as the Python interactive shell: - ^R followed by a partial string to search - Hit ^R again to get the previous match, repeat as required - Hit ^A/^E to move the cursor to the beginning/end of the line, stopping the "search mode". This allows you to use arrow up/down from that point in the readline history. 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 Sun Oct 2 16:34:21 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 2 Oct 2005 22:34:21 +0200 Subject: A Moronicity of Guido van Rossum References: <1128003857.930444.47650@g14g2000cwa.googlegroups.com><1128013745.763757.144280@g44g2000cwa.googlegroups.com><1128176637.146092.314200@o13g2000cwo.googlegroups.com> <434031f6$0$73596$ed2619ec@ptn-nntp-reader03.plus.net> Message-ID: "Michael" wrote: > List comprehensions get their name (AFAICT) very clearly from set > comprehensions in mathematics. As a result anyone who has ever seen > a set comprehension in maths goes "oooh, I see". They're not the same, but > IMO they're close enough to warrant that name. fwiw, they've also been around for ages: http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?list+comprehension (the name goes back to the early eighties, the construct is older than that) From ark at acm.org Sun Oct 16 14:27:04 2005 From: ark at acm.org (Andrew Koenig) Date: Sun, 16 Oct 2005 18:27:04 GMT Subject: [Info] PEP 308 accepted - new conditional expressions References: <3q4ro9Fd770nU3@individual.net> <3q6oo1Fddg7eU3@individual.net> <7xr7b5zq31.fsf@ruckus.brouhaha.com> <1129129852.92dc41cf1bd445c448e00bd42ec59500@teranews> <4rmdnW7aD-pYAdDenZ2dnUVZ_sudnZ2d@powergate.ca> Message-ID: "Peter Hansen" wrote in message news:4rmdnW7aD-pYAdDenZ2dnUVZ_sudnZ2d at powergate.ca... > Dave Hansen wrote: >> So lose the "if." >> >> R = C then A else B I think that part of the argument for the "A if C else B" syntax is that "then" is not currently a reserved word. From noway at sorry.com Sat Oct 15 20:00:08 2005 From: noway at sorry.com (Giovanni Bajo) Date: Sun, 16 Oct 2005 00:00:08 GMT Subject: Some set operators References: <1129408019.100885.323870@g47g2000cwa.googlegroups.com> <1h4hwtl.np9wjhchw3duN%aleax@mail.comcast.net> Message-ID: Alex Martelli wrote: > I still vaguely hope that in 3.0, where backwards incompatibilities > can be introduced, Python may shed some rarely used operators such as > these (for all types, of course). I hope there is no serious plan to drop them. There is nothing wrong in having such operators, and I wouldn't flag bit operations as "rarely used". They are very common when calling C-based API and other stuff. I know I use them very often. They have a clear and well-understood meaning, as they appear identical in other languages, including the widely-spread C and C++. Giovanni Bajo From aleax at mail.comcast.net Wed Oct 12 17:39:02 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Wed, 12 Oct 2005 23:39:02 +0200 Subject: Adding a __filename__ predefined attribute to 2.5? References: <1129098667.336115.303060@g47g2000cwa.googlegroups.com> <1129103007.870187.101790@g44g2000cwa.googlegroups.com> <1129150883.303899.259570@g43g2000cwa.googlegroups.com> Message-ID: <1h4ce9x.v65tbpm7xivfN%aleax@mail.comcast.net> Rune Strand wrote: > > those modules are already imported when Python gets to your code, so > > the only "overhead" you're saving is a little typing. > > I don't understand this. Could you please elaborate? - if sys or os > are not imported for any other causes how are they already imported? The "other causes" are always present, since these modules include functionality Python always needs -- a fact that is no big secret, either. For example: you know (I assume and hope) that Python's import statement finds files to import along directories (and zipfiles) listed in sys.path -- so how do you think 'sys' itself can possibly get 'imported' in the first place, since the import mechanism depends on one of sys's attributes...? Answer: sys is a built-in module, compiled into the Python interpreter itself. There are several, see sys.builtin_file_names for a list. 'os' is a slightly different case -- it's not built-in, but gets imported anyway during startup because other modules need it anyway. In my build of Python 2.4.1, there are 16 built-in modules, and 9 others that aren't built-in but get imported at startup -- check sys.modules on your version for the total number of modules that are in memory by the time any code of yours runs. (This is with -S to inhibit Python from reading the site.py module, otherwise you might get more... but never, I believe, could you get fewer). > Maybe I'm wrong here, and accessing the filesystem and reading the > module into memory represents no cost. My mistake, in that case. Your mistake is due to a different case: the filesystem access and reading have ALREADY happened (for os; for sys, as I explained, the mechanism is different). Therefore, an import does NO such access and reading -- it just gets the module object from (e.g.) sys.modules['os']. > > wow. that's one lousy optimization... > > > here's a *shorter* piece of code, which is also readable and portable, and > > a lot easier to type on most keyboards: > > > import os > > __filename__ = os.path.basename(__file__) > > It may be lousy, but it requires no imports. And, as I said in the The point is that there's no substantial advantage to "requiring no imports". Python, if anything, already has too many built-ins -- once backwards compatibility can be broken (i.e., in 3.0), many of them should be moved to standard library modules, "requiring imports" (which are cheap operations anyway). The desire for MORE built-ins with no real advantage (since "requiring no imports" ISN'T a true advantage) is definitely misplaced. Alex From rNOSPAMon at flownet.com Wed Oct 19 14:41:44 2005 From: rNOSPAMon at flownet.com (Ron Garret) Date: Wed, 19 Oct 2005 11:41:44 -0700 Subject: question about timestamp and MySQLdb References: Message-ID: In article , "Sean Berry" wrote: > I am using MySQLdb to connect to a database and retrieve a timestamp from a > table. The problem is I want the timestamp as a long, unformatted and all. > > In the table I have a timestamp like this > 20051019111617 > > But, when I retrieve the value and print it I get > 2005-10-19 11:16:17 > > I want the numeric version, not the converted date. Any suggestions? Two suggestions: 1. Read up on strftime. 2. Rethink what you're doing because it's almost certainly wrong. rg From steve at holdenweb.com Thu Oct 20 20:05:35 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 21 Oct 2005 01:05:35 +0100 Subject: reload fails if module not in sys.path In-Reply-To: <1129849234.985211.141940@g47g2000cwa.googlegroups.com> References: <1129849234.985211.141940@g47g2000cwa.googlegroups.com> Message-ID: Lonnie Princehouse wrote: > So, it turns out that reload() fails if the module being reloaded isn't > in sys.path. > > Maybe it could fall back to module.__file__ if the module isn't found > in sys.path?? > ... or reload could just take an optional path parameter... > > Or perhaps I'm the only one who thinks this is silly: > > >>>>my_module = imp.load_module(module_name, *imp.find_module(module_name,path)) >>>>reload(my_module) > > Traceback (most recent call last): > File "", line 1, in ? > ImportError: No module named whatever > You appear to have failed to load some module called "whatever", which I presume is the value of module_name? > > I guess I could just deal with this by fiddling with sys.path or using > imp.load_module again, but.. um.. I like to complain. ;-) > That's OK, but you may find fiddling with sys.path is more productive :-) > The context here is that I'm loading user-defined modules as plugins, > and I don't want to keep the plugin directory in sys.path because of > potential module name conflicts. > Hmm. I know that if your module isn't in sys.modules your reload will fail: >>> import trPyCard # picking a moduule at random >>> import sys >>> del sys.modules['trPyCard'] >>> reload(trPyCard) Traceback (most recent call last): File "", line 1, in ? ImportError: reload(): module trPyCard not in sys.modules >>> Apart from that, it would seem sensible not to try and use reload if you haven't used a kosher import mechanism - there are many caveats on the reload() documentation, and the mechanisms it uses aren't spelled out anywhere but in the interpreter source. It would seem easier just to ensure that the plugins directory(ies) appear first on sys.path and use __import__(). imp is high magic. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From zhu_dave at yahoo.com Mon Oct 3 17:02:17 2005 From: zhu_dave at yahoo.com (Celine & Dave) Date: Mon, 3 Oct 2005 14:02:17 -0700 (PDT) Subject: Python Debug Build Message-ID: <20051003210217.88812.qmail@web30614.mail.mud.yahoo.com> Hi, What happens if I build Python with debug option (--with-pydebug)? Do I see any changes in my program output? What is --with-pydebug good for? Thanks. __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com From mhardas at cs.kent.edu Thu Oct 13 15:05:44 2005 From: mhardas at cs.kent.edu (mhardas at cs.kent.edu) Date: Thu, 13 Oct 2005 15:05:44 -0400 (EDT) Subject: ImportError: No module named dbm In-Reply-To: References: <2229.131.123.36.10.1129218983.squirrel@webmail.cs.kent.edu> Message-ID: <4416.131.123.36.10.1129230344.squirrel@webmail.cs.kent.edu> Hi, thanks for the reply. firstly i couldnt find the DBM module for python 2.3.5, trustix system and i386 hardware platform. so i downloaded gnu dbm for python 2.3.5 and i568( precisly, python-gdbm-2.3.5-4tr.i586), simply assuming it could just work. but trying to install gives me the following error, error: failed dependencies: python = 2.3.5 is needed by python-gdbm-2.3.5-4tr I am preety sure its python 2.3.5 tht is installed. Can you shed some light or give some pointers. Thanks again, appreciate it. Manas. > mhardas at cs.kent.edu wrote: > >> Can you tell me how do I go about getting the dbm module and install >> it.?? > > http://www.google.com/search?q=trustix+python+dbm > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From steve at REMOVETHIScyber.com.au Tue Oct 25 19:26:37 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Wed, 26 Oct 2005 09:26:37 +1000 Subject: Top-quoting defined [was: namespace dictionaries ok?] References: <86ll0h2so4.fsf@bhuda.mired.org> Message-ID: On Tue, 25 Oct 2005 17:27:55 -0400, Mike Meyer wrote: >> On Tuesday 25 October 2005 00:31, Duncan Booth wrote: >> Their differences in styles, like mine, probably arise from the culture of >> their respective fields. Most, like me, may not even know what the heck you >> are talking about. Also, here is a well written synopsis of the arguments in >> favor of top-posting and they may even be strong enough to legitimize the >> practice: >> http://alpage.ath.cx/toppost/toppost.htm > > Well, if I could find a 300 baud modem, I might understand his > objection to not top-posting (he really only has one). Perhaps he is hosting his website on a server with a 300 baud modem? It times out for me... *wink* A: Because it messes up the order in which people read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying email habit? I wouldn't object to top-posting nearly so much if the average top-poster had the writing skills of an illiterate sloth hunter in the jungles of Borneo[1], but sadly most of them don't. I get people replying to an email three weeks after I sent them the original, and they top-post the answer "Yes, I agree". When I read it, my brain reboots from the sheer inanity of it. You agree to *what*? Do I really care enough to read through the entire thread -- which you've so *thoughtfully* quoted in its entirety, eight levels deep, thank you very much -- to find out what you are agreeing to? And then when I do read through it, I discover that what was actually asked was three or four *specific* questions like "How much memory would you like your new PC to have?" and "Would you like wireless?". Top-posting encourages stupid mistakes like that, by encouraging people to hit send after they've said the first thing they thought of, without actually reading through the email to see if there are other issues that need to be dealt with. [1] There are no sloths in Borneo. -- Steven. From fccoelho at gmail.com Thu Oct 6 08:55:14 2005 From: fccoelho at gmail.com (Flavio) Date: 6 Oct 2005 05:55:14 -0700 Subject: updating local() In-Reply-To: References: <1128530014.323801.290360@g47g2000cwa.googlegroups.com> Message-ID: <1128603314.197733.119160@g47g2000cwa.googlegroups.com> Ok, I got it! Its vey insecure, and it is not guaranteed to work. Fine. Now what would you do if you wanted to pass a lot of variables (like a thousand) to a function and did not wanted the declare them in the function header? Fl?vio From fairwinds at eastlink.ca Mon Oct 17 13:50:31 2005 From: fairwinds at eastlink.ca (David Pratt) Date: Mon, 17 Oct 2005 14:50:31 -0300 Subject: Stripping ASCII codes when parsing In-Reply-To: <*firstname*nlsnews-93FF0F.12484617102005@news.verizon.net> Message-ID: <82F62990-3F36-11DA-AE8C-000A27B3B070@eastlink.ca> This is very nice :-) Thank you Tony. I think this will be the way to go. My concern ATM is where it will be best to unicode. The data after this will go into dict and a few processes and into database. Because input source if not explicit encoding, I will have to assume ISO-8859-1 I believe but could well be cp1252 for most part ( because it says no ASCII (0-30) but alright ASCII chars 128-254) and because most are Windows users. Am thinking to unicode after stripping these characters and validating text, then unicoding (utf-8) so it is unicode in dict. Then when I perform these other processes it should be uniform and then it will go into database as unicode. I think this should be ok. Regards, David On Monday, October 17, 2005, at 01:48 PM, Tony Nelson wrote: > In article , > David Pratt wrote: > >> I am working with a text format that advises to strip any ascii >> control >> characters (0 - 30) as part of parsing data and also the ascii pipe >> character (124) from the data. I think many of these characters are >> from a different time. Since I have never seen most of these >> characters >> in text I am not sure how these first 30 control characters are all >> represented (other than say tab (\t), newline(\n), line return(\r) ) >> so >> what should I do to remove these characters if they are ever >> encountered. Many thanks. > > Most of those characters are hard to see. > > Represent arbitrary characters in a string in hex: "\x00\x01\x02" or > with chr(n). > > If you just want to remove some characters, look into "".translate(). > > nullxlate = "".join([chr(n) for n in xrange(256)]) > delchars = nullxlate[:31] + chr(124) > outputstr = inputstr.translate(nullxlate, delchars) > _______________________________________________________________________ > _ > TonyN.:' > *firstname*nlsnews at georgea*lastname*.com > ' > > -- > http://mail.python.org/mailman/listinfo/python-list > From nothingcanfulfill at gmail.com Tue Oct 4 16:11:29 2005 From: nothingcanfulfill at gmail.com (ncf) Date: 4 Oct 2005 13:11:29 -0700 Subject: wxPython equiv. to tag_configure Message-ID: <1128456689.100365.196050@g47g2000cwa.googlegroups.com> Hi all. I'm trying to do a system where I'm working on a set of windows for both Tkinter and wxPython, and have come across a lovely little bump in the road. Tkinter's Text object has tag_* methods, but I don't know of a good way to do tag-related stuff with wxPython. In the wxWidgets manual, I see a wxHtmlWindow object, but nothing like that seems to exist when I dir() wxPython. Does anyone have any suggestions? Thanks in advance. From martin.witte at gmail.com Fri Oct 14 11:53:14 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 14 Oct 2005 08:53:14 -0700 Subject: Problems with properties In-Reply-To: References: Message-ID: <1129305194.247036.35550@g43g2000cwa.googlegroups.com> If you change it to this it works. You should provide a get and a set function for a property. class Task: def __init__(self, value): self._command = value def setCommand(self, value): self._command = value def getCommand(self): return self._command command=property(getCommand, setCommand) class taskTest(TestCase): def testTask(self): t = Task("dir c:") c = t.command self.assertEquals("dir c:", c) # should fail, but doesn't t.command = "foo Bar" self.assertEquals("dir c:", t.command) if __name__ == "__main__": unittest.main() From gsakkis at rutgers.edu Wed Oct 12 11:50:17 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Wed, 12 Oct 2005 11:50:17 -0400 Subject: A Tree class, my $0.02 contribution to the python community. References: Message-ID: <1129132506.ab1e6295283286960cd21918db1ebac4@teranews> "Antoon Pardon" wrote: > Comments are welcome: > > http://www.pardon-sleeuwaegen.be/antoon/avltree.html How about adding two shortcut methods, nextkey(k) and prevkey(k), to return the next and previous key respectively ? For instance nextkey would be equivalent to (untested): def nextkey(self, key): iter = self[key:] first = iter.next() if key not in self: return first else: return iter.next() Also for consistency, nextvalue(k), prevvalue(k), nextitem(k), previtem(k) would be reasonable additions. And a question: what does step do if the keys are not integers since you restrict step to be integer ? George From gandalf at designaproduct.biz Thu Oct 6 08:53:56 2005 From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy) Date: Thu, 06 Oct 2005 14:53:56 +0200 Subject: /usr/bin/env python, force a version In-Reply-To: <_n81f.14624$BS3.663683@phobos.telenet-ops.be> References: <1128597929.636452.223890@o13g2000cwo.googlegroups.com> <_n81f.14624$BS3.663683@phobos.telenet-ops.be> Message-ID: <43451E64.4060005@designaproduct.biz> Roel Schroeven wrote: >Laszlo Zsolt Nagy wrote: > > >>manatlan at gmail.com wrote: >> >> >> >>>I've got a trouble, and i think that anybody there can help me >>> >>>I've got a python script which i distribute in somes packages for *nix. >>>This script is full of python and need python 2.4 ! And i'd like to >>>display a message when the user doesn't have a python2.4 version. >>> >>> >>> >>> >>>>>import sys >>>>>sys.version >>>>> >>>>> >>'2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]' >> >> > >Yes, but the problem is also that Debian (not only Sid, but also stable >and testing) has python 2.4 but it is not the default, i.e. >/usr/bin/python is a symlink to /usr/bin/python2.3 even if >/usr/bin/python2.4 is available to. > > Hmm. Idea one: Create a list of possible locations. First of all, use your PATH, and then add common locations: ['/bin','/usr/bin','/opt/bin','/usr/local/bin'] # etc. Then use a list of the possible executable names: ['python','python2.3','python2.4'] # etc Finally using these combinations, execute each executeable with python -V and examine its output. This may work, but I'm affraid there is no general solution. The system administrator can install different python versions to virtually any location. But I don't think you should be affraid of that. If a system admin installs different versions into strange locations, then he will take the responsibility to fix python programs that need a specific version. But in most cases, looking for a python executable on your PATH should be enough; and it is the most I would expect from an application. :-) Last idea: - create a configuration file that resides beside your Python program - take the path to the good executeable there - if the program was started with the wrong version, but you have the path to the good one (from the config file), then re-execute - otherwise print an error message telling the required version AND how the user can set it up in the config file Third idea (for Windows only): read available versions from the registry. ;-) Best, Les From dcrespo at gmail.com Thu Oct 27 16:26:25 2005 From: dcrespo at gmail.com (dcrespo) Date: 27 Oct 2005 13:26:25 -0700 Subject: How to replace all None values with the string "Null" in a dictionary Message-ID: <1130444785.353905.85380@g47g2000cwa.googlegroups.com> Hi all, How can I replace all None values with the string 'Null' in a dictionary? For example: convert this: a = {'item1': 45, 'item2': None} into this: a = {'item1': 45, 'item2': 'Null'} Thanks Daniel From johnnyandfiona at hotmail.com Sat Oct 29 23:03:09 2005 From: johnnyandfiona at hotmail.com (Johnny Lee) Date: 29 Oct 2005 20:03:09 -0700 Subject: How to translate python into C In-Reply-To: References: <1130491053.787273.201650@g44g2000cwa.googlegroups.com> <1130493304.961498.226200@g47g2000cwa.googlegroups.com> <1130493811.719479.160450@z14g2000cwz.googlegroups.com> Message-ID: <1130641389.709221.40670@o13g2000cwo.googlegroups.com> Thanks Szabolcs and Laurence, it's not the crash of python but the crash of cygwin. We can locate the line number but when we submit the crash to cygwin's mail list, they told us they don't speak python. So I'm just trying to re-produce the crash in C. Regards, Johnny From toufeeqh at gmail.com Wed Oct 5 02:23:39 2005 From: toufeeqh at gmail.com (Toufeeq Hussain) Date: Wed, 5 Oct 2005 11:53:39 +0530 Subject: Help needed in OOP-Python In-Reply-To: References: Message-ID: Hi Fredrik, On 10/5/05, Fredrik Lundh wrote: > > Toufeeq Hussain wrote: > > > I have 3 modules which have class declarations in them and which > implement > > multiple inheritance. > > > Traceback (most recent call last): > > File "E:\PyPBM\PyPBM\test_case.py", line 7, in ? > >TH = constraint.Option1_Rule1() > > there's no line that says "TH = constraint.Option1_Rule1()" in the > code you're posted. looks like you didn't really post the code you > tested... > my bad. :( It's there under "script" but in a different form. Script ----- import Module3 Test_Case = Module3.Option1_Rule1() Test_Case.Option1_constraint() Test_Case = "Module3.Option1_Rule1()" corresponds to "TH = constraint.Option1_Rule1()" My coding is really really bad,that's why I changed the names to more human readable form(Module1,2.. etc). Thanks for pointing it out, Toufeeq -- Get Firefox:http://www.mozilla.org/products/firefox/ The fastest, safest and best Browser !! -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVETHIScyber.com.au Sun Oct 9 06:43:46 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 09 Oct 2005 20:43:46 +1000 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <8ohgk1p9s6pgaq8d67bgpjg7i8i22ngiul@4ax.com> Message-ID: On Sat, 08 Oct 2005 22:25:23 +0000, Roedy Green wrote about HTML emails: > Just how long do you want to stall evolution? Evolution doesn't mean "use whatever broken solution Microsoft and Hotmail popularized, just because all my friends are using it." If and when somebody puts out a good rich text email format, I'll use it. Until then, I won't use HTML. > Do you imagine people 200 years from now will be still be using pure > ASCII text unable to find a solution to JavaScript viruses (turn off > JS), pop-up( disable popups) etc.? Firstly, I don't care what people will be using in 200 years. I don't care if in 200 years the default email format is so big and bloated that it takes three weeks to download even a single sentence, because I won't be around to suffer. If you think that people will be using the current data formats for email in two centuries, you're crazy. -- Steven. From lasse at vkarlsen.no Sun Oct 30 13:26:29 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Sun, 30 Oct 2005 19:26:29 +0100 Subject: Need Python Pro for Help!! Plzz In-Reply-To: <5uSdnSSK7vYrTfneRVn-pQ@giganews.com> References: <5uSdnSSK7vYrTfneRVn-pQ@giganews.com> Message-ID: blah at blah.blah wrote: > Need python Pro at newtopython at googlegroups.com , if u wanna help, plz > reply to that address. We are python beginners. need a real good > Python Programmer for Help. TIA!! If you need help, post questions to the newsgroups. That way you might get help from several people instead of just one. -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From claudio.grondi at freenet.de Thu Oct 13 19:11:59 2005 From: claudio.grondi at freenet.de (Claudio Grondi) Date: Thu, 13 Oct 2005 23:11:59 -0000 Subject: Yes, this is a python question, and a serious one at that (moving to Win XP) References: Message-ID: <3r80ugFi4defU1@individual.net> What I can point you to is not Python, but embedding it in Python is a question of executing one line of Python code triggering its execution. I think you will be fascinated by its features and ease of use and how well it is suited to fit into your needs: http://www.autoitscript.com/autoit3/index.php With it you will start to see, that forcing to obey to Windows way of doing things has not only bad sides. Is there something similar for another OSs-es (especially Linux)? Claudio "Kenneth McDonald" schrieb im Newsbeitrag news:mailman.2030.1129235229.509.python-list at python.org... > For unfortunate reasons, I'm considering switching back to Win XP > (from OS X) as my "main" system. Windows has so many annoyances that > I can only compare it to driving in the Bay Area at rush hour (OS X > is like driving in Portland at rush hour--not as bad, but getting > there), but there are really only a couple of things that are really, > absolutely preventing me from making the switch. Number one is the > lack of a decent command line and command-line environment, and I'm > wondering (hoping) if perhaps someone has written a "Python shell"-- > something that will look like a regular shell, let users type in > commands, maybe have some of the nice features of bash etc. like tab > completion, etc, and will then execute an underlying python script > when the command is entered. I'm not thinking of IDLE, but something > that is really aimed more at being a system terminal, not a Python- > specific terminal. > > Yes, I know that Cygwin is out there, but last I looked, they still > went through the Win command-line window, which imposes a lot of > restrictions. > > More generally, has anyone written any python programs to administer > various Win settings for which one must otherwise delve deep into > mazes of twisty little dialogs, all alike? Or to help out with other > annoyances? I know there are a lot of general utilities, but if > they're in Python, I can also use them as a starting base for my own > needs. > > Finally, a significant incentive in doing this is that I could avoid > a lot of installation hassle, since virtually everything has at least > a decent installation package for Win. (I'd hoped this would happen > for OS X, but it never has). Can anyone think of important python- > related packages (release level, not cutting edge alphas) for which > this might not be the case? > > Many thanks, > Ken From iainking at gmail.com Fri Oct 14 05:23:34 2005 From: iainking at gmail.com (Iain King) Date: 14 Oct 2005 02:23:34 -0700 Subject: [PIL]: Question On Changing Colour In-Reply-To: <434eb32d$0$29544$4fafbaef@reader1.news.tin.it> References: <00fe01c5cf7c$410750e0$69820257@Gavana> <434eb32d$0$29544$4fafbaef@reader1.news.tin.it> Message-ID: <1129281814.178263.171520@z14g2000cwz.googlegroups.com> Andrea Gavana wrote: > I have tried your solution, Terry: > > > new_hue # your 'basic color', just the hue part > > rgb_base # color from the basic button image > > rgb_new # the new color you want to replace rgb_base with > > > > rgb_new = hsv_to_rgb( (new_hue,) + rgb_to_hsv(rgb_base)[1:]) > > > thanks a lot for your suggestion! However, either I did not understand it > correctly or I am doing something stupid in my code. Here is a small > example: > > from colorsys import * > > # that is the old colour --> GREY > rgb_old = (0.7, 0.7, 0.7) > > # Transform the new colour in HSV > hsv_old = rgb_to_hsv(rgb_old[0], rgb_old[1], rgb_old[2]) > > # this is the new colour --> BLUE > rgb_new = (0.0, 0.0, 1.0) > > # Transform the new colour in HSV > hsv_new = rgb_to_hsv(rgb_new[0], rgb_new[1], rgb_new[2]) > > # I take only the Hue part of the new colour > new_hue = hsv_new[0] > > # Get the new colour > rgb_new = hsv_to_rgb(new_hue, hsv_old[1], hsv_old[2]) > > print rgb_old > print rgb_new > print rgb_old == rgb_new > > > This prints: > > (0.69999999999999996, 0.69999999999999996, 0.69999999999999996) > (0.69999999999999996, 0.69999999999999996, 0.69999999999999996) > True > > So, no matter what colour I choose as a "new" colour, the Hue part of the > new colour doesn't change in RGB. In other words, leaving the old value for > "Saturation" and "Value" makes the presence of the "Hue" part useless. But > why in the world does this happen? If a colour is defined by 3 values, > changes in every single value should change the colour too... Not with HSV. The hue determines which 'color' it will be - red, blue, indigo, whatever. That Saturation determined how vibrant this 'color' will be. V is brightness (I can't remember what the V actually stands for). Each of these values scales from 0 to 1, or 0% to 100%, however you want to thiink about it. If you try and picture the gradient you'd get by plotting this range as a line, then: The H line would be a spectrum of colours, like a rainbow. Say we pick H to be RGB #FF0000 - Red The S line would be a gradient ranging from grey (absense of color) to red. The V line would be a gradient ranging from black (completely dark) to red. So on the HSV scale, grey is represented by a saturation of 0 - meaning none of H is present in the color; the color in question being determined purely by it's brightness (V). So when you pick your HSV triplet for a grey color, you have to set S to 0. You can set H to anything at all - because S is 0, no tint of H will appear in the color at all. Iain http://www.snakebomb.com From davids at webmaster.com Tue Oct 25 18:36:28 2005 From: davids at webmaster.com (David Schwartz) Date: Tue, 25 Oct 2005 15:36:28 -0700 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> <3s6l8mFmj3fjU1@individual.net> <0hm233-0ut.ln1@news.it.uc3m.es> Message-ID: "Peter T. Breuer" wrote in message news:0hm233-0ut.ln1 at news.it.uc3m.es... >> McDonald's won't sell a Burger King their burger patties. > McDonald's are not in the business of wholesale distribution of burger > patties so your statement is simply sited in the wrong universe of > discourse. I don't know what drugs you're on, but the McDonald's corporation most certainly is in the business of the wholesale distribution of burger patties. One key reason to become a franchisee is to access their wholesale distribution network. > Coming back to the current universe of discourse, I assure > you that a McDonald's director can go into a Burger King and buy a > burger like anyone else, so no discrimination. Mind you - I'm not sure > if they'd let Ronald in. He's obviously dangerously nutty. That's not even remotely analogous. Microsoft didn't say that customers who bought OS2 couldn't buy Windows. They said (in acutality something less than that) people who buy Windows wholesale can't also resell other operating systems. This is perfectly analogous to McDonald's saying that retailers who buy their burger patties wholesale can't also sell Whoppers. >> You only run into a problem under United States law if the company is >> a >> monopoly. And I've already addressed that issue in this thread. > If MacDonalds were wholesale suppliers of hamburgers to the > distribution trade, They are wholesale suppliers to those people who agree to their distribution terms. This requires, among other things, that you prepare them in a precise way and only sell approved items. > then they couldn't discriminate among their > customers for the purposes of altering the competitive nature of the > market in hamburger sales to you and me across the counter. I'm afraid I don't understand what "altering the competitive nature of the market in hamburger sales" actually means. What is it that you are claiming they can't do? > Companies > have been sued for trying that - sports shoe manufacturers, I seem to > recall. They've tried to make sure their shoes are sold only by > specified outlets at specified prices, in order to artificially manage > the market. That's illegal. Sued they got (or perhaps "suede"). What, precisely, is illegal? DS From chrisgarland67 at hotmail.com Tue Oct 4 17:53:30 2005 From: chrisgarland67 at hotmail.com (Cigar) Date: 4 Oct 2005 14:53:30 -0700 Subject: Controlling who can run an executable In-Reply-To: <*firstname*nlsnews-32A291.12103704102005@news.verizon.net> References: <1128395422.904212.318930@g44g2000cwa.googlegroups.com> <*firstname*nlsnews-32A291.12103704102005@news.verizon.net> Message-ID: <1128462810.732754.200570@o13g2000cwo.googlegroups.com> Tony Nelson wrote: > In article <1128395422.904212.318930 at g44g2000cwa.googlegroups.com>, > "Cigar" wrote: > > > I am developing a program for a client. She runs a shop where her > > clients bring in items for sale or short term buyback. Development of > > the program has been going great but she's mentioned that there is a > > 'feature' coming up in the next couple of weeks that she'd like me to > > implement that has me a bit worried. > > > > My client has told me a story of how she hired someone from a competing > > store and that person had brought a copy of the program her competition > > was using to track clients and transactions. He couldn't demonstrate > > the program for one reason or another because it was protected in a way > > that neither could circumvent. (She didn't remember how it was > > protected, she had hired this person a long time ago.) > > > > Now that I'm three months into the development of this program, my > > client tells me she would like to protect her investment by preventing > > her employees from doing the same to her. (Going to the competition > > and using her program.) > ... > > Call the competition and ask them what they used. Point out that it > worked. If they won't tell you, just look at their software until you > find out. > ________________________________________________________________________ > TonyN.:' *firstname*nlsnews at georgea*lastname*.com > ' Sorry. All I have is this wonderful story to tell everyone. This employee she hired no longer works for her and the 'disk' that nobody to could get working is gone as well. Sadly there's nothing left for me to forensically examine. From mwm at mired.org Sun Oct 23 01:30:36 2005 From: mwm at mired.org (Mike Meyer) Date: Sun, 23 Oct 2005 01:30:36 -0400 Subject: best way to replace first word in string? References: <1129822003.246170.303920@f14g2000cwb.googlegroups.com> <861x2dbcwv.fsf@bhuda.mired.org> Message-ID: <86u0f894w3.fsf@bhuda.mired.org> Steven D'Aprano writes: > On Sat, 22 Oct 2005 14:54:24 -0400, Mike Meyer wrote: >>> The string formatting is two orders of magnitude faster than the >>> concatenation. The speed difference becomes even more obvious when you >>> increase the number of strings being concatenated: >> The test isn't right - the addition test case includes the time to >> convert the number into a char, including taking a modulo. > I wondered if anyone would pick up on that :-) > You are correct, however that only adds a constant amount of time to > the time it takes for each concatenation. That's why I talked about order > of magnitude differences. If you look at the vast increase in time taken > for concatenation when going from 10**5 to 10**6 iterations, that cannot > be blamed on the char conversion. True. string addition is O(n^2); the conversion time is O(n). But fair's fair. > At least, that's what it looks like to me -- I'm perplexed by the *vast* > increase in speed in your version, far more than I would have predicted > from pulling out the char conversion. I can think of three > possibilities: Everything got faster, so it wasn't just pulling the chr conversion. > (1) Your PC is *hugely* faster than mine; It's a 3Ghz P4. > (2) Your value of x is a lot smaller than I was using (you don't actually > say what x you use); or It's still in the buffer, and I copied it from your timings: >>> x = 100000 > (3) You are using a version and/or implementation of Python that has a > different underlying implementation of string concatenation. I'm runing Python 2.4.1 built with GCC 3.4.2. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From jbperez808 at yahoo.com Wed Oct 26 02:24:13 2005 From: jbperez808 at yahoo.com (Jon Perez) Date: Wed, 26 Oct 2005 14:24:13 +0800 Subject: p2exe using wine/cxoffice In-Reply-To: <200509151243.53106.jstroud@mbi.ucla.edu> References: <200509151243.53106.jstroud@mbi.ucla.edu> Message-ID: James Stroud wrote: > "better". The only reason I want this functionality is to make my software > available to windoze users--despite their unfortunate ignorance, they are > people too. That's what I always say. Actually, I think it's many unix/linux users who are ignorant of just how nice, stable and productive Windows can be as a desktop environment. ... and I really mean that. ;-). Ever since Win2K got rid of the constant blue screens, the reasons for switching over to Linux have grown less and less urgent. The 'Nix desktop environments are growing visibly more mature with each passing year, but device support in Linux is still decidedly inferior and it still takes far too much time to do some things you take for granted under Windoze. I'm experienced enough with Linux that I can customize a distribution like Slackware to a fair extent, but for desktop work, I stay in Windows almost exclusively. I have this bunch of Linux zealots in a mailing list to thank for encouraging me to realize how good Windows can be. From cgian31 at katamail.com Thu Oct 20 14:59:04 2005 From: cgian31 at katamail.com (cgian31) Date: 20 Oct 2005 11:59:04 -0700 Subject: bypassing web forms hardcoding login and password Message-ID: <1129834744.777983.319170@g14g2000cwa.googlegroups.com> I need to hide the complexity from users to access an information webpage, which is normally accessible after filling in a web form with the correct data. The address of the information webpage is like https://external.address.com/info.asp? where is a number generated by the server. This number (always different) is generated by the server only when you open the first web page in your browser, fill in the right values in 2 fields (user, password) and click Login. Any advices? From gdamjan at gmail.com Mon Oct 31 17:35:19 2005 From: gdamjan at gmail.com (Damjan) Date: Mon, 31 Oct 2005 23:35:19 +0100 Subject: cx_Oracle, is anything selected? Message-ID: Is there a way to see if the SELECT in cx_Oracle didn't return anything? I want to optimize the situation when the number of selected rows is zero. Is select count(*) the only option, seems inefficient? -- damjan From steve at REMOVETHIScyber.com.au Sun Oct 9 11:40:34 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 10 Oct 2005 01:40:34 +1000 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <41hhk195gcipfarnqu85ggs606aqi89ea1@4ax.com> <2dadnfArEfWwvdTeRVnzvA@telenor.com> Message-ID: On Sun, 09 Oct 2005 15:50:12 +0200, Lasse V?gs?ther Karlsen wrote: > Tim Tyler wrote: > >>>Only if your photos are so obscure and confusing that they need captions. >>> >>>"Here's Johnny with the dog. Here is Johnny with the dog again. This one >>>is Johnny on his own. Here is the dog. Oh look, it is Johnny with the dog >>>again -- that's the dog on the left, in case it isn't clear. Just for a >>>change, this is Johnny wearing a hat. It is blue with a feather in it, >>>in case you couldn't tell from, oh I don't know, looking at the actual >>>picture." >> >> >> What have you got against captions? >> >> Giving photos captions is a *very* common practice. > > Perhaps he has a search engine that can find blue hats in an image and > recognize people? Yes. It is called "eyes". I look at the image, and miracle upon miracles, I recognise Johnny wearing a hat. Then, if I have any need to save that image rather than trash it, I name it and file it in a directory appropriately, so that I can instantly find it later without needing to call up a search engine. Honestly, anyone would think that photos and photo albums never existed before Google. Why force one particular bad technological solution on everyone for the sake of something which many people don't even perceive as a problem? -- Steven. From toufeeqh at gmail.com Wed Oct 5 01:34:23 2005 From: toufeeqh at gmail.com (Toufeeq Hussain) Date: Wed, 5 Oct 2005 11:04:23 +0530 Subject: Help needed in OOP-Python Message-ID: Hello gurus, Python n00b here trying to learn some OOP-Python.Here's my problem. I have 3 modules which have class declarations in them and which implement multiple inheritance. Module1 -------- class OptionClass: def __init__ (self,name,ORSpecNumber,AltToItselfStart,AltToItselfEnd) : self.Name = name self.ORSpecNumber = ORSpecNumber self.AltToItselfStart = AltToItselfStart self.AltToItselfEnd = AltToItselfEnd class Warning: def __init__(self,Warn_number,Warn_name,Warn_type,Warn_text) : self.Warn_name = Warn_name self.Warn_number = Warn_number self.Warn_type = Warn_type self.Warn_text = Warn_text def Fire(self) : common_subs.write_to_out_file('FOO_OUT',self.Warn_text) class characterestic: def __init__(self,char_name,char_type,char_value) : self.Char_name = char_name self.Char_type = char_type self.Char_value = char_value In Module2 I have a class which derives from OptionClass of Module1. Module2 ------------ import Module1 class Option1(Module1.OptionClass): def __init__(self) : Module1.OptionClass.__init__('Blah Blah','OR0001','0000','0000') option_char = Module1.characterestic ('strOperationalWeightsTemplate','int',1000) Module3 has a Class which Derives from the Class defined in Module2. Module3 ------------ import Module1 import Module2 class Option1_Rule1(declaration.Option1): def __init__(self) : Module2.Option1.__init__(self) Option1_warning = Module1.Warning(1,'This is a warning name','Compatibility','Blah Blah,warning text which gets printed') def Option1_constraint(self): if isinstance(self,Module2.Option1): print 'condition satisfied' self.FOO_warning.Fire() else : pass Finally I have a simple script which does the instantiation of the Class defined in Module3. Script ----- import Module3 Test_Case = Module3.Option1_Rule1() Test_Case.Option1_constraint() Problem is when I run the above script it throws out the following error. Traceback (most recent call last): File "E:\PyPBM\PyPBM\test_case.py", line 7, in ? TH = constraint.Option1_Rule1() File "E:\PyPBM\PyPBM\constraint.py", line 13, in __init__ declaration.Option1.__init__(self) TypeError: __init__() takes no arguments (1 given) in the above errors: test_case is the above script. constraint => Module3 declaration => Module2 superclass => Module1 Help required. Thanks, Toufeeq -- Get Firefox:http://www.mozilla.org/products/firefox/ The fastest, safest and best Browser !! -------------- next part -------------- An HTML attachment was scrubbed... URL: From theller at python.net Thu Oct 6 10:55:56 2005 From: theller at python.net (Thomas Heller) Date: Thu, 06 Oct 2005 16:55:56 +0200 Subject: Absolultely confused... References: <7jcqbu2h.fsf@python.net> Message-ID: Jeremy Moles writes: > Thanks for the reply. :) > > I may be missing something critical here, but I don't exactly grok what > you're saying; how is it even possible to have two instances of > PyType_vector3d? It is (like all the examples show and all the extension > modules I've done in the past) a static structure declared and assigned > to all at once, only once. > > Am I misunderstanding the point? :) > > /me ducks > > On Thu, 2005-10-06 at 16:26 +0200, Thomas Heller wrote: >> Jeremy Moles writes: >> >> > So, here is my relevant code: >> > >> > PyArg_ParseTuple(args, "O!", &PyType_vector3d, &arg1) >> > >> > And here ismy error message: >> > >> > argument 1 must be pylf.core.vector3d, not pylf.core.vector3d >> > The only reason that I can think of for this error message is that the type of the argument is something that has a repr of 'pylf.core.vector3d', but the type object is not the same as your 'PyType_vector3d' pointer. As I said, use a source debugger or some other way to find out, or use a debug build of Python and step through the PyArg_ParseTuple code to find out why the call fails. Thomas From samrobertsmith at gmail.com Tue Oct 25 03:23:23 2005 From: samrobertsmith at gmail.com (Shi Mu) Date: Tue, 25 Oct 2005 00:23:23 -0700 Subject: pickle In-Reply-To: <1130223861.28336.6.camel@blackwidow> References: <1130223861.28336.6.camel@blackwidow> Message-ID: <1d987df30510250023u5d679c9co4cd6f960df6edf1b@mail.gmail.com> what does the following code mean? y = pickle.load(file("cnumber.pickle", "r")) also, I can not understand "f" in pickle.dump(x, f) On 10/25/05, marduk wrote: > On Mon, 2005-10-24 at 23:55 -0700, Shi Mu wrote: > > I got a sample code and tested it but really can not understand the > > use of pickle and dump: > > > > >>> import pickle > > >>> f = open("try.txt", "w") > > >>> pickle.dump(3.14, f) > > >>> pickle.dump([1,2,3,4], f) > > >>> f.close() > > The pickle module "serializes" python objects. You can "dump" a python > object that can later be loaded: > > >>> x = complex(2,3.5) > >>> f = open("cnumber.pickle", "w") > >>> import pickle > >>> pickle.dump(x, f) > >>> f.close() > >>> y = pickle.load(file("cnumber.pickle", "r")) > >>> y > (2+3.5j) > > > From grante at visi.com Tue Oct 4 21:16:01 2005 From: grante at visi.com (Grant Edwards) Date: Wed, 05 Oct 2005 01:16:01 -0000 Subject: check html file size References: <1128473042.653989.175990@o13g2000cwo.googlegroups.com> Message-ID: <11k6aahfhqcgacc@corp.supernews.com> On 2005-10-05, Xah Lee wrote: > would anyone like to translate the following perl script to > Python or Scheme (scsh)? Sure. It'll cost you $110/hour with a 2-hour minimum. Where do I send the invoice? -- Grant Edwards grante Yow! I'll take ROAST BEEF at if you're out of LAMB!! visi.com From john at castleamber.com Sat Oct 8 19:39:27 2005 From: john at castleamber.com (John Bokma) Date: 8 Oct 2005 23:39: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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> Message-ID: Rich Teer wrote: > On Sat, 8 Oct 2005, Roedy Green wrote: > >> Some people use email PRIMARILY for sharing photos. > > WHat the hell has that got to do with HTML email? The photo doesn't have to be included (as in attached)? with the email? > Sending photos > is an example of what attachments are for. Yeah, yeah, and 640K is enough for everybody. Same song, different tune. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From godoy at ieee.org Mon Oct 24 11:42:51 2005 From: godoy at ieee.org (Jorge Godoy) Date: Mon, 24 Oct 2005 13:42:51 -0200 Subject: Python vs Ruby References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> <1129883505.814349.306860@g44g2000cwa.googlegroups.com> <86fyqt9j9x.fsf@bhuda.mired.org> <1h4ukde.1gc4cgu1a252ggN%aleaxit@yahoo.com> <86y84k95c5.fsf@bhuda.mired.org> <1h4vl5j.1sg46l1irzgfmN%aleaxit@yahoo.com> <1130154629.382286.33090@g43g2000cwa.googlegroups.com> <1h4xfpb.1oh4ntjwcvubfN%aleaxit@yahoo.com> Message-ID: <87acgyly4k.fsf@ieee.org> aleaxit at yahoo.com (Alex Martelli) writes: > forwards a lot to Python 3.0!-). But -- the "dream" solution would be > to work closely with customers from the start, XP-style, so features go > into the code in descending order of urgence and importance and it's > hardly ever necessary to remove them. We do that often with two of our customers here. After the first changes, they asked for more. And them some other and when it finally ended, the project was like we had suggested, but instead of doing this directly, the client wanted to waste more money... :-( Even if we earnt more money, I'd rather have the first proposal accepted instead of wasting time working on what they called "essential features". > But if I had do nominate ONE use case for "making code smaller" it would > be: "Once, And Only Once" (aka "Don't Repeat Yourself"). Scan your code > ceaselessly mercilessly looking for duplications and refactor just as > mercilessly when you find them, "abstracting the up" into functions, > base classes, etc... And I'd second that. Code can be drastically reduced this way and even better: it can be made more generic, more useful and robustness is improved. -- Jorge Godoy From maksim.kasimov at gmail.com Tue Oct 4 12:13:10 2005 From: maksim.kasimov at gmail.com (Maksim Kasimov) Date: Tue, 04 Oct 2005 19:13:10 +0300 Subject: how to debug when "Segmentation fault" Message-ID: Hello, my programm sometime gives "Segmentation fault" message (no matter how long the programm had run (1 day or 2 weeks). And there is nothing in log-files that can points the problem. My question is how it possible to find out where is the problem in the code? Thanks for any help. Python 2.2.3 FreeBSD -- Best regards, Maksim Kasimov mailto: maksim.kasimov at gmail.com From pierre.barbier at cirad.fr Thu Oct 6 16:57:44 2005 From: pierre.barbier at cirad.fr (Barbier de Reuille) Date: 06 Oct 2005 20:57:44 GMT Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86u0fxi7gf.fsf@bhuda.mired.org> <434545b7$0$662$626a14ce@news.free.fr> <86mzlmpo5r.fsf@bhuda.mired.org> Message-ID: <43458fc7$0$660$626a14ce@news.free.fr> Dans l'article <86mzlmpo5r.fsf at bhuda.mired.org>, Mike Meyer a ?crit : > Pierre Barbier de Reuille writes: >> Mike Meyer a ?crit : >>> Antoon Pardon writes: >>> >>>>Op 2005-10-03, Steven D'Aprano schreef : >>>> >>>>>On Mon, 03 Oct 2005 13:58:33 +0000, Antoon Pardon wrote: >>>> >>>>Declarations also allow easier writable closures. Since the declaration >>>>happens at a certain scope, the run time can easily find the correct >>>>scope when a variable is rebound. >>> If it happens at runtime, then you can do it without declarations: >>> they're gone by then. Come to think of it, most functional languages - >>> which are the languages that make the heaviest use of closures - don't >>> require variable declarations. >> Well, can you give a single example of such language ? Because all the >> functionnal language I know but one do need variable declaration : lisp, >> scheme, ocaml, haskell do need variable declaration ! Erlang do not ... > > Scheme and lisp don't need variable declerations. Last time I looked, > Schemd didn't even *allow* variable declerations. When you want local variable in lisp you do : (let ((a 3)) (+ a 1)) For global variable you may do: (defparameter *a* 4) or: (defvar *a* 4) However, either way, variable assignment is done via : (setf *a* 5) (setf a 10) This is what I call variable declaration as you have different way to declare global variables and to assign them ... So the two operations are well defined and different. And here there is a difference between static language and declarative ones ... Lisp is a dynamic language that needs variable declarations. > >>> Only in a few cases. Type inferencing is a well-understood >>> technology, and will produce code as efficient as a statically type >>> language in most cases. >> Type inferencing only works for statically typed languages AFAIK ! In a >> dynamically typed languages, typing a variable is simply impossible as >> any function may return a value of any type ! > > I think we're using different definitions of statically typed > here. A language that is statically typed doesn't *need* type > inferencing - the types are all declared! Type determines the thypes > by inferenceing them from an examination of the program. So, for > instance, it can determine that this function: Well, indeed ... statically typed means only one thing : each *variable* has a *static* type, i.e. a type determined at compile time. Once again, OCaml and Haskell *are* statically typed but as they have type inference you don't *need* to explicitely type your functions / variables. However you *may* if you want ... > > def foo(): > return 1 > > Won't ever return anything but an integer. > >>>>I think language matters shouldn't be setlled by personal preferences. >>> I have to agree with that. For whether or not a feature should be >>> included, there should either be a solid reason dealing with the >>> functionality of the language - meaning you should have a set of use >>> cases showing what a feature enables in the language that couldn't be >>> done at all, or could only be done clumsily, without the feature. >> Wrong argument ... with that kind of things, you would just stick with >> plain Turing machine ... every single computation can be done with it ! > > "Computation" is is not the same thing as "Functionality". If you > think otherwise, show me how to declare an object with a Turing > machine. Well, that was "bad spirit" from me ;) My argument here wasn't serious in any mean ... > > And there's also the issue of "clumsily". Turing machines are clumsy > to program in. > > >>> Except declarations don't add functionality to the language. They >>> effect the programing process. And we have conflicting claims about >>> whether that's a good effect or not, all apparently based on nothing >>> solider than personal experience. Which means the arguments are just >>> personal preferences. >> Well, so why not *allow* for variable declaration ? Languages like Perl >> does that successfully ... you don't like : you don't do ! you like : >> you do ! A simple option at the beginning of the file tell the compilor >> if variable declaration is mandatory or not ! > > Perl is a red herring. Unless it's changed radically since I last > looked, undeclared variables in Perl have dynamic scope, not lexical > scope. While dynamically scoped variables are a powerful feature, and > there have been proposals to add them to Python, having them be the > default is just *wrong*. If I were writing in Perl, I'd want > everything declared just to avoid that. Of course, if Python behaved > that way, I'd do what I did with Perl, and change languages. I never said to adopt the whole Perl variable semantic. I just pointed what I think is a good idea in Perl and that help (IMHO) precising what I intended ... > >>> Antoon, at a guess I'd say that Python is the first time you've >>> encountered a dynamnic language. Being "horrified" at not having >>> variable declarations, which is a standard feature of such languages >>> dating back to the 1950s, is one such indication. >> Dynamic language and variable declaration are non-related issues ! You >> can have statically-typed language without variable declaration (i.e. >> BASIC) and dynamically-typed language with (i.e. Lisp) ! Please, when >> you says something about languages, at least give 1 name of language >> asserting what you're saying ! > > Declerations and typing are *also* non-related issues. See Perl. Also > see the subject line. That was just my point ... > >>> Dynamic languages tend to express a much wider range of programming >>> paradigms than languages that are designed to be statically >>> compiled. Some of these paradigms do away with - or relegate to the >>> level of "ugly performance hack" - features that someone only >>> experienced with something like Pascal would consider >>> essential. Assignment statements are a good example of that. >> Well, could you be more specific once more ? I can't that many paradigm >> only available on dynamically typed languages ... beside duck-typing >> (which is basically a synonym for dynamically-typed) > > I said "dynamic languages", *not* "dynamically typed languages". They > aren't the same thing. Dynamic languages let you create new functions, > variables and attributes at run time. Python lets you delete them as > well. This means that simle declarations can't tell you whether or > not a variable will exist at runtime, because it may have been added > at run time. Ok, I misunderstood ... however, can you still point some *usefull* paradigm available to dynamic languages that you cannot use with static ones ? As there are so many, it shouldn't be hard for you to show us some ! > >>> Given these kinds of differences, prior experience is *not* a valid >>> reason for thinking that some difference must be wrong. Until you have >>> experience with the language in question, you can't really decide that >>> some feature being missing is intolerable. You're in the same position >>> as the guy who told me that a language without a goto would be >>> unusable based on his experience with old BASIC, FORTRAN IV and >>> assembler. >> After more than two years of Python programming, I still fill the need >> for variable declarations. It would remove tons of bugs for little works >> and would also clarify the scope of any single variable. > > Maybe you're still writing code for a language with declerations? I > never felt that need. Then again, I came to Python from a language > that didn't require declerations: Scheme. > >>> Pick one of the many languages that don't require declarations. Try >>> writing a code in them, and see how much of a problem it really is in >>> practice, rather than trying to predict that without any >>> information. Be warned that there are *lots* of variations on how >>> undeclared variables are treated when referenced. Python raises >>> exceptions. Rexx gives them their print name as a value. Other >>> languages do other things. >> Well, IMO, worst case is silently give a default value, like PHP (or >> apparently Rexx) does ... this can hide bugs for month if a single >> test-case is missing ! >> >> Well, in the end, I would really like an *option* at the beginning of a >> module file requiring variable declaration for the module. It would >> satisfy both the ones who want and the ones who don't want that ... > > Nope. It would just change the argument from "Python should have ..." > to "You should always use ..." or "Module foo should use ...". > > References: Message-ID: On 10/3/05, spiffo wrote: > I am a corporate developer, working for a single company. Got a new project > coming up and wondering if I should stay with Python for this new, fairly > large project, are jump back on the 'safe' M$ bandwagon using a dot net > language? Cross platform is NOT an issue, but COMPLETE control/compatability > with MsSql Server (current and future versions) certainly is. > > Quick History > > Started out 10+ yrs ago using FoxPro, upgrading as Fox did, was a good > system but never really loved it due to many factors I won't get into now. > > Did alot of work in Delphi, once version 5 came out... really loved it for > awhile. Began using MS SQL server as database. > > Had a HUGE re-write of an old dos-based database system to do, did alot of > work on it in Delphi 7, but really began to have issues with Delphi, even > tho alot of it is fantastic. Hey, you might want to take a look at Dabo . It was written by a couple of ex-Fox guys, and is a complete 3-tier app framework. They support several databases on the backend, and have announced that they are looking for someone to help them add MS-SQL to that list. -- # p.d. From david at jotax.com Tue Oct 25 16:54:54 2005 From: david at jotax.com (David Poundall) Date: 25 Oct 2005 13:54:54 -0700 Subject: Tricky import question. In-Reply-To: <435e8530.945320799@news.oz.net> References: <1130247555.359770.169070@o13g2000cwo.googlegroups.com> <435e8530.945320799@news.oz.net> Message-ID: <1130273694.368284.128650@g43g2000cwa.googlegroups.com> repr() is a new one on me I am afraid, and I have yet to achieve any decent competance with global and local lists. As you probaly noticed earlier, I managed to bungle my way through this time. However, I will log this thread away for when I next get stuck with a bindings. Thank you Bengt :-) From trentm at ActiveState.com Fri Oct 14 15:25:55 2005 From: trentm at ActiveState.com (Trent Mick) Date: Fri, 14 Oct 2005 12:25:55 -0700 Subject: Moving to Win XP as a Python developer In-Reply-To: References: <434fdd3b$1@nntp0.pdx.net> Message-ID: <20051014192555.GA12926@ActiveState.com> [Thomas Heller wrote] > I have an elisp function bound to a key in XEmacs that starts cmd in the > directory where the current buffer is. IMO this is very convenient. To > access explorer from that command prompt (in the rare cases that I need > it) I use 'start .'. I kind of have the same thing with Dave's Quick Search Deskbar (http://www.dqsd.net/) and my little "go" script (http://trentm.com/projects/go/). The keystrokes to open a cmd.exe shell in my "src" folder is down to: # to focus in the Quick Search Deskbar textbox go src or to open Explorer in that dir: go -o src or in another "tagged" dir: go ~ # open in my home dir DQSD is a fantastic tool for speeding up launching other things, too: mainly Google searches. Cheers, Trent -- Trent Mick TrentM at ActiveState.com From raims at dot.com Thu Oct 20 12:27:22 2005 From: raims at dot.com (Lawrence Oluyede) Date: Thu, 20 Oct 2005 18:27:22 +0200 Subject: How to retrieve the filename of a module References: <1129824268.735371.230910@g49g2000cwa.googlegroups.com> Message-ID: Il 2005-10-20, mku ha scritto: > Hi, > > there?s a function inside a module. How can these function retrieve > the path+name of his module ? (The path is most important). > That should also work if the module is part of a package. rhymes at voodoo:~ $ cat > test.py print __file__ import os print os.path.abspath(__file__) rhymes at voodoo:~ $ python test.py test.py /home/rhymes/test.py Bye -- Lawrence http://www.oluyede.org/blog From my_email_is_posted_on_my_website at munged.invalid Mon Oct 17 20:40:29 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Tue, 18 Oct 2005 00:40:29 GMT Subject: Microsoft Hatred FAQ References: <1129491006.021102.43920@g14g2000cwa.googlegroups.com> <86zmp8zsjk.fsf@bhuda.mired.org> Message-ID: <13h8l1p0i29vie16r31fbbblfl65iudrgd@4ax.com> On Mon, 17 Oct 2005 00:17:03 -0400, Mike Meyer wrote or quoted : > >Yup. When NS was the 800 lb gorilla on they acted like MS, I think you would need to give some examples. They gave away a free browser. What other evil thing did they do? -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From arotem at juniper.net Sun Oct 16 12:48:39 2005 From: arotem at juniper.net (arotem) Date: 16 Oct 2005 09:48:39 -0700 Subject: TypeError: unbound method PrintInput() must be called with test instance as first argument (got test instance instead) Message-ID: <1129481319.436107.16950@f14g2000cwb.googlegroups.com> Hi, I am trying to call an unbound method (PrintInput) with the object instance as the first argument but getting the following error: "TypeError: unbound method PrintInput() must be called with test instance as first argument (got test instance instead)" Below is the sample code (test) for this purpose (two files). Any help is greatly appreciated. Thanks in Advance, Anat Sample Code: File 1 - input_file.py: #!/usr/bin/env python from test import * CMD = (test.PrintInput, float(2)) File 2 - test.py: from input_file import * class test: def __init__(self): _test = 2 def PrintInput(self, input): print "Input is = %s"%(input) if __name__== "__main__": print "Unit testing" inst = test() print CMD cmd = CMD[0] param = CMD[1:] cmd(inst,param) # this is the problematic line From cce at clarkevans.com Tue Oct 25 14:15:02 2005 From: cce at clarkevans.com (Clark C. Evans) Date: Tue, 25 Oct 2005 14:15:02 -0400 Subject: feature request / max size limit on StringIO Message-ID: <20051025181502.GA48563@prometheusresearch.com> Hello. I've not been able to use cStringIO since I have the need to ensure that the memory buffers created are bounded within a resonable limit set by specifications. No, this code does not properly belong in my application as the modules that use "files" should not have to care about any resource limitations that may be imposed. class LimitedBuffer(StringIO): def __init__(self, buffer = None, maxsize = 5 * 1000 * 1000): StringIO.__init__(self,buffer) self.cursize = 0 self.maxsize = maxsize def write(self,str): self.cursize += len(str) if self.cursize > self.maxsize: raise IOError("allocated buffer space exceeded") return StringIO.write(self,str) Kind Regards, Clark Evans From mwm at mired.org Sat Oct 15 02:59:43 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 15 Oct 2005 02:59:43 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: <86ll0vs1sw.fsf@bhuda.mired.org> "Jeroen Wenting" writes: >>> Q: Microsoft's Operating System is used over 90% of PCs. If that's >>>not monopoly, i don't know what is. >> They got where they are by CHEATING. That is why they are evil, not >> because they have a large market share. > no, they got their by clever marketing and generally having a product that > was easier to use for the average user than anything the competition made > and a lot more powerful than other products created for their main target > market. What you call "clever marketing" the DOJ calls "monopolistic practices". The courts agreed with the DOJ. Having had several large PC manufacturers refuse to sell me a system without some form of Windows because MS made it impossible for them to compete if they didn't agree to do so, I agree with the courts and the DOJ. MS didn't start chanting the "Ease of Use" Mantra into it after Apple did - which happened long after MS had a sufficient stranglehold on the industry to force anti-competitive contracts down the throats of their "partners". Ease of use is something that Apple is much better at than MS, which is why Apple is dominating the market, right? > Prices would be far far higher than they are today I disagree. Before Gates decided to sell BASIC, software was very cheap. It started getting cheap again in the late 80s. Now that cheap software is threatening MS, they're doing their best to shut down all the sources of quality cheap software, with there usual disregard for truth, legality, ethics or the good of either the customer or their business partners. > Without Microsoft 90% of us would never have seen a computer more powerful > than a ZX-81 and 90% of the rest of us would never have used only dumb > mainframe terminals. Oh, horseshit. You clearly weren't paying attention to what the rest of the microcomputer industry was doing while Gates was selling IBM non-existent software. While IBM was introducing 16-bit processors and DOS was doing a flat file system, Tandy was selliig systems - for a fraction of the price of any MS-DOS based system - that were multitasking, multiuser, had an optional windowing system that came with a complete (for the time) office suite. Of course, that was while Tandy still thought they could sell computers by selling better computers than you could get running MS software. But it was already to late for that. MS single-handedly set the industry back 20 years. > IBM's prediction that there would be 5 computers (not counting game > computers like the Comodores and Spectrums) by 2000 would likely have come > true. I see. You're a troll. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From mlist at fastwebnet.it Tue Oct 4 17:44:45 2005 From: mlist at fastwebnet.it (billie) Date: Tue, 4 Oct 2005 23:44:45 +0200 Subject: Mantain IDE colors and paste them in an HTML page Message-ID: Hi all. I need to insert a Python source in an HTML page mantaining to coloration gives by the IDE. I tried the export function of scite but it does not generate a proper HTML code that permit me to copy and paste it into another HTML page. Does anyone got any suggestion? Regards From jepler at unpythonic.net Mon Oct 3 20:06:12 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Mon, 3 Oct 2005 19:06:12 -0500 Subject: Exception raising, and performance implications. In-Reply-To: <1128375280.034852.119910@o13g2000cwo.googlegroups.com> References: <1128375280.034852.119910@o13g2000cwo.googlegroups.com> Message-ID: <20051004000612.GA9424@unpythonic.net> On Mon, Oct 03, 2005 at 02:34:40PM -0700, leo wrote: > I come from a java background, where Exceptions are a big Avoid Me, but > are the performance implications the same in Python? We're expecting a > big load on our app (100,000 users/hour) , so we'd like to be as tuned > as possible. I don't know what you do for each user, but here's a data point: My 1.8GHz Sempron (firmly in the "budget" category) uses a fairly unoptimized piece of software called aether[1] to serve my blog and a few other things. It uses Apache and good old fashioned cgi-bin one-process-per-request to serve up most pages. It parses a substantial amount of Python code each time with execfile (not using byte-compiled files). It still does this in 87ms on average (albeit for a simple page), or about 41k requests per hour. By simply buying a faster CPU, or by avoiding execfile, or by using a higher-performance technology than CGI, or with judicious use of caching, I'm sure I could reach 100,000 requests per hour, and by using several of the techniques together I might be able to reach 400k requests per hour. Probably it would be after these fairly obvious, high-level optimization ideas were exhausted that I would look at the code at a microscopic level for optimization ideas. But because my website is stuck on the slow end of a DSL line, there's not much point to any of this. Jeff [1] http://www.logarithmic.net/pfh/aether (not my site) -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From lasse at vkarlsen.no Wed Oct 12 02:29:40 2005 From: lasse at vkarlsen.no (=?UTF-8?B?TGFzc2UgVsOlZ3PDpnRoZXIgS2FybHNlbg==?=) Date: Wed, 12 Oct 2005 08:29:40 +0200 Subject: bizarro world (was Re: Python Doc Problem Example: sort() (reprise)) References: <1128937897.500935.254770@o13g2000cwo.googlegroups.com> <1129033426.009136.256600@g47g2000cwa.googlegroups.com> <1129071507.829655.252340@g44g2000cwa.googlegroups.com> Message-ID: Bryan wrote: > mr. xah... would you be willing to give a lecture at pycon 2006? i'm > sure you would draw a huge crowd and a lot of people would like to meet > you in person... > > thanks. > I think that would be a highly un-pythonesque crowd. Python isn't much in the sense of limitations, but that crowd probably needs to be limited in one way or another, like "only 2 rotten fruits per person" or similar. -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From aisaac0 at verizon.net Thu Oct 13 14:25:12 2005 From: aisaac0 at verizon.net (David Isaac) Date: Thu, 13 Oct 2005 18:25:12 GMT Subject: extract PDF pages Message-ID: While pdftk is awesome http://www.accesspdf.com/pdftk/ I am looking for a Python solution. Just for PDF page extraction. Any hope? Thanks, Alan Isaac From mwm at mired.org Sat Oct 22 17:54:44 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 22 Oct 2005 17:54:44 -0400 Subject: Question about inheritance... References: <1130017209.078943.119990@g43g2000cwa.googlegroups.com> Message-ID: <86slut9pzv.fsf@bhuda.mired.org> "KraftDiner" writes: > I have a base class called Shape > And then classes like Circle, Square, Triangle etc, that inherit from > Shape: > > My quesiton is can a method of the Shape class call a method in Circle, > or Square etc...? Yup: >>> class Shape(object): ... def commented_draw(self): ... print "Drawing", self.__class__.__name__ ... self.draw() ... >>> class Circle(Shape): ... def draw(self): ... print "Drawing a Circle" ... >>> c = Circle() >>> c.commented_draw() Drawing Circle Drawing a Circle >>> Or maybe you meant invoking them directly, which a method in Shape would do by calling Circle.draw(self). The latter is ugly - you should use self.draw() to invoke the draw routine that's correct for self. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From steve at REMOVETHIScyber.com.au Thu Oct 20 09:46:51 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Thu, 20 Oct 2005 23:46:51 +1000 Subject: Microsoft Hatred FAQ References: <867jcbzdw9.fsf@bhuda.mired.org> <4vcbl1dkek9kr86embmgrj70vk945t99ho@4ax.com> <35jbl1dprs4v1o87i0tapc2husjqiqm6fi@4ax.com> <4355ea72$1_3@news.melbourne.pipenetworks.com> Message-ID: On Thu, 20 Oct 2005 13:17:14 +0000, axel wrote: > Employees have *no* obligations towards the shareholders of a company. > They are not employed or paid by the shareholders, they are employed > by the company itself which is a separate legal entity. > > It is a different matter for the board of directors of a company. The board of directors are also employees of the company. That's why the company can fire them. -- Steven. From codecraig at gmail.com Wed Oct 12 09:31:06 2005 From: codecraig at gmail.com (Java and Swing) Date: 12 Oct 2005 06:31:06 -0700 Subject: C Wrapper Function, crashing Python? In-Reply-To: References: <1129122046.417746.100120@g47g2000cwa.googlegroups.com> Message-ID: <1129123866.536068.69520@g43g2000cwa.googlegroups.com> Antoon, I just saw that to. I updated the code like so... static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { // this will store the result in a Python object PyObject *finalResult; // get arguments from Python char *result = 0; char *in= 0; char *aString = 0; char *bString = 0; MY_NUM *a = (MY_NUM *) PyMem_Malloc((20 * sizeof(MY_NUM) + 1); // the array will be 20 long MY_NUM *b = (MY_NUM *) PyMem_Malloc((20 * sizeof(MY_NUM) + 1); // the array will be 20 long int ok = PyArg_ParseTuple(args, "sss", &in, &aString, &bString); if (!ok) return 0; // do work to get a and b // count - returns an int; GetVal - returns a MY_NUM * (a pointer to a MY_NUM array) a = GetVal(aString, count(aString, ",")); b = GetVal(bString, count(bString, ",")); // make function call, which returns a char * result = doStuff(in, a, b); // save result in Python string finalResult = PyString_FromString(result); // free memory PyMem_Free(a); PyMem_Free(b); free(aString); free(bString); free(result); // return the result as a Python string return finalResult; } ..as you can see, i malloc'ed memory, and free'd the memory. However, I still have python crashing (after only 3 successful calls to doStuff). And yes, doStuff is a plain C function...nothing related to Python. Antoon Pardon wrote: > Op 2005-10-12, Java and Swing schreef : > > static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { > > // this will store the result in a Python object > > PyObject *finalResult; > > > > // get arguments from Python > > char *result = 0; > > char *in= 0; > > char *aString = 0; > > char *bString = 0; > > MY_NUM *a; > > MY_NUM *b; > > int ok = PyArg_ParseTuple(args, "sss", &in, &aString, &bString); > > if (!ok) return 0; > > > > // do work to get a and b > > // count - returns an int; GetVal - returns a char * > > a = GetVal(aString, count(aString, ",")); > > b = GetVal(bString, count(bString, ",")); > > > > // make function call, which returns a char * > > result = doStuff(in, a, b); > > > > // save result in Python string > > finalResult = PyString_FromString(result); > > > > // free memory > > PyMem_Free(result); > > PyMem_Free(a); > > PyMem_Free(b); > > > > // return the result as a Python string > > return finalResult; > > } > > > > ...from python I can call this function 4 times...works fine. WHen I > > call it for the fifth time python.exe crashes. im thinking some memory > > problem in the wrapper function perhaps...but I am not sure. The > > actually C function, doStuff can be called 5, 6,7...N times without a > > problem > > so i know its gotta be my wrapper. > > > > Any ideas? Thanks! > > Well assuming your doStuff is a C function that knows nothing of python. > it might be the PyMem_Free(result). > http://docs.python.org/api/memoryInterface.html says the following: > > void PyMem_Free(void *p) > Frees the memory block pointed to by p, which must have been > returned by a previous call to PyMem_Malloc() or PyMem_Realloc(). > Otherwise, or if PyMem_Free(p) has been called before, undefined > behavior occurs. If p is NULL, no operation is performed. > > But your result wasn't allocated by a PyMem_Malloc, it was returned > to you by a C function. > > -- > Antoon Pardon From steve at holdenweb.com Mon Oct 17 02:57:39 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 17 Oct 2005 07:57:39 +0100 Subject: UI toolkits for Python In-Reply-To: <3rg3aiFjgc47U1@individual.net> References: <7xslv56ud1.fsf@ruckus.brouhaha.com> <3ras6oFit2djU1@individual.net> <3rg3aiFjgc47U1@individual.net> Message-ID: Claudio Grondi wrote: > "Steve Holden" schrieb im Newsbeitrag [...] [Claudio] >>>I don't fully understand your attitude here. The Web Browser interface > > has > >>>all I can imagine is required for a GUI, so what is missing when you >>>consider, that you can generate custom images on the fly on the server > > and > >>>let the user shape the page without requesting CPU power from the server >>>using JavaScript. >> >>In this case then, I'm afraid the failure is in your imagination :-) > > > Any useful hints towards enlightenment except criticism? > Perhpas the mistake I made was bearing in mind the title of the thread, and the fact that this is a Python newsgroup. > >>>I don't even name here the not really beeing itegral part of Internet >>>Browsers JavaApplets and any other kind of plugin stuff. >>>The only issue I can see with this approach is the speed of responding > > to > >>>user interactions, but for really optimize this one needs a compiled >>>language anyway. >>>What is that complex, that it can't be solved using an Internet Browser > > as a > >>>GUI? >>>Do I miss here something? >>> >> >>While you are correct in saying (I paraphrase) that HTML interfaces >>nowadays can offer a rich graphical interface, it can be quite difficult >>to manage state maintenance between the two components (web server, web >>client) in the system. > > > The cause of confusion here is, that HTML interfaces don't necessary need a > web server and HTTP to work. I mean, that Internet Browsers > have an API which allow access to them directly, so they can be used without > a server as a kind of GUI library supporting widgets programmed > in HTML and JavaScript (I haven't used them yet in this form, but I think > it should be no problem - right or not?). > You are perfectly correct that interfaces can be programmed in the browser. As has already been said, with the adoption of standards like CSS2, it's even possible to make such stuff run across multiple browser platforms (at the moment, though, just try writing an interface that makes table rows appear and disappear in a cross-browser fashion: you'll find the stylesheet techniques you need to use for Mozilla and IE are very different). But this doesn't help you at all if you are trying to interface to Python logic. > >>A "proper" GUI runs all functionality inside a single process, and >>allows much easier control over complex interactions, creation of >>dynamic dialogues, and so on. > > Complex and dynamic is in my eyes possible with HTML and JavaScript, so I > still don't see where is a problem with this approach. I have programmed > already a HTML and JavaScript driven server platform and know about (the > solvable) problems with the back-button and sessions (it is sure not the > easiest way of programming a GUI). > The only disadvantage of not using plugins or Java is, that real time > interactions are not possible, but this is in my eyes usually not the > requirement for a standard kind of GUI with no gaming, no Virtual Reality > and no timing of user response down to milliseconds (but consider, that with > a good speed of connection it is even possible to play blitz chess over the > Internet). > So, back to the subject: with an HTML/Javascript interface, how do you propose to bolt Python logic into the same process? Or do you admit that the application that interacts with such an interface either has to be all JavaScript or in a separate process? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From bokr at oz.net Sat Oct 29 03:48:39 2005 From: bokr at oz.net (Bengt Richter) Date: Sat, 29 Oct 2005 07:48:39 GMT Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <867jbxfpvb.fsf@bhuda.mired.org> <1h55ri3.1hzntdk1dtxpa7N%aleaxit@yahoo.com> Message-ID: <43632812.1249162210@news.oz.net> On Fri, 28 Oct 2005 20:03:17 -0700, aleaxit at yahoo.com (Alex Martelli) wrote: >Mike Meyer wrote: > ... >> Except if you can't read the file into memory because it's to large, >> there's a pretty good chance you won't be able to mmap it either. To >> deal with huge files, the only option is to read the file in in >> chunks, count the occurences in each chunk, and then do some fiddling >> to deal with the pattern landing on a boundary. > >That's the kind of things generators are for...: > >def byblocks(f, blocksize, overlap): > block = f.read(blocksize) > yield block > while block: > block = block[-overlap:] + f.read(blocksize-overlap) > if block: yield block > >Now, to look for a substring of length N in an open binary file f: > >f = open(whatever, 'b') >count = 0 >for block in byblocks(f, 1024*1024, len(subst)-1): > count += block.count(subst) >f.close() > >not much "fiddling" needed, as you can see, and what little "fiddling" >is needed is entirely encompassed by the generator... > Do I get a job at google if I find something wrong with the above? ;-) Regards, Bengt Richter From gh at ghaering.de Tue Oct 4 05:20:43 2005 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Tue, 04 Oct 2005 11:20:43 +0200 Subject: Python Debug Build In-Reply-To: References: <20051003210217.88812.qmail@web30614.mail.mud.yahoo.com> Message-ID: <4342496B.9070607@ghaering.de> Fredrik Lundh wrote: > "Celine & Dave" wrote: > > >>What happens if I build Python with debug option >>(--with-pydebug)? Do I see any changes in my program >>output? What is --with-pydebug good for? > > > from the README: > > --with-pydebug: Enable additional debugging code to help track down > memory management problems. This allows printing a list of all > live objects when the interpreter terminates. And that's why it's very useful for when developing Python extension modules. Not only does it help find reference count problems, --with-pydebug on, Python sometimes also complains earlier if you do "stupid" things in the C code. Or gives a helpful error message before crashing ;-) -- Gerhard From richie at entrian.com Fri Oct 7 09:42:12 2005 From: richie at entrian.com (Richie Hindle) Date: Fri, 07 Oct 2005 14:42:12 +0100 Subject: When someone from Britain speaks, Americans hear a "British accent"... In-Reply-To: References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kbgj7421kd560@corp.supernews.com> <4h5ck1hkqq0ls83pq0lodkb51tsda4053k@4ax.com> Message-ID: [Richie] > Your previous post to this thread was chock-full of split nominatives: "The > Hollywood voice", "the specific regional accent", "the English-speaking > world", "the original French". And you call yourself a grammarian. [Steve] > I am presuming this post was meant to be a joke? It was. > No smileys, though, so you force us to make up our own minds. Yes. 8-) > Or is "the green tomato" also unacceptable? It ought to be considered unacceptable by people who think that "to correctly apply" is unacceptable, which is the point that Stephen was making: > *Real* pedants will know that English is not Latin, does not follow the > grammatical rules of Latin, and that just because split infinitives are > impossible -- not forbidden, impossible -- in Latin is no reason to forbid > them in English. Split nominatives like "the green tomato" are also impossible in Latin, but no-one seems to object to their use in English. -- Richie Hindle richie at entrian.com From eight02645999 at yahoo.com Tue Oct 11 21:34:30 2005 From: eight02645999 at yahoo.com (eight02645999 at yahoo.com) Date: 11 Oct 2005 18:34:30 -0700 Subject: where to get modules for python Message-ID: <1129080870.418774.76390@f14g2000cwb.googlegroups.com> hi i am new to python and was wondering where can i find modules for python? Something very much like what CPAN has for Perl. I am searching for SSL/SSH modules for use in Python. thanks From Dennis.Benzinger at gmx.net Tue Oct 25 11:31:55 2005 From: Dennis.Benzinger at gmx.net (Dennis Benzinger) Date: Tue, 25 Oct 2005 17:31:55 +0200 Subject: Math markup in code documentation? In-Reply-To: <1130251116.027733.123750@g47g2000cwa.googlegroups.com> References: <1130251116.027733.123750@g47g2000cwa.googlegroups.com> Message-ID: <435e4fe3$1@news.uni-ulm.de> schwehr at gmail.com schrieb: > Done any one have a way (and examples) of how to do math markups in the > docstrings of function and class definitions such that the equations > get typeset in the generated html documentation? I'll take any markup > system that'll do the job... MathML or LaTeX possible? > [...] Try Doxygen: http://www.doxygen.org Examples of formulas are here: http://www.stack.nl/~dimitri/doxygen/formulas.html Doxygen has the advantage that you can use it for a variety of programming languages. Bye, Dennis From fumanchu at amor.org Thu Oct 20 03:10:49 2005 From: fumanchu at amor.org (fumanchu) Date: 20 Oct 2005 00:10:49 -0700 Subject: sqlstring -- a library to build a SELECT statement In-Reply-To: <1129774730.887128.314960@z14g2000cwz.googlegroups.com> References: <1129774730.887128.314960@z14g2000cwz.googlegroups.com> Message-ID: <1129792249.206990.239680@g49g2000cwa.googlegroups.com> grunar at gmail.com wrote: > These objects (such as sqlstring.Select), represent > complex SQL Statements, but as Python objects. The benefit is that you > can, at run-time, "build" the statement pythonically, without > getting bogged down in String Manipulation. The theory is that once in > use, things that were complex (string magic) become simpler, and allow > the program to worry about higher-level issues. > ... > Some of this stuff has been around for a while (using "magic" objects > to build where clauses, etc.). But I'm trying to take it all the > way--to a legit Select statement. > > While still in the early stages, it does work with a great many sql > statements, as seen in the test suite. Currently supported are CASE > statements, Nested conditional clauses, nested queries and most join > types. At this point, I'm interested in getting feedback from the > community on several fronts: > > 1. The Operator Overload model. I've chosen to overload Python's > operators to give a short-hand syntax to most of the things you'd > want to do with a select statement. The rest are accessable via > methods. Currently ** is the "where" operator, // is the "in" > operator, % the "like" operator and ^ aliases columns. Other > overloads are as you'd expect- + / - * == all result in Expression > Objects that dish out the right SQL string. The question is, is the > "leap" in syntax to confusing? Is there a cleaner way to do this? > (Functions for example) The big operator question will be: how will "and" and "or" be implemented? This is always a sticking point because of Python's short-circuiting behaviors regarding them (the resultant bytecode will include a JUMP). An alternative is to stuff the representation into a string, which can then be parsed however one likes. For Dejavu (http://projects.amor.org/dejavu), I didn't do either one--instead I used lambdas to express the where clause, so that: f = logic.Expression(lambda x: ('Rick' in x.Name) or (x.Birthdate == datetime.date(1970, 1, 1))) units = sandbox.recall(Person, f) might produce, in the bowels of the ORM: "SELECT * FROM [Person] WHERE [Person].[Name] Like '%Rick%' or [Person].[Birthdate] = #1/1/1970#" Note that the tablename is provided in a separate step. The translation is based on the codewalk.py and logic.py modules, which are in the public domain if you want to use any part of them. See http://projects.amor.org/dejavu/svn/trunk/ > 2. How to best add further sql function support? Adding magic > callable objects to columns came to mind, but this has it's own set > of issues. I'm leaning towards a magic object in the sqlstring > module. For example: > > sqlstring.F.substring(0, 4, person.first_name) > > would result in: substring(0, 4, person.first_name). the F object > could be put in the local scope for short-hand. This is a hard problem, since your sqlstring module doesn't control the result sets, and so can't provide fallback mechanisms if a given database does not support a given function (or operator, or minute detail of how a function or operator works; for example, LIKE is case-insensitive in MS SQL Server but case-sensitive in PostgreSQL). If you're going to use subclasses to handle "database-specific overwrites" (below), then you'll probably want to stick such functions in that base class (and override them in subclasses), as well. > 3. I'm undecided on how best to handle database specific > overwrites. I want this to be as easy as possible. I'm thinking about > subclassing Expressions with a naming scheme on the Sub-Class (such as > CaseExpression_oracle). Then the __init__ factory could dish out the > right version of the object based on the requestor. This brings up > lots of questions, such as how to support multiple types of databases > at the same time. See the Adapter and SQLDecompiler classes in http://projects.amor.org/dejavu/svn/trunk/storage/db.py (and the store*.py modules) for some examples of using subclassing to produce database-specific syntax. There, it's one Adapter class per supported DB-type; you might consider keeping the Expression objects themselves free from SQL, and transform the Expressions to SQL in a separate class, which you could then subclass. Just a couple of thoughts from someone who's done the string-manipulation dance once before. ;) I must admit I've always punted when it came time to produce complex joins or CASE statements--Dejavu simply doesn't provide that level of expressivity, preferring instead to hide it behind the object layer. Robert Brewer System Architect Amor Ministries fumanchu at amor.org From zanesdad at bellsouth.net Wed Oct 5 11:24:25 2005 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Wed, 05 Oct 2005 11:24:25 -0400 Subject: How to create temp file in memory??? In-Reply-To: References: Message-ID: <4343F029.4020708@bellsouth.net> Wenhua Zhao wrote: >I have a list of lines. I want to feed these lines into a function. >The input of this function is a file. >I want to creat a temp file on disk, and write the list of lines into >this temp file, then reopen the file and feed it to the function. >Can I create a this temp file on memory??? > > > >Jeremy Jones wrote: > > >>Wenhua Zhao wrote: >> >> >> >>>A.T.T >>> >>>Thanks a lot. >>> >>> >>> >>> >>If you could elaborate a bit more, it might be helpful. I'm guessing >>you want something like StringIO or cStringIO. >> >> >>- jmj >> >> If the function takes a file object as an argument, you should be able to use StringIO or cStringIO. - jmj From tamer at remove-this-tammura.at-and.this Wed Oct 5 08:53:45 2005 From: tamer at remove-this-tammura.at-and.this (Tamer Fahmy) Date: Wed, 05 Oct 2005 14:53:45 +0200 Subject: how to debug when "Segmentation fault" References: Message-ID: On Tue, 04 Oct 2005 19:13:10 +0300, Maksim Kasimov wrote: > my programm sometime gives "Segmentation fault" message (no matter how > long the programm had run (1 day or 2 weeks). And there is nothing in > log-files that can points the problem. My question is how it possible to > find out where is the problem in the code? Thanks for any help. > > Python 2.2.3 > FreeBSD you could start your program within a gdb session like so: $ gdb python GNU gdb 6.1.1 [FreeBSD] Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-marcel-freebsd"...(no debugging symbols found)... (gdb) r foo.py Starting program: /usr/bin/python foo.py ... once your progmam segfaults you can then inspect the stack through: (gdb) bt cheers, tamer. -- hardware, n: The parts of a computer system that can be kicked. From jwentingathornetdotdemondotnl Sun Oct 16 05:54:20 2005 From: jwentingathornetdotdemondotnl (Jeroen Wenting) Date: Sun, 16 Oct 2005 11:54:20 +0200 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: <11l48tuqj7m11b5@corp.supernews.com> "Mike Meyer" wrote in message news:86ll0vs1sw.fsf at bhuda.mired.org... > "Jeroen Wenting" writes: >>>> Q: Microsoft's Operating System is used over 90% of PCs. If that's >>>>not monopoly, i don't know what is. >>> They got where they are by CHEATING. That is why they are evil, not >>> because they have a large market share. >> no, they got their by clever marketing and generally having a product >> that >> was easier to use for the average user than anything the competition made >> and a lot more powerful than other products created for their main target >> market. > > What you call "clever marketing" the DOJ calls "monopolistic > practices". The courts agreed with the DOJ. Having had several large > PC manufacturers refuse to sell me a system without some form of > Windows because MS made it impossible for them to compete if they > didn't agree to do so, I agree with the courts and the DOJ. > And were later forced to rescind. The judge who wrote that opinion is well known for his anti-Microsoft activism. >> Prices would be far far higher than they are today > > I disagree. Before Gates decided to sell BASIC, software was very > cheap. It started getting cheap again in the late 80s. Now that cheap > software is threatening MS, they're doing their best to shut down all > the sources of quality cheap software, with there usual disregard for > truth, legality, ethics or the good of either the customer or their > business partners. > WordPerfect (to take an example) cost several thousand dollars. When Microsoft released Office 4 for a few hundred WP was forced to lower prices radically, and so was Lotus (to name a few). >> IBM's prediction that there would be 5 computers (not counting game >> computers like the Comodores and Spectrums) by 2000 would likely have >> come >> true. > > I see. You're a troll. > nope, I'm just sick and tired of trolls like you calling everyone who doesn't share their hatred of Microsoft a troll. From gsakkis at rutgers.edu Tue Oct 18 19:11:01 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Tue, 18 Oct 2005 19:11:01 -0400 Subject: Intersection of lists/sets -- with a catch References: <1129673443.076527.152520@g49g2000cwa.googlegroups.com> Message-ID: <1129677062.dffd24a2066c21ee2d9a4ca0df992496@teranews> "Carl Banks" wrote: > Howabout something like this (untested): > > class CmpProxy(object): > def __init__(self,obj): > self.obj = obj > def __eq__(self,other): > return (self.obj.att_a == other.obj.att_b > and self.obj.att_b == other.obj.att_b) > def __hash__(self): > return hash((self.obj.att_a,self.obj.att_b)) > > set_a = set(CmpProxy(x) for x in list_a) > set_b = set(CmpProxy(y) for y in list_b) > overlaps = [ z.obj for z in set_a.intersection(set.b) ] Or more generally: class Comparable(object): def __init__(self, obj, key): self.obj,self._key = obj,key def __hash__(self): return hash(self._key(self.obj)) def __eq__(self, other): return self._key(self.obj) == self._key(other.obj) if __name__ == '__main__': some_list = ["hello", "world"] another_list = ["HeLlO", "word"] key = str.lower some_set = set(Comparable(x,key) for x in some_list) another_set = set(Comparable(x,key) for x in another_list) print "overlaps:", [x.obj for x in some_set.intersection(another_set)] print "unique_some:", [x.obj for x in some_set.difference(another_set)] print "unique_another:", [x.obj for x in another_set.difference(some_set)] George From michael at stroeder.com Mon Oct 10 19:21:55 2005 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Tue, 11 Oct 2005 01:21:55 +0200 Subject: Send password over TCP connection In-Reply-To: References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> <1128979760.251637.316480@o13g2000cwo.googlegroups.com> <7xk6glhvgl.fsf@ruckus.brouhaha.com> Message-ID: Dan Stromberg wrote: > On Mon, 10 Oct 2005 15:13:14 -0700, Paul Rubin wrote: >> >>Use SRP if you can. > > Where can I learn more about this? http://www.faqs.org/rfcs/rfc2945.html Ciao, Michael. From luke at webber.com.au Wed Oct 19 02:40:50 2005 From: luke at webber.com.au (Luke Webber) Date: Wed, 19 Oct 2005 16:40:50 +1000 Subject: Microsoft Hatred FAQ In-Reply-To: References: <86ll0vs1sw.fsf@bhuda.mired.org> <867jcbzdw9.fsf@bhuda.mired.org> <4vcbl1dkek9kr86embmgrj70vk945t99ho@4ax.com> <35jbl1dprs4v1o87i0tapc2husjqiqm6fi@4ax.com> Message-ID: <4355ea72$1_3@news.melbourne.pipenetworks.com> David Schwartz wrote: > "Roedy Green" wrote in > message news:35jbl1dprs4v1o87i0tapc2husjqiqm6fi at 4ax.com... >>On Tue, 18 Oct 2005 20:30:42 -0700, "David Schwartz" >> wrote or quoted : > >>> No, taken stupidly. Hint: would or would not MS executives disobeying >>>the law constitute a betrayal of their obligation to their shareholders? > >>You stated it literally as if making maximum profit for the >>shareholders were the only consideration in determining conduct. > > No, I did not. I said that their obligation is to their shareholders. As much as I hate to jump in on this thread, well I'm gonna... I think you'll find that companies have all manner of legal obligations. Certainly to their shareholders, but beyond that they have an obligation to their clients, who pay them for their services, and to any individual or entity which might be harmed by their actions. A classic case in point would be Philip Morris, who did everything they could to protect their shareholders, but who shirked their duty of care to their customers and the the public at large. They have since paid heavily for that failure. >>If that is not what you mean, I think you need to hedge more. > > I was perfectly clear. This is a lot of deliberate misunderstanding > going on in this thread and very little of it is from my side. All that means to me is that your misunderstanding is not deliberate. Luke From quiteblack at gmail.com Tue Oct 11 10:07:44 2005 From: quiteblack at gmail.com (quiteblack at gmail.com) Date: 11 Oct 2005 07:07:44 -0700 Subject: how to(can we ?) pass argument to .py script ? Message-ID: <1129039664.425406.265670@f14g2000cwb.googlegroups.com> howdy~ i wrote a .py file and it works fine, my goal is to pass argument to that py file when it get executed, and accept that argument within py file, eg. i prefer a command like below: python test.py -t and then, i may get "-t" within test.py for later use. i have no ideas how to do and i'm really stuck, can anyone help ? From neuromancer at wanadoo.fr Tue Oct 18 21:52:57 2005 From: neuromancer at wanadoo.fr (TokiDoki) Date: Wed, 19 Oct 2005 03:52:57 +0200 Subject: How to organize Python files in a (relatively) big project Message-ID: Hello there, I have been programming python for a little while, now. But as I am beginning to do more complex stuff, I am running into small organization problems. It is possible that what I want to obtain is not possible, but I would like the advice of more experienced python programmers. I am writing a relatively complex program in python that has now around 40 files. At first, I had all of my files in one single directory, but now, with the increasing number of files, it is becoming hard to browse my directory. So, I would want to be able to divide the files between 8 directory, according to their purpose. The problem is that it breaks the 'import's between my files. And besides,AFAIK, there is no easy way to import a file that is not in a subdirectory of the current file (I suppose I could adjust the os.path in every file, but that seems not very elegant to me). I thought about turning the whole into a package. But I have to change every 'import module_name' into 'from package_name.sub_directory_name import module_name' which is a little bit time consuming and not very flexible (if I change my mind about the subdirectory a file belongs to, I will have to track again every import to correct them) So, basically, here is the point: is there an 'elegant' way to keep my files in separate directory and still be able to import between them with simple 'import filename'? And if not, what would be the standard way to organize numerous python files belonging to the same project? Thank you, TokiDoki From flupke at nonexistingdomain.com Thu Oct 27 11:02:22 2005 From: flupke at nonexistingdomain.com (flupke) Date: Thu, 27 Oct 2005 15:02:22 GMT Subject: time conversion In-Reply-To: References: Message-ID: <2_58f.33249$b55.1588325@phobos.telenet-ops.be> flupke wrote: > Is there an easy to convert following hour notation hh:mm > to decimals? > For instance 2 hours and 30 minutes as 2:30 to 2,50 > I don't really know where to search for this kind of conversion. > > Thanks, > Benedict I found a way. Not sure if it's the best: time = "2:3" factor = 100.0/60.0 time_parts = time.split(":") minutes = int(float(time_parts[1]) * factor) if ( len(str(minutes)) == 1 ): minutes *= 10 # to get 50 instead of 5 time_new = "%s,%.02s" % (time_parts[0],minutes) print "%s -> %s " % (time,time_new) From gerryandsharon at sympatico.ca Sun Oct 30 16:40:10 2005 From: gerryandsharon at sympatico.ca (GerShar) Date: Sun, 30 Oct 2005 16:40:10 -0500 Subject: Problem: Windows Command line Pipe to stdin Message-ID: <15b9f.1703$J14.49315@news20.bellglobal.com> Python 2.3 on Windows XP The following works when run from the command line. import sys text = sys.stdin.read() # do something on the text # ... sys.stdout.write(text) But if the above code is used as a filter program that gets another programs output as shown below, it fails as shown. C:\>textGen.py | filter.py Traceback (most recent call last): File "C:\filter.py", line 4, in ? text = sys.stdin.read() IOError: [Errno 9] Bad file descriptor Any ideas on what is happening and how to fix it? From fredrik at pythonware.com Thu Oct 13 12:38:21 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 13 Oct 2005 18:38:21 +0200 Subject: Technical question on complexity. References: Message-ID: Jerzy Karczmarczuk wrote: > Anybody knows where I can find a concrete and guaranteed answer to the following > extremely basic and simple question? > > What is the complexity of appending an element at the end of a list? amortized O(1) > Concatenating with another? O(n) > The point is that I don't know what is the allocation policy... If Python lists > are standard pointer-chained small chunks, then obviously linear. But perhaps > there is some optimisation, after all a tuple uses a contiguous chunk, so it > *might* be possible that a list is essentially equivalent to an array, with its > length stored within, and adding something may be done in constant time a list consists of a single array of PyObject pointers, plus "allocated" and "current size" fields. when you append, allocation is only done when needed, and the new size is chosen carefully to keep the number of allocations low. see the source for details (the exact "overallocation" strategy varies some- what in different Python versions). From grante at visi.com Thu Oct 20 13:45:17 2005 From: grante at visi.com (Grant Edwards) Date: Thu, 20 Oct 2005 17:45:17 -0000 Subject: need some advice on x y plot References: <1129823043.104864.73750@f14g2000cwb.googlegroups.com> Message-ID: <11lfltdrulivj6b@corp.supernews.com> On 2005-10-20, Larry Bates wrote: > I would try to live with time scale being fixed I don't understand what you mean by "the time scale being fixed". It's not. If you just pass the time,value pairs to gnuplot, it does exactly what it should. > and insert > None (or whatever value is used by charting package) for > times where observations were not taken. This will mean that > you have to preprocess your data by determining a time step > step value that will fit your data. If you get 3 observations > each 10 minutes apart then one an hour later, you will need to > insert 5 empty observations in the list before the last > observation. > > Example: > > 1:00 > 1:10 > 1:20 > 2:20 > > 1:00 > 1:10 > 1:20 > 1:30 > 1:40 > 1:50 > 2:00 > 2:10 > 2:20 That's completely unnecessary. Just pass a set of time,value pairs and they'll get plotted as desired. -- Grant Edwards grante Yow! As a FAD follower, at my BEVERAGE choices are visi.com rich and fulfilling! From steve at REMOVETHIScyber.com.au Mon Oct 17 09:16:42 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 17 Oct 2005 23:16:42 +1000 Subject: [newbie]Is there a module for print object in a readable format? References: Message-ID: On Mon, 17 Oct 2005 11:31:46 +0200, enrico.sirola_NOSPAM wrote: >>>>>> "James" == James Gan writes: > > James> I want the object printed in a readable format. For > > [...] > > James> I tried pickled, marshel. They do different work. Is there > James> another module which do this kind of job? > > from pprint import pprint > pprint(object) I don't think that even comes *close* to what James wants. py> import pprint py> pprint.pprint([1,2,3,4,[0,1,2], 5]) [1, 2, 3, 4, [0, 1, 2], 5] -- Steven. From fredrik at pythonware.com Sat Oct 22 03:40:12 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 22 Oct 2005 09:40:12 +0200 Subject: get a copy of a string leaving original intact References: <2387F0EED10A4545A840B231BBAAC722607F70@slcimail1.slcgov.com> Message-ID: "Bell, Kevin" wrote: > I ended up slicing my string into a new one, rather than trying to have > a copy of the string to alter in one case, or leave intact in another > case. given that you cannot modify strings in place in Python, that comment probably doesn't match what your code really did... ("s = f" doesn't copy the string, it just binds a new name to the existing string object. "s = s.replace" doesn't modify that object; it creates a new one, and binds the same name to that one in- stead) From mwm at mired.org Mon Oct 3 01:15:54 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 03 Oct 2005 01:15:54 -0400 Subject: Will python never intend to support private, protected and public? References: <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xll1gvk7w.fsf@ruckus.brouhaha.com> <1128001308.905398.321670@g44g2000cwa.googlegroups.com> <311b5ce105092908332c12164c@mail.gmail.com> <7xbr2btv84.fsf@ruckus.brouhaha.com> <7xy85fvxny.fsf@ruckus.brouhaha.com> <86vf0inlt3.fsf@bhuda.mired.org> <7xd5mq9ir9.fsf@ruckus.brouhaha.com> <86wtkym33t.fsf@bhuda.mired.org> <7xll1d7l2c.fsf@ruckus.brouhaha.com> <86slvlmdnv.fsf@bhuda.mired.org> <7xr7b3spri.fsf@ruckus.brouhaha.com> <86br27mztp.fsf@bhuda.mired.org> <7x8xxbidtp.fsf@ruckus.brouhaha.com> <86ll1bkz99.fsf@bhuda.mired.org> <7xpsqn6wpx.fsf@ruckus.brouhaha.com> Message-ID: <8664sfkwol.fsf@bhuda.mired.org> Paul Rubin writes: > Mike Meyer writes: >> I'd say CPython was missing the features that you need to guarantee >> that. Missing quite a *lot* of features, in fact. But Python has never >> been about keeping people from writing bad code - it's about helping >> people write good code. > Privilege separation is considered a good coding practice. How does > Python help it? With conventions and name mangling. Which are only slightly less effective than the C++/Java technic for doing the same thing. >> Pretty much every attempt to restrict what other programmers do in >> Python has failed - for "implementation issues". I think that's a good >> sign that this kind of thing isn't going to work without some serious >> work on the interpreter. > You could take it as a sign that the interpreter could benefit from > some serious work. If you want it to become a secure environment to run untrusted code in, then it definitely neede some serious work. I'd recommend starting by copying /dev/null over all the .c and .h files. Of course, not everyone wants that from Python, so they don't get any benefit from such work. > I don't know the situation in Jython. I was going to suggest Jython as a better bet for getting something rexec-like to work. Java was at least intended to provide a secure environment to run untrusted code in, so you're not building on quicksand. IronPython might also be worth a look, based on what little (and it's very little) I know about .NET. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From jepler at unpythonic.net Tue Oct 4 14:44:54 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Tue, 4 Oct 2005 13:44:54 -0500 Subject: Newbie regular expression ? In-Reply-To: <1128450779.107011.5370@z14g2000cwz.googlegroups.com> References: <1128450779.107011.5370@z14g2000cwz.googlegroups.com> Message-ID: <20051004184454.GA29124@unpythonic.net> Here are two ideas that come to mind: files = glob.glob("UNQ*.dat") + glob.glob("Unq*.dat") + glob.glob("unq.dat") files = [f for f in glob.glob("*.dat") if f[:3] in ("UNQ", "Unq", "unq")] Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From jepler at unpythonic.net Tue Oct 18 09:08:16 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Tue, 18 Oct 2005 08:08:16 -0500 Subject: Bloodhound.Exploit.49 trojan found in MIMEBase.pyc In-Reply-To: References: Message-ID: <20051018130816.GA3752@unpythonic.net> It's almost certainly a false positive. In my day job we run into false positive antivirus detections like this once or twice a year, and typically get a runaround from the AV vendor (who often have the gall to suggest that we should buy a copy of their broken software before they'll fix their problems) Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From http Sun Oct 2 13:55:41 2005 From: http (Paul Rubin) Date: 02 Oct 2005 10:55:41 -0700 Subject: python guru.. for a short conversation regarding bittorrent.. References: Message-ID: <7xvf0fu7ky.fsf@ruckus.brouhaha.com> "bruce" writes: > if there's anyone here that i could talk with (phone) who's knowledgable > about these areas, i'd appreciate it. i'm trying to get a much better > understanding of the actual underlying app. There's a #bittorrent irc channel on irc.freenode.net. Try there. From hancock at anansispaceworks.com Mon Oct 10 16:56:33 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Mon, 10 Oct 2005 15:56:33 -0500 Subject: non descriptive error In-Reply-To: <4349A3CD.8030603@open-networks.net> References: <4346002C.3080504@open-networks.net> <200510070240.56350.hancock@anansispaceworks.com> <4349A3CD.8030603@open-networks.net> Message-ID: <200510101556.33681.hancock@anansispaceworks.com> On Sunday 09 October 2005 06:12 pm, Timothy Smith wrote: > Terry Hancock wrote: > >By looking at the source code for DutyShift.py? > > > well DUH thank you captain obvious! Well, since you apparently missed the subtlety, you DID NOT GIVE ADEQUATE INFORMATION if you expected to get some kind of answer. If you can't post the whole module, AT LEAST try to reproduce the problem. If a program doesn't show you where the error occurs, you can usually find out by "instrumenting" the code, which means, put in "print" statements. You should be able to localize the problem, THEN, it would be appropriate to post a question about it here, with a listing of the code showing where the error occurs. The only way I'd have imagined this happening is if you have something like try: 1 = 2 except: print "error" in your code. Which might still be the case, given the way you claim to have "fixed" the problem (since the kind of error a bad indent would've given you should look different, unless it was caught, as above). Now, it's not inconceivable that some unforseen thing makes Python itself do this, but it's MUCH more likely that it's something in YOUR CODE that does it. So you have the responsibility to localize it, and at least show us what is being executed when this "error" occurs. Certainly, if there WERE such a bug, no one would be able to find it without you doing that. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From jelle.feringa at ezct.net Thu Oct 20 11:34:04 2005 From: jelle.feringa at ezct.net (Jelle Feringa / EZCT Architecture & Design Research) Date: Thu, 20 Oct 2005 17:34:04 +0200 Subject: Modules and Namespaces Message-ID: <02d301c5d58b$b4a50050$0b01a8c0@JELLE> ##I'm sorry to stir up such a well discussed topic yet again, but namespaces are a point of confusion to me... I took the effort of organizing my Python code (scripting a cad program calles Rhino) in well defined classes, which would be a terrific thing if I didn't got stuck in namespace issues. I have a module that launches the application I'm scripting via win32com; rhino.load from rhino import load RS = load.RS So the application, with all its methods are now available through the RS (RhinoScript) object from rhino import SRF # is where things get stuck The RS object is the application scripted via COM, where all its method reside. In my module, SRF, I'm not importing anything, though it refers to the RS object all the time. Such as: class srfBase: '''Base class inherited by the srf* classes, binding general Rhino surface functionality to a particular surface generation method''' def __init__(self): self.id = 'self.id srfBase' pass def isBrep(self): return RS.IsBrep(self.id) def isPointInSurface(self, coord): return RS.IsPointInSurface(self.id, coord) How do I make the RS object available to the imported SRF module, such that my module code and program code both refer to RS as the application object being scripted? Cheers, Jelle. From hrvoje at despammed.com Tue Oct 4 16:23:06 2005 From: hrvoje at despammed.com (Hrvoje Blazevic) Date: Tue, 04 Oct 2005 22:23:06 +0200 Subject: Idle Message-ID: How do I get Idle to work on Linux? I've tried to compile 2.4.2 on Fedora core 4, and Suse 9.3, but Idle is after make install either missing (Fedora), or reports **Idle can't import Tkinter... ** Thanks -- Hrvoje From fredrik at pythonware.com Sun Oct 2 03:38:54 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 2 Oct 2005 09:38:54 +0200 Subject: Statement orders References: <1128236799.839645.101270@g14g2000cwa.googlegroups.com> Message-ID: Monu Agrawal wrote: > Hi I am making a gui based tool. When user preses a perticular button I > am running a heavy command, before this I want to say user to wait with > a image showing infront of her. > > My code is like: > > def loadData(self): > top=Toplevel(self.parent) > top.focus_set() > self.parent.wm_title("Loading Data...") + top.update() # flush the event queue > os.system('a heavy command') > os.system('another heavy command) > top.destroy() From sjmaster at gmail.com Thu Oct 6 18:08:07 2005 From: sjmaster at gmail.com (Steve M) Date: 6 Oct 2005 15:08:07 -0700 Subject: Bug in COM Makepy utility? (ActivePython 2.4) Message-ID: <1128636487.225741.266930@g43g2000cwa.googlegroups.com> When I use the COM Makepy utility on one computer with WindowsXP, ActivePython 2.3 and I select the library Microsoft Word 10.0 Object Library (8.2), things work fine. When I have WindowsXP, ActivePython 2.4 (build 247) and Microsoft Word 11.0 Object Library (8.3), then I get the following SyntaxError, and on two different computers I tested this. More on the error below, but has anyone else had this problem? Will there soon be a newer build of ActivePython? I've never used the standard Python distribution with manually installed win32all package, just because its so easy to deploy ActivePython. Should I consider switching, now that I'm on the topic? >>> Generating to C:\Python24\lib\site-packages\win32com\gen_py\00020905-0000-0000-C000-000000000046x0x8x3\__init__.py Building definitions from type library... Generating... Importing module Failed to execute command: from win32com.client import makepy;makepy.main() Traceback (most recent call last): File "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\toolmenu.py", line 103, in HandleToolCommand exec "%s\n" % pyCmd File "", line 1, in ? File "C:\Python24\lib\site-packages\win32com\client\makepy.py", line 363, in main GenerateFromTypeLibSpec(arg, f, verboseLevel = verboseLevel, bForDemand = bForDemand, bBuildHidden = hiddenSpec) File "C:\Python24\lib\site-packages\win32com\client\makepy.py", line 274, in GenerateFromTypeLibSpec gencache.AddModuleToCache(info.clsid, info.lcid, info.major, info.minor) File "C:\Python24\Lib\site-packages\win32com\client\gencache.py", line 555, in AddModuleToCache mod = _GetModule(fname) File "C:\Python24\Lib\site-packages\win32com\client\gencache.py", line 634, in _GetModule mod = __import__(mod_name) File "C:\Python24\lib\site-packages\win32com\gen_py\00020905-0000-0000-C000-000000000046x0x8x3\__init__.py", line 2831 '{00020960-0000-0000-C000-000000000046}' : 'Pane', '{00020961-0000-0000-C000-000000000046}' : 'Windows', ^ SyntaxError: invalid syntax I don't entirely understand the error (I'm rather ignorant of the whole process Makepy is doing, come to think of it...). First of all, when I load the file with the alleged syntax error into Scite, the line where the caret is pointing to is actually 2838, not line 2831. Further, I cannot detect any syntax errors based on visual inspection. In fact, when I copy/paste lines 2830-2840 into a new script and put "d = {" before the lines and "}" after the lines, it is syntactically valid python that executes without complaint. I don't know how "dynamically" this file is being generated, but somethin' ain't right. From fredrik at pythonware.com Tue Oct 25 04:23:34 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 25 Oct 2005 10:23:34 +0200 Subject: Hi All - Newby References: <435ddd20$1@news1.veridas.net> Message-ID: "Ask" wrote: > As an example, if I create a window, I've been unable to force it to be a certain size, and put a > button (widget) at (say) 20,40 (x & y). Is window formatting possible? I'm pretty sure all GUI toolkits can do that, but the exact details depend on the library you're using. (if you're using Tkinter, see this page: http://effbot.org/tkinterbook/place.htm ) From jepler at unpythonic.net Mon Oct 10 23:01:40 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Mon, 10 Oct 2005 22:01:40 -0500 Subject: Looking for info on Python's memory allocation In-Reply-To: <434B1A99.8040107@REMOVEMEcyber.com.au> References: <434B1A99.8040107@REMOVEMEcyber.com.au> Message-ID: <20051011030140.GC21569@unpythonic.net> While there may be a discussion somewhere in the archives, the comments in listobject.c are enlightening too. /* Ensure ob_item has room for at least newsize elements, and set * ob_size to newsize. If newsize > ob_size on entry, the content * of the new slots at exit is undefined heap trash; it's the caller's * responsiblity to overwrite them with sane values. * The number of allocated elements may grow, shrink, or stay the same. * Failure is impossible if newsize <= self.allocated on entry, although * that partly relies on an assumption that the system realloc() never * fails when passed a number of bytes <= the number of bytes last * allocated (the C standard doesn't guarantee this, but it's hard to * imagine a realloc implementation where it wouldn't be true). * Note that self->ob_item may change, and even if newsize is less * than ob_size on entry. */ [...] /* This over-allocates proportional to the list size, making room * for additional growth. The over-allocation is mild, but is * enough to give linear-time amortized behavior over a long * sequence of appends() in the presence of a poorly-performing * system realloc(). * The growth pattern is: 0, 4, 8, 16, 25, 35, 46, 58, 72, 88, ... */ "linear-time amortized behavior" (i.e., that list.append() is O(1) on average) is the important characteristic you're probably looking for. CVS source for listobject.c can be seen here: http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Objects/listobject.c?rev=2.227&view=markup Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From mwm at mired.org Mon Oct 3 18:58:18 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 03 Oct 2005 18:58:18 -0400 Subject: packaging a python project and associated graphics files References: Message-ID: <867jcujjhx.fsf@bhuda.mired.org> Rajarshi Guha writes: > Hi, I've been trying to package a python project and I'm a little confused > about how I distribute some PNG's that the program uses as icons. > > Using distutils I can set the data_files argument of setup() and get my > data files located in, say, /usr/local/mydata. > > However when I write my code, it would seem that I have to hardcode the > above path. But this would mean that while working on the code I would > need to have it 'installed' on my system (or else actually make the above > directory). > > This seems a little unwieldy. How do people handle this situation? With symlinks from the installed location to the source tree. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From spe.stani.be at gmail.com Tue Oct 25 20:39:49 2005 From: spe.stani.be at gmail.com (SPE - Stani's Python Editor) Date: 25 Oct 2005 17:39:49 -0700 Subject: wxListbook layout problem In-Reply-To: References: <1130256419.199548.313950@f14g2000cwb.googlegroups.com> <435e8045$0$20495$4fafbaef@reader4.news.tin.it> Message-ID: <1130287189.312391.161440@f14g2000cwb.googlegroups.com> It is definitely a bug. The same problem also happens with wx.LB_BOTTOM. Tested on WinXP (SP2), python 2.4.1, wxPython 2.6.1.0 Stani -- SPE - Stani's Python Editor http://pythonide.stani.be http://pythonide.stani.be/manual/html/manual.html From http Thu Oct 13 14:44:21 2005 From: http (Paul Rubin) Date: 13 Oct 2005 11:44:21 -0700 Subject: Python's garbage collection was Re: Python reliability References: <3r6i0uFi3qb8U2@uni-berlin.de> <7xfyr5kfgm.fsf@ruckus.brouhaha.com> <3r6osdFhsfjgU1@uni-berlin.de> <7xvf0168nq.fsf@ruckus.brouhaha.com> <434e7967$1@nntp0.pdx.net> <7xr7apqw1y.fsf@ruckus.brouhaha.com> <434ea2ad$1@nntp0.pdx.net> Message-ID: <7x3bn5s1dm.fsf@ruckus.brouhaha.com> Scott David Daniels writes: > > I think most of the time, branch prediction will prevent the cache > > flush. > But, branch prediction is usually a compiler thing, based on code > that is, in this case, a spot in the interpreter that is actually > taking both sides of the branch quite often. If you split the > interpreter to have a "presumed int" side, you might do OK, but > that is not how the code works at the moment. Yes, I'm hypothesizing a native-code compiler as might come out of the PyPy project. > > if you have two tagged integers, > > you can add and subtract them without having to twiddle the tags. > You can do so only once you discover you have two tagged integers. > The test for tagged integers (rather, the subsequent branch) is the > thing that blows the pipe. I mean in cases where the compiler can determine that it's dealing with small ints. That might be harder in Python than in Lisp, given how dynamic Python is. > > The alternative (tag==1 means integer) means you don't have to mask > > off the tag bits to dereference pointers, and you can still add a > > constant to a tagged int by simply adjusting the constant > > appropriately. > And this presumes an architecture which byte-addresses and only > uses "aligned" addresses. Yes, that would describe just about every cpu for the past 30 years that's a plausible Python target. From lycka at carmen.se Mon Oct 17 12:09:31 2005 From: lycka at carmen.se (Magnus Lycka) Date: Mon, 17 Oct 2005 18:09:31 +0200 Subject: Writing an immutable object in python In-Reply-To: <1129562898.812915.238430@g14g2000cwa.googlegroups.com> References: <1129562898.812915.238430@g14g2000cwa.googlegroups.com> Message-ID: Mapisto wrote: > Hi, > > I've noticed that if I initialize list of integers in the next manner: > > >>>>my_list = [0] * 30 > > > It works just fine, even if I'll try to assign one element: > > >>>>id( my_list[4] ) > > 10900116 > >>>>id( my_list[6] ) > > 10900116 > >>>>my_list[4] = 6 >>>>id( my_list[4] ) > > 10900044 > >>>>id( my_list[6] ) > > 10900116 > > The change in the poision occurs becouse int() is an immutable object. No, it happens because you assign my_list[4] to a different object. Obviously, 0 and 6 can't be located in the same place in RAM. The difference lies in doing something like "my_list[n] = X" rather than changing the state of a shared existing object as in something like "my_list[n].f(X)". > if I will do the same with a user-defined object, This reference > manipulating will not happen. Really? >>> class C: ... pass ... >>> my_list = [C()]*30 >>> id(my_list[4]) 1003056 >>> id(my_list[6]) 1003056 >>> my_list[4] = C() # Another instance >>> id(my_list[4]) 986048 >>> id(my_list[6]) 1003056 From gsakkis at rutgers.edu Fri Oct 14 22:41:00 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Fri, 14 Oct 2005 22:41:00 -0400 Subject: XML dom question References: <1129339019.065675.314480@g14g2000cwa.googlegroups.com> Message-ID: <1129344063.eb6990d4cd74331d8defb9b71b046420@teranews> "George" wrote: > How can I do the following in python: > > [snipped] In exactly the same way you could do it if you actually read the replies to the thread with the same topic you posted yesterday. Duh! George From themightydoyle at gmail.com Sun Oct 16 00:49:07 2005 From: themightydoyle at gmail.com (themightydoyle at gmail.com) Date: 15 Oct 2005 21:49:07 -0700 Subject: How to get a raised exception from other thread In-Reply-To: <1129434873.307336.112030@g47g2000cwa.googlegroups.com> References: <1129326320.914350.171460@o13g2000cwo.googlegroups.com> <1129434185.879062.61600@o13g2000cwo.googlegroups.com> <1129434873.307336.112030@g47g2000cwa.googlegroups.com> Message-ID: <1129438147.182266.196790@g44g2000cwa.googlegroups.com> Nevermind. I found a better solution. I used shared memory to create a keep-alive flag. I then use the select function with a specified timeout, and recheck the keep-alive flag after each timeout. Thanx for all the input. From ptb at oboe.it.uc3m.es Tue Oct 25 18:06:21 2005 From: ptb at oboe.it.uc3m.es (Peter T. Breuer) Date: Wed, 26 Oct 2005 00:06:21 +0200 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: In comp.os.linux.misc David Schwartz wrote: > "Steven D'Aprano" wrote in message > news:pan.2005.10.25.16.12.33.746996 at REMOVETHIScyber.com.au... >> The first two points are factually wrong, and the third is an opinion >> based on the concept, as far as I can see, that Microsoft should be >> allowed to do anything they like, even if those actions harm others. > Of course this alleged "harm" is simply a lack of a benefit. > Why is Burger King allowed to close at 10PM? That harms me when I'm > hungry after 10. They can close when they like because the policy is not discriminatory, nor is part of an attempt to manage the market. If they were to do things that harmed the market - such as telling meat suppliers that supplied them that they couldn't supply anyone else, that would be a possible candidate for anti-competitive behaviour suits. It would have to be shown that the arrangement WAS materially anti-competitive, though, and that's difficult to conceive of because MacDonalds does not constitute a major portion of the market demand for corned beef, so they don't have the leverage. Peter From sybrenUSE at YOURthirdtower.com.imagination Thu Oct 27 02:50:10 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Thu, 27 Oct 2005 08:50:10 +0200 Subject: assignment to reference References: <435feab7$0$31384$626a14ce@news.free.fr> Message-ID: Bruno Desthuilliers enlightened us with: > for obj in (a, b, c): > if obj == 'cabbage': > obj = 'coconut' Doesn't work on my Python: Python 2.4.2 (#2, Sep 30 2005, 21:19:01) [GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a = 'apple' >>> b = 'banana' >>> c = 'cabbage' >>> for obj in (a, b, c): ... if obj == 'cabbage': ... obj = 'coconut' ... >>> c 'cabbage' >>> 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 eugene at boardkulture.com Fri Oct 7 14:38:14 2005 From: eugene at boardkulture.com (EuGeNe) Date: Fri, 07 Oct 2005 20:38:14 +0200 Subject: Book "Python and Tkinter Programming" In-Reply-To: <1128690443.478697.33250@g44g2000cwa.googlegroups.com> References: <1128620086.240847.235490@g44g2000cwa.googlegroups.com> <1128690443.478697.33250@g44g2000cwa.googlegroups.com> Message-ID: It is available as PDF from the editor ... Manning. In my recollection for 25 USD projecktzero wrote: > striker wrote: > >>Does anyone who has this book willing to sell it. Please e-mail me the >>condition and any other details if you are interested. >>Thanks, >>Kevin > > > half.com has a couple of people selling it. One for $35.24 and another > for $129.97. > From spammers-go-here at spam.invalid Wed Oct 19 12:32:54 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Wed, 19 Oct 2005 12:32:54 -0400 Subject: Converting 2bit hex representation to integer ? References: <43567027$0$41144$14726298@news.sunsite.dk> <-_2dndLn4eEm78veRVn-qg@comcast.com> <4356740c$0$41148$14726298@news.sunsite.dk> Message-ID: <43567508$0$41148$14726298@news.sunsite.dk> Madhusudan Singh wrote: > Larry Bates wrote: > >> Can you give us an example. I don't know what two bit >> hex means (takes at least 4 bits to make a hex digit). > > Like 64(base 16)=100. > I am referring to 64 in the above. > >> >> Now I'm going to try to guess: >> >> If the data is binary then all you need to do is to >> use the struct.unpack module to convert to integer. > > Doesn't unpack presume that the input is a string ? If so, is it safe to > convert binary data to string using str() ? Followup to this : I just tried : n=str(x) print struct.unpack("b",n) I get (51,) The corresponding output of binascii.b2a_hex(x) is 33. And 51_10=33_16. So that checks out. What is the deal with the parenthesis and the comma ? From grante at visi.com Thu Oct 13 17:32:12 2005 From: grante at visi.com (Grant Edwards) Date: Thu, 13 Oct 2005 21:32:12 -0000 Subject: UI toolkits for Python References: <7xslv56ud1.fsf@ruckus.brouhaha.com> Message-ID: <11ktkis6d2ko16b@corp.supernews.com> On 2005-10-13, Paul Rubin <> wrote: > The answer to each of those questions points to Tkinter. It comes > with Python by default (the least installation hassles of any > toolkit), is pretty reliable, has a reasonably Pythonic interface, and > I don't understand the question about external libraries. > > However, Tkinter not most people's favorite, because the widgets look > crude, they don't resemble the native widgets of any popular platform, > and the widget set is somewhat limited. Aside from the look & feel issue with Tk, the other objection sometimes heard is that Tk is integrated into Python by including Tcl as well (as opposed to doing an actual Tk binding the way some other languages have done). It's an eminently practical approach, but it sure makes you feel dirty. -- Grant Edwards grante Yow! Hey!! Let's watch at the' ELEVATOR go UP and visi.com DOWN at th' HILTON HOTEL!! From aleaxit at yahoo.com Fri Oct 28 22:56:37 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 28 Oct 2005 19:56:37 -0700 Subject: Newbie question: string replace References: <1130258229.662596.228630@g49g2000cwa.googlegroups.com> <3s7620FlqdmnU1@uni-berlin.de> <1130521026.584455.288370@g44g2000cwa.googlegroups.com> <86slule9vy.fsf@bhuda.mired.org> <1130527656.685340.235470@g44g2000cwa.googlegroups.com> Message-ID: <1h55rde.xau95e1ldjtftN%aleaxit@yahoo.com> Steven D'Aprano wrote: > On Fri, 28 Oct 2005 12:27:36 -0700, usgog at yahoo.com wrote: > > > hm...Is there a way to get rid of the newline in "print"? > > Yes, by using another language *wink* Ending the print statement with a comma also works;-) > Or, instead of using print, use sys.stdout.write(). Yep, generally better than 'print'. Alex From mwm at mired.org Thu Oct 27 19:28:27 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 27 Oct 2005 19:28:27 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <66u633-etj.ln1@news.it.uc3m.es> <7xbr1aewtq.fsf@ruckus.brouhaha.com> <86acgulv5z.fsf@localhost.localdomain> <7xvezi8ypy.fsf@ruckus.brouhaha.com> <86y84ehd3j.fsf@bhuda.mired.org> Message-ID: <86hdb2h750.fsf@bhuda.mired.org> "David Schwartz" writes: > "Mike Meyer" wrote in message > news:86y84ehd3j.fsf at bhuda.mired.org... >> I've noticed something strange that makes me wonder the same >> thing. Everytime someone compares MS's behavior with that of any other >> criminals, he responds about MS's activity being "equated to that of >> criminals with guns", and refuses to discuss the issue. Ironically, >> while no one else has so much as compared MS to criminals with guns - >> after all, they're white collar criminals - David Schwartz called the >> DOJ official who were investigating MS "criminals with guns pointed >> out [MS officers] heads". > I can't understand why you would post an outright lie like this. I, on the other hand, understand why you accuse me of lying. You don't have an answer to the claim, so you call the claim false. SOP for you. > "Ironically, while no one else has so much as compared MS to criminals with > guns". I defy you to find *one* place where I complain that MS behavior is > equated to the actual use of force where that is not in fact done in > precisely the thread I'm replying to. The first one is at: http://groups.google.com/group/comp.lang.python/msg/8422f41c9fe137b0?dmode=source&hl=en The original comment was: >> No, they didn't ask for more than Windows were worth. They tilted the >> playing field against MS competitors by causing consumers to pay MS >> money for products they didn't receive. In most countries, taking >> money from unwilling victims without giving them anything in exchange >> is called "theft". Note that no mention is made of guns or force - just a definition of theft. Unless you're so narrowminded that nothing short of pointing a gun at someone and demanding money from them is stealing from them, there is no way that this can be equated to the actual use of force. And if you do believe that definition of stealing, I'll do your bookkeeping for free - and I won't steal from you. Your reply: > It is not theft if you can simply say "no" to the deal and all that >happens is that you don't get the product. Your argument is preposterous. If >you accept arguments that equate guns with arguments, the next step is that >using a gun is a rational response to an argument one doesn't like. Oh wait, >you're already there. Wherein you accuse me of equating MS's actions with using guns, which is *exactly* what I said you do. There are lots more examples of you doing this kind of thing. Like I said, everytime someone compares MS's behavior with some less controversial criminal behavior, you act like they accused MS of holding people up at gunpoint. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From fredrik at pythonware.com Wed Oct 26 03:57:27 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 26 Oct 2005 09:57:27 +0200 Subject: more than 100 capturing groups in a regex References: <1130160675.270886.208420@z14g2000cwz.googlegroups.com><1130253162.790086.59130@o13g2000cwo.googlegroups.com> <1130312136.411976.118780@o13g2000cwo.googlegroups.com> Message-ID: Joerg Schuster wrote: > > if you want to know why 100 is a reasonable and non-random choice, I > > suggest checking the RE documentation for "99 groups" and the special > > meaning of group 0. > > I have read everything I found about Python regular expressions. But I > am not able to understand what you mean. What is so special about 99? it's the largest number than can be written with two decimal digits. From peter at engcorp.com Sat Oct 22 08:35:34 2005 From: peter at engcorp.com (Peter Hansen) Date: Sat, 22 Oct 2005 08:35:34 -0400 Subject: Listening for keypress in the background In-Reply-To: References: Message-ID: Mathias Dahl wrote: > I have created a small Python program that is running on my desktop. > > How can I make it listen for a certain keypress (say, Windows-key + > space) in a controlled fashion even when it is not the program having > focus? > > I need to do this running under GNOME in Mandrake GN/Linux 10. Search Google for "python keylogger". -Peter From mekstran at scl.ameslab.gov Tue Oct 4 12:22:24 2005 From: mekstran at scl.ameslab.gov (Michael Ekstrand) Date: Tue, 4 Oct 2005 11:22:24 -0500 Subject: how to debug when "Segmentation fault" In-Reply-To: References: Message-ID: <200510041122.25067.mekstran@scl.ameslab.gov> On Tuesday 04 October 2005 11:13, Maksim Kasimov wrote: > my programm sometime gives "Segmentation fault" message (no matter > how long the programm had run (1 day or 2 weeks). And there is > nothing in log-files that can points the problem. My question is how > it possible to find out where is the problem in the code? Thanks for > any help. What extension modules are you using? I've never seen "stock" Python (stable release w/ only included modules) segfault, but did see a segfault with an extension module I was using the other week (lxml IIRC, but I'm not sure). - Michael From larry.bates at websafe.com Wed Oct 19 12:22:21 2005 From: larry.bates at websafe.com (Larry Bates) Date: Wed, 19 Oct 2005 11:22:21 -0500 Subject: Converting 2bit hex representation to integer ? In-Reply-To: <43567027$0$41144$14726298@news.sunsite.dk> References: <43567027$0$41144$14726298@news.sunsite.dk> Message-ID: <-_2dndLn4eEm78veRVn-qg@comcast.com> Can you give us an example. I don't know what two bit hex means (takes at least 4 bits to make a hex digit). Now I'm going to try to guess: If the data is binary then all you need to do is to use the struct.unpack module to convert to integer. Larry Bates Madhusudan Singh wrote: > Hi > > I am using binascii.b2a_hex to convert some binary data to hex. The result > is a two bit hex representation (i. e., without the leading hex). How do I > convert the resulting two bit representation into an integer ? > > Thanks. From davids at webmaster.com Tue Oct 25 14:44:16 2005 From: davids at webmaster.com (David Schwartz) Date: Tue, 25 Oct 2005 11:44:16 -0700 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> <3s6l8mFmj3fjU1@individual.net> Message-ID: "Peter T. Breuer" wrote in message news:lgs133-7ub.ln1 at news.it.uc3m.es... >> Yes, it certainly is. However, it is also Microsoft's right as a >> seller >> to refuse discounts to those who also sell competing products. You may >> not > No it is not their "right"! That would be a discriminatory practice, > not to mention an anti-competitive practice. Totally. Businesses have the right to be discriminatory and anti-competitive in this way. McDonald's won't sell a Burger King their burger patties. This is both discriminatory and anti-competitive, but also perfectly legal, moral, and proper. You only run into a problem under United States law if the company is a monopoly. And I've already addressed that issue in this thread. DS From stefan.behnel-n05pAM at web.de Wed Oct 26 14:44:20 2005 From: stefan.behnel-n05pAM at web.de (Stefan Behnel) Date: Wed, 26 Oct 2005 20:44:20 +0200 Subject: Attribute value of instance method non-modifiable? Message-ID: Hi! I just stumbled over this: .>>> class test(object): ... def t(): pass ... t.testval = 1 ... .>>> test.t .>>> test.t.testval 1 .>>> test.t.testval = 2 Traceback (most recent call last): File "", line 1, in ? AttributeError: 'instancemethod' object has no attribute 'testval' .>>> dir(test.t) ['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__get__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'im_class', 'im_func', 'im_self', 'testval'] >>> test.t.im_func.testval = 2 >>> test.t.testval 2 >>> While I understand that a function is different from an instance method, it is rather far from intuitive that the instance method provides read access to the attribute of the enclosed function but not write access. Does anyone know if this is a deliberate implementation decision? Is there any reasoning behind that? Stefan From peter at engcorp.com Fri Oct 21 18:35:29 2005 From: peter at engcorp.com (Peter Hansen) Date: Fri, 21 Oct 2005 18:35:29 -0400 Subject: Python vs Ruby In-Reply-To: References: <1129778582.411476.259500@o13g2000cwo.googlegroups.com> <1129781346.035866.16660@g43g2000cwa.googlegroups.com> Message-ID: Bryan wrote: > Dave Cook wrote: >> Cale? You mean Python has more ruffage? > > i think you mean "kale" not "cale". nothing like a hot bowl of tofu > kale soup while reading the recipes in the "python cookbook". Well, if he's going to talk about "ruffage" instead of "roughage", perhaps he really did mean "cale" and not "kale". ;-) From ms at cerenity.org Sun Oct 2 15:16:47 2005 From: ms at cerenity.org (Michael) Date: Sun, 02 Oct 2005 20:16:47 +0100 Subject: A Moronicity of Guido van Rossum References: <1128003857.930444.47650@g14g2000cwa.googlegroups.com> <1128013745.763757.144280@g44g2000cwa.googlegroups.com> <1128176637.146092.314200@o13g2000cwo.googlegroups.com> Message-ID: <434031f6$0$73596$ed2619ec@ptn-nntp-reader03.plus.net> Xah Lee wrote: > as i have hinted > ( http://xahlee.org/perl-python/list_comprehension.html ), the > so-called List Comprehension is just a irregular syntax to facilitate > generating lists. The name is a terrible jargon, and the means is also > quite fucked up. The proper name should be something like > ListGenerator, and the proper means should be the plain function. List comprehensions get their name (AFAICT) very clearly from set comprehensions in mathematics. As a result anyone who has ever seen a set comprehension in maths goes "oooh, I see". They're not the same, but IMO they're close enough to warrant that name. > i'm running a project that will code Table in Perl and Python and Java. > You can read about the spec and source code here: > http://xahlee.org/tree/Table.html > (note: the Python version there isn't complete) I just took a look at your python version. I'd agree it's incomplete. Indeed it doesn't implement what you say it does. You seem to have re-invented "apply" since you simply (badly) pass a set of arguments provided by the user to a function provided by the user. The description of the code you are pointing at bears absolutely no resemblance whatsoever to the functionality you describe. And you criticise the way other people name & describe their code, when you can't show the skills you criticise in others? I know naming and documentation are not easy skills, and if people take a *civil* tone in suggested improvements, criticism (and suggestions) can be helpful. However, I'd suggest /finishing/ your glass house /before/ you start throwing stones, or else you'll never be able to smash it up the neighbourhood properly. Michael. From aleaxit at yahoo.com Fri Oct 21 21:21:47 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 21 Oct 2005 18:21:47 -0700 Subject: override a property References: <43542065$0$21621$636a15ce@news.free.fr> <4354ABB3.1030203@jessikat.fsnet.co.uk> <4354b324$0$21023$636a55ce@news.free.fr> Message-ID: <1h4s9ug.k3op7dg6c66hN%aleaxit@yahoo.com> Robin Becker wrote: ... > in answer to Bengt & Bruno here is what I'm sort of playing with. Alex > suggests class change as an answer, but that looks really clunky to me. > I'm not sure what Changing class is indeed 'clunky', though it might have been necessary depending on how one interpreted your original specs. > Alex means by > > > A better design might be to use, instead of the builtin > > type 'property', a different custom descriptor type that is specifically > > designed for your purpose -- e.g., one with a method that instances can > > call to add or remove themselves from the set of "instances overriding > > this ``property''" and a weak-key dictionary (from the weakref module) > > mapping such instances to get/set (or get/set/del, if you need to > > specialize "attribute deletion" too) tuples of callables. > > I see it's clear how to modify the behaviour of the descriptor instance, > but is he saying I need to mess with the descriptor magic methods so they > know what applies to each instance? If (e.g.) __set__ needs to behave differently when applied to certain instances rather than others, then it had better be "messed with" (overridden) compared to property.__set__ since the latter has no such proviso. Of course, your architecture as sketched below (taking advantage of the fact that property.__set__ always calls a certain callable, and you get to control that callable) is OK too. > ## my silly example > class ObserverProperty(property): > def __init__(self,name,observers=None,validator=None): > self._name = name > self._observers = observers or [] > self._validator = validator or (lambda x: x) > self._pName = '_' + name > property.__init__(self, > fset=lambda inst, value: self.__notify_fset(inst,value), > ) Why not just fset=self.__notify_fset ? I fail to see the added value of this lambda. Anyway...: > def __notify_fset(self,inst,value): > value = self._validator(value) > for obs in self._observers: > obs(inst,self._pName,value) > inst.__dict__[self._pName] = value > > def add(self,obs): > self._observers.append(obs) ...this class only offers sets of observers *per-descriptor instance*, not ones connected to a specific 'inst' being observed. My point is, you could add the latter pretty easily. > def obs0(inst,pName,value): > print 'obs0', inst, pName, value > > def obs1(inst,pName,value): > print 'obs1', inst, pName, value > > class A(object): > x = ObserverProperty('x') > > a=A() > A.x.add(obs0) > > a.x = 3 > > b = A() > b.x = 4 > > #I wish I could get b to use obs1 instead of obs0 > #without doing the following > class B(A): > x = ObserverProperty('x',observers=[obs1]) > > b.__class__ = B > > b.x = 7 You can, if you have a way to call, say, b.x.add_per_inst(b, obs1). Such as, adding within ObserverProperty: self._observers_per_inst = {} in the init, and changing the notification method to do: def __notify_fset(self,inst,value): value = self._validator(value) observers = self._observers_per_inst.get(inst) if not observers: observers = self._observers for obs in observers: obs(inst,self._pName,value) inst.__dict__[self._pName] = value and a new method add_per_inst: def add_per_inst(self, inst, obs): self._observers_per_inst.setdefault(inst,[]).append(obs) Of course, you most likely want to use weak rather than normal references here (probably to both instances and observers), but that's a separate issue. Alex From mwm at mired.org Sat Oct 22 19:22:34 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 22 Oct 2005 19:22:34 -0400 Subject: High Order Messages in Python References: <1130015536.273136.295800@g43g2000cwa.googlegroups.com> Message-ID: <86oe5h9lxh.fsf@bhuda.mired.org> "eduardo.padoan at gmail.com" writes: > I'm reading about "high order messages" in Ruby by Nat Pryce, and > thinking if it could be util and if so, if it could be done in Python. > Someone already tried? Yes, I'm pretty sure it could be done in Python. All it really needs is the ability to catch references to undefined attributes, which Python has. You make the HOM of your collection class return an object with a reference to self, and the __getattr__ method of that classs then invokes getattr on each object in the referenced collection instance for the undefined method, manipulating the result as appropriate for that HOM, and returning a new list. But this really isn't a very good fit for Python. This is really a feature for more aggressively OO languages. To make the examples HOMs described really useful, you want to add them to some base class for collections. But that base class doesn't exist in Python - Python just isn't that OO. You could add various HOMs to lists, tuples, generators and iterators - but then anyone who wanted to create a new sequence class would have to add all of the HOMs that their clients might want to use. The pythonic way would be to add a function that works with all the various sequence types - which would then automatically work with any user-defined classes that quacked like a sequence. It's not very OO - but it is pythonic. In fact, Python already has functions that capture the functionality of the example HOMs in the links you posted: where and unless are handled by filter. in_order_of and in_reverse_order_of are handled by sorted. do is is handled by map. Of course, recent versions of python provide list comprehensions as preferable to some of these functions. That said, HOM's are a *very* powerful mechanism. The examples - and my discussion of them - cover just one very broad use case. There may be others where they are a better fit with Python. Having examples of how to do these kinds of things around is probably worthwhile. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From lasse at vkarlsen.no Tue Oct 11 07:37:57 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Tue, 11 Oct 2005 13:37:57 +0200 Subject: How to do *args, **kwargs properly Message-ID: I must be missing something but what is the proper way to do a function using such arguments ? Specifically I'm looking for: - ability to take an unspecified number of "positional arguments" - ability to take optional named arguments that follows the first arguments - raise appropriate errors if I use the wrong named arguments for instance: fn(1, 2, 3) fn(1, 2, 3, cmp=lambda x, y: y-x) fn(1, 2, 3, cpm=lambda x, y: y-x) # TypeError on this Is the following the way to go ? def fn(*values, **options): comparison = cmp for key, value in options.iteritems(): if key == "cmp": comparison = value else: raise TypeError, "'%s' is an invalid keyword argument for this function" % key # rest of function here or is the "proper python" way simply this: def fn(*values, **options): if "cmp" in options: comparison = options["cmp"] else: comparison = cmp # rest of function here and thus ignoring the wrong parameter names? -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From kenneth.m.mcdonald at sbcglobal.net Wed Oct 19 17:34:51 2005 From: kenneth.m.mcdonald at sbcglobal.net (Kenneth McDonald) Date: Wed, 19 Oct 2005 16:34:51 -0500 Subject: UI toolkits for Python In-Reply-To: <11lcnqt2c7jhmcc@corp.supernews.com> References: <7xslv56ud1.fsf@ruckus.brouhaha.com> <3ras6oFit2djU1@individual.net> <3rg3aiFjgc47U1@individual.net> <3rlj78Fjsu7mU1@individual.net> <3rmh1uFk236lU1@individual.net> <11lcnqt2c7jhmcc@corp.supernews.com> Message-ID: I'd have to agree with this. Unfortunately, the only way to use Swing (in a reasonable manner) from Python is to use Jython, and Jython has other shortcomings that make me not want to use it. Sigh. Ken On 19-Oct-05, at 9:59 AM, Ed Jensen wrote: > Claudio Grondi wrote: > >> I haven't seen any really platform-independent software yet and I >> don't >> expect to see any in the future. >> It is simply not possible to have one, even if much progress was >> done lately >> in many areas in order to try to approach it as close as possible. >> > > Java + Swing is probably as good as it gets when the goal is to write > platform independent software. > -- > http://mail.python.org/mailman/listinfo/python-list > From python-url at phaseit.net Mon Oct 17 11:54:22 2005 From: python-url at phaseit.net (Cameron Laird) Date: Mon, 17 Oct 2005 15:54:22 +0000 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Oct 17) Message-ID: QOTW: "If you don't have the time to be paranoid, try taking the time to straighten out identity theft." -- K. G. Schneider "The best way to make classes on the fly is generally to call the metaclass with suitable parameters (just like, the best way to make instances of any type is generally to call that type)." -- Alex Martelli What code is good to read? The Standard Library. The Indexed Packages. The Cheese Shop. Bit Torrent. Much else--that is, far more than any one person can digest: http://groups.google.com/group/comp.lang.python/browse_thread/thread/da095d94c77fe2c7/ Windows demands a developer rely on poorly-documented tricks in order to be productive. What *are* those tricks? IPython, autoit, ...: http://groups.google.com/group/comp.lang.python/browse_thread/thread/3c6f3201a61d41f0/ Most Python programmers live happily without thought of what codecs do for them. If you're among the few for whom charmap performance is an issue, though, you'll be thankful to Tony Nelson for this Fastcharmap contribution: http://groups.google.com/group/comp.lang.python/browse_thread/thread/481fda74e4c69dc/ Do you want to iterate over the same iterable multiple times? There's help (itertool's tee(), for example) for your sort: http://groups.google.com/group/comp.lang.python/browse_thread/thread/77def05340a81dec/ Jeff Epler and Peter Otten explain the very first step--often the most puzzling one--in working with other-than-English texts: http://groups.google.com/group/comp.lang.python/browse_thread/thread/5b9e46bbc66e19f8/ http://groups.google.com/group/comp.lang.python/browse_thread/thread/ee3feda62cfe42cd/ ======================================================================== 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 There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. 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 michaelschneider at fuse.net Fri Oct 14 11:41:02 2005 From: michaelschneider at fuse.net (Michael Schneider) Date: Fri, 14 Oct 2005 11:41:02 -0400 Subject: Problems with properties Message-ID: Hello All, I have been working on learning how to use python properties. The get property access is working, but the the set property is not working. Rather then dispatching the property assignment to setNothing, the property object is being replaced with a string. I must be doing something very stupid here. Could someone please point out my error, I have dents in my forehead for this one. Thanks, Mike ------------------------------------------------------------------ from unittest import TestCase import unittest class Task: def __init__(self,command): self._command = command def setNothing(self, value): raise AttributeError def getCommand(self): return self._command command=property(getCommand, setNothing) class taskTest(TestCase): def testTask(self): t = Task("dir c:") c = t.command self.assertEquals("dir c:", c) # should fail, but doesn't t.command = "foo Bar" self.assertEquals("dir c:", t.command) if __name__ == "__main__": unittest.main() From iminal4 at netscape.net Wed Oct 19 07:49:40 2005 From: iminal4 at netscape.net (iminal) Date: 19 Oct 2005 04:49:40 -0700 Subject: A little help with time calculations In-Reply-To: References: <1129653655.247941.248440@g47g2000cwa.googlegroups.com> <1129670245.463881.317270@g43g2000cwa.googlegroups.com> Message-ID: <1129722580.470171.161220@g43g2000cwa.googlegroups.com> thanks From codecraig at gmail.com Wed Oct 12 09:00:46 2005 From: codecraig at gmail.com (Java and Swing) Date: 12 Oct 2005 06:00:46 -0700 Subject: C Wrapper Function, crashing Python? Message-ID: <1129122046.417746.100120@g47g2000cwa.googlegroups.com> static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { // this will store the result in a Python object PyObject *finalResult; // get arguments from Python char *result = 0; char *in= 0; char *aString = 0; char *bString = 0; MY_NUM *a; MY_NUM *b; int ok = PyArg_ParseTuple(args, "sss", &in, &aString, &bString); if (!ok) return 0; // do work to get a and b // count - returns an int; GetVal - returns a char * a = GetVal(aString, count(aString, ",")); b = GetVal(bString, count(bString, ",")); // make function call, which returns a char * result = doStuff(in, a, b); // save result in Python string finalResult = PyString_FromString(result); // free memory PyMem_Free(result); PyMem_Free(a); PyMem_Free(b); // return the result as a Python string return finalResult; } ...from python I can call this function 4 times...works fine. WHen I call it for the fifth time python.exe crashes. im thinking some memory problem in the wrapper function perhaps...but I am not sure. The actually C function, doStuff can be called 5, 6,7...N times without a problem so i know its gotta be my wrapper. Any ideas? Thanks! From fredrik at pythonware.com Sat Oct 29 02:48:18 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 29 Oct 2005 08:48:18 +0200 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com><3sf070Fo0klqU1@individual.net> <3sg8hiFmvbo7U1@individual.net> <864q70evci.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > Did you do timings on it vs. mmap? Having to copy the data multiple > times to deal with the overlap - thanks to strings being immutable - > would seem to be a lose, and makes me wonder how it could be faster > than mmap in general. if you use "mmap" to read large files sequentially, without calling "madvise", the system may try to keep old pages around just in case, and won't do as much read-ahead as it can do. if you're low on memory, that means that the system may waste some time swapping out data for other applications, rather than throwing away data that you know that you will never look at again. if you have reasonably large files and you're not running on an overcrowded machine, this is usually not a problem. (does Python's mmap module support madvise, btw? doesn't look like it does...) From lassevk at gmail.com Tue Oct 4 05:57:31 2005 From: lassevk at gmail.com (=?iso-8859-1?q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: 4 Oct 2005 02:57:31 -0700 Subject: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please! In-Reply-To: <1128419720.504389.323330@g14g2000cwa.googlegroups.com> References: <43424bee$0$38666$edfadb0f@dread12.news.tele.dk> <1128419720.504389.323330@g14g2000cwa.googlegroups.com> Message-ID: <1128419851.051846.90030@g47g2000cwa.googlegroups.com> Ok, when re-reading my post it seems that I'm saying that Python has no roadmap. That was not my intent. I meant projects other than Python, even though the problems I got with 2.4.2 is real, I suspect there's something in Komodo that is the problem since I can run all my python programs with 2.4.2 without problems, just not in Komodo. I'll go wash my mouth now :P From steve at REMOVETHIScyber.com.au Sun Oct 9 14:16:03 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 10 Oct 2005 04:16:03 +1000 Subject: Function decorator that caches function results References: <7x4q7rt3yl.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 09 Oct 2005 17:39:23 +0200, Fredrik Lundh wrote: > only if you're obsessed with CPython implementation details. No. I'm obsessed with finding out what closures are, since nobody seems to have a good definition of them! However, I have learnt some things: closures are something which functions HAVE, not ARE. The func_closure attribute is just part of the implementation of the closure. Some languages have closures and some don't. And a closure is something that lets a function object access the lexical scope that existed when the function object was created, e.g. the namespace of the function which created it. Am I getting there now? -- Steven who is very grateful for the time folks have taken to explain this. From mwm at mired.org Mon Oct 17 17:18:03 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 17 Oct 2005 17:18:03 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <1129491006.021102.43920@g14g2000cwa.googlegroups.com> <86zmp8zsjk.fsf@bhuda.mired.org> Message-ID: <86k6gbzvuc.fsf@bhuda.mired.org> Steven D'Aprano writes: > On Mon, 17 Oct 2005 00:17:03 -0400, Mike Meyer wrote: >> Yup. When NS was the 800 lb gorilla > When was this? When did Netscape have a monopoly in any market? Starting with the release of Netscape 1.0, until MS decided to take it away from them. At one time they owned 95%+ of the browser market. It was standard practice at that time for web sites to be designed for - and only work properly with - NS; questions asked on the wwww groups were routinely answered with solutions that only worked in NS; "cross-platform" testing meant making sure your pages worked in NS on both the Mac and Windows. > Netscape was never the 800 lb gorilla. You're wrong. >> on they acted like MS, > When did Netscape executives perjure themselves in court? > When did Netscape commit fraud? Astro-turfing? Patent infringement? Theft > of code? As I already stated, Netscape wasn't as good at the game as MS. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From maxx at easynews.com Fri Oct 7 18:14:36 2005 From: maxx at easynews.com (maxx at easynews.com) Date: Fri, 07 Oct 2005 18:14:36 -0400 Subject: Contest snub? Message-ID: Notice anything strange here? The Python entry seems to have edged the PHP entries, but is not declared the victor. Source is missing as well (the archive is empty.) http://www.apress.com/promo/fractal/seesource.html Hmmmm... an irrational fear of snakes perhaps? From fredrik at pythonware.com Sat Oct 8 14:54:36 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 8 Oct 2005 20:54:36 +0200 Subject: Python's Performance References: <434779F1.9080508@designaproduct.biz> <20051008172825.77615.qmail@web30612.mail.mud.yahoo.com> Message-ID: Dave wrote: > Yes, I would like to know how many internal string operations are done inside > the Python interpreter. when you're doing what? how do you define "internal string operations", btw? From aahz at pythoncraft.com Thu Oct 6 17:05:29 2005 From: aahz at pythoncraft.com (Aahz) Date: 6 Oct 2005 14:05:29 -0700 Subject: New Python book References: <6.2.1.2.2.20051005150954.0741e1d0@rcblue.com> <43452f51$1@nntp0.pdx.net> Message-ID: In article <43452f51$1 at nntp0.pdx.net>, Scott David Daniels wrote: > >You could ask over on comp.lang.python.education comp.lang.python.education is a rogue newsgroup; it won't appear on many newsservers. -- 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 ramen at lackingtalent.com Mon Oct 31 23:58:57 2005 From: ramen at lackingtalent.com (Dave Benjamin) Date: Mon, 31 Oct 2005 22:58:57 -0600 Subject: Rename files with numbers In-Reply-To: References: <1130776390.085587.116270@g43g2000cwa.googlegroups.com> <1130784747.373637.108040@g14g2000cwa.googlegroups.com> <1130789205.862429.10090@g43g2000cwa.googlegroups.com> <20051031220841.GF2575@kitchen.client.attbi.com> Message-ID: On Mon, 31 Oct 2005, Micah Elliott wrote: > On Oct 31, Micah Elliott wrote: >> Now I need to go beautify my collection. :-) > > While a fun exercise, there are probably already dozens (or > thousands?) of utilities in existence that do this and much more. Seconded. I initially considered writing a script to rename a huge pile of MP3 files, but halfway through, I thought, "there's *got* to be a better way". I found this app: http://www.softpointer.com/tr.htm Bought it the next day. Holy crap, what a gigantic timesaver. It looks up albums based on track lengths, downloads titles from freedb and Amazon, does ID3 tagging, renaming, moves files into separate directories... I busted through about 20 gigs of MP3s in three days. I kid you not. If this is just a fun toy Python project, don't let me discourage you, but if you have more than a handful of albums to rename, trust me. This problem has been solved. Here's a list of apps, including Tag&Rename, that can query freedb: http://www.freedb.org/freedb_aware_apps.php -- .:[ dave benjamin: ramen/[sp00] ]:. \\ "who will clean out my Inbox after I'm dead[?]" - charles petzold From steve at REMOVETHIScyber.com.au Sun Oct 9 06:58:32 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 09 Oct 2005 20:58:32 +1000 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> Message-ID: On Sun, 09 Oct 2005 07:40:55 +0000, Roedy Green wrote: > There is nothing wrong with formatted text. You are confusing > formatted text with spam. No. YOU are confusing HTML email (broken, dangerous, bad) with formatted text (maybe good, maybe bad). I've hated HTML emails well before I received my first spam. I still hate it, long after I've got my spam problem under control. If and when somebody comes up with a non-broken, non-dangerous way of allowing formatting in emails, I'll consider it. But HTML is not and never will be that format. -- Steven. From simon at arrowtheory.com Mon Oct 24 22:23:41 2005 From: simon at arrowtheory.com (Simon Burton) Date: 24 Oct 2005 19:23:41 -0700 Subject: namespace dictionaries ok? In-Reply-To: References: Message-ID: <1130207021.408597.322950@g14g2000cwa.googlegroups.com> Yes! I do this a lot when i have deeply nested function calls a->b->c->d->e and need to pass args to the deep function without changing the middle functions. In this situation I think i would prefer this variation: class Context(dict): def __init__(self,**kwds): dict.__init__(self,kwds) def __getattr__(self, name): return self.__getitem__(name) def __setattr__(self, name, value): self.__setitem__(name, value) def __delattr__(self, name): self.__delitem__(name) def foo(ctx): print ctx.color, ctx.size, ctx.shape foo( Context(color='red', size='large', shape='ball') ) This is looking like foo should be a method of Context now, but in my situation foo is already a method of another class. Simon. From graham.fawcett at gmail.com Fri Oct 14 16:33:30 2005 From: graham.fawcett at gmail.com (Graham Fawcett) Date: 14 Oct 2005 13:33:30 -0700 Subject: MS Word Outline -> reStructuredText script? In-Reply-To: <1129319634.407351.27080@z14g2000cwz.googlegroups.com> References: <1129319634.407351.27080@z14g2000cwz.googlegroups.com> Message-ID: <1129322010.339492.319420@g49g2000cwa.googlegroups.com> Jim wrote: > Hi, > > I'm using reStructuredText as a format for some group documentation, > and often my co-workers take notes during meetings in Word's outline > mode. Does anyone already have a python script that will convert from > Word (or the Open Office file format version of a word document) to > reStructured Text? I don't have a script; but if you have to roll your own, you might consider having your colleagues save their Word documents in XML format. Office 2003, and perhaps slightly earlier versions, do this. Then you can "simply" parse the XML and transform it into anything you like, including a reST document. If you cannot convince them, then you could also have your script automate Word, via win32com.client.Dispatch('Word.Application'), and do the save-as-XML yourself before parsing the generated XML. At the end of the day, I think this would be easier than, e.g., trying to use win32com to traverse the document's object model. Graham From davids at webmaster.com Thu Oct 27 14:04:08 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 11:04:08 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <66u633-etj.ln1@news.it.uc3m.es> <7xbr1aewtq.fsf@ruckus.brouhaha.com> Message-ID: "John Gordon" wrote in message news:djr3mn$ekm$1 at reader2.panix.com... > In "David Schwartz" > writes: >> What is an "illegal monopoly"? > A monopoly that acts in certain ways, abusing its monopoly power. There's > nothing inherently illegal about having a monopoly; it only becomes > illegal > when you abuse the power. That's just not true. When you abuse the power, the abuse itself is illegal, but it doesn't make the monopoly itself illegal. This is like saying a person who uses his bat to hit people has an "illegal bat". When you say "it only become illegal", you are just being vague. Nothing becomes illegal. The abuse is illegal, but it never was legal. DS From ajikoe at gmail.com Thu Oct 13 04:37:49 2005 From: ajikoe at gmail.com (ajikoe at gmail.com) Date: 13 Oct 2005 01:37:49 -0700 Subject: how to make this code faster In-Reply-To: References: <1129183717.183243.100540@g49g2000cwa.googlegroups.com> Message-ID: <1129192669.716031.269340@g44g2000cwa.googlegroups.com> hello, I found that scipy only works with python 2.3 or? I don't know if the logic is correct: 1. loop inside loop uses a lot of resources 2. Numeric or Numpy can make program faster 3. It use kind of Array/Matrix analysis style 4. We have to change our algorithms so that Numeric or Numpy can help us, Matrix style Best Regards, pujo From bonono at gmail.com Thu Oct 20 20:15:15 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 20 Oct 2005 17:15:15 -0700 Subject: Python vs Ruby In-Reply-To: References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> Message-ID: <1129853715.441205.322480@g49g2000cwa.googlegroups.com> I don't think you really need to give to much time in weighting between python or Ruby. Both are fine. But Python has the obvious advantage that it has much more modules than Ruby so many things you don't need to implement if you have real work to do. I recommend you give haskell a shot if you are "in" to programming because it makes you think differently, not necessary better(at least not all the time) but helps. I am not sure your intention but I think there isn't a one language fits all situation here. I frequently use the following: C/C++ - for linux kernel hacking etc., many library out there still use it python - generic stuff SQL - nothing beats it for many business apps haskell - a language to train my brain javascript - Web front end other than haskell and SQL, the others are more or less the same to me so getting familiar with them is not too difficult. Amol Vaidya wrote: > I've done a lot of studying on my own, and taken the classes that my > high-school offers. I feel that I have a fairly good understanding of Java, > and basic OO concepts due to that. I've created some semi-complex programs > in java, in my opinion, such as networked checkers, 8-player blackjack, a > space-shooter type game, a copy of mario (one level, anyway), and some other > stuff. I've also done a bit of studying on C. I've done a few projects in C, > including another space-shooter type of game using SDL, an IRC client and > some simple database-type programs. I also gave a shot at assembly using > NASM for x86 before, but didn't get too far. I wrote some trivial code -- > wrote to the video buffer, played with some bios interrupts, stuff like > that. The only thing I did in assembly was create a program that loads at > boot-up, and loads another program that just reiterates whatever you type > in. I only did that because I was curious. That's about as far as my > programming knowledge/experience goes. > > Well, I'm not sure what you mean by programming concepts. I'm familiar with > OO through Java, and procedural programming through C. I'd be more detailed, > but I'm not exactly sure what you are asking. Sorry. > > I have no idea what Scheme is, but I'll cettainly look it up as soon as I'm > done writing this. > > I've never given Perl a shot. It was another language I considered learning, > but my father's friend told me to go with Python or Ruby. > > Thanks for your help. Hopefully I wasn't too lengthy in this post. From free.condiments at gmail.com Sat Oct 22 18:35:41 2005 From: free.condiments at gmail.com (Sam Pointon) Date: 22 Oct 2005 15:35:41 -0700 Subject: High Order Messages in Python In-Reply-To: <1130019099.772664.103360@g47g2000cwa.googlegroups.com> References: <1130015536.273136.295800@g43g2000cwa.googlegroups.com> <1130019099.772664.103360@g47g2000cwa.googlegroups.com> Message-ID: <1130020541.862804.232650@g47g2000cwa.googlegroups.com> This can be suitably applied to Python with the use of Higher Order Functions, though. It's not quite the Ruby version because Python allows you to use functions as first-class objects, complicating the All-You-Can-Do-Is-Pass-A-Message philosophy. This is my 5-minute implementation: class HigherOrderList(list): def do(self, func): return HigherOrderList(each(self, func)) def where(self, pred): return HigherOrderList(mass_test(self, pred)) def mass_test(iterable, pred): for item in iterable: if pred(item): yield item def each(iterable, method): for item in iterable: yield method(item) From lasse at vkarlsen.no Thu Oct 6 13:42:27 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Thu, 06 Oct 2005 19:42:27 +0200 Subject: Merging sorted lists/iterators/generators into one stream of values... Message-ID: I need to merge several sources of values into one stream of values. All of the sources are sorted already and I need to retrieve the values from them all in sorted order. In other words: s1 = [10, 20, 30, 40, 50] s2 = [15, 25] s3 = [17, 27, 37] for value in ???(s1, s2, s3): print value will print out 10, 15, 17, 20, 25, 27, 30, 37, 40, 50 in that order. The sources are cursors retrieving data from several databases, not from the same server, and there's a potential for a large number of rows from several of the sources. As such, any method that would load it all into memory and sort it is no good as it would too much memory. Is there a function or whatnot in Python that will do what I want? I have come up with my own method but since it uses generators I'm not sure how much overhead there is. Additionally, since the values retrieved from the cursors will be dictionaries of "fieldname":value pairs, the method would either need to handle that construct (and be told what fieldname to sort on), or be able to take a function object to use for the comparison operation. Basically, I'll use my own function for this unless someone can point me to something that is already available. Couldn't seem to find anything in the builtin modules but I didn't find glob.glob when I was looking for how to find filenames either so who knows what it's called :) Since I need to deal with a variable list of sources (that is, 2 in one application, 3 in another and 4-5 in a third), a simple 2-source method isn't enough but if it's better than what I do for 2 sources then I can make a wrapper for it, since that's what I do anyway. -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From grante at visi.com Sat Oct 29 09:17:25 2005 From: grante at visi.com (Grant Edwards) Date: Sat, 29 Oct 2005 13:17:25 -0000 Subject: popen2 References: <1130524659.070912.256550@o13g2000cwo.googlegroups.com> Message-ID: <11m6tj5q9rskma1@corp.supernews.com> On 2005-10-29, Piet van Oostrum wrote: >>>>>> "g.franzkowiak" (gf) wrote: > >>gf> If starts a process with popen2.popen3('myprogram') and myprogram.exe is >>gf> running before, I've a connection to the second process, not to the first. >>gf> I can find the process by name before I start a process with popen2..., >>gf> but how bcan I connect t this process with a pipe ? > > You have to use a named pipe. That would require that the application know about the named pipe and open it. I don't think there is any way to swap a pipe in for stdin/stdout once a process is running. -- Grant Edwards grante Yow! NOW, I'm supposed at to SCRAMBLE two, and HOLD visi.com th' MAYO!! From http Sun Oct 9 17:51:26 2005 From: http (Paul Rubin) Date: 09 Oct 2005 14:51:26 -0700 Subject: Python reliability References: Message-ID: <7xr7au1hr5.fsf@ruckus.brouhaha.com> Ville Voipio writes: > The software should be running continously for > practically forever (at least a year without a reboot). > Is the Python interpreter (on Linux) stable and > leak-free enough to achieve this? I would say give the app the heaviest stress testing that you can before deploying it, checking carefully for leaks and crashes. I'd say that regardless of the implementation language. From fredrik at pythonware.com Sun Oct 23 06:22:36 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 23 Oct 2005 12:22:36 +0200 Subject: Syntax across languages References: <1130052687.396109.145420@o13g2000cwo.googlegroups.com><1130055226.967456.266220@z14g2000cwz.googlegroups.com> <1130061421.835890.156890@g44g2000cwa.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > Thank you Fredrik Lundh for showing everybody that indeed lot of people > feel the need of such function in Python too. you seem to be missing the point: all those versions are highly optimized, and tuned for the specific use-cases. a generic flatten would be useless in all three cases. From simon at arrowtheory.com Mon Oct 24 20:33:50 2005 From: simon at arrowtheory.com (Simon Burton) Date: 24 Oct 2005 17:33:50 -0700 Subject: how to use new AST goodies Message-ID: <1130200430.365124.211950@g49g2000cwa.googlegroups.com> Hello, i've just found out that the ast-branch has been merged into the main python cvs. ** Woohoo ! ** I'd like to experiment with this, does anyone know where to start ? It seems that the parser module still produces the same junk as before. So where do we find these nice high level AST objects ? thanks, Simon. From suman.karumuri at gmail.com Wed Oct 12 01:29:33 2005 From: suman.karumuri at gmail.com (suman.karumuri at gmail.com) Date: 11 Oct 2005 22:29:33 -0700 Subject: Parser suggestion In-Reply-To: <87ek77k4m1.fsf@ieee.org> References: <87ek77k4m1.fsf@ieee.org> Message-ID: <1129094973.866150.301290@g47g2000cwa.googlegroups.com> Take a look at PLY. There is an example lexer in the download for parsing fortran. From duncan.booth at invalid.invalid Tue Oct 25 13:23:53 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 25 Oct 2005 17:23:53 GMT Subject: Weird import behavior References: <1130260282.027302.49370@g44g2000cwa.googlegroups.com> Message-ID: Tommytrojan wrote: > import string > import os > > class T: > def __init__(self): > try: > print 'xxx nothing to do' > except ImportError: > print 'got an import error' > import os as string > > print 'xxxx string module', string > > t=T() > > > The import clause in the except statement (although never executed) > removes the reference to the string module imported at the beginning of > the script. Any idea why this is the case? Quoting the error message would have made the answer instantly clear to everyone, including probably yourself: UnboundLocalError: local variable 'string' referenced before assignment Assigning to the variable 'string' anywhere in the function makes it a local variable throughout the function. Use 'global string' if you want the import to affect the global variable. From rschroev_nospam_ml at fastmail.fm Thu Oct 6 08:03:06 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Thu, 06 Oct 2005 12:03:06 GMT Subject: /usr/bin/env python, force a version In-Reply-To: References: <1128597929.636452.223890@o13g2000cwo.googlegroups.com> Message-ID: <_n81f.14624$BS3.663683@phobos.telenet-ops.be> Laszlo Zsolt Nagy wrote: > manatlan at gmail.com wrote: > >> I've got a trouble, and i think that anybody there can help me >> >> I've got a python script which i distribute in somes packages for *nix. >> This script is full of python and need python 2.4 ! And i'd like to >> display a message when the user doesn't have a python2.4 version. >> >> >>>> import sys >>>> sys.version > '2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]' Yes, but the problem is also that Debian (not only Sid, but also stable and testing) has python 2.4 but it is not the default, i.e. /usr/bin/python is a symlink to /usr/bin/python2.3 even if /usr/bin/python2.4 is available to. It would be nice if there was a general way to specify that a script should be interpreted by python2.4, even if it is not the default, in a way that works on all platforms. But I don't see how that should work. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From prasad.c.iyer at capgemini.com Mon Oct 24 08:06:39 2005 From: prasad.c.iyer at capgemini.com (Iyer, Prasad C) Date: Mon, 24 Oct 2005 17:36:39 +0530 Subject: Small utility program for the windows Message-ID: Hi, I am trying to create a small utility program which would be configured in registry. Something like this Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\*\shell\ShortCut\command] @="\"python C:\\workspace\\python\\Tut\\ShortCut.py\"" It gives me access denied exception when I try it. Can anyone help me out. Following is the code from Tkinter import * import sys class BaseClass(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.grid() self.createWidget() def createWidget(self): self.text=Text(self, width=20, height=3) self.text.grid(row=0,column=0) Button(self, text="ok", command=self.addText).grid(row=1, column=0) def addText(self): print "hello world" baseClass=BaseClass() print sys.argv[0] for i in range(0, len(sys.argv)): print sys.argv[i] baseClass.mainloop() I have to modify the code further so that it takes argument. This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. From rschroev_nospam_ml at fastmail.fm Mon Oct 17 18:27:21 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Mon, 17 Oct 2005 22:27:21 GMT Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: John Bokma wrote: > Roel Schroeven wrote: > > >>John Bokma wrote: >> >>>Roel Schroeven wrote: >>> >>>>But that's not the point; the point is that they have the choice. >>>>If MS had it its way, they wouldn't have that choice. >>> >>> >>>I doubt that. But even if you're right, do you really think that MS >>>is the only evil company on earth working like this? Do you really >>>think that companies like Disney, Sony, Intel, AMD, Apple, etc work >>>any different? >> >>No, I do not think that MS is the only company that uses shady >>tactics. Also I didn't use the word 'evil', since I think it is too >>strong for what even MS does. But the fact is that MS is convicted for >>abusing its monopoly position. > > > If just one got convicted it means that some got away with it, and still > am. I'm not going to answer this one anymore. Other companies use shady tactics too, I already said that, but we're talking about MS now. >>>>Thousands and thousands of website work perfectly in all of the >>>>aforementioned websites right now. >>> >>>Maybe you define perfectly different then me, but have a look at the >>>Acid tests for example. Even between minor versions of for example >>>Firefox, or Opera there are differences in rendering. I won't call >>>that perfectly, but maybe because I am a programmer. >> >>Differences in rendering are perfectly acceptable on the World Wide >>Web. > > > Not the differences I am talking about. There is ambiguity in for > example the CSS working drafts (or recommendations, too lazy to check > their current state). Maybe check out what the acid test is (actually > there are two IIRC). Also, wonder why if the differences I am talking > about are "perfectly acceptable" why some are fixed between different > versions (e.g. Opera). I know what the ACID test is. I also know that we're talking about the browser wars and that those date from long before the ACID tests were created. >>>Others just pick Intel, because it's Intel. The same is happening for >>>MS. People just buy MS, they don't care that it's cheaper (or maybe >>>"cheaper") to install Linux + OpenOffice (for example). MS, so it's >>>good. >> >>Popularity is not the same as quality. > > > Did I state such a thing? That's what I gathered from "People just buy MS, ... . MS, so it's good." Maybe I misunderstood, in which case I apologize. Still, doesn't matter since it also is completely besides the point. > Moreover, quality doesn't (in general) sell in > this world. If you think so, wake up. I'm very well aware of that. > Or do you really consider the Linux desktop (any of them) quality? Actually yes. Are they better than MS's desktop? Depends on one's needs. If I didn't need MS for my job, there's a very big chance I would only use Linux. Or MacOS X. >>I still fail to see your point. The original issue was the browser >>wars. Tim Roberts wondered why Microsoft went through the efforst of >>dominating the browser market, even if they don't make any money on >>IE. David Schwartz gave the answer: MS did it to prevent the OS from >>becoming a commodity, since that would allow users to freely choose >>their own OS. > > > *the* answer? LOL. I doubt it, since David's *the answer* isn't > happening. As I asked in another reply: can you name several companies > MS acquired to justify their fears of a major paradigm shift towards > notworking computing? I read that other reply of yours, and David's reply to it. He replied much better than I could have done, but I agree with what he said so I'll just refer to his reply. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From spe.stani.be at gmail.com Fri Oct 14 11:28:13 2005 From: spe.stani.be at gmail.com (SPE - Stani's Python Editor) Date: 14 Oct 2005 08:28:13 -0700 Subject: UI toolkits for Python References: Message-ID: <1129303693.449162.79960@g47g2000cwa.googlegroups.com> Something to consider when writing cross-platform applications with any gui toolkit is that it never works out of the box. Despite what they might promise you. If you have yourself access to a Windows, Linux and Mac OS X computer, you probably won't have any problem to make it fully cross-platform. If you work on Windows, but don't have a Mac, than you will have a hard time, if not almost impossible when you write complex applications. I've tried all python gui toolkits and my conclusion was for small applications that are distributed as python source use Tkinter, otherwise wxPython. Arguments are: - very supportive community (wxPython mailing lists, just ask a question and everybody helps you out in no time) - native, professional look & feel - best licensing for all platforms (commercial use allowed) - very rich widget set, continuously extended by the community (see eg. widgets from Andrea Gavana http://xoomer.virgilio.it/infinity77/eng/freeware.html) - wxGlade makes GUI design really easy (http://wxglade.sourceforge.net/) Stani http://pythonide.stani.be (SPE - Stani's Python Editor) From deets at nospam.web.de Mon Oct 10 18:25:54 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 11 Oct 2005 00:25:54 +0200 Subject: Python's Performance In-Reply-To: <861x2t2m7s.fsf@bhuda.mired.org> References: <20051008040614.47429.qmail@web30607.mail.mud.yahoo.com> <178B879D-FDB6-458C-BE00-A03820D98703@advfn.com> <1128888628.643764@yasure> <861x2t2m7s.fsf@bhuda.mired.org> Message-ID: <3r083iFh53h7U1@uni-berlin.de> Mike Meyer wrote: > Donn Cave writes: > >>I agree that there are many shades of grey here, but there's also a >>real black that's sharply distinct and easy to find -- real native >>code binaries are not interpreted. > > > Except when they are. Many machines are microcoded, which means your > "real native code binary" is interpreted by a microcode program stored > in the control store. Most machines don't have a writeable control > store (WCS), so you generally can't change the interpreter, but that's > not always true. In the simple case, a WCS lets the vendor fix > "hardware" bugs by providing a new version of the microcode. In the > extreme cases, you get OS's in which the control store is part of the > process state, so different processes can have radically different > formats for their "native code binaries". > > Then there's the Nanodata QM-1, whose microcode was interpreted by > "nanocode". Or the transmeta processor, that emulated x86 ops. Diez From gsakkis at rutgers.edu Wed Oct 19 21:44:00 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Wed, 19 Oct 2005 21:44:00 -0400 Subject: Upper/lowercase regex matching in unicode References: Message-ID: <1129772640.0bb78237f73a16f8af46ac6825a7115b@teranews> "Jason Stitt" wrote: > What's the best way to match uppercase or lowercase characters with a > regular expression in a unicode-aware way? Obviously [A-Z] and [a-z] > aren't going to cut it. I thought there were character classes of the > form ::upper:: or similar syntax, but can't find them in the docs. > Maybe I'm getting it mixed up with Perl regexen. > > The upper() and lower() methods do work on accented characters in a > unicode string, so there has to be some recognition of unicode case > in there somewhere. > > Thanks, > > Jason http://tinyurl.com/7jqgt George From sharidas at zeomega.com Mon Oct 10 01:51:29 2005 From: sharidas at zeomega.com (Satchidanand Haridas) Date: Mon, 10 Oct 2005 11:21:29 +0530 Subject: best Pythonic way to do this sort: Python newb In-Reply-To: References: <7xbr1y9e1c.fsf@ruckus.brouhaha.com> Message-ID: <434A0161.20601@zeomega.com> ---- Satchidanand Haridas (sharidas at zeomega dot com) ZeOmega (www.zeomega.com) Open Minds' Open Solutions Sean Berry wrote: >"Paul Rubin" wrote in message >news:7xbr1y9e1c.fsf at ruckus.brouhaha.com... > > >>"Sean Berry" writes: >> >> >>>myList = [[value1, value2, value3],[value1, value2, value3], ...] >>> >>>I have a function which takes value3 from the lists above and returns >>>another value. I want to use this returned value to sort the lists. >>> >>>So, my resultant list would be ordered by the return value of the >>>function with value3 as its argument. >>> >>>From a relative Python newb, what is the best way to do this? >>> >>> >>def get_key(x): return x[2] >>sorted_list = sorted(myList, key=get_key) >> >> > >Sorry if I am missing something. But. what is sorted here? > >My simplified function looks like this > >def myFunction( myNumber ): > "do some math calculations to myNumber" > return "result of calculations" > >So, I want to sort myList by the return of myFunction( value3 ) > >I tried doing the following... with no luck so far >myList.sort(lambda x, y: cmp(myFunction(x[2]), myFunction(y[2])) > > > I think the above statement should be as follows: myList.sort(lambda x, y: cmp(myFunction(x[2]) - myFunction(y[2])) hope that helps. regards, Satchit From sean_mcilroy at yahoo.com Fri Oct 28 17:28:36 2005 From: sean_mcilroy at yahoo.com (Sean McIlroy) Date: 28 Oct 2005 14:28:36 -0700 Subject: tkinter blues (greens, reds, ...) In-Reply-To: References: <1130519159.921821.164420@z14g2000cwz.googlegroups.com> Message-ID: <1130534916.236147.314810@g43g2000cwa.googlegroups.com> i'm using the canned colors ("pink", "orange", etc). should i try changing to explicit color specifications to see if that makes a difference? i'm not sure what the other guy meant by a "soft toy", but i take it the idea is to try and construct a correctness proof for the script, and see what keeps it (the proof) from working. it's a sound idea, of course, but the script is pretty darn straightforward, as you can see (below). anyway, i'll let you know how it turns out. peace ############################ green = 'green' orange = 'orange' pink = 'pink' yellow = 'yellow' red = 'red' blue = 'blue' fb = 'frontback' ud = 'updown' lr = 'leftright' def select(x,a,b): return b[a.index(x)] def frontback(orientation): return select(orientation,[fb,ud,lr],[fb,lr,ud]) def updown(orientation): return select(orientation,[fb,ud,lr],[lr,ud,fb]) def leftright(orientation): return select(orientation,[fb,ud,lr],[ud,fb,lr]) class cell: def __init__(self, circlecolor, pointercolor, orientation, coordinates): self.circlecolor = circlecolor self.pointercolor = pointercolor self.orientation = orientation self.coordinates = coordinates def endpoint(self): a,b = self.coordinates if self.orientation==fb: if abs(a)==1: return [2*a,2*b] if abs(a)==2: return [a/2,b/2] if self.orientation==ud: return [+a,-b] if self.orientation==lr: return [-a,+b] class cube: def __init__(self): self.ful = cell(green, blue, fb, [-2,+2]) self.fur = cell(orange, blue, fb, [+2,+2]) self.fdl = cell(pink, blue, fb, [-2,-2]) self.fdr = cell(yellow, blue, fb, [+2,-2]) self.bul = cell(green, red, fb, [-1,+1]) self.bur = cell(orange, red, fb, [+1,+1]) self.bdl = cell(pink, red, fb, [-1,-1]) self.bdr = cell(yellow, red, fb, [+1,-1]) self.cells = [self.ful,self.fur,self.fdl,self.fdr,self.bul,self.bur,self.bdl,self.bdr] def redraw(self,*cells): for x in cells: A = x.coordinates B = x.endpoint() erase(*A) drawpointer(color=x.pointercolor,*(A+B)) drawcircle(color=x.circlecolor,*A) def display(self): self.redraw(*self.cells) def cycle(self,a,b,c,d,funct): x = d.circlecolor y = d.pointercolor z = funct(d.orientation) d.circlecolor = c.circlecolor d.pointercolor = c.pointercolor d.orientation = funct(c.orientation) c.circlecolor = b.circlecolor c.pointercolor = b.pointercolor c.orientation = funct(b.orientation) b.circlecolor = a.circlecolor b.pointercolor = a.pointercolor b.orientation = funct(a.orientation) a.circlecolor = x a.pointercolor = y a.orientation = z rubik = cube() def F1_(): rubik.cycle(rubik.ful,rubik.fur,rubik.fdr,rubik.fdl,frontback) def F2_(): rubik.cycle(rubik.fdl,rubik.fdr,rubik.fur,rubik.ful,frontback) def B1_(): rubik.cycle(rubik.bdl,rubik.bdr,rubik.bur,rubik.bul,frontback) def B2_(): rubik.cycle(rubik.bul,rubik.bur,rubik.bdr,rubik.bdl,frontback) def U1_(): rubik.cycle(rubik.bul,rubik.bur,rubik.fur,rubik.ful,updown) def U2_(): rubik.cycle(rubik.ful,rubik.fur,rubik.bur,rubik.bul,updown) def D1_(): rubik.cycle(rubik.bdl,rubik.bdr,rubik.fdr,rubik.fdl,updown) def D2_(): rubik.cycle(rubik.fdl,rubik.fdr,rubik.bdr,rubik.bdl,updown) def L1_(): rubik.cycle(rubik.ful,rubik.bul,rubik.bdl,rubik.fdl,leftright) def L2_(): rubik.cycle(rubik.fdl,rubik.bdl,rubik.bul,rubik.ful,leftright) def R1_(): rubik.cycle(rubik.fur,rubik.bur,rubik.bdr,rubik.fdr,leftright) def R2_(): rubik.cycle(rubik.fdr,rubik.bdr,rubik.bur,rubik.fur,leftright) def F1(): F1_(); rubik.redraw(rubik.ful,rubik.fur,rubik.fdr,rubik.fdl) def F2(): F2_(); rubik.redraw(rubik.fdl,rubik.fdr,rubik.fur,rubik.ful) def B1(): B1_(); rubik.redraw(rubik.bdl,rubik.bdr,rubik.bur,rubik.bul) def B2(): B2_(); rubik.redraw(rubik.bul,rubik.bur,rubik.bdr,rubik.bdl) def U1(): U1_(); rubik.redraw(rubik.bul,rubik.bur,rubik.fur,rubik.ful) def U2(): U2_(); rubik.redraw(rubik.ful,rubik.fur,rubik.bur,rubik.bul) def D1(): D1_(); rubik.redraw(rubik.bdl,rubik.bdr,rubik.fdr,rubik.fdl) def D2(): D2_(); rubik.redraw(rubik.fdl,rubik.fdr,rubik.bdr,rubik.bdl) def L1(): L1_(); rubik.redraw(rubik.ful,rubik.bul,rubik.bdl,rubik.fdl) def L2(): L2_(); rubik.redraw(rubik.fdl,rubik.bdl,rubik.bul,rubik.ful) def R1(): R1_(); rubik.redraw(rubik.fur,rubik.bur,rubik.bdr,rubik.fdr) def R2(): R2_(); rubik.redraw(rubik.fdr,rubik.bdr,rubik.bur,rubik.fur) def solve(): rubik.__init__() rubik.display() def scramble(): n = 15 from random import randint f = [F1_,F2_,B1_,B2_,U1_,U2_,D1_,D2_,L1_,L2_,R1_,R2_] for i in range(n): f[randint(0,11)]() rubik.display() canvaswidth = 380 canvasheight = 330 def coordinates(x,y): return (canvaswidth/2+68*x),(canvasheight/2-68*y) def drawcircle(x,y,color): r = (20,15)[abs(x)==1] a,b = coordinates(x,y) canvas.create_oval(a-r,b-r,a+r,b+r,fill=color) def drawpointer(x1,y1,x2,y2,color): a1,b1 = coordinates(x1,y1) a2,b2 = coordinates(float(x1+x2)/2,float(y1+y2)/2) canvas.create_line(a1,b1,a2,b2,width=2,fill=color,arrow=LAST) def erase(x,y): a,b = coordinates(x,y) p = canvas.find_overlapping(a-10,b-10,a+10,b+10) q = [x for x in p if canvas.type(x) in ('oval','line')] for x in q: canvas.delete(x) def drawbackground(): A = coordinates(+1,+1) B = coordinates(+1,-1) C = coordinates(-1,+1) D = coordinates(-1,-1) E = coordinates(+2,+2) F = coordinates(+2,-2) G = coordinates(-2,+2) H = coordinates(-2,-2) canvas.create_polygon(fill='',outline='black',*(C+A+E+G+C)) canvas.create_polygon(fill='',outline='black',*(C+G+H+D+C)) canvas.create_polygon(fill='',outline='black',*(A+E+F+B+A)) canvas.create_polygon(fill='',outline='black',*(H+F+B+D+H)) from Tkinter import * root = Tk() ######################################################## back = Frame(root,borderwidth=3) back.pack(side=TOP) Button(back,text='<<<<',command=B1).pack(side=LEFT) Label(back,width=10,text='BACK').pack(side=LEFT) Button(back,text='>>>>',command=B2).pack(side=LEFT) ######################################################## top = Frame(root,borderwidth=3) top.pack(side=TOP) Button(top,text='<<<<',command=U1).pack(side=LEFT) Label(top,width=10,text='TOP').pack(side=LEFT) Button(top,text='>>>>',command=U2).pack(side=LEFT) ######################################################## mid = Frame(root) mid.pack(side=TOP) left = Frame(mid,borderwidth=5) left.pack(side=LEFT) Button(left,text='^\n^',width=3,command=L1).pack(side=TOP) Label(left,height=6,text='L\nE\nF\nT').pack(side=TOP) Button(left,text='v\nv',width=3,command=L2).pack(side=TOP) canvas = Canvas(mid,width=canvaswidth,height=canvasheight) canvas.pack(side=LEFT,expand=1,fill=BOTH) right = Frame(mid,borderwidth=5) right.pack(side=LEFT) Button(right,text='^\n^',width=3,command=R1).pack(side=TOP) Label(right,height=6,text='R\nI\nG\nH\nT').pack(side=TOP) Button(right,text='v\nv',width=3,command=R2).pack(side=TOP) ######################################################## bottom = Frame(root,borderwidth=3) bottom.pack(side=TOP) Button(bottom,text='<<<<',command=D1).pack(side=LEFT) Label(bottom,width=10,text='BOTTOM').pack(side=LEFT) Button(bottom,text='>>>>',command=D2).pack(side=LEFT) ######################################################## front = Frame(root,borderwidth=3) front.pack(side=TOP) Button(front,text='<<<<',command=F1).pack(side=LEFT) Label(front,width=10,text='FRONT').pack(side=LEFT) Button(front,text='>>>>',command=F2).pack(side=LEFT) ######################################################## ctrl = Frame(root,borderwidth=20) ctrl.pack(side=TOP) Button(ctrl,text='SOLVE',command=solve).pack(side=LEFT) Label(ctrl,width=3,text='').pack(side=LEFT) Button(ctrl,text='SCRAMBLE',command=scramble).pack(side=LEFT) ######################################################## root.title('rubik') drawbackground() rubik.display() root.mainloop() From robert.kern at gmail.com Thu Oct 6 10:15:12 2005 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 06 Oct 2005 07:15:12 -0700 Subject: updating local() In-Reply-To: <1128607448.235410.152590@o13g2000cwo.googlegroups.com> References: <1128530014.323801.290360@g47g2000cwa.googlegroups.com> <1128603314.197733.119160@g47g2000cwa.googlegroups.com> <3qkmjcFfbem9U1@uni-berlin.de> <1128607448.235410.152590@o13g2000cwo.googlegroups.com> Message-ID: Flavio wrote: > Ok, its not thousands, but more like dozens of variables... > I am reading a large form from the web which returns a lot of values. > (I am Using cherrypy) > > I know I could pass these variables around as: > > def some_function(**variables): > ... > > some_function(**variables) > > but its a pain in the neck to have to refer to them as > variables['whatever']... > > dont you think? Use a Bunch. class Bunch(dict): def __init__(self, *args, **kwds): dict.__init__(self, *args, **kwds) self.__dict__ = self -- 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 my_email_is_posted_on_my_website at munged.invalid Mon Oct 24 01:28:53 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Mon, 24 Oct 2005 05:28:53 GMT Subject: Microsoft Hatred FAQ References: <11l16dst501kjdd@corp.supernews.com> <11l48meji6u4e69@corp.supernews.com> <2X95f.14513$vV4.3483@fe08.lga> <435ad152$17$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: On Sun, 23 Oct 2005 23:16:24 GMT, Roedy Green wrote or quoted : >>As well as blame. The commercialization of the Internet was grossly >>mismanaged. Take the InterNIC - please! > >As global bureaucracies go, I think they have done a good job. Can >you imagine herding the cats of egotistical dictators and politicians >from every country on earth who have not a clue about what the >function of domain are? Imagine assigning two letter abbreviations to 200 five years olds and getting them to accept their assignments. That would be a much easier task. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From jgrahn-nntq at algonet.se Fri Oct 7 08:50:19 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 7 Oct 2005 12:50:19 GMT Subject: Can Python replace TCL/Expect References: <1128578298.778640.313900@g49g2000cwa.googlegroups.com> <6ncf13-2ps.ln1@lairds.us> Message-ID: On Thu, 06 Oct 2005 17:08:03 GMT, Cameron Laird wrote: > In article , > Jorgen Grahn wrote: > . > . > . >>It depends. I do not feel /that/ advanced, but I've been bitten by pexpect's >>limitations several times in several places. >> >>... which puts me in a weird position ;-) I /loathe/ the Tcl language, but I >>have to admit that its expect functionality is far superior to Python's. > . > . > . > On to more constructive matters: what are you doing about > Pexpect's limitations? Have the maintainers responded to you > when you write? Are you tempted to compose enhancements for > yourself? There is hobby hacking, and there is work. I've encountered pexpect during work, and haven't had the time and energy to look into it. I hereby apologize to the pexpect developers. Not for whining, but for not helping out. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From donn at u.washington.edu Mon Oct 10 18:46:29 2005 From: donn at u.washington.edu (Donn Cave) Date: Mon, 10 Oct 2005 15:46:29 -0700 Subject: Python's Performance References: <20051008040614.47429.qmail@web30607.mail.mud.yahoo.com> <178B879D-FDB6-458C-BE00-A03820D98703@advfn.com> <1128888628.643764@yasure> <861x2t2m7s.fsf@bhuda.mired.org> Message-ID: In article <861x2t2m7s.fsf at bhuda.mired.org>, Mike Meyer wrote: > Donn Cave writes: > > I agree that there are many shades of grey here, but there's also a > > real black that's sharply distinct and easy to find -- real native > > code binaries are not interpreted. > > Except when they are. Many machines are microcoded, which means your > "real native code binary" is interpreted by a microcode program stored > in the control store. Most machines don't have a writeable control > store (WCS), so you generally can't change the interpreter, but that's > not always true. In the simple case, a WCS lets the vendor fix > "hardware" bugs by providing a new version of the microcode. In the > extreme cases, you get OS's in which the control store is part of the > process state, so different processes can have radically different > formats for their "native code binaries". > > Then there's the Nanodata QM-1, whose microcode was interpreted by > "nanocode". Fine -- given a Python Chip computer, Python programs are native code. It can use microcode, if that helps. The VAX/11 microcode was just a software extension of the CPU hardware, implementing some extra instructions, the way I remember it. I don't recall that it was of any more than academic interest to anyone using the computer - though it may have been software in a sense, it was on the hardware side of the wall. On the software side of the wall, if your program can go over the wall by itself, then it's native. Donn Cave, donn at u.washington.edu From spe.stani.be at gmail.com Sun Oct 16 18:23:08 2005 From: spe.stani.be at gmail.com (SPE - Stani's Python Editor) Date: 16 Oct 2005 15:23:08 -0700 Subject: Calling an exe from Python? In-Reply-To: <1129492892.037665.123590@g44g2000cwa.googlegroups.com> References: <1129492892.037665.123590@g44g2000cwa.googlegroups.com> Message-ID: <1129501388.075484.138870@g49g2000cwa.googlegroups.com> Slightly offtopic, but you can translate any double clicking (*.exe, *.pdf, *.html, ...) in the Windows Explorer into: import os os.startfile(fileName) Stani -- SPE - Stani's Python Editor http://pythonide.stani.be From chris.cavalaria at free.fr Tue Oct 18 07:06:20 2005 From: chris.cavalaria at free.fr (Christophe) Date: Tue, 18 Oct 2005 13:06:20 +0200 Subject: Question on class member in python In-Reply-To: <1129630576.414181.276570@z14g2000cwz.googlegroups.com> References: <1129537638.714752.120290@g49g2000cwa.googlegroups.com> <1129624952.836150.159520@g44g2000cwa.googlegroups.com> <1h4mjkh.163t6yf4f20krN%aleaxit@yahoo.com> <1129630576.414181.276570@z14g2000cwz.googlegroups.com> Message-ID: <4354d70b$0$2656$626a14ce@news.free.fr> Johnny Lee a ?crit : > Alex Martelli ??? > > >>Johnny Lee wrote: >> >> >>>But I still wonder what's the difference between the A().getMember and >>>A().member besides the style >> >>Without parentheses after it, getMember is a method. The difference >>between a method object and an integer object (which is what member >>itself is in your example) are many indeed, so your question is very >>strange. You cannot call an integer, you cannot divide methods, etc. >> >> >>Alex > > > Sorry, I didn't express myself clear to you. I mean: > b = A().getMember() > c = A().member > what's the difference between b and c? If they are the same, what's the > difference in the two way to get the value besides the style. > Second form is better because it makes it easier to refactor. Like, at first A had a direct access to the member member. But later you want to control the access to it. So you change it into a property and you don't need to change client code. From cfajohnson at gmail.com Sat Oct 22 20:37:15 2005 From: cfajohnson at gmail.com (Chris F.A. Johnson) Date: Sat, 22 Oct 2005 20:37:15 -0400 Subject: best way to replace first word in string? References: <1129822003.246170.303920@f14g2000cwb.googlegroups.com> <88e3c$4359d217$d8fea545$17293@PRIMUS.CA> <6rsp23-s0t.ln1@rogers.com> <7f153$435ad0ef$d1b71608$16495@PRIMUS.CA> Message-ID: On 2005-10-22, William Park wrote: > Chris F.A. Johnson wrote: >> On 2005-10-22, William Park wrote: >> > hagai26 at gmail.com wrote: >> >> I am looking for the best and efficient way to replace the first word >> >> in a str, like this: >> >> "aa to become" -> "/aa/ to become" >> >> I know I can use spilt and than join them >> >> but I can also use regular expressions >> >> and I sure there is a lot ways, but I need realy efficient one >> > >> > I doubt you'll find faster than Sed. >> >> On the contrary; to change a string, almost anything will be faster >> than sed (except another external program). >> >> If you are in a POSIX shell, parameter expansion will be a lot >> faster. >> >> In a python program, one of the solutions already posted will be >> much faster. > > Care to put a wager on your claim? In a shell, certainly. If one of the python solutions is not faster than sed (e.g., os.system("sed .....")) I'll forget all about using python. -- Chris F.A. Johnson ================================================================== Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress From eurleif at ecritters.biz Mon Oct 10 07:19:20 2005 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Mon, 10 Oct 2005 11:19:20 GMT Subject: Changing an AST In-Reply-To: <1128941690.030540.258790@g43g2000cwa.googlegroups.com> References: <1128941690.030540.258790@g43g2000cwa.googlegroups.com> Message-ID: beza1e1 wrote: > Is it possible compiler.parse a statement, then change and then > execute/resolve it? This should work: >>> from compiler.pycodegen import ModuleCodeGenerator >>> from compiler.misc import set_filename >>> from compiler import parse >>> >>> tree = parse('foo = 42') >>> set_filename('', tree) >>> code = ModuleCodeGenerator(tree).getCode() >>> exec code >>> foo 42 Also, if you need to turn an AST back into Python code, I have some ugly code for doing that: . From mekstran at scl.ameslab.gov Thu Oct 13 16:50:29 2005 From: mekstran at scl.ameslab.gov (Michael Ekstrand) Date: Thu, 13 Oct 2005 15:50:29 -0500 Subject: UI toolkits for Python In-Reply-To: <33765778-7F70-438D-8020-1FEC94CE1FA9@sbcglobal.net> References: <33765778-7F70-438D-8020-1FEC94CE1FA9@sbcglobal.net> Message-ID: <200510131550.29598.mekstran@scl.ameslab.gov> On Thursday 13 October 2005 15:17, Kenneth McDonald wrote: > 1) Which plays best with Python? Ideally, it would already have some > higher-level python libraries to hide the grotty stuff that is almost > never needed when actually implementing apps. wxPython plays reasonably well. I've just started playing with PyGTK+glade, and am highly impressed with that. > 4) Ease of installation/use on OS X? Ease of installation and use, wxPython is good. General OS X goodness, wxPython has been exhibiting highly weird behavior. Plus some useful widgets don't work well (if at all) on Mac. wxWidgets also feels very old-Windows-ish. For example, it's built around having 1 toolbar for a window; for my application, that's not going to work so well, and I'm also having issues with some things related to dynamically creating toolbars and changing the toolbar. - Michael From tjue1 at sussex.ac.uk Tue Oct 25 11:11:39 2005 From: tjue1 at sussex.ac.uk (Matthew Fowler) Date: Tue, 25 Oct 2005 16:11:39 +0100 Subject: Errno 8 Exec format error Message-ID: <1130253099.435e4b2b37812@webmail.sussex.ac.uk> Hi there I have been porting python to the Etrax platform and everything seems to be working. However when I run the program in question I get: "problem with execution of xhpl on AxisProduct: [Errno 8] Exec format error" Im looking for any help to try and solve this issue. Am I correct in thinking that Python is reporting this problem? If so has anybody experienced this problem before? Thank You Matt From robert.kern at gmail.com Fri Oct 21 05:25:23 2005 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 21 Oct 2005 02:25:23 -0700 Subject: Should i pick up Numeric, Numarray or SciPy.core? In-Reply-To: <1129884370.881194.20420@g47g2000cwa.googlegroups.com> References: <1129884370.881194.20420@g47g2000cwa.googlegroups.com> Message-ID: jelle wrote: > #No rant intended > > I'm not at all confused wether I should learn an one of the advanced > array modules, I'm slightly confused over which I should pick up. I'm > impressed with the efforts of SciPy and Scientific, but since I'm > fairly new to programming & OO, choosing Numarray over Numeric hasnt > been that satisfactory at all, which is not a problem of the quality of > Numarray, but the fact that a lot of modules still heavily realy on > Numeric. Which, with my fragile knowledge in programming is rather > confusing sometimes. Since its seems its far from pragmatic to opt > solely for either one of them. So Scipy.core looks like the ticket for > me here, doesnt it? Before putting an effort into it, I'd like to know > whether this would make sense, certainly since scipy.core is in its > early stages, and documentation isnt available yet (for free that is... > its not clear to me why I should pay for software in its early stages, > when it extents on efforts freely available) The software itself is absolutely free. The complete documentation for scipy_core specifically is available for a fee, but you will get free updates as the documentation is expanded and as soon as a certain number of copies have been purchased or a certain amount of time has passed, the documentation will be made available free of charge. The book does not extend "on efforts freely available," either; it's entirely new. However, not much has changed between Numeric and scipy_core, so most of the Numeric documentation still applies. There is fairly good docstring coverage in any case. > Curious for your opinions, I definitely think the Scipy.core effort is > terrific, but right now I'm wondering whether its a pragmatic choice. scipy_core is the future. Most of the complete scipy package has been ported over at the moment. However, if you need to use other code that depends on Numeric (like Konrad Hinsen's Scientific), then you can use Numeric for the time being and port your code to scipy_core using the provided conversion script. The API on the Python side hasn't changed too dramatically. -- 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 my_email_is_posted_on_my_website at munged.invalid Tue Oct 18 22:57:01 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 19 Oct 2005 02:57:01 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <11l48meji6u4e69@corp.supernews.com> <2X95f.14513$vV4.3483@fe08.lga> Message-ID: On 18 Oct 2005 13:21:19 -0500, joe at invalid.address wrote or quoted : >existed then. > >Yes, he deserves credit for what he did. He nevertheless created a >false impression in what he said. If he hadn't created that false >impression, there would not have been any jokes about him. If all he >said was what he actually did, this would never have been an issue. It is standard procedure to twist another politician's words and tease him like a gang of 4 year olds. Think of poor Mr. Bush. People quote him all the time. :-) See http://mindprod.com/politics/bushisms.html -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From codecraig at gmail.com Thu Oct 6 08:43:14 2005 From: codecraig at gmail.com (Java and Swing) Date: 6 Oct 2005 05:43:14 -0700 Subject: Swig and pointers In-Reply-To: References: <1128541976.495441.46140@f14g2000cwb.googlegroups.com> Message-ID: <1128602594.608766.53440@g47g2000cwa.googlegroups.com> im sorry, why would it be md_ptr? what is md_ptr? i tried.. %include cpointer.i %pointer_functions(MY_DIGIT, digit_ptr) ptr = new_digit_ptr() doIt("a message", ptr) ...doesnt work..still needs a DIGIT ** From mekstran at scl.ameslab.gov Tue Oct 4 18:32:40 2005 From: mekstran at scl.ameslab.gov (Michael Ekstrand) Date: Tue, 4 Oct 2005 17:32:40 -0500 Subject: wxPython equiv. to tag_configure In-Reply-To: <1128456689.100365.196050@g47g2000cwa.googlegroups.com> References: <1128456689.100365.196050@g47g2000cwa.googlegroups.com> Message-ID: On Oct 4, 2005, at 3:11 PM, ncf wrote: > In the wxWidgets manual, I see a wxHtmlWindow object, but nothing like > that seems to exist when I dir() wxPython. wxHtmlWindow is in the wx.html module. -Michael From robert.h.boyd at gmail.com Fri Oct 21 21:57:45 2005 From: robert.h.boyd at gmail.com (Robert Boyd) Date: Fri, 21 Oct 2005 21:57:45 -0400 Subject: Python vs Ruby In-Reply-To: <89DF2CF9-408E-4D9E-8E43-003D23006C24@pengale.com> References: <1129776956.254389.188040@z14g2000cwz.googlegroups.com> <89DF2CF9-408E-4D9E-8E43-003D23006C24@pengale.com> Message-ID: On 10/19/05, Jason Stitt wrote: > > How can we improve Python's competitiveness in this arena? "Pie"? Or > can we do even better than Lua? Ptooey! I'm sure I could really evangelize use of it at work were it called Ptooey ;) As if Plone, Zope, and (non-Python) Shibboleth weren't getting me enough funny looks. And I haven't even started telling co-workers about Django. Rob From pmartin at snakecard.com Fri Oct 21 15:18:40 2005 From: pmartin at snakecard.com (Philippe C. Martin) Date: Fri, 21 Oct 2005 19:18:40 GMT Subject: how to modify text in html form from python References: <0Ra6f.5050$q%.616@newssvr12.news.prodigy.com> Message-ID: PS: If my question is not clear, I am trying to "share" the form between the client and server. just as many sites out there allow you to modify existing data: 1) the server pops up a form with your data in it. 2) the client can modify it and submit. I know this is a _basic_ question, sorry. Philippe Philippe C. Martin wrote: > Hi, > > I am trying to change the data in a form field from python. The following > code does not crash but has no effect as if "form" is just a copy of the > original html form. > > Must I recreate the form order to do that ? > > My point is for the client to be able to re-read the modified data. > > > Thanks, > > Philippe > #!/usr/bin/python > > import cgi > import os > import sys > import logging > import cgi > sys.stderr = sys.stdout > print "Content-type: text/html\n" > try: > form = cgi.FieldStorage() > #logging.warning (form) > > except: > logging.exception("\nEXCEPTION 1") > try: > > form['tosrv'].value = "TEST" > except: > logging.exception("\nEXCEPTION 2") > pass > > > > Smart Logon >

Smart Logon

>
>
> >
> > TO SERVER:
> >
> FROM SERVER
> >

> > >

>
> > From stewart.midwinter at gmail.com Wed Oct 12 21:52:18 2005 From: stewart.midwinter at gmail.com (stewart.midwinter at gmail.com) Date: 12 Oct 2005 18:52:18 -0700 Subject: Bad magic no. in python zipfile Message-ID: <1129168338.457437.276820@z14g2000cwz.googlegroups.com> I've been experimenting with the python zipfile module, and have run into a snag. I'm able to create a new zipfile with the module's ZipFile class and add files to it. After closing the file, I'm able to view the contents of it with WinZip. I can also confirm that it is a python zip file by using the is_zipfile() method. All good so far. However, under some circumstances, I am unable to later read the file and extract its contents. As soon as a I attempt to instantiate a new ZipFile instance, I receive an error regarding Bad Magic number. In the past, I've seen that when trying to use a .pyc module, created with one Python version, using another Python version. But in this case, I created the zip file under Python 2.4.2 and tried to open it under Python 2.4.2 as well. Any ideas on what to do? (apart from giving up on Python and using winzip?) On a separate topic, zipfile wasn't available under Python 1.5.2. I need to create zip files using that old version, since it's the only one installed on a remote server. Any suggestions on what to do? thanks S From grig.gheorghiu at gmail.com Thu Oct 13 14:57:19 2005 From: grig.gheorghiu at gmail.com (Grig Gheorghiu) Date: 13 Oct 2005 11:57:19 -0700 Subject: Well written open source Python apps In-Reply-To: References: <1129214592.342917.100090@g43g2000cwa.googlegroups.com> Message-ID: <1129229839.857857.288180@o13g2000cwo.googlegroups.com> This is really synchronicity in action! I started to think yesterday about putting together a project that measures the 'goodness' of Python packages in the PyPI Cheese Shop repository. I call it the "Cheesecake" project. I took the liberty of citing Micah's post in a blog entry that I just posted: Comments/suggestions welcome! Grig From michele.petrazzo at TOGLIunipex.it Thu Oct 20 12:13:48 2005 From: michele.petrazzo at TOGLIunipex.it (Michele Petrazzo) Date: Thu, 20 Oct 2005 18:13:48 +0200 Subject: sort problem Message-ID: <4357c22d$0$8481$5fc30a8@news.tiscali.it> I have a list of lists (a grid table) that can have about 15000 - 20000 "rows" and 10 "cols", so: 1 [ [ 'aaa', 'vv', 'cc', 23, ... ], 2 [ 'aav', 'vv', 'cc', 45, ... ], ... 15000 [ 'sad', 'ad', 'es', 123, ... ], ] I need to sort this list, but I need to specify two things: the "column" and its type (string or int), so for example in this list, I want to sort the fourth column that has int values. The type because that I want that 1, 2, 12 will be sort in this order, not 1, 12, 2 like strings. I have already tried to modify some code found on aspn, but the results are always too slow for me, about 30-40 sec. Can someone has some code or some point where can I start for speedup my code? Thanks, Michele From fredrik at pythonware.com Fri Oct 14 01:47:30 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 14 Oct 2005 07:47:30 +0200 Subject: Adding a __filename__ predefined attribute to 2.5? References: <1129098667.336115.303060@g47g2000cwa.googlegroups.com><1129150883.303899.259570@g43g2000cwa.googlegroups.com> <1129230950.305013.302200@g49g2000cwa.googlegroups.com> Message-ID: Rune Strand wrote: > I've read a lot of your comments the last years. Your friendliness > always strikes me. terseness != unfriendlyness From jhu at metrigenix.com Thu Oct 6 16:39:54 2005 From: jhu at metrigenix.com (James Hu) Date: Thu, 6 Oct 2005 16:39:54 -0400 Subject: ctypes questions Message-ID: <90DEA7ED93F71A4580CEDF76A02682EA03ACB4@torexch.metrigenix.com> Convert unsigned long imageSize; Frame.pBuffer=new unsigned char[ imageSize ] To buffer = (c_ubyte * imageSize)() # create array Frame.pBuffer = addressof(buffer) Frame.pBuffer = (c_ubyte * imageSize)() TypeError: can't multiply sequence by non-int Please help me out, thanks in advance James From larry.bates at websafe.com Mon Oct 10 14:25:09 2005 From: larry.bates at websafe.com (Larry Bates) Date: Mon, 10 Oct 2005 13:25:09 -0500 Subject: convert char to byte representation In-Reply-To: References: Message-ID: <434AB205.8000304@websafe.com> ord(c) gives you decimal representation of a character. -Larry Bates Philipp H. Mohr wrote: > Hello, > > I am trying to xor the byte representation of every char in a string with > its predecessor. But I don't know how to convert a char into its byte > representation. This is to calculate the nmea checksum for gps data. > > e.g. everything between $ and * needs to be xor: > $GPGSV,3,1,10,06,79,187,39,30,59,098,40,25,51,287,00,05,25,103,44* > to get the checksum. > > > Thank you for you help. > > Phil From mde at micah.elliott.name Wed Oct 19 23:37:47 2005 From: mde at micah.elliott.name (Micah Elliott) Date: Wed, 19 Oct 2005 20:37:47 -0700 Subject: How to organize Python files in a (relatively) big project In-Reply-To: References: Message-ID: <20051020033747.GD4541@kitchen.client.attbi.com> On Oct 19, Jarek Zgoda wrote: > Micah Elliott napisa?(a): > > >>How to install this structure eg. on Linux? What layout do you > >>recommend? It's tempting to use /opt hierarchy for installation > >>target (as it gives relatively much freedom within application > >>directory), but many administrators are reluctant to use this > >>hierarchy and prefer more standarized targets, such as /usr or > >>/usr/local. > > > > Read about (and use) the Python-provided distutils, and let it do the > > work for you. In particular, > > > > discusses installation location. The file name is a misnomer; it's > > equally applicable to linux. > > I think that installing *application* (not misc. library) modules in > site-packages is at least stupid idea... They're not. > ...as it makes a special filesystem inside other, much more > standarized filesystem (Windows, FHS, etc.). Why not to do this > usual way: libraries to $prefix/lib/$appname-$version, binary to > $prefix/bin, shared files to $prefix/share/$appname, etc -- and > appropriately on Windows. It is done more the FHS way than you might realize. Assuming sys.prefix is '/usr', then using distutils my manpages go to '/usr/share/man', my tools/scripts that I want my users to access go to '/usr/bin' (and I could even put my config files in '/usr/../etc' or maybe just '/etc' but I haven't had to do that). So only your modules end up in '/usr/lib/python', but that seems appropriate anyway. It is the simplest way for '/usr/bin/python' to locate your modules, since it already knows to look in '/usr/lib/python' for modules. If you put your modules in say /usr/lib/fooapp then how would python know where to look for your modules? You would have users messing with something called PYTHONPATH or you would end up with boilerplate or custom install logic to set sys.path according to special user needs. But why go through the trouble? Just let distutils do the work for you. I don't want my users to know anything about my *modules* that end up in /usr/lib/python or that such a thing as PYTHONPATH even exists. If you prefer the /opt route (or /tmp or $HOME or whatever), then distutils can create your filesystem structure beneath that accordingly. -- _ _ ___ |V|icah |- lliott http://micah.elliott.name mde at micah.elliott.name " " """ From strombrg at dcs.nac.uci.edu Mon Oct 10 17:40:24 2005 From: strombrg at dcs.nac.uci.edu (Dan Stromberg) Date: Mon, 10 Oct 2005 21:40:24 GMT Subject: Send password over TCP connection References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> <1128979760.251637.316480@o13g2000cwo.googlegroups.com> Message-ID: On Mon, 10 Oct 2005 14:29:20 -0700, dcrespo wrote: > ?Beautiful and elegant solution! > > Two copies of the password: one on the client, the other on the server. > > 1. Client wants to connect > 2. Server generates a random_alphanumeric_string and sends it to the > client > 3. Both Client and Server creates a hash string from > > 4. Client sends the hash string to the server > 5. Server compares his hash result with the hash string received from > de client. > > I think it is a very good solution, Isn't it? Sounds like it, but how is it different from what I just described? :) Oh, also, I'm not 100% how much the alphanumeric part impacts things. You may or may not get a better result by using a random string with all bits random, not just the bits that vary in ASCII for letters and numbers. Anyway, for an example of this sort of thing, you might look over my fallback-reboot program at http://dcs.nac.uci.edu/~strombrg/fallback-reboot/ It uses RIPEMD-160 for the hash. The server side is in C (to reduce dependencies to a bare minimum), but the client side is in python (for convenience). From g.franzkowiak at onlinehome.de Mon Oct 3 11:48:47 2005 From: g.franzkowiak at onlinehome.de (g.franzkowiak) Date: Mon, 03 Oct 2005 17:48:47 +0200 Subject: struct.unpack In-Reply-To: References: Message-ID: Peter Otten schrieb: > g.franzkowiak wrote: > > >>The dataObject was read from a named pipe as an byte stream >> >>state, dataObject = win32file.ReadFile(handle, nbytes, None) >>print repr(dataObject) >> ==> '\x01\x02\x03\x04\x00\x00\x00\x00\x00\x00\x0..... >> >>With Frederiks help operates this fine > > > I do not doubt that. My point was that instead of the suggested > > # Fredrik > obj = "".join(list(dataObject[:4])) > > the simpler > > # me > obj = dataObject[:4] > > might work as well. I cannot test it here, but judging from > > http://aspn.activestate.com/ASPN/docs/ActivePython/2.3/pywin32/win32file__ReadFile_meth.html > > the resulting dataObject is a buffer and buffer slices seem to be just > strings. > > >>print repr(dataObject) >> ==> '\x01\x02\x03\x04\x00\x00\x00\x00\x00\x00\x0..... > > > Hmm, that looks as if dataObject were a string -- please post the result of > > print type(dataObject) > > just to help me restore my peace of mind :-) > > Peter > Hello Peter, was a node in my mind, the data comes as a string (with readfile always) << type(dataObject) = 'str' >> and << type(dataObject:4) = 'str' >> also ;-) I've dropped the loop with list/join and the result is the same. Thank you :-)) gerd From steve at REMOVETHIScyber.com.au Sat Oct 15 23:01:22 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 16 Oct 2005 13:01:22 +1000 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: On Sat, 15 Oct 2005 15:48:18 -0700, David Schwartz wrote: > "Mike Meyer" wrote in message > news:86ll0vs1sw.fsf at bhuda.mired.org... > >> What you call "clever marketing" the DOJ calls "monopolistic >> practices". The courts agreed with the DOJ. Having had several large >> PC manufacturers refuse to sell me a system without some form of >> Windows because MS made it impossible for them to compete if they >> didn't agree to do so, I agree with the courts and the DOJ. > > Go down to your local car dealer and see if you can buy a new car > without an engine. That's a false analogy. A better analogy is, "go to your local car dealer and see if you can buy a new car with the tyres of your choice." Even non-technical types can choose to run a non-Windows operating system on an Intel-compatible PC. So why do the tier-one vendors and all laptop manufacturers make their machines available only with Windows? Or on the very few occasions they will offer a naked PC, the price is the same as for PC + Windows. I'm aware of talk that Dell is selling Linux PCs at Walmart for less than the same hardware plus Windows. Talk is cheap -- I'm not aware of anyone who has actually seen these Linux PCs. I'd love to know either way. (Oh, and since I am in Australia, and we haven't yet been invaded by Walmart, I can't go and look for myself.) -- Steven. From tim at vegeta.ath.cx Sun Oct 16 03:23:06 2005 From: tim at vegeta.ath.cx (Tim Hammerquist) Date: Sun, 16 Oct 2005 07:23:06 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <11l369039d6ppe0@corp.supernews.com> Message-ID: Greymaus wrote: > Was that the Color Computer III running OS9 Level II for an > operating system, that you're talking about? Motorola 6809 > processor? HELLUVA little computer! OS9 was a bit quirky, > though, even for a UNIX clone. I loved my little CoCo! I had the original CoCo, upgraded with the 5 1/4" floppy drive, and later upgraded the whole system to CoCo 3 with OS9. <3 <3 <3 Of course, it all went downhill from there. MS-DOS 3.1, Pascal, Windows 3.1... *sigh* 10 years later, things picked up. Huzzah! Tim Hammerquist From mirandacascade at yahoo.com Wed Oct 19 23:04:07 2005 From: mirandacascade at yahoo.com (mirandacascade at yahoo.com) Date: 19 Oct 2005 20:04:07 -0700 Subject: Minimizing Connection reset by peer exceptions Message-ID: <1129777447.614500.232050@z14g2000cwz.googlegroups.com> This may be more of a socket question than a python question; not sure. Using this code to instantiate/connect/set options connectionHandle = socket.socket(socket.AF_INET, socket.SOCK_STREAM) errorStatus = connectionHandle.connect_ex((ipAddress, port)) connectionHandle.setsockopt(socket.SOL_SOCKET, socket.SO_RCVTIMEO, 60000) Using this code to send: retSendAll = connectionHandle.sendall(messageToHost) Followed by this code to recv: bufferSize = 500000 responseBuffer = connectionHandle.recv(bufferSize) Occasionally (perhaps 5% of the time) the following exception gets raised: (10054, 'Connection reset by peer') Are there any changes I can make to the code above to eliminate the 10054 errors or to reduce the probability of encountering the 10054 error? Are there any settings that make the 'Connection reset by peer' condition less likely? Other posts on this subject seem to suggest that this can only be handled by: 1) detecting the 10054 error 2) issuing a message explaining the 'connection reset' condition followed by something along the lines of 'try again later'. From jeremy at emperorlinux.com Fri Oct 7 07:30:18 2005 From: jeremy at emperorlinux.com (Jeremy Moles) Date: Fri, 07 Oct 2005 07:30:18 -0400 Subject: PyObject_New In-Reply-To: <43462a69$0$6776$9b622d9e@news.freenet.de> References: <43462a69$0$6776$9b622d9e@news.freenet.de> Message-ID: <1128684618.4472.41.camel@localhost.localdomain> I just noticed this response right as I sent my other message. For some reason my news reader didn't thread it, so it was all by itself... Please disregard the rant concerning creation of objects in C. :) /me hugs Martin /me ducks and hides! On Fri, 2005-10-07 at 09:57 +0200, "Martin v. L?wis" wrote: > Jeremy Moles wrote: > > PyObject* obj = _PyObject_New(&PyType_MyType); > > obj = PyObject_Init(obj, &PyType_MyType); > > > > ... > > > > return obj; > > The call to PyObject_Init is redundant: _PyObject_New > is malloc+init. However, this shouldn't cause any crashes (except in the > debug build). PyObject_Init is documented as > > Initialize a newly-allocated object op with its type and initial > reference. Returns the initialized object. If type indicates that the > object participates in the cyclic garbage detector, it is added to the > detector's set of observed objects. Other fields of the object are not > affected. > > [I don't know where the mentioning of GC comes from - it appears to be > incorrect] > > > When "obj" gets back to the interpreter, Python sees it (or rather, it's > > __repr__) in accordance with what it "should" be. However, any attempt > > to USE the object results in a segfault. I feel my problem is simply > > that I'm not allocating "obj" correctly in the C++ function. > > It doesn't crash because of the allocation - this code is correct. > However, it is also incomplete: none of the state of the new object > gets initialized in the fragment you are showing. So it likely crashes > because the members of the object are stray pointers or some such, > and accessing them causes a crash. > > Regards, > Martin From http Sun Oct 9 17:48:44 2005 From: http (Paul Rubin) Date: 09 Oct 2005 14:48:44 -0700 Subject: Function decorator that caches function results References: <7x4q7rt3yl.fsf@ruckus.brouhaha.com> Message-ID: <7xvf061hvn.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Is it correct to say that Python *always* creates a closure whenever a def > or lambda is executed? Or is it only for *certain* defs/lambdas? The word closure is being used two different ways. First of all the computer-science term "closure" which means a combination of a function and its lexical environment. Second of all the data field named "closure" which lives inside certain function objects in Python. The second one is created only in certain Python functions but that's an implementation detail. It was added because in the old days, Python didn't support closures at all, so implementing them was done straightforwardly by adding a field that contains the closure environment, for Python functions that needed it. So the answer to your first question above is "always" in the CS sense and "only for certain defs/lambdas" in the implementation sense. > Is it correct to talk about functions *having* closures, or that they > *are* closures, or that the function is *part of* a closure? The function is part of the closure. I think you're a little confused by implementation issues. In Python, functions are first-class objects, like class instances or strings. If you say x = 'foo' + 'bar' a new string is created out of nowhere. If you say def f(x): return x+3 a new function is created out of nowhere. Lambda notation maybe shows more clearly that functions are values: f = (lambda x: x+3) is the same as the "def f" above. Let's go back a step. Do you understand what a free variable is? Let's say: def f(): print x f refers to x but x is not defined in f. We say x is "free" in f. In the old days, this could only mean one thing: x was a global variable. Python didn't have nested scopes. If a variable wasn't found in a function's locals, it could only come from the globals that are shared across all functions. Python now has nested scopes. That means x doesn't have to come from the globals, it can be a local from some surrounding function: def g(n): x = n # x is local to g def f(): print x f() When you run g(3), Python prints 3. That's not too confusing, right? Suppose instead of calling f, you return it. You can do that in Python: def g(n): x = n # x is local to g def f(): print x return f h3 = g(3) # h3 is the function g creates when you run it What will happen when you call h3()? It prints 3. How did it know to do that? Because h3 doesn't just contain executable bytecode, it also contains f's lexical environment from when g ran. (f's lexical environment means the values of f's free variables from outer scopes at the time f was created). Now suppose you say: h5 = g(5) # make a new function See, h3 and h5 are two different functions: h3() # still prints 3 h5() # prints 5 They contain the same executable code, but different lexical environments. The combination of executable code plus lexical environment is called a closure (CS term). In Python, every function is a (CS) closure. The environment lives in a field called func_closure or something like that. However, when there are no free variables, Python doesn't bother creating that field. That was ALWAYS the case in old versions of Python. Python didn't recognize nested scopes; there were only locals and globals. > If all functions are closures, what does it mean to say that some > languages (e.g. Java, C++, C#) don't have closures but merely > simulate them? Are there any languages that don't have closures? Those languages listed there don't have closures. They don't even have first-class functions. Imagine what the h3 and h5 examples from above would do in those languages. To be fair, there's an argument that closures are un-Pythonic: you can use class instances instead. You could say: class G: def __init__(self, n): self.x = n def __call__(self): return self.x h3 = G(3) h5 = G(5) and h3() prints 3 and h5() prints 5, just like the corresponding closures. But now you've polluted the name space with this extra class G, and (depending on the situation) maybe you've written more cumbersome code. It's partly a matter of taste and preferences. To Lisp and Scheme users, closures are very natural. To OOP programmers, maybe they're confusing and unnecessary. From nephish at xit.net Tue Oct 25 17:11:32 2005 From: nephish at xit.net (nephish at xit.net) Date: 25 Oct 2005 14:11:32 -0700 Subject: need some advice on x y plot In-Reply-To: <1130267203.357225.180410@g14g2000cwa.googlegroups.com> References: <1129823043.104864.73750@f14g2000cwb.googlegroups.com> <1130253519.330211.92880@o13g2000cwo.googlegroups.com> <1130267203.357225.180410@g14g2000cwa.googlegroups.com> Message-ID: <1130274692.380890.24220@f14g2000cwb.googlegroups.com> WE DID IT ! little more tinkering and correcting this diff = start_time - end_time (vrs the other way around) and its working. so many thanks gents, a lot ! From steve at REMOVETHIScyber.com.au Sun Oct 16 12:13:49 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 17 Oct 2005 02:13:49 +1000 Subject: subtle side effect of generator/generator expression References: <1129470158.623786.135010@g14g2000cwa.googlegroups.com> Message-ID: On Sun, 16 Oct 2005 15:52:54 +0200, Fredrik Lundh wrote: > bonono at gmail.com wrote: > >> I initially thought that generator/generator expression is cool (sort of >> like the lazy evaluation in Haskell) until I notice this side effect. >> >> >>>a=(x for x in range(2)) >> >>>list(a) >> [1,2] >> >>>list(a) >> [] >> >> Would this make generator/generator expression's usage pretty limited ? > > nope. In fairness, it is a pretty big Gotcha. >> As when the program/system goes beyond a single module, this behaviour >> can cause subtle bugs ? > > sure, in the same way as > > >>> f = open(filename) > >>> f.read() > 'hello world\n' > >>> f.read() # oops! > '' > > causes subtle bugs (that is, almost never) Are you saying that the bugs it causes aren't subtle? *wink* -- Steven From sybrenUSE at YOURthirdtower.com.imagination Tue Oct 11 02:40:10 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Tue, 11 Oct 2005 08:40:10 +0200 Subject: Let My Terminal Go References: <1129010288.251817.147690@z14g2000cwz.googlegroups.com> Message-ID: mystilleef at gmail.com enlightened us with: > When gVim is launched from a shell terminal, it completely frees the > terminal. [...] How do I implement this in my application written in > python? Using fork() and by catching the HUP signal. 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 Oct 21 00:16:05 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 21 Oct 2005 00:16:05 -0400 Subject: fun with lambdas References: Message-ID: <86sluvtshm.fsf@bhuda.mired.org> Robert Kern writes: > Juan Pablo Romero wrote: >> Hello! >> >> given the definition >> >> def f(a,b): return a+b >> >> With this code: >> >> fs = [ lambda x: f(x,o) for o in [0,1,2]] >> >> or this >> >> fs = [] >> for o in [0,1,2]: >> fs.append( lambda x: f(x,o) ) >> >> I'd expect that fs contains partial evaluated functions, i.e. >> >> fs[0](0) == 0 >> fs[1](0) == 1 >> fs[2](0) == 2 >> >> But this is not the case :( >> >> What is happening here? > > Namespaces. The functions are looking up o at runtime. In both cases, o > is bound to the last object in [0,1,2] once the iteration is finished. > > Try this (although I'm sure there are better ways): > > In [4]: fs = [lambda x, o=o: f(x, o) for o in [0,1,2]] > > In [5]: fs[0](0) > Out[5]: 0 > > In [6]: fs[0](1) > Out[6]: 1 > > In [7]: fs[0](2) > Out[7]: 2 Right explanation. Right solution. Wrong examples. He wanted to see: >>> fs[0](0) 0 >>> fs[1](0) 1 >>> fs[2](0) 2 >>> List comprehensions were purposely designed to mimic for loops, which (unlike other languages) don't create a new variable for each pass through the loop. ((They also "leak" the variable to the surrounding namespace.) So you need to capture the current value of the loop index somewhere. An alternative (and maybe slightly cleaner) method is: >>> def makef(a): ... return lambda b: a + b ... >>> fs = [makef(o) for o in [0, 1, 2]] >>> fs[0](0) 0 >>> fs[1](0) 1 >>> fs[2](0) 2 >>> Generator comprehensions have the same issue: >>> fs = list(lambda x: f(o, x) for o in [0, 1, 2]) >>> fs[0](0) 2 >>> fs[1](0) 2 >>> fs[2](0) 2 >>> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From iddw at hotmail.com Wed Oct 12 18:02:23 2005 From: iddw at hotmail.com (Dave Hansen) Date: Wed, 12 Oct 2005 22:02:23 GMT Subject: Jargons of Info Tech industry References: <1124804082_1011@spool6-east.superfeed.net> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <5hrik11q3p5ugcjm4hmmgqgq20o8fdrhr9@4ax.com> <7x4q7q2yer.fsf@ruckus.brouhaha.com> <8q0rk1tiktr86ksdu55mgsqffpkf2uus1c@4ax.com> Message-ID: <1129154547.6d0f3b178a128cc5f647dc0e128bc180@teranews> On Wed, 12 Oct 2005 21:44:22 GMT, Roedy Green wrote: [...] >Obviously you can't trust anything code-like that arrives from >strangers. It is an extension of the law Mommy laid down not to take >candy from strangers. > >However, formatted text is not code. Pictures are not code. It is >unfair to tar them with the brush of JavaScript or the goofy things >Outlook does with enclosures. http://www.microsoft.com/technet/security/bulletin/MS04-028.mspx Summary: a buffer overflow problem in Microsoft's JPEG redering library, used my almost all Windoze email and web clients, would allow an attacker to execute any arbitrary code he wished on your computer simply by tricking you into viewing a doctored JPEG image. Since solved (this problem is _so_ last year, dahling), but it belies your assertion that "pictures are not code." Regards, -=Dave -- Change is inevitable, progress is not. From roy at panix.com Fri Oct 7 08:16:12 2005 From: roy at panix.com (Roy Smith) Date: Fri, 07 Oct 2005 08:16:12 -0400 Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <3qi8erFf252rU1@uni-berlin.de> <3qkdbrFfgga9U1@uni-berlin.de> <3qkn7qFffkl6U1@uni-berlin.de> <3qkr1hFfgj5uU1@uni-berlin.de> <7xr7ax690j.fsf@ruckus.brouhaha.com> <434651f4$0$11145$626a14ce@news.free.fr> <7xwtkp8rwy.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > What this is about (to me at least) is the edit-debug cycle. Let's > say I write some Python code, using assert to validate datatypes. > Maybe I've made 4 errors. I then write a test function and run it. > Boom, the first assert fails. I fix the first error, run again. > Boom, the next assert fails. Fix the next error, run again, boom, > fix, etc. Four edit-debug cycles. > > With static typing, I run the compiler, get 4 error messages, fix all > 4, and can get on with the next phase of testing with three fewer edit > cycles. That's certainly the plan, but my experience is that it's not the whole story, for a few reasons. 1) I can often run 4 Python edit-debug cycles in the time it takes me to run a single C++ cycle, especially if there's a whole pile of build system gunk layered on top of the raw compile step. 2) When I get a bunch of compile errors, I know that many of them are just cascaded from a single problem. Thus, I tend to fix the first one and only take a quick look at all the others. If it's obvious what the problem is, I'll fix it, but as often as not, I'll just recompile and see what pops out the next time. 3) Many times, I'll spend more time making the compiler happy than the protection it affords me is worth. C++ is such a complex language, it's really hard to write a compiler which follows every detail of the spec, and the details are what kills you. We had a case the other day where a const_cast of a reference returned by a function worked just fine on Solaris, but failed on HPUX. We ended up with three guys digging through reference manuals trying to figure out how const_cast and references are supposed to interact. We ended up deciding what we were doing was legal, but we still had to devise a work-around so it compiled on all platforms. It's actually a little more complex than that, because we don't even write raw const_cast's, we use a CONST_CAST macro to work around older compilers that don't support modern casting, so we burned a little more time double-checking that our macro expansion wasn't at fault. We could have done a lot of Python edit-debug cycles in the time it took to sort that one out. From my_email_is_posted_on_my_website at munged.invalid Thu Oct 27 08:19:36 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Thu, 27 Oct 2005 12:19:36 GMT Subject: Microsoft Hatred FAQ References: <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> Message-ID: On Thu, 27 Oct 2005 04:06:16 -0700, "David Schwartz" wrote, quoted or indirectly quoted someone who said : > Well shit, how surprising that they wouldn't want to do business with >you if you broke your agreements with them. You could have a more productive debate with a talking coke machine than you. -- Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching. From g.franzkowiak at onlinehome.de Sun Oct 2 17:41:54 2005 From: g.franzkowiak at onlinehome.de (g.franzkowiak) Date: Sun, 02 Oct 2005 23:41:54 +0200 Subject: struct.unpack In-Reply-To: References: Message-ID: Fredrik Lundh schrieb: > "g.franzkowiak" wrote: > > >>I've read a pipe and store it in a object. >>My next step was the separation from 4 bytes with >>obj = string.join(list(dataObject)[:4] ==> '\x16 \x00 \x00 \x00' >>and the converting by >>value = struct.unpack('I', obj) generated the error >>"unpack str size does not match format" >> >>Unfortunately is len(obj) 7, but integer lengt 4. >>Why 7 ? > > > because string.join inserts a space between the bytes, by default (as > your example shows) > > if you really need that join(list) thing (it's not clear how you read it, but > I find it a bit hard to believe that you've managed to read it into some- > thing that's supported by list but not unpack), you can do > > obj = string.join(list(dataObject)[:4], "") > > or > > obj = "".join(list(dataObject[:4])) > > or some variation thereof. > > > > > I've also found the problem with som tests. The best of this was: tmpList = list(dataObject)[:4]) obj = tmpList[0]+tmpList[1]+tmpList[2]+tmpList[3]. But your suggestions are much better and new for me - both. Thanks gerd From bart.lateur at pandora.be Sat Oct 1 09:08:05 2005 From: bart.lateur at pandora.be (Bart Lateur) Date: Sat, 01 Oct 2005 13:08:05 GMT Subject: OT: Phases of the moon [was Re: A Moronicity of Guido van Rossum] References: <1128003857.930444.47650@g14g2000cwa.googlegroups.com> <1128013745.763757.144280@g44g2000cwa.googlegroups.com> <1128015868.201617.153240@g14g2000cwa.googlegroups.com> <0001HW.BF63479501083049F0407550@news.individual.de> Message-ID: Steven D'Aprano wrote: >A skeptical policeman who says he doesn't actually believe the moon >affects behaviour nevertheless reports that "last weekend" things were >really crazy, and it was a full moon. Somebody writes in to correct him: >no, the full moon is actually "tomorrow". As a similar example: I've been told by various women independently, that "there are more babies born near a full moon." So... is there a correlation between insanity and babies being born? :) -- Bart. From mynewsa at gmail.com Thu Oct 20 16:16:40 2005 From: mynewsa at gmail.com (Amol Vaidya) Date: Thu, 20 Oct 2005 20:16:40 GMT Subject: Python vs Ruby References: Message-ID: Thank you for all the great information and links! I think I will do what a lot of you reccomended and try both for myself, the only problem is finding time with homework, college applications, and SATs coming up. I'll let you know how it turns out. Again, thank you all for the help. From frithiof.jensen at die_spammer_die.ericsson.com Tue Oct 4 05:57:45 2005 From: frithiof.jensen at die_spammer_die.ericsson.com (Frithiof Andreas Jensen) Date: Tue, 4 Oct 2005 11:57:45 +0200 Subject: "no variable or argument declarations are necessary." References: <43412d69$0$11141$626a14ce@news.free.fr> Message-ID: "bruno modulix" wrote in message news:43412d69$0$11141$626a14ce at news.free.fr... > James A. Donald wrote: > > I am contemplating getting into Python, which is used by engineers I > > admire - google and Bram Cohen, but was horrified > > "horrified" ??? > > Ok, so I'll give you more reasons to be 'horrified': > - no private/protected/public access restriction - it's just a matter of > conventions ('_myvar' -> protected, '__myvar' -> private) > - no constants (here again just a convention : a name in all uppercase > is considered a constant - but nothing will prevent anyone to modify it) > - possibility to add/delete attributes to an object at runtime > - possibility to modify a class at runtime > - possibility to change the class of an object at runtime > - possibility to rebind a function name at runtime > .... > > If you find all this horrifying too, then hi-level dynamic languages are > not for you !-) Not to mention that since the O.P. seem to assume that the compiler will protect against deliberate subversion by evil programmers then he must be further "horrified" to learn that, although it is harder to do the above in f.ex. C++, it is not at all impossible, a carefully crafted pointer or a little devious sub-classing goes a long way. If all else fails, The humble Linker holds the Word of Power! Tampering with linking is both the easiest way to subvert code reviews, language checks and boundaries and also the hardest to discover because the tampering will be buried somewhere deep inside the build process, the part that never, ever gets reviewed because it is automated anyway and too complex entirely so nobody sane will actually mess with it once it "works" i.e. produces runnable code!. Finally, given proper permissions, one can of course re-link the binary executable, should the occasion merit. Like when one needs HIP in Telnet which is an absolute b****rd to build on a modern Linux box. (Somebody build that *once* in maybe 1978, I think ;-) One can replace classes in Jar archives too - possibly one can even get the Java runtime to load the "new version" of a jar archive in preference to the shipped one ... I.O.W: Superficially, the compile-time checks of Java and C++ provides some checks & boundaries but it comes at the expense of much more machinery with many more intricate movable parts than *also* can be interfered with (or broken). Python is simple and self-contained, thus it is pretty obvious - or at least not too difficult, to check what *actually* goes on with an application. If there is no trust, nothing can be done safely. If there is trust, then most of the percieved safety just get in the way of work. From brakjoller at gmail.com Sat Oct 22 10:21:51 2005 From: brakjoller at gmail.com (Mathias Dahl) Date: Sat, 22 Oct 2005 16:21:51 +0200 Subject: Listening for keypress in the background References: Message-ID: Peter Hansen writes: >> How can I make it listen for a certain keypress (say, Windows-key + >> space) in a controlled fashion even when it is not the program having >> focus? >> >> I need to do this running under GNOME in Mandrake GN/Linux 10. > > Search Google for "python keylogger". Thanks, good idea! The relevant pages I found only link to Windows-specific keyloggers though. I just got another idea on a solution for my main problem (invoking my sleeping app) and that would be to let my window manager execute a small "invoker" program that would communicate with the sleeping app. The question is, which is the easiest way to communicate with a running Python program? Signals? TCP/IP (not really, right?) Pipes? From raims at dot.com Thu Oct 27 10:29:41 2005 From: raims at dot.com (Lawrence Oluyede) Date: Thu, 27 Oct 2005 16:29:41 +0200 Subject: Python vs Ruby References: Message-ID: Il 2005-10-27, Andy Leszczynski ha scritto: > How Ruby solves the problem of global interpreter lock? AFAIK Ruby does not have those kind of problems, it does not have "real" threads but it emulates them via software -- Lawrence http://www.oluyede.org/blog From piet at cs.uu.nl Tue Oct 4 05:51:33 2005 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 04 Oct 2005 11:51:33 +0200 Subject: question about smtplib References: <1128366567.887891.267520@g43g2000cwa.googlegroups.com> <1128380307.865252.289510@f14g2000cwb.googlegroups.com> <1494k1pvqvo9lg21q8bhi9qrgmc2ftl5kn@4ax.com> Message-ID: >>>>> Tim Roberts (TR) wrote: >TR> nephish at xit.net wrote: >>> cool. so this line >>> server = smtplib.SMTP(localhost) >>> is when i connect ? >TR> Use the source, Luke. Source code for every standard module is included on >TR> your hard disk. If you look in the __init__ for "class SMTP", your >TR> question will be answered. The documentation should be the ultimate reference for the API. The source is just implementation detail which may change in the future. -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From larry.bates at websafe.com Mon Oct 3 15:06:46 2005 From: larry.bates at websafe.com (Larry Bates) Date: Mon, 03 Oct 2005 14:06:46 -0500 Subject: Graphical debugger/code explorer In-Reply-To: References: Message-ID: Eclipse - http://www.eclipse.org/ http://wiki.python.org/moin/EclipsePythonIntegration Florian Lindner wrote: > Hello, > in order to understand python code from a larger project (Zope 3) I'm > looking for a tool that helps me with that. It should also help > What (graphical) application running on Linux can you recommend? > > Thanks, > > Florian From jmdeschamps at cvm.qc.ca Wed Oct 26 15:52:46 2005 From: jmdeschamps at cvm.qc.ca (jean-marc) Date: 26 Oct 2005 12:52:46 -0700 Subject: textwidget.tag_bind("name", "", self.donothing) not working In-Reply-To: <1130266889.246361.268610@g47g2000cwa.googlegroups.com> References: <1130266889.246361.268610@g47g2000cwa.googlegroups.com> Message-ID: <1130356366.749611.148240@g14g2000cwa.googlegroups.com> but you don't want to use the state=DISABLED option because it gray's out the field showing people that it is not available for editing, right? From natanvivo at gmail.com Mon Oct 17 07:07:21 2005 From: natanvivo at gmail.com (Natan) Date: 17 Oct 2005 04:07:21 -0700 Subject: Run process with timeout Message-ID: <1129547240.998935.126970@g14g2000cwa.googlegroups.com> Hi. I have a python script under linux where I poll many hundreds of interfaces with mrtg every 5 minutes. Today I create some threads and use os.system(command) to run the process, but some of them just hang. I would like to terminate the process after 15 seconds if it doesn't finish, but os.system() doesn't have any timeout parameter. Can anyone help me on what can I use to do this? Thank you From ajikoe at gmail.com Wed Oct 5 03:10:12 2005 From: ajikoe at gmail.com (ajikoe at gmail.com) Date: 5 Oct 2005 00:10:12 -0700 Subject: While and If messing up my program? In-Reply-To: References: Message-ID: <1128496212.482205.8380@g14g2000cwa.googlegroups.com> hi, to get howmany element list appear you can code: ttllst=[4,3,45,3] for x in ttllst: print x, ttllst.count(x) pass to get non duplicate element list you can code: ttllst=[4,3,45,3] print list(set(ttllst)) Cheers, pujo From eurleif at ecritters.biz Wed Oct 19 18:05:23 2005 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Wed, 19 Oct 2005 22:05:23 GMT Subject: Converting 2bit hex representation to integer ? In-Reply-To: <4356703e$0$41144$14726298@news.sunsite.dk> References: <4356703e$0$41144$14726298@news.sunsite.dk> Message-ID: Madhusudan Singh wrote: > I am using binascii.b2a_hex to convert some binary data to hex. The > result is a two bit hex representation (i. e., without the leading > 0x). Surely you mean two-byte? > How do I convert the resulting two bit representation into an integer > ? int(foo, 16) From davids at webmaster.com Mon Oct 24 16:02:20 2005 From: davids at webmaster.com (David Schwartz) Date: Mon, 24 Oct 2005 13:02:20 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <86k6g59ke6.fsf@bhuda.mired.org> <5y47f.174197$RW.59989@fe2.news.blueyonder.co.uk> Message-ID: wrote in message news:5y47f.174197$RW.59989 at fe2.news.blueyonder.co.uk... > In comp.lang.perl.misc David Schwartz wrote: > >> This is about whether we're talking *ABOUT* America, you idiot. It's >> as >> if he said the press has no freedom, and I replied, "if you want to talk >> about some country where that's true, fine, but this discussion presumed >> America as the basis". > >> Remember, he is the one who said the government owned the economy. >> That >> may be true in some countries, but it's simply *FALSE* in this country. >> Our >> government has limited powers and ownership of the economy is not one of >> them. > I see that you cannot make a reasoned argument against the fact that > property in the form of houses is taxed in America. What does that have to do with anything? Look, this isn't a politics or an economy newsgroup. I don't have to make rigorously valid economic or political arguments. It's sufficient that they be valid with respect to the subject at hand. And you can watch people reply to me by saying, "yeah, well that isn't correct for Afghanistan". Well, guess what, Microsoft isn't an Afghanistan company. > Also may I remind you that these newsgroups are international. So what? We are talking about a United States' company's actions with respect to United States laws. There is no reason to make this about philosophy, politics, law, international relations or any such things. If we did that, we would wind up on tangents (just like this one!) that have nothing whatsoever to do with Microsoft. Yes, in a discussion about Microsoft, I will make economic or political statements that aren't 100% valid in every possible imaginable case. But guess what? They'll be 100% valid for the case we're discussing. And you can watch all the replies about how my statement isn't true in every possible case. Well, guess what? I only care about one case. DS From zhu_dave at yahoo.com Sat Oct 8 00:06:14 2005 From: zhu_dave at yahoo.com (Dave) Date: Fri, 7 Oct 2005 21:06:14 -0700 (PDT) Subject: Python's Performance Message-ID: <20051008040614.47429.qmail@web30607.mail.mud.yahoo.com> Hello All, I would like to gather some information on Python's runtime performance. As far as I understand, it deals with a lot of string objects. Does it require a lot string processing during program execution? How does it handle such time-consuming operations? Is there a way to find out how many string operations (perhaps in the underlying system) ) it does during program execution? Thanks a lot for your help! --------------------------------- Yahoo! Music Unlimited - Access over 1 million songs. Try it free. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bronger at physik.rwth-aachen.de Fri Oct 21 04:48:24 2005 From: bronger at physik.rwth-aachen.de (Torsten Bronger) Date: Fri, 21 Oct 2005 10:48:24 +0200 Subject: Python vs Ruby References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> <1129883505.814349.306860@g44g2000cwa.googlegroups.com> Message-ID: <87sluvs1bb.fsf@wilson.rwth-aachen.de> Hall?chen! "Harald Armin Massa" writes: > Casey, > >> I have heard, but have not been able to verify that if a program is >> about >> 10,000 lines in C++ >> it is about >> 5,000 lines in Java >> and it is about >> 3,000 lines in Python (Ruby to?) > > BTW: it is normally only 50 lines in Perl. Not that you could read > it, though At least they could form a heart. Tsch?, Torsten. -- Torsten Bronger, aquisgrana, europa vetus ICQ 264-296-646 From davids at webmaster.com Thu Oct 27 03:48:25 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 00:48:25 -0700 Subject: Microsoft Hatred FAQ References: <3s6l8mFmj3fjU1@individual.net> <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> Message-ID: Roedy Green wrote: > On Thu, 27 Oct 2005 02:28:46 +0200, "Peter T. Breuer" > wrote, quoted or indirectly quoted someone who > said : >> I'm a bit curious about this. If I were a business person, I would >> simply have created two busineses (two accounts, etc.). One business >> sells only machines with MS on and pays the MS tax on all its >> machines. One business sells only machines without MS on and pays >> the MS tax on none of its machines. >> >> What's up with that? > Try the same thing to deal with a Mafia extortion racket. This is precisely my point. Your premise is that a gun is no different from a persuasive argument. You need this principle to justify responding to arguments you don't like with guns. I reject this premise at its roots. > We are not talking about legal agreements. We are talking junior Mafia > style enforcement. Can you cite any evidence of Microsoft actually using or threatening force? DS From steve at REMOVETHIScyber.com.au Fri Oct 7 08:24:49 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Fri, 07 Oct 2005 22:24:49 +1000 Subject: Python recipes: list mixin, improved timeit, etc References: Message-ID: On Thu, 06 Oct 2005 21:03:33 -0700, barnesc wrote: > I added some recipes to the Python Cookbook: > > - listmixin > > Use ListMixin to create custom list classes from a small subset of > list methods: > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440656 That looks great. Now, if only I understood mixins: what are they, and what they are for, and in particular, how they differ from mere subclassing. I've spent some time searching for a good definition on the web, but the main problem I've found is that most discussions on mixins assume you already know what they are. Those that don't are talking about Ruby or Lisp or some other language other than Python. I don't speak those languages, so their code examples don't make a lot of sense to me. Anyhoo, I've struggled on, but obviously I Just Don't Get It because using mixins looks like subclassing to me. Can anyone help me understand what's going on? Thanks, -- Steven. From http Sun Oct 2 23:03:28 2005 From: http (Paul Rubin) Date: 02 Oct 2005 20:03:28 -0700 Subject: Will python never intend to support private, protected and public? References: <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xll1gvk7w.fsf@ruckus.brouhaha.com> <1128001308.905398.321670@g44g2000cwa.googlegroups.com> <311b5ce105092908332c12164c@mail.gmail.com> <7xbr2btv84.fsf@ruckus.brouhaha.com> <7xy85fvxny.fsf@ruckus.brouhaha.com> <86vf0inlt3.fsf@bhuda.mired.org> <7xd5mq9ir9.fsf@ruckus.brouhaha.com> <86wtkym33t.fsf@bhuda.mired.org> <7xll1d7l2c.fsf@ruckus.brouhaha.com> <86slvlmdnv.fsf@bhuda.mired.org> <7xr7b3spri.fsf@ruckus.brouhaha.com> Message-ID: <7xd5mni9of.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > The philosophy of dynamic languages like Python is that the class designer > shouldn't be the only one who decides whether or not a particular variable > should be private or public. I don't see that as part of the philosophy of dynamic languages. For example, the Python language spec describes a way to reach the private variables of class instances (through name mangling) but not a way to get at the private variables of closures or generators (though you can still do that in CPython through some implementation-specific hacks). I don't think those implementation hacks are a deep philosophical consequence of anything, and Python would still be Python without them. I don't see why generator designers should be any different from class designers in your logic. Why is it so important for freedom-loving programmers to be able to mess with the private variables of instances but not of generators? How are they different? (Answer: They are not different. Both are unimportant.) > The class designer is assumed to know their class best, and therefore be > in a position to know what variables are dangerous or inconvenient to leak > and which are not. But the class user is the person who knows their own > needs best, and therefore best to know whether their needs are such that > they are willing to take that risk. Why do you think the designer and user are necessarily not the same person? Maybe an app writer wants to create some fault tolerance by implementing privilege separation inside an application. I mentioned in another post that I wrote a crypto class that does exactly that, by putting the crypto variables in a separate Python interpreter from the client, and communicating by RPC over sockets. I'm both the designer and the user, and I wanted to protect the data in some of the classes I wrote from code from possible misbehavior of other classes that I wrote. With private variables, I could do that in a single process with reasonable security and much less overhead. > Why should the class designer get a monopoly on deciding what the > class user can or cannot do? Um, because the designer wrote the code? If the designer chose an algorithm that's not to the user's liking, the user's only way to fix it is by modifying the code (and thereby becoming a co-designer). What's special about instance variables, that they should all be accessible from elsewhere in the program without modifying the code? > If you believe that the class designer should have the privilege of > prohibiting certain uses of the class, Not the class, just instances of the class in a running program. The user can always repurpose the class by modifying the code and making new instances of the modified class. > you will vote for private variables. If you believe that the class > users should have more freedom, you will vote against them. You're assuming some kind of conflict between the designer and the user. If the app is such that a conflict actually exists (e.g. the user is a possibly-hostile applet), then letting the designer enforce security is essential. If no conflict exists, then the designer and user (who might be the same person) can work out something to their satisfaction. > "Truly" private variables have an advantage of making the class > designer's life somewhat easier -- not much, but a little. But that > advantage comes at the cost of making the class user's life somewhat > harder -- not much, but a little -- by restricting what they can > do. Your private variable may be just what they need to solve some > problem you never even thought of. The right way to extend or override class method behavior is by subclassing or changing the implementation. This notion of reaching into the private variables of running instances is a violation of type safety and a silly hack. From fredrik at pythonware.com Tue Oct 4 01:52:11 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 4 Oct 2005 07:52:11 +0200 Subject: question about smtplib References: <1128366567.887891.267520@g43g2000cwa.googlegroups.com> <1128380307.865252.289510@f14g2000cwb.googlegroups.com> Message-ID: nephish at xit.net wrote: > cool. so this line > server = smtplib.SMTP(localhost) > is when i connect ? http://www.python.org/doc/lib/module-smtplib.html "If the optional host and port parameters are given, the SMTP connect() method is called with those parameters during initialization." "For normal use, you should only require the initialization/ connect, sendmail(), and quit() methods. An example is included below." From lasse at vkarlsen.no Thu Oct 27 09:23:12 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Thu, 27 Oct 2005 15:23:12 +0200 Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <1130417205.892409.230580@g14g2000cwa.googlegroups.com> Message-ID: David Schwartz wrote: > Lasse V?gs?ther Karlsen wrote: > > >>I would think that if I set up a shop and wanted to have the word >>"Microsoft" as part of the shop name, there would be some rules >>dictating what products I could and could not sell, yes. Wether those >>rules are set forth in a law somewhere or Microsoft set them forth >>themselves, I would find it hard to believe that the law would >>prohibit them from doing so. > > >>Otherwise I could set up a shop, call it "Microsoft Porsgrunn" and >>sell machines with only Linux installed. > > >>I think Microsoft would be allowed to say "No, you can't do that". > > > Burger King won't let you sell Whoppers or buy their burger patties > wholesale no matter what you want to call your store unless you take the > whole franchise deal. It's an all-or-nothing package. With very few limits, > companies do get to choose how their products are branded, marketed, and > sold. Yes, and that's not what Microsoft has ever done. There have always been lots of shops selling Microsoft merchandise without being a Microsoft franchise in the sense Burger King shops are. That's why I still say your comparison is a bad one. -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From http Thu Oct 13 17:50:16 2005 From: http (Paul Rubin) Date: 13 Oct 2005 14:50:16 -0700 Subject: Send password over TCP connection References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> <1128979760.251637.316480@o13g2000cwo.googlegroups.com> <1129033311.936104.140960@g14g2000cwa.googlegroups.com> <1129235140.938321.134990@g49g2000cwa.googlegroups.com> <7xfyr56szy.fsf@ruckus.brouhaha.com> <1129239949.955964.241500@g47g2000cwa.googlegroups.com> Message-ID: <7xoe5t6q93.fsf@ruckus.brouhaha.com> "dcrespo" writes: > > Can you say what your application is? That will help figure out > > how far you need to go to protect these passwords, and what > > alternatives might be possible. > > Sure, no problem (see this on fixed text): Well, I mean, what kind of data is it? Sports chat? Personal correspondence? Financial info like credit card numbers? Medical records? Military/diplomatic traffic? I'm asking how severe the security requirements are. > All ClientServers log in supplying only one hashed password. It is > hashedly stored in MasterServer. Why do you want to do that? All of them get compromised if the one password is compromised. What do you mean by "password"? If it's not something a user has to remember and type in, then I hope you mean a long random string rather than a password. I sort of remember your mentioning this though. > All this is sustented over a VPN. If the VPN is any good, it should authenticate all the peers in some reasonable way, so why do you need this password stuff at all? From apardon at forel.vub.ac.be Thu Oct 13 03:56:11 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 13 Oct 2005 07:56:11 GMT Subject: A Tree class, my $0.02 contribution to the python community. References: <1129132506.ab1e6295283286960cd21918db1ebac4@teranews> Message-ID: Op 2005-10-12, George Sakkis schreef : > "Antoon Pardon" wrote: >> Comments are welcome: >> >> http://www.pardon-sleeuwaegen.be/antoon/avltree.html > > How about adding two shortcut methods, nextkey(k) and prevkey(k), to return the next and previous > key respectively ? For instance nextkey would be equivalent to (untested): I'll file this as: I'll probably never need it, so I'm going to resist the temptation to add them now. If i find out I'm wrong, I can still do so later. > def nextkey(self, key): > iter = self[key:] > first = iter.next() > if key not in self: return first > else: return iter.next() I think the if statement can be replaced by: if not self.cmp(key, first) == 0: return first > Also for consistency, nextvalue(k), prevvalue(k), nextitem(k), previtem(k) would be reasonable > additions. > > And a question: what does step do if the keys are not integers since you restrict step to be integer > ? It skips keys/items/values. >>> radio = [ ... 'alfa', 'bravo', 'charlie', 'delta', 'echo', 'foxtrot', 'golf', 'hotel', 'india', ... 'juliet', 'kilo', 'lima', 'mike', 'november', 'oscar', 'papa', 'quebec', 'romeo', ... 'sierra', 'tango', 'uniform', 'victor', 'whiskey', 'x-ray', 'yankee', 'zulu' ] >>> >>> letters = 'abcdefghijklmnopqrstuvwxyz' >>> from avltree import Tree >>> t=Tree(zip(radio,letters)) >>> t.keys('choco',None,3) ['delta', 'golf', 'juliet', 'mike', 'papa', 'sierra', 'victor', 'yankee'] >>> t.values('bureau',None,4) ['c', 'g', 'k', 'o', 's', 'w'] What would you have in mind if step would have been a string here? -- Antoon Pardon From mwm at mired.org Thu Oct 27 21:24:03 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 27 Oct 2005 21:24:03 -0400 Subject: specify arbitrary library directory directly in code? References: <1130460222.700509.195130@g47g2000cwa.googlegroups.com> Message-ID: <864q72h1sc.fsf@bhuda.mired.org> scooterm at hotmail.com writes: > ### Initial Findings > After searching around a bit, it appears that python does not have a > built-in mechanism for specifying arbitrary directories as the first > place to look for module code. There are options that allow one to > specify alternate directories, but all these options require changes > to environment variables, or changes (or additions) to the files in > the standard package directories. > > But if you define 'built-in mechanism' meaning a change that only > requires modifying the code in 'faa_script.py' ... then there is > no 'built-in mechanism'. > > ### Question > Are the initial findings correct? If not, can you specify the code > (or the link to the documentation) that specifies how to do what I > am trying to do? If the initial findings are correct, are there any > alternative workarounds to allow faa_script.py to automatically > discover module code in specific sibling directories? No, the findings aren't correct. You can manipulate the search path directly. import sys sys.path.insert(0, "/directory/to/search") will cause future imports to search /directory/to/search before all other directories. Likewise, sys.append("/directory/to/search") will search it after other directories. Docs here: http://www.python.org/doc/2.2.3/tut/node8.html#SECTION008200000000000000000 http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From benji at benjiyork.com Fri Oct 7 13:54:38 2005 From: benji at benjiyork.com (Benji York) Date: Fri, 07 Oct 2005 13:54:38 -0400 Subject: Matching zero only once using RE In-Reply-To: <1128706522.319929.75310@g49g2000cwa.googlegroups.com> References: <1128706522.319929.75310@g49g2000cwa.googlegroups.com> Message-ID: <4346B65E.4040903@benjiyork.com> GregM wrote: > I am trying to see if a web page contains the exact text: > You have found 0 matches It is unclear to me why you're using a regex at all. If you want to find the *exact* text "You have found 0 matches" perhaps you should do something like this: if "You have found 0 matches" in pagetext: print 'yes' else: print 'no' -- Benji York From frithiof.jensen at die_spammer_die.ericsson.com Mon Oct 24 04:07:36 2005 From: frithiof.jensen at die_spammer_die.ericsson.com (Frithiof Andreas Jensen) Date: Mon, 24 Oct 2005 10:07:36 +0200 Subject: create user message for wxPython References: Message-ID: "James Hu" wrote in message news:mailman.2323.1129839922.509.python-list at python.org... Hi, > There are 2 wxPython application, A and B and need to exchange msg. I do not think that wx even has a mechanism for sending events between applications.? You need some other tool, like a socket, a named pibe, some windows specific event queue library (gack!), or maybe a toolkit like PYRO, SPREAD e.t.c. depending on your *reason* for needing this in the first place. I am partial to PYRO myself. ... and you do need an event loop in any case to map from: "remote event" <-> "message protocol" <-> "local event" ... at least that makes it easier to test than "raw" event's which are harder to control. From david at jotax.com Thu Oct 27 16:01:43 2005 From: david at jotax.com (David Poundall) Date: 27 Oct 2005 13:01:43 -0700 Subject: Counting Threads In-Reply-To: References: <1130435220.846203.86320@g44g2000cwa.googlegroups.com> <1130435796.917475.295830@g14g2000cwa.googlegroups.com> Message-ID: <1130443303.870376.119470@g49g2000cwa.googlegroups.com> >> But the count isn't doint what I expected. I was after a increment >> after every time the class was used ireespective of instance. >I have no idea what that last sentence above means... On re-reading it - neither do I. Sorry about that. What I meant to say was that I was after an increment in the count variable (the class attribute) not an increment only within the class instances. Because the variable was being set to zero every time the class was instantiated I wasn't getting the true usage count. > ServerThreads.GlobalThreadCount = 0 That was what the syntax I was missing. > You appear to know there is a difference in spelling between these two > "demons"... but only "daemon" is correct. "Deamon" is a misspelling. That one certainly slipped under the radar. >You would want to wrap it with a threading.Lock() to > protect it in that case. Will do. > But, again, using a global at all is wrong anyway I posted using this sytax as it was nearly working - but I knew there was a serious clanger in the code and you pointed it out when you identified it was the class attribute syntax I was after. Peter, thank you for taking the time to unpick my code. It's much apreciated. I have only been coding with Python for the past couple of weeks and switching my brain to work with Python classes has been a bit of a challenge. I wil re-read the document section on style tips before I get too far into my app, as I would really like to be able to code in a Pythonesque fashion. David. From mde at micah.elliott.name Wed Oct 5 14:15:31 2005 From: mde at micah.elliott.name (Micah Elliott) Date: Wed, 5 Oct 2005 11:15:31 -0700 Subject: Extending Python In-Reply-To: <1128533901.767470.279220@z14g2000cwz.googlegroups.com> References: <1128533901.767470.279220@z14g2000cwz.googlegroups.com> Message-ID: <20051005181531.GE32363@kitchen.client.attbi.com> On Oct 05, Tuvas wrote: > I am looking for a good tutorial on how to extend python with C > code. I have an application built in C that I need to be able to use > in Python. I have searched through various sources, starting of > course with the Python site itself, and others, but I felt a bit > lacking from the Python site, it seems it was only made for those > who installed the source distribution, as for the other people... > Anyways, thanks for the help! I have no experience with this, but I see that Alex Martelli's "Python In A Nutshell" has quite a few pages on the subject. -- Micah Elliott From jarrod.roberson at gmail.com Tue Oct 25 17:32:19 2005 From: jarrod.roberson at gmail.com (fuzzylollipop) Date: 25 Oct 2005 14:32:19 -0700 Subject: simple send only command line jabber client in python? Message-ID: <1130275939.113598.194000@z14g2000cwz.googlegroups.com> I want to be able to send jabber messages from an subversion post-commit hook script. All I need is a simple library to connect to a server and send a message. I looked at all the half-finished and overly complex projects and can't find anything that fits the bill. What I did find I can't get to work correctly, probably because everything is 2 years old and out of date. Any ideas? From http Mon Oct 10 08:54:49 2005 From: http (Paul Rubin) Date: 10 Oct 2005 05:54:49 -0700 Subject: socketServer questions References: <1128699247.9040.15.camel@athop1.ath.vt.edu> <7xll15paha.fsf@ruckus.brouhaha.com> <1128718708.7800.2.camel@athop1.ath.vt.edu> <7xoe61yoa2.fsf@ruckus.brouhaha.com> <1128774994.14078.2.camel@athop1.ath.vt.edu> <7xu0frogwj.fsf@ruckus.brouhaha.com> <1128948284.15030.7.camel@athop1.ath.vt.edu> Message-ID: <7x4q7po7l2.fsf@ruckus.brouhaha.com> rbt writes: > > I don't understand the question. HMAC requires that both ends share a > > secret key; does that help? > > That's what I don't get. If both sides have the key... how can it be > 'secret'? All one would have to do is look at the code on any of the > clients and they'd then know everything, right? Yes, clients have to keep the key secure. > > What do you mean by verification? > > I'm trying to keep script kiddies from tampering with a socket server. I > want the server to only load a valid or verified string into its log > database and to discard everything else. If the clients can keep a secret key secure, then use hmac. Note that if there's lots of clients, they shouldn't all use the same secret key. Instead, for client #i, let that client's key be something like hmac(your_big_secret, str(i)).digest() and the client would send #i as part of the string. You'd use #i to recompute the client's key and then use that derived key to verify the string. This is called "key derivation" or "key diversification". If an attacker gets hold of that client's key and starts hosing you, you can disable that key without affecting the other ones. (The client is issued only the derived key and never sees the big secret). > Strings could come to the socket server from anywhere on the Net from > any machine. This is outside my control. What is there to prevent a > knowledgeable person from finding the py code on a client computer, > understanding it and then being able to forge a string that the server > will accept? Yes, if you're concerned about insecure clients, you have a much more complex problem. But your x..z..y scheme is far worse than hmac. Once the attacker figures that out, there's no security at all. What is the actual application, if you can say? Depending on the environment and constraints, various approaches are possible. From hancock at anansispaceworks.com Mon Oct 17 18:22:25 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Mon, 17 Oct 2005 17:22:25 -0500 Subject: [PIL]: Question On Changing Colour In-Reply-To: <008001c5d030$79890e40$5b923652@Gavana> References: <008001c5d030$79890e40$5b923652@Gavana> Message-ID: <200510171722.25069.hancock@anansispaceworks.com> On Thursday 13 October 2005 02:58 pm, Andrea Gavana wrote: > # that is the old colour --> GREY > rgb_old = (0.7, 0.7, 0.7) > > So, no matter what colour I choose as a "new" colour, the Hue part of the new colour doesn't change in RGB. In other words, leaving the old value for "Saturation" and "Value" makes the presence of the "Hue" part useless. But why in the world does this happen? If a colour is defined by 3 values, changes in every single value should change the colour too... Turns out this is a bad example for the HSV transformation. The saturation of pure grey is 0, and the hue is undefined (which means it probably takes a default value, or is left wherever you set it -- it has no effect). So what happens is that an HSV hue change leaves pure grays untouched. The RGB to HSV coordinate transform is going from a 3D cartesian system to a *cylindrical* coordinate system, where the long axis of the cylinder is "value", the radius is "saturation", and the angle is "hue". your neutral gray is going to be about 0.7 up the "value" axis, but with no saturation, the hue makes no difference in the outcome. The transformation I suggested was rotating the HSV system about the axis, by substituting the hue. So, if you had, for example, a bright red, you'd get a bright blue, instead (because we got the hue from "process blue" / rgb=(0,0,1)). But gray stays gray. > Ah, thanks God for the existence of RGB ;-) Well, it may be that the hue transform just isn't what you're looking for. We could also preserve only the value, forcing saturation to 1 and hue to the specified hue: >>> hsv_new = (hue_tgt, 1.0, hsv_old[2]) >>> rgb_new = hsv_to_rgb(*hsv_new) >>> rgb_new (0.0, 0.0, 0.69999999999999996) (You might get a more aesthetically pleasing outcome with a less pure color, by setting the saturation lower). Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From aleaxit at yahoo.com Tue Oct 18 07:18:54 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 18 Oct 2005 13:18:54 +0200 Subject: Question on class member in python References: <1129537638.714752.120290@g49g2000cwa.googlegroups.com> <1129624952.836150.159520@g44g2000cwa.googlegroups.com> <1h4mjkh.163t6yf4f20krN%aleaxit@yahoo.com> <1129630576.414181.276570@z14g2000cwz.googlegroups.com> Message-ID: <1h4mo01.lsbv3p6iysfgN%aleaxit@yahoo.com> Johnny Lee wrote: > Alex Martelli ??? Now that's a peculiar question... > > Johnny Lee wrote: > > > > > But I still wonder what's the difference between the A().getMember and > > > A().member besides the style > > > > Without parentheses after it, getMember is a method. The difference > > between a method object and an integer object (which is what member > > itself is in your example) are many indeed, so your question is very > > strange. You cannot call an integer, you cannot divide methods, etc. > > > > > > Alex > > Sorry, I didn't express myself clear to you. I mean: > b = A().getMember() > c = A().member > what's the difference between b and c? If they are the same, what's the > difference in the two way to get the value besides the style. If getMember's body is nothing but a 'return self.member', then there is no difference -- 'assert b is c'. What is the difference between: x = 2 and y = 2+2-2*2/2 ??? Answer: in terms of final results, no difference. On the other hand, the second approach does a lot of obviously useless and intricate computation, so it's a sheer waste of time and effort. Exactly the same answer applies to your question -- obtaining the .member attribute "indirectly", by calling a method that returns it, does some obviously useless and moderately intricate computation, which in some ways is a waste of (some) time and effort. That's all! Alex From csheppard91 at gmail.com Sun Oct 2 13:00:23 2005 From: csheppard91 at gmail.com (csheppard91 at gmail.com) Date: 2 Oct 2005 10:00:23 -0700 Subject: forum Message-ID: <1128272422.987128.295820@g43g2000cwa.googlegroups.com> Forum commuication is easier, and I've just started a new forum and would like to invite all of you to sign up and post there. I'm still looking for moderators and anyone who will help out. If you are intersted: www.wizardsolutionsusa.com -- follow the forum link. Remember it doesn't take but a minute of your time to sign up, so help me out! From fredrik at pythonware.com Tue Oct 4 14:44:10 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 4 Oct 2005 20:44:10 +0200 Subject: Newbie regular expression ? References: <1128450779.107011.5370@z14g2000cwz.googlegroups.com> Message-ID: "len" wrote: >I have the following statement and it works fine; > > list1 = glob.glob('*.dat') that's a glob pattern, not a regular expression. > however I now have an additional requirement the the string must begin > with any form of "UNQ,Unq,unq,..." list1 = glob.glob('*.dat') list1 = [file for file in list1 if file.lower().startswith("unq")] From steve at REMOVETHIScyber.com.au Wed Oct 5 08:53:11 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Wed, 05 Oct 2005 22:53:11 +1000 Subject: bug or feature? References: <1128508770.727391.313300@f14g2000cwb.googlegroups.com> Message-ID: On Wed, 05 Oct 2005 03:39:30 -0700, beza1e1 wrote: > Coming back from a bug hunt, i am not sure what to think of this python > behaviour. [snip code] > The point seems to be, that lst=[] creates a class attribute (correct > name?), which is shared by all instances of A. So a.lst ist the same > object as b.lst, despite the fact, that object a is different to object > b. Not a bug, but not really a feature as such, it is a side-effect of the way Python works. I guess that makes it a gotcha. Argument defaults are set at compile time. You set the argument default to a mutable object, an empty list. Every time you call the function, you are appending to the same list. This is not a problem if your argument default is a string, or a number, or None, since these are all immutable objects that can't be changed. I suppose someone might be able to come up with code that deliberately uses this feature for good use, but in general it is something you want to avoid. Instead of: def spam(obj, L=[]): L.append(obj) do this: def spam(obj, L=None): if L is None: L = [] L.append(obj) -- Steven. From nicopernetty at nowhere.fr Sun Oct 9 11:48:15 2005 From: nicopernetty at nowhere.fr (Nicolas Pernetty) Date: Sun, 9 Oct 2005 17:48:15 +0200 Subject: Continuous system simulation in Python References: <20051007011222.1aeab426@linuxcestcomplique.fr> <1128708054.819697.232950@o13g2000cwo.googlegroups.com> <20051007224533.08bde751@linuxcestcomplique.fr> <1128832565.028584.10590@z14g2000cwz.googlegroups.com> Message-ID: <20051009174815.1571392f@linuxcestcomplique.fr> Hello Phil, I'm currently looking to see if I can build upon SimPy, thus making it an hybrid system simulator. That would be a great step for the community. Main difficulty would be to build a framework which isn't clumsy, like you said. I have close to no experience in Python and object oriented development, but I'm fairly advanced in C and procedural development, and of course in continuous sytem simulator. I'll keep you informed of my investigations... I've downloaded your zip files, but unfortunately I have no access to Windows. Are you able to send me only the sources ? Thanks in advance, *********** REPLY SEPARATOR *********** On 8 Oct 2005 21:36:05 -0700, phil_nospam_schmidt at yahoo.com wrote : > Nicholas, > > I have a particular interest in this subject as well. I've also used > the Python/Scipy combination, and it is a tantalizing combination, but > I found it to be a bit more clumsy than I'd like. Plus, my need for > continuous-time simulation is not as great as it has been in the past. > > That said, I've been down this path before (see > http://custom.lab.unb.br/pub/asme/DYNAMICS/BUFORD1.zip), and I would > be interested in helping to develop something. I agree that Python > would be a great foundation to build upon. > From gsakkis at rutgers.edu Sun Oct 9 19:24:49 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: 9 Oct 2005 16:24:49 -0700 Subject: Python reliability In-Reply-To: References: Message-ID: <1128900289.144843.161060@g43g2000cwa.googlegroups.com> Steven D'Aprano wrote: > On Sun, 09 Oct 2005 23:00:04 +0300, Ville Voipio wrote: > > > I would need to make some high-reliability software > > running on Linux in an embedded system. Performance > > (or lack of it) is not an issue, reliability is. > > [snip] > > > The software should be running continously for > > practically forever (at least a year without a reboot). > > Is the Python interpreter (on Linux) stable and > > leak-free enough to achieve this? > > If performance is really not such an issue, would it really matter if you > periodically restarted Python? Starting Python takes a tiny amount of time: You must have missed or misinterpreted the "The software should be running continously for practically forever" part. The problem of restarting python is not the 200 msec lost but putting at stake reliability (e.g. for health monitoring devices, avionics, nuclear reactor controllers, etc.) and robustness (e.g. a computation that takes weeks of cpu time to complete is interrupted without the possibility to restart from the point it stopped). George From niels.ellegaard at gmail.com Mon Oct 10 06:17:51 2005 From: niels.ellegaard at gmail.com (Niels L Ellegaard) Date: 10 Oct 2005 03:17:51 -0700 Subject: Writing an xmgr/grace file as text (not interactive) Message-ID: <1128939471.025646.84050@g49g2000cwa.googlegroups.com> Can someone suggest a package that allows me to write a data file for xmgr. So far I have found some packages that allow me to start an interactive xmgrace session from python, but I would rather have a package that write a text file. I realize that xmgr can read text-files, and that the format of an xmgr-file is easy to read, but if someone has allready done this work then I would rather steal it and save my own time :) Thanks in advance Niels From duncan.booth at invalid.invalid Sat Oct 8 09:53:28 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 8 Oct 2005 13:53:28 GMT Subject: Function decorator that caches function results References: Message-ID: Lasse V?gs?ther Karlsen wrote: > However, this: > > for index in range(1, 101): > print index, fibonacci(idx = index) > > this one uses the kwargs list of arguments, and I'm not sure how to > change my function to take that into account. > > Does anyone have any clues as to how to do that? > > The solution would have to consider fibonacci(50) and fibonacci(idx = > 50) as the same call and thus retrieve the second one from the cache. > Most of your gain comes from caching the recursive calls, not from caching the original call. If the solution doesn't consider keyword arguments equivalent to positional arguments, it will make *one* call to the real function, and then the recursive call will still come out of the cache, so the net result will still be to give you almost all the speedup you wanted. Unless the results stored in the cache are very large data structures, I would suggest that you simply store (args,kwargs) as the cache key and accept the hit that sometime you'll cache the same call multiple times. From steve at holdenweb.com Fri Oct 14 00:25:11 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 14 Oct 2005 05:25:11 +0100 Subject: Python's garbage collection was Re: Python reliability In-Reply-To: <7xfyr5qdxh.fsf@ruckus.brouhaha.com> References: <3r6i0uFi3qb8U2@uni-berlin.de> <7xfyr5kfgm.fsf@ruckus.brouhaha.com> <3r6osdFhsfjgU1@uni-berlin.de> <7xvf0168nq.fsf@ruckus.brouhaha.com> <434e7967$1@nntp0.pdx.net> <7xr7apqw1y.fsf@ruckus.brouhaha.com> <434ea2ad$1@nntp0.pdx.net> <7x3bn5s1dm.fsf@ruckus.brouhaha.com> <3r83a5Fi1rt6U1@uni-berlin.de> <7xfyr5qdxh.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > "Diez B. Roggisch" writes: > >>>Yes, that would describe just about every cpu for the past 30 years >>>that's a plausible Python target. >> >>No. The later 68K (>68020) could address on odd adresses. And AFAIK >>all x86 can because of their 8080 stemming. > > > Yes, "could" but not "does" in terms of what any reasonable actual > compiler implmementations do. You get a huge performance hit for > using unaligned data. The one exception is you could conceivably have > character strings starting at odd addresses but it's no big deal to > start them all on 4-byte (or even 2-byte) boundaries. You made your original assertion in response to Diez saying >>And this presumes an architecture which byte-addresses and only >> uses "aligned" addresses. He was talking about the arachiteecture, for Pete's sake, not a compiler. I personally find it irritating that you continue to try and justify your assertions even when you are plainly on shaky ground, which tends to make the threads you are involved in endless. Sorry for the ad hominem remarks, which I normally try and avoid, but this (ab)uses newsgroup bandwidth unnecessarily. Unwillingness to admit any mistake can be rather unattractive. Can't you, just once, say "I was wrong"? Or are you perchance related to President Bush? Better still, just let these small things go without further comment. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From codecraig at gmail.com Tue Oct 11 15:35:17 2005 From: codecraig at gmail.com (Java and Swing) Date: 11 Oct 2005 12:35:17 -0700 Subject: Help creating extension for C function In-Reply-To: References: <1128714478.552412.135950@g47g2000cwa.googlegroups.com> <1129049460.649101.96890@g47g2000cwa.googlegroups.com> <1129056123.654224.18070@z14g2000cwz.googlegroups.com> <1129058051.426314.28670@g43g2000cwa.googlegroups.com> Message-ID: <1129059317.847237.215260@g14g2000cwa.googlegroups.com> Carsten..thanks so much...that was it! DUH! Carsten Haese wrote: > On Tue, 2005-10-11 at 15:14, Java and Swing wrote: > > Anyhow, I need PyBuildValue to work. > > Try Py_BuildValue. > > HTH, > > Carsten Haese. From deets at nospam.web.de Tue Oct 25 12:50:07 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 25 Oct 2005 18:50:07 +0200 Subject: Newbie question: string replace In-Reply-To: <1130258229.662596.228630@g49g2000cwa.googlegroups.com> References: <1130258229.662596.228630@g49g2000cwa.googlegroups.com> Message-ID: <3s7620FlqdmnU1@uni-berlin.de> usgog at yahoo.com wrote: > I have a config file with the following contents: > service A = { > params { > dir = "c:\test", > username = "test", > password = "test" > } > } > > I want to find username and replace the value with another value. I > don't know what the username value in advance though. How to do it in > python? Could be done using regular expressions. Ususally for such tasks one would prefer pythons string manipulation functions, but if you want to preserve whitespace, I think a rex is in order here: import re, sys new_name = "foobar" rex = re.compile(r'(^.*username *=[^"]*")([^"]*)(".*$)') for line in sys.stdin: m = rex.match(line) if m is not None: line = "%s%s%s\n" % (m.group(1), new_name, m.group(3)) sys.stdout.write(line) use with python script.py < config_in > config_out Regards, Diez From steve at holdenweb.com Sat Oct 22 09:45:32 2005 From: steve at holdenweb.com (Steve Holden) Date: Sat, 22 Oct 2005 14:45:32 +0100 Subject: python problems with dos lineendings in python-scripts In-Reply-To: <200510212137.41565.marco@morca.de> References: <200510212137.41565.marco@morca.de> Message-ID: marco wrote: > hi folks, > > i can not run any python scripts with dos lineendings under cygwin's python. > if i run such a scripts i get stupid syntax error messages from python. > > what can i do to run these scripts without changing the lineending of these scripts. > > regards marco > The only time line endings will make a difference is if there's a carriage return on the shebang line. If you run the script using python script.py you should find that you get no problems at all. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From rrr at ronadam.com Thu Oct 20 10:47:43 2005 From: rrr at ronadam.com (Ron Adam) Date: Thu, 20 Oct 2005 14:47:43 GMT Subject: destroy your self???? In-Reply-To: <1129797667.477066.170090@g43g2000cwa.googlegroups.com> References: <1129776816.148308.210460@g44g2000cwa.googlegroups.com> <1129797667.477066.170090@g43g2000cwa.googlegroups.com> Message-ID: James wrote: > Doesn't work for classes because self has no global reference. True. To make it work one would need to track instances and names and do comparisons... and so on. So it's not worth it. ;-) Cheers, Ron From grante at visi.com Tue Oct 4 17:42:12 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 04 Oct 2005 21:42:12 -0000 Subject: how to get any available port References: <1128456405.664869.170530@g47g2000cwa.googlegroups.com> <11k5pgpp19v0ec@corp.supernews.com> <7xbr25xbot.fsf@ruckus.brouhaha.com> <11k5qpiri213s59@corp.supernews.com> <7xslvhj7xq.fsf@ruckus.brouhaha.com> Message-ID: <11k5tpkffpf1567@corp.supernews.com> On 2005-10-04, Paul Rubin <> wrote: > Grant Edwards writes: >> > In the nomenclature of some of these applications, that kind >> > of transfer is called a client to client connection. Both >> > ends are called clients. >> >> IIRC, we were talking about TCP sockets. > So, there's a reasonable application for wanting to open a > listener port without binding any specific port number. Alice > would just ask her OS to assign her a port (say it assigns > 23789) and listen on it, instead of having to contend with > other apps on the same IP for some specific port number. Then > she'd send a message through the chat server asking Bob to > connect to port 23789 on her machine. Ah. Got it. > I'm not sure if there's a way to do this. Do you happen to > know? IIRC, you just call bind() with a port number of zero, and then use some method-or-other on the bound socket to find out what port it's bound to. -- Grant Edwards grante Yow! Life is a POPULARITY at CONTEST! I'm REFRESHINGLY visi.com CANDID!! From tdwdotnet at gmail.com Fri Oct 21 06:09:55 2005 From: tdwdotnet at gmail.com (Tim Williams (gmail)) Date: Fri, 21 Oct 2005 11:09:55 +0100 Subject: do cc list from smtplib In-Reply-To: <4358BBDE.3070902@holdenweb.com> References: <1129887280.469124.107340@g14g2000cwa.googlegroups.com> <9afea2ac0510210244q5373a840k@mail.gmail.com> <4358BBDE.3070902@holdenweb.com> Message-ID: <9afea2ac0510210309h46cd215cw@mail.gmail.com> On 21/10/05, Steve Holden wrote: > > Assuming that TO and CC are single addresses it would be saner to use: > :) Assuming that the envelope TOs (inc CCs) are the same as the Header-TOs and Header-CCs Actually, I think this would be safer ! > def email(HOST,FROM,TO,CC, RECIPS, SUBJECT,BODY): .. .. .. server.sendmail(FROM,RECIPS,body) RECIPS = list of SMTP recipients TO & CC = Text representation of some/all/none of the SMTP recipients and/or other text RECIPS should be either a single address as a string *or* a list containing 1 or more addresses From Dennis.Benzinger at gmx.net Tue Oct 25 11:05:36 2005 From: Dennis.Benzinger at gmx.net (Dennis Benzinger) Date: Tue, 25 Oct 2005 17:05:36 +0200 Subject: Documentation for iteration in mappings Message-ID: <435e49b8$1@news.uni-ulm.de> Hi! I must be blind because I didn't find anything in the documentation which says iterating over an dictionary iterates over its keys. For example a_dictionary = {0: "zero", 1: "one"} for x in a: print x gives you 0 1 Where is this information hidden? :) Bye, Dennis From scott.daniels at acm.org Fri Oct 28 12:03:20 2005 From: scott.daniels at acm.org (Scott David Daniels) Date: Fri, 28 Oct 2005 09:03:20 -0700 Subject: replace words In-Reply-To: References: <1130310159.632687.295020@g44g2000cwa.googlegroups.com> Message-ID: <43624aee$1@nntp0.pdx.net> Peter Otten wrote: > hagai26 at gmail.com wrote: > > >>What is the way for replacing in a string from . to . the sentence? >>for example: >>"been .taken. it may be .left. there, >>even if the .live coals were not. cleared" >>I want to do this-> replace(\.(.*)\.,\.start (1) end\.) >>result: >>"been .start taken end. it may be .start left end. there, >>even if the .start live coals were not end. cleared" > > > Use \1 to refer to the group in the substitution expression. > You also need to change the regex to non-greedy match (the trailing ?). > Otherwise you only get one big match from .taken ... not. > > import re > s = ("been .taken. it may be .left. there, " > "even if the .live coals were not. cleared") > > r = re.compile(r"\.(.*?)\.") > print r.sub(r".start \1 end.", s) > > Peter > Perhaps you can use a variant of: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/231347 def wrap(source, pre, post): gen = iter(source) for portion in gen: yield portion try: bracketed = gen.next() except StopIteration: break yield pre yield bracketed yield post def mangledots(string): return ''.join(wrap(string.split('.'), '.start ', ' end.')) print mangledots('been .taken. it may be .left. there, ' 'even if the .live coals were not. cleared') --Scott David Daniels scott.daniels at acm.org From alexs at advfn.com Tue Oct 18 08:25:53 2005 From: alexs at advfn.com (Alex Stapleton) Date: Tue, 18 Oct 2005 13:25:53 +0100 Subject: Hygenic Macros In-Reply-To: <51543672-464E-4C0D-8982-089C15821709@advfn.com> References: <51543672-464E-4C0D-8982-089C15821709@advfn.com> Message-ID: Ahar got it http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122 Would something like that be any use? On 18 Oct 2005, at 13:21, Alex Stapleton wrote: > I seem to remember a rather ugly hack at some point in the past that > created a new "operator" like so > > A |dot| B > > where dot was an object which had the OR operator for left and right > arguments redefined seperately so that it only made sense when used > in that syntax. > > I guess you could hack something together along the same lines. I > just wish I could remember what it was called, it's on the > ActiveState Cookbook somewhere. > > On 18 Oct 2005, at 13:17, Adriaan Renting wrote: > > >> Using numarray/pylab there's also dot: >> >> >>>>> from pylab import * >>>>> A = array(range(10)) >>>>> B = array(range(10)) >>>>> A * B >>>>> >>>>> >> [ 0, 1, 4, 9,16,25,36,49,64,81,] >> >> >>>>> dot(A, B) >>>>> >>>>> >> 285 >> >> It might also make your code more readable. I would like "A dot B", >> but even using ipython >> I can only get as close as "dot A, B" >> >> >> >>>>> Dan Farina 10/18/05 1:33 pm >>> >>>>> >>>>> >> David Pokorny wrote: >> >> >>> Hi, >>> >>> Just wondering if anyone has considered macros for Python. I have >>> one >>> good use case. In "R", the statistical programming language, you can >>> multiply matrices with A %*% B (A*B corresponds to pointwise >>> multiplication). In Python, I have to type >>> >>> import Numeric >>> matrixmultiply(A,B) >>> >>> which makes my code almost unreadable. >>> >>> Thanks, >>> David >>> >>> >> >> The problem here is that Python's parse trees are of non-trivial >> ugliness. >> >> A page on the compiler.ast module: >> http://docs.python.org/lib/node792.html >> >> it is, in fact, perfectly possible to write yourself a pre- >> processor for >> your particular application. You may have to fiddle with the token >> you >> want for notation depending on how the AST fleshes out (% is used >> by at >> least a couple of things, after all). My cursory familiarity with >> python grammar suggests to me that this particular choice of token >> could >> be a problem. >> >> I would say try it and see. Keep in mind though that since >> Python's AST >> is not a trivial matter like it is in Lisp and the like that doing >> metaprogramming of this sort probably falls into the category of >> black >> magic unless it turns out to be very trivial. >> >> Another option is to define your own tiny class that will override >> the >> __mult__ method so that you can simply do: >> >> A * B >> >> Which may not be what you want. >> >> df >> -- >> 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 apardon at forel.vub.ac.be Wed Oct 12 09:58:23 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 12 Oct 2005 13:58:23 GMT Subject: A Tree class, my $0.02 contribution to the python community. References: Message-ID: Op 2005-10-12, Steve Holden schreef : > Antoon Pardon wrote: >> Comments are welcome: >> >> http://www.pardon-sleeuwaegen.be/antoon/avltree.html > Does this type bear any relationship at all to what most people call a > tree, which is a bifurcated data structure? Or do you call it a tree for > some other reason? The underlying implementation is an AVL balanced binary tree with inorder threading. > Sounds like "cdict" might be a better name ... I don't know. The python dictionary type with its name, seem to refer to how it is implemented, so I thought Tree was an appropiate name here as it is implemented as a tree. -- Antoon Pardon From rbt at athop1.ath.vt.edu Mon Oct 10 08:44:44 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Mon, 10 Oct 2005 08:44:44 -0400 Subject: socketServer questions In-Reply-To: <7xu0frogwj.fsf@ruckus.brouhaha.com> References: <1128699247.9040.15.camel@athop1.ath.vt.edu> <7xll15paha.fsf@ruckus.brouhaha.com> <1128718708.7800.2.camel@athop1.ath.vt.edu> <7xoe61yoa2.fsf@ruckus.brouhaha.com> <1128774994.14078.2.camel@athop1.ath.vt.edu> <7xu0frogwj.fsf@ruckus.brouhaha.com> Message-ID: <1128948284.15030.7.camel@athop1.ath.vt.edu> On Sat, 2005-10-08 at 14:09 -0700, Paul Rubinhttp: wrote: > rbt writes: > > Off-topic here, but you've caused me to have a thought... Can hmac be > > used on untrusted clients? Clients that may fall into the wrong hands? > > How would one handle message verification when one cannot trust the > > client? What is there besides hmac? Thanks, rbt > > I don't understand the question. HMAC requires that both ends share a > secret key; does that help? That's what I don't get. If both sides have the key... how can it be 'secret'? All one would have to do is look at the code on any of the clients and they'd then know everything, right? > What do you mean by verification? I'm trying to keep script kiddies from tampering with a socket server. I want the server to only load a valid or verified string into its log database and to discard everything else. Strings could come to the socket server from anywhere on the Net from any machine. This is outside my control. What is there to prevent a knowledgeable person from finding the py code on a client computer, understanding it and then being able to forge a string that the server will accept? Does that make sense? From tuvas21 at gmail.com Wed Oct 19 16:18:14 2005 From: tuvas21 at gmail.com (Tuvas) Date: 19 Oct 2005 13:18:14 -0700 Subject: Extention Woes Message-ID: <1129753094.056781.319720@z14g2000cwz.googlegroups.com> I am in the process of writing an extention module, and am coming up with lots of problems. Perhaps someone could be of use. I keep getting data that isn't what I'm sending the program. Let me give the line of C code and Python Code and output to illistrate the problem. write_can(can_han,0x0140,'abcd') if (PyArg_ParseTuple(args("iiz#",&can_han,&com,&data,&len) return NULL; Okay, so I put in a print statement to print out the variables can_han, com, data, and length. The results were more or less this (I don't have copy/paste at the moment, so... 1357 com->0 len->4 str->,/p. Anways, the variable can_han was correct, the length is correct, but the com and the string are garbage. Any ideas as to why this may be? Thanks! From deets at nospam.web.de Thu Oct 6 10:35:27 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 06 Oct 2005 16:35:27 +0200 Subject: "no variable or argument declarations are necessary." In-Reply-To: References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <3qi8erFf252rU1@uni-berlin.de> <3qkdbrFfgga9U1@uni-berlin.de> <3qkn7qFffkl6U1@uni-berlin.de> Message-ID: <3qkr1hFfgj5uU1@uni-berlin.de> > Suppose we have a typesystem which has the type ANY, which would mean > such an object could be any type. You could then have homogenous lists > in the sense that all elements should be of the same declared type and > at the same time mix all kind of type in a particular list, just > as python does. The you have JAVA Object or C void*. Which cause all kinds of runtime troubles.... because they essentially circumvene the typechecking! > > So how would this limit python. The limitation is that in static languages I must _know_ what type to cast such an ANY, before calling anything on it. Otherwise its useless. >>even though ususally the contents of a list >>share some common behaviour. And that exactly is the key point here: in >>a statically typed world, that common behaviour must have been extracted >>and made explicit. > > > Would my suggestion be classified as a statically typed world? See above. > > >>Which is the cause for that notorious java io API. >>And, to extend the argument to ML-type type-checking, there you need a >>disjoint union of the possible types - _beforehand_, and the code >>dealing with it has to be aware of it. >> >>In python OTH, I just pass objects I like into the list - if they >>behave, fine. > > > But now we are no longer talking about how typechecking would limit > the language but about convenience for the user. That's dialectics. Limits in the language limit the user and make things inconvenient. Diez From codecraig at gmail.com Wed Oct 12 09:01:55 2005 From: codecraig at gmail.com (Java and Swing) Date: 12 Oct 2005 06:01:55 -0700 Subject: C Extension - return an array of longs or pointer? In-Reply-To: <1129121392_1305@spool6-east.superfeed.net> References: <1129117594.467541.164640@g14g2000cwa.googlegroups.com> <1129121392_1305@spool6-east.superfeed.net> Message-ID: <1129121397.404505.41070@g47g2000cwa.googlegroups.com> Interesting...thanks. Any good tutorials out there, other than the python doc for ext? thanks. Brandon K wrote: > All the veteran programmers out there can correct me, but the way I did > it in my extension was this: > > static PyObject *wrap_doNumberStuff(PyObject* self, PyObject* args) > { > char* in = 0; > char* x = 0; > long* result = 0; > int i = 0; > PyObject* py = PyTuple_New() > int ok = PyArg_ParseTuple(args,"ss",&in, &x); > if(!ok) return NULL; > > result = doNumberStuff(in,x): > len = sizeof(result)/sizeof(long) > for(i;i < len; i++) > PyTuple_SET_ITEM(py, i,Py_BuildValue("l",*result[i]) > } > > Simple enough idea...i'm not quite sure if I've done everything > correctly with the pointers, but I'm sure you can figure that out, the > algorithm is simple enough. > > > Hi, > > I have been posting about writing a C extension for Python...so far, > > so good. At least for the "simple" functions that I need to wrap. > > > > Ok, my c function looks like... > > > > MY_NUM *doNumberStuff(const char *in, const char *x) { ... } > > > > MY_NUM is defined as, typedef unsigned long MY_NUM; (not sure if that > > matters, or can i just create a wrapper which handles longs?) > > > > anyhow..for my wrapper I have this.. > > > > static PyObject *wrap_doNumberStuff(PyObject *self, PyObject args) { > > char *in = 0; > > char *x = 0; > > long *result = 0; > > int ok = PyArg_ParseTuple(args, "ss", &in, &x); > > if (!ok) return 0; > > > > result = doNumberStuff(in, x); > > > > return Py_BuildValue("l", result); > > } > > > > ...my question is...in the c code, result is a pointer to an array of > > longs, how can I get the returned result to be a list or something > > similar to an array in Python? > > > > ...I also have a function which returns a character array (denoted by a > > char *)...would it work the same as the previous question? > > > > Thanks!! > > > > > ----== Posted via Newsgroups.com - Usenet Access to over 100,000 Newsgroups ==---- > Get Anonymous, Uncensored, Access to West and East Coast Server Farms! > ----== Highest Retention and Completion Rates! HTTP://WWW.NEWSGROUPS.COM ==---- From spe.stani.be at gmail.com Thu Oct 20 15:38:04 2005 From: spe.stani.be at gmail.com (SPE - Stani's Python Editor) Date: 20 Oct 2005 12:38:04 -0700 Subject: Fund raising for SPE (Python IDE) on Mac Os X is great success!! Message-ID: <1129837084.074460.51840@f14g2000cwb.googlegroups.com> Hi, I'd like to thank everyone who contributed, especially Richard Brown from Dartware and Rick Thomas. I'm highly impressed that the smallest user base of SPE collected the largest donation ever to SPE. Now it's my turn to impress the SPE Mac users. As such the light is green for SPE on the Mac. First I will buy a Mac and get used to it. Then I will optimize SPE for the Mac and try to release simultaneously. Be patient as this will take some time. The next releases (0.7) will be based on work I did before. But from 0.8 releases SPE will also be tested & developed on Mac. Please subscribe to the mailing list as a developer, user and/or mac user. Of course donations are still welcome. Stani http://pythonide.stani.be http://pythonide.stani.be/manual/html/manual.html From usgog at yahoo.com Fri Oct 28 15:27:36 2005 From: usgog at yahoo.com (usgog at yahoo.com) Date: 28 Oct 2005 12:27:36 -0700 Subject: Newbie question: string replace In-Reply-To: <86slule9vy.fsf@bhuda.mired.org> References: <1130258229.662596.228630@g49g2000cwa.googlegroups.com> <3s7620FlqdmnU1@uni-berlin.de> <1130521026.584455.288370@g44g2000cwa.googlegroups.com> <86slule9vy.fsf@bhuda.mired.org> Message-ID: <1130527656.685340.235470@g44g2000cwa.googlegroups.com> hm...Is there a way to get rid of the newline in "print"? From steve at holdenweb.com Mon Oct 17 12:53:36 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 17 Oct 2005 17:53:36 +0100 Subject: List of strings to list of floats ? In-Reply-To: <4353d2a2$0$41138$14726298@news.sunsite.dk> References: <4351d29e$0$41148$14726298@news.sunsite.dk> <4353d2a2$0$41138$14726298@news.sunsite.dk> Message-ID: Madhusudan Singh wrote: > skip at pobox.com wrote: > > >> Madhusudan> Is it possible to convert a very long list of strings to a >> Madhusudan> list of floats in a single statement ? >> >> Madhusudan> I have tried float(x) and float(x[:]) but neither work. I >> Madhusudan> guess I would have to write a loop if there isn't a way. >> >>Try: >> >> >>> los = ["123.0", "2", "1e-6"] >> >>> map(float, los) >> [123.0, 2.0, 9.9999999999999995e-07] >> >>> [float(s) for s in los] >> [123.0, 2.0, 9.9999999999999995e-07] >> >>Skip > > > Thanks. Now, a slightly more complicated question. > > Say I have two lists of floats. And I wish to generate a list of floats that > is a user defined function of the two lists. > > I tried : > > def rpyth(x,y): > r=sqrt(pow(x,2.0)+pow(y,2.0)) > return r > > r1n=map(rpyth,x2n[1:len(x2n)-1],y2n[1:len(y2n)-1]) > > And I get an error complaining about floats. ... but the error message is a secret so you don't want to tell us what it was? It's more helpful if you actually copied and pasted the exact error traceback you see, as this avoids any potential answerer having to guess what went wrong. A brief description of what you were trying to do is also helpful, since it isn't obvious at first glance why you are omitting some of hte list elements. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From skip at pobox.com Mon Oct 10 11:27:14 2005 From: skip at pobox.com (skip at pobox.com) Date: Mon, 10 Oct 2005 10:27:14 -0500 Subject: Default argument to __init__ In-Reply-To: <1128955812.913224.150760@z14g2000cwz.googlegroups.com> References: <1128955812.913224.150760@z14g2000cwz.googlegroups.com> Message-ID: <17226.34898.484673.486203@montanaro.dyndns.org> vaibhav> Here's a piece of Python code and it's output. The output that vaibhav> Python shows is not as per my expectation. Hope someone can vaibhav> explain to me this behaviour: ... Yes, your default arg is evaluated once, at method definition time and shared betwee all instances of MyClass. See the thread last week on the same thing for more detail. Skip From Email_Gateway at kingswaygroup.com Fri Oct 28 02:33:45 2005 From: Email_Gateway at kingswaygroup.com (Email_Gateway at kingswaygroup.com) Date: Fri, 28 Oct 2005 08:33:45 +0200 (CEST) Subject: Virus found in a message you sent Message-ID: <20051028063345.5BA051E4002@bag.python.org> A virus was found in a message sent by this account. --- Scan information follows --- Result: Virus Detected Virus Name: W32.Mydoom.gen at mm File Attachment: document.ex_ Attachment Status: deleted --- Original message information follows --- From: python-list at python.org To: may.lau at kingswaygroup.com Date: Fri, 28 Oct 2005 14:26:47 -1200 Received: from python.org ([210.3.29.131]) by pop3.kingswaygroup.com (SAVSMTP 3.1.0.29) with SMTP id M2005102814334104824 for ; Fri, 28 Oct 2005 14:33:41 +0800 From adsheehan at eircom.net Mon Oct 24 06:31:25 2005 From: adsheehan at eircom.net (adsheehan at eircom.net) Date: 24 Oct 2005 03:31:25 -0700 Subject: Embedded Python - Sharing memory among scripts, threads In-Reply-To: <1129897094.417949.181120@g47g2000cwa.googlegroups.com> References: <1129897094.417949.181120@g47g2000cwa.googlegroups.com> Message-ID: <1130149885.504714.257230@g43g2000cwa.googlegroups.com> Any ideas? From alainpoint at yahoo.fr Fri Oct 7 15:07:56 2005 From: alainpoint at yahoo.fr (alainpoint at yahoo.fr) Date: 7 Oct 2005 12:07:56 -0700 Subject: Python interpreter bug In-Reply-To: References: <1128686833.994339.295780@f14g2000cwb.googlegroups.com> <1128692705.964188.5720@z14g2000cwz.googlegroups.com> <1128694071.902605.201440@o13g2000cwo.googlegroups.com> Message-ID: <1128712076.122513.18090@g43g2000cwa.googlegroups.com> > Steve Holden wrote: >Consider: >>> a = {1:'one'} >>> b = {2:'two'} >>> c = {1:'one'} >>> a is c False >>> a in [b, c] True >>> >What would you have Python do differently in these circumstances? You mean: What i would do i if i was the benevolent dictator ? I would make a distinction between mutables and immutables. Immutables would test for equality and mutables would test for identity. Membership testing for objects is a very common use case which is totally unrelated to their being sorted according to a key. I am no expert on languages so i could be wrong. Don't hesitate to correct me. Alain From jg.lists at sympatico.ca Tue Oct 11 12:53:43 2005 From: jg.lists at sympatico.ca (Jim Gallacher) Date: Tue, 11 Oct 2005 12:53:43 -0400 Subject: mod_python In-Reply-To: <1129016557.060339.136600@g49g2000cwa.googlegroups.com> References: <1129016557.060339.136600@g49g2000cwa.googlegroups.com> Message-ID: <434BEE17.2010708@sympatico.ca> Python_it wrote: > Today I was busy to install mod_python. > > I have put the line > > LoadModule python_module libexec/mod_python.so > > into the httpd.conf file. > It Works! > Apache load mod_python /3.2.2.b Python2.4 > > But my problem is where I have to place te following code in de > httpd.conf? > > > AddHandler mod_python .py > PythonHandler mptest > PythonDebug On > > > Because al the tutorials write this. But where? > > If I try to put the code some where, > apache give the following message by testing the configure: > Multiple arguments not (yet) supported > But what i have to change or replace. Your problem is not related to the location of the section. Apache doesn't like spaces in , so try quoting your path. Also, the Apache docs state that "forward slashes should always be used as the path separator in Apache, even for Windows". So try the following in your config file: . > I test with the next file: > > C:\Program Files\Apache Group\Apache2\htdocs\project\ > mptest.py > > from mod_python import apache > > def handler(req): > req.content_type = 'text/plain' > req.send_http_header() > req.write('mptest.py\n') > return apache.OK > > Is this code enough for testing? > Yes. You are more likely to get timely help on the mod_python mailing list. See http://www.modpython.org/ for subscription information. Personally I only read c.l.p when I'm looking for cheap entertainment. Some people on this list just crack me up. :) Regards, Jim From peter at engcorp.com Sat Oct 22 05:56:42 2005 From: peter at engcorp.com (Peter Hansen) Date: Sat, 22 Oct 2005 05:56:42 -0400 Subject: C replacement for Queue module In-Reply-To: <1129934643.874242.37150@g47g2000cwa.googlegroups.com> References: <1129934643.874242.37150@g47g2000cwa.googlegroups.com> Message-ID: Jonathan Ellis wrote: > I'm working on an application that makes heavy use of Queue objects in > a multithreaded environment. > > By "heavy" I mean "millions of calls to put and get, constituting ~20% > of the app's run time." The profiler thinks that a significant amount > of time is spent in this code -- not just a consumer waiting for a > producer, but actual _empty, notify calls, etc. I wonder if the use case would support hand-crafting an alternative. Queues appear fairly heavy weight (when you look at the implementation), and while they are very robust, if your own needs allow putting many items in at the same time, or getting many items out, for example, then perhaps you could come up with a much faster alternative based on the primitives (e.g. Event, Condition, etc) and perhaps some wrapped data structure other than the list that Queues use. -Peter From paul at boddie.org.uk Tue Oct 25 10:06:55 2005 From: paul at boddie.org.uk (Paul Boddie) Date: 25 Oct 2005 07:06:55 -0700 Subject: pyxpcom and firefox References: Message-ID: <1130249215.612363.36310@z14g2000cwz.googlegroups.com> Philippe C. Martin wrote: > I write this post here because I do not manage to get in touch with mozilla > dev people: [...] > 1) has anyone compiled/installed pyxpcom with firefox 1.5xx ? > 2) is there a plan to make it a .xpi (the pyxpcom xpi for mozilla does not > install into firefox). I can't answer these questions, unfortunately, but you may be better off asking them on the pyxpcom mailing list: http://listserv.activestate.com/mailman/listinfo/pyxpcom Paul From aleaxit at yahoo.com Sun Oct 23 22:12:11 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 23 Oct 2005 19:12:11 -0700 Subject: Tricky Areas in Python References: <1130097286.772836.94930@g44g2000cwa.googlegroups.com> <1h4wbvb.1dblc4317zeuw2N%aleaxit@yahoo.com> Message-ID: <1h4wfoz.q84tcv1tjyxxeN%aleaxit@yahoo.com> Andrew Durdin wrote: > On 10/24/05, Alex Martelli wrote: > > I may branch out into more advanced stuff such as asking > > for an example use case for a closure, a custom descriptor, or an import > > hook, for example > > Isn't that approaching things from the wrong angle? You're asking them > to synthesise a problem for a given solution, rather than analyse a > problem to determine an appropriate solution. Asking questions like > these tests memory more than competence -- for example, if you ask me > of a use case for a closure, the only answer I could give would be to > remember a problem I'd solved in the past using one. And why do you think that would be wrong? If you've used closures, you know what you've used them for, and (I would hope) why. If you've never used them, you're welcome to answer "I have no idea why anybody would wanna use THAT crazy thing for" (I always give points for honesty;-), or else try to bluff your way through (sorry, no points for chutzpah!-). I don't know of any issue that could be solved ONLY by a closure (we didn't have closures in 1.5.2 yet we made out excellently well anyhow;-), after all. The point is, does the candidate really understand closures (ideally by practical experience)? Within the limited confines of a less-than-an-hour interview (which is what we normally use -- several interviewers, but no more than about 45 minutes each, with different focus for each interviewer) I believe that asking for use cases is a perfectly good way to gauge if a candidate fully understands (ideally by experience) a certain language feature. It's not just Python, btw. When I'm asked to focus on C++ skills, I will similarly ask, e.g., what a use case would be for virtual inheritance, say. How ELSE would you gauge, within that very limited time-span, a candidate's grasp of some advanced language feechur?-) Alex From steve at REMOVETHIScyber.com.au Sat Oct 15 08:58:03 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sat, 15 Oct 2005 22:58:03 +1000 Subject: Comparing lists References: <1128930699.799657.146210@g47g2000cwa.googlegroups.com> <1128952417.0544cc73190bbbd4e683448c137969c8@teranews> <434ba977@nntp0.pdx.net> <1129216693.445956.155490@g47g2000cwa.googlegroups.com> Message-ID: On Sat, 15 Oct 2005 06:31:53 +0200, Christian Stapfer wrote: > "jon" wrote in message > news:1129216693.445956.155490 at g47g2000cwa.googlegroups.com... >> >> To take the heat out of the discussion: >> >> sets are blazingly fast. > > I'd prefer a (however) rough characterization > of computational complexity in terms of Big-Oh > (or Big-whatever) *anytime* to marketing-type > characterizations like this one... Oh how naive. The marketing department says: "It's O(N), so it is blindingly fast." Translation: the amount of computation it does is linearly proportional to N. The constant of proportionality is 1e10. The marketing department says: "Our competitor's product is O(N**2), so it runs like a three-legged dog." Translation: the amount of computation it does is linearly proportional to N squared. The constant of proportionality is 1e-100. You do the maths. Big O notation is practically useless for judging how fast a single algorithm will be, or how one algorithm compares to another. It is only useful for telling you how a single algorithm will scale as the input increases. It is very common for sensible programmers to fall back on a "less efficient" O(N**2) or even O(2**N) algorithm for small amounts of data, if that algorithm runs faster than the "more efficient" O(N) or O(log N) algorithm. In fact, that's exactly what the sort() method does in Python: for small enough lists, say, under 100 elements, it is quicker to run an O(N**2) algorithm (shell sort I believe) than it is to perform the complex set up for the merge-sort variant used for larger lists. As for sets, they are based on dicts, which are effectively hash tables. Hash tables are O(1), unless there are collisions, in which case the more common algorithms degenerate to O(N). So, a very rough and ready estimate of the complexity of the algorithm using sets would be somewhere between O(1) and O(N) depending on the details of Python's algorithms. So, let's do an experiment, shall we? from sets import Set import time def compare_and_separate_with_sets(A, B): AB = Set(A+B) A = Set(A) B = Set(B) only_A = list(A-B) only_B = list(B-A) both_AB = list(AB - Set(only_A+only_B)) return (only_A, only_B, both_AB) def timeit(f, args, n): """Time function f when called with *args. For timing purposes, does n calls of f. Returns the average time used per call in seconds. """ loopit = range(n) t = time.time() for i in loopit: results = f(*args) t = time.time() - t return t/n def single_test(N): print ("N = %-8d" % N), A = range(N) B = range(N/2, 3*N/2) return timeit(compare_and_separate_with_sets, (A, B), 20) def test_Order(): # test how compare_and_separate_with_sets scales with size for i in range(7): print single_test(10**i) Now run the test code: py> test_Order() N = 1 0.000219106674194 N = 10 0.000135183334351 N = 100 0.000481128692627 N = 1000 0.0173740386963 N = 10000 0.103679180145 N = 100000 0.655336141586 N = 1000000 8.12827801704 In my humble opinion, that's not bad behaviour. It looks O(log N) to me, and quite fast too: about 8 seconds to compare and separate two lists of one million items each. The craziest thing is, the amount of time it took to write and test two different algorithms was probably 1% of the time it would take to hunt up theoretical discussions of what the big O behaviour of the algorithms would be. -- Steven. From steve at REMOVETHIScyber.com.au Sun Oct 2 19:06:37 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 03 Oct 2005 09:06:37 +1000 Subject: Will python never intend to support private, protected and public? References: <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xll1gvk7w.fsf@ruckus.brouhaha.com> <1128001308.905398.321670@g44g2000cwa.googlegroups.com> <311b5ce105092908332c12164c@mail.gmail.com> <7xbr2btv84.fsf@ruckus.brouhaha.com> <7xy85fvxny.fsf@ruckus.brouhaha.com> <86vf0inlt3.fsf@bhuda.mired.org> <7xd5mq9ir9.fsf@ruckus.brouhaha.com> <86wtkym33t.fsf@bhuda.mired.org> <7xll1d7l2c.fsf@ruckus.brouhaha.com> <86slvlmdnv.fsf@bhuda.mired.org> <7xr7b3spri.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 02 Oct 2005 12:05:53 -0700, Paul Rubin wrote: > I just don't understand your point here. Yes, you can do all those > things and leak any variable. However, if you want to NOT leak some > particular variable, "private" lets you code in a way that lets you > easily confirm that you didn't leak it. I think folks are missing an important point here. The philosophy of dynamic languages like Python is that the class designer shouldn't be the only one who decides whether or not a particular variable should be private or public. The designer can *suggest*, but not force. The class user is free to ignore that suggestion. The class designer is assumed to know their class best, and therefore be in a position to know what variables are dangerous or inconvenient to leak and which are not. But the class user is the person who knows their own needs best, and therefore best to know whether their needs are such that they are willing to take that risk. Why should the class designer get a monopoly on deciding what the class user can or cannot do? If you believe that the class designer should have the privilege of prohibiting certain uses of the class, you will vote for private variables. If you believe that the class users should have more freedom, you will vote against them. "Truly" private variables have an advantage of making the class designer's life somewhat easier -- not much, but a little. But that advantage comes at the cost of making the class user's life somewhat harder -- not much, but a little -- by restricting what they can do. Your private variable may be just what they need to solve some problem you never even thought of. Python cannot be all things to all people, although it can be many things. There are always trade-offs to be made. Java makes the trade-off one way, Python the other. -- Steven. From vvoipio at kosh.hut.fi Fri Oct 14 07:20:39 2005 From: vvoipio at kosh.hut.fi (Ville Voipio) Date: Fri, 14 Oct 2005 14:20:39 +0300 (EEST) Subject: UI toolkits for Python References: Message-ID: In article , Kenneth McDonald wrote: > 4) Ease of installation/use on OS X? There are two questions which may restrict your choice rather a lot: #1 Should the UI look the same on each platform or should it look the same as all other apps on the platform? #2 Are you trying to make a simple installation package which includes everything needed? With OS X compatibility you tend to come across with the fact that many "OS X compatible" things are actually X11 things. X11 certainly looks different from Aqua (the native interface). Also, X11 is not always installed, and some unixish things require using Fink to install them. Not something Joe A. User usually has on his Mac. GTK is an example of this. There is an Aqua version of GTK, but it seems to be rather outdated. The newer versions run on X11 but installing them may be just laborious or then plain pain depending on your luck. And you still need the X11 installed. So, if you are looking for something that looks like Mac and works like Mac, do not touch anything with X11. OTOH, if you just need to get something working on your own OS X computer, then X11 is fine. --- I have tried using wxPython for Mac/Windows cross-platform GUIs. This far it seems to work fine, but I have not tried anything very fancy. Mac applications have the OS X looks, and Windows applications look Windowsish. Without having a single line of platform-dependent code. Making simple installation files (exe for Windows and dmg for OS X) seems to work, as well. So, the installation should be easy for the user. - Ville -- Ville Voipio, Dr.Tech., M.Sc. (EE) From pdirezze at rogers.com Tue Oct 11 08:51:28 2005 From: pdirezze at rogers.com (Paul DiRezze) Date: Tue, 11 Oct 2005 08:51:28 -0400 Subject: Learning Python In-Reply-To: <7e6dnQAA36FTBtfeRVn-rg@rogers.com> References: <7e6dnQAA36FTBtfeRVn-rg@rogers.com> Message-ID: These are all great suggestions. Thanks to all who replied. paul From rrr at ronadam.com Mon Oct 31 18:24:13 2005 From: rrr at ronadam.com (Ron Adam) Date: Mon, 31 Oct 2005 23:24:13 GMT Subject: Arguments for button command via Tkinter? In-Reply-To: References: <1130768146.414955.106780@g47g2000cwa.googlegroups.com> <1130768592.010756.97890@g49g2000cwa.googlegroups.com> Message-ID: Steve Holden wrote: > Francesco Bochicchio wrote: > >> Il Mon, 31 Oct 2005 06:23:12 -0800, dakman at gmail.com ha scritto: >> >> >>> And yet the stupidity continues, right after I post this I finnally >>> find an answer in a google search, It appears the way I seen it is to >>> create a class for each button and have it call the method within that. >>> If anyone else has any other ideas please tell. >> >> >> >> This is how I do it: Supposing I have three buttons b1, b2 and b3, and I >> want for each button to call the same callback with, as argument, the >> button itself: >> >> >> def common_callback(button): >> # callback code here >> >> >> class CallIt(objetc): >> def __init__(function, *args ): >> self.function, self.args = function, args >> def __call__(self, *ignore): >> self.function(button, *self.args) >> >> b1['command']= CallIt(common_callback, b1) >> b2['command']= CallIt(common_callback, b2) >> b3['command']= CallIt(common_callback, b3) >> >> This way you need only one class (a sort of custom callable) and >> its instances gets called by Tkinter and in turn calls your >> callback with the proper arguments. >> > I don't see why this is preferable to having the callback as a bound > method of the button instances. What's the advantage here? It looks > opaque and clunky to me ... I'm not sure on the advantage either. I just recently started handling my buttons with button id's. def __init__(self, *args, **kwds): ... b1 = Tk.Button( frame, text=button, command=self.command(button) ) ... The button label is used as the id above, but a number or code could also be used. def command(self, id): """ Assign a command to an item. The id is the value to be returned. """ def do_command(): self.exit(event=id) return do_command In this case it's a dialog button so it calls the exit method which sets self.return to the button id before exiting. Cheers, Ron From twic at urchin.earth.li Sat Oct 1 19:43:11 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Sun, 2 Oct 2005 00:43:11 +0100 Subject: A rather unpythonic way of doing things In-Reply-To: <37ll1gci8v.fsf@chiark.greenend.org.uk> References: <37ll1gci8v.fsf@chiark.greenend.org.uk> Message-ID: On Thu, 29 Sep 2005, Peter Corbett wrote: > One of my friends has recently taken up Python, and was griping a bit > about the language (it's too "prescriptive" for his tastes). In > particular, he didn't like the way that Python expressions were a bit > crippled. So I delved a bit into the language, and found some sources of > syntactic sugar that I could use, and this is the result: > > http://www.pick.ucam.org/~ptc24/yvfc.html It's this sort of thing that makes it clear beyond all shadow of a doubt that Cambridge should be razed to the ground. Keep up the good work. tom -- I'm not quite sure how that works but I like it ... From timr at probo.com Sun Oct 2 02:15:48 2005 From: timr at probo.com (Tim Roberts) Date: Sun, 02 Oct 2005 06:15:48 GMT Subject: What encoding is used when initializing sys.argv? References: Message-ID: <7ouuj119k1sd5sgkeq8g38fp99s8lge3ga@4ax.com> Neil Hodgson wrote: > >Petr Prikryl: > >> ... I have discovered that >> I do not understand what encoding should be used >> to convert the sys.argv into unicode. > > Martin mentioned CP_ACP. In Python on Windows, this can be accessed >as the "mbcs" codec. > >import sys >print repr(sys.argv[1]) >print repr(unicode(sys.argv[1], "mbcs")) > >C:\bin>python glurp.py abc?? >'abc\xdf\x95' >u'abc\xdf\u2022' There's another entry in my "keep this post forever" file. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From grante at visi.com Tue Oct 11 10:37:22 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 11 Oct 2005 14:37:22 -0000 Subject: When someone from Britain speaks, Americans hear a "British accent"... References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kdtk2t4kksp25@corp.supernews.com> Message-ID: <11knjh2g01gsded@corp.supernews.com> On 2005-10-10, Terry Hancock wrote: >> Cool. While we're on the topic, has anybody else noticed that >> "guys" is acceptible and commonly used to refer to a group of >> women, > > Yeah, though it depends on where you are. I assumed you could tell that from my accent. :) >> Likewise, "dude" is often used when addressing a female but >> almost never when speaking about one in the third person. > > This I have never witnessed. That's bizarre. At least in the upper midwest it seems quite common for teen-age boys/girls to address each other as "dude". For example "Dude, you have got to go to the concert with us". But, if somebody refers to "that dude over there in the blue jaket," the "dude" is invariably a male. -- Grant Edwards grante Yow! I am NOT a nut.... at visi.com From bonono at gmail.com Wed Oct 26 08:35:41 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 26 Oct 2005 05:35:41 -0700 Subject: Windows vs Linux [was: p2exe using wine/cxoffice] In-Reply-To: References: Message-ID: <1130330141.634726.150330@z14g2000cwz.googlegroups.com> oops, stand corrected. As I don't use the feature more than ctrl-r and up/down arrow. Tim Golden wrote: > Thanks to both of you. But that much I already knew. It's not > that I have *no* knowledge about readline: I did at least > read the manuals when I got stuck! But as far as I can tell > from my experience and from the docs -- and I'm not near a > Linux box at the mo -- having used ctrl-r to recall line x > in the history, you can't just down-arrow to recall x+1, x+2 etc. > Or can you? > > (Sorry guys; I realise this is more stuff for comp.os.linux or > comp.commandlineshells.bash or whatever it's called. But if > someone *did* know the answer, I'd be really happy!) > > 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 john at castleamber.com Wed Oct 19 05:08:08 2005 From: john at castleamber.com (John Bokma) Date: 19 Oct 2005 09:08:08 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <11l48meji6u4e69@corp.supernews.com> <6u1cl1dvqaac21klrqsoumsoh0ugrbom9e@4ax.com> Message-ID: Jerzy Karczmarczuk wrote: [ this thread ] > The pollution *is* there, despite the possibility of individual > screening. The subject and the contents violates some basic nsgroup > principles, such as topicality. One to ten irrelevant postings do no > harm. More than hundred - become annoying. Cross-posting to 5 groups > is bad. Please go away. The problem is that adding "please stop, please go away" postings to this thread have 0 effect. Or worse, people posting such messages, and tweaking the FollowUp-To: header resulting in more and more pollution. It doesn't work, sad but true. Best is to kill the entire thread, hope the long discussion stays in it, and dies out, and doesn't spark similar discussions. Also refraining from posting to any thread started by Xah Lee (I guess it was "our" troll again), no matter how tempting, might help (I am going to try, again). > Claiming that this is an interesting, "great" thread is utterly silly > in this context. Shall Python newsgroup discuss the trial of Saddam > Hussein as well? And should it be crossposted to: comp.lang.perl.misc, comp.unix.programmer, comp.lang.java.programmer, and comp.os.linux.misc? -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From jwkenne at attglobal.net Tue Oct 18 14:08:01 2005 From: jwkenne at attglobal.net (John W. Kennedy) Date: Tue, 18 Oct 2005 14:08:01 -0400 Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <11l48meji6u4e69@corp.supernews.com> <2X95f.14513$vV4.3483@fe08.lga> Message-ID: joe at invalid.address wrote: > "John W. Kennedy" writes: > > >>Michael Heiming wrote: >> >>>Let's not forget about the Internet, they invented together with >>>Al Gore and of course the wheel! >> >>No fair picking on Al Gore. All he ever claimed was that he was the >>Congressional point man for the "Information Superhighway", which he >>was. > > > Well, what he said was > > "During my service in the United States Congress, I took the > initiative in creating the Internet." > > What you say he did is what he actually did, but what he said gives a > different impression. I don't think he's careless or stupid, so I > think he said that in order to create the impression in the minds of > the people listening to the interview that he's responsible for the > internet. For "the Internet" as 99% of the American people comprehend it, he /was/ largely responsible, on the political end. The fact that the "Information Superhighway" turned out to be implemented as a massive explosion of the former ARPANet was an unforeseeable accident of history, resulting from the coincidental timing of the "Information Superhighway" initiative, the introduction of the Web, and (to some degree) the ARPANet worm. -- John W. Kennedy "The pathetic hope that the White House will turn a Caligula into a Marcus Aurelius is as na?ve as the fear that ultimate power inevitably corrupts." -- James D. Barber (1930-2004) From mynews44 at yahoo.com Fri Oct 21 16:39:17 2005 From: mynews44 at yahoo.com (googleboy) Date: 21 Oct 2005 13:39:17 -0700 Subject: A question about searching with multiple strings Message-ID: <1129927157.674735.13000@g44g2000cwa.googlegroups.com> Hi there. I have defined a class called Item with several (about 30 I think) different attributes (is that the right word in this context?). An abbreviated example of the code for this is: class Item(object): def __init__(self, height, length, function): params = locals() del params['self'] self.__dict__.update(params) def __repr__(self): all_items = self.__dict__.items() return '%s,%s,%s' % (self.height, self.length, self.function) I have a csv file that I use to store and retrieve all the info about each Item, one item per line. I have written a little peice of python that lets me search through all Items (after reading them into a variable called all_items) and will return matching results: for item in all_items: strItem = str(item) m = re.search(p[i], strItem, flags = re.I) if m: height = getattr(item, "height") length = getattr(item, "length") function = getattr(item, "function") print "height is %s, length is %s and function is %s" % height, length, function This has the limitation of only working over a single search item. I want to be able to search over an uncontrollable number of search strings because I will have people wanting to search over 2, 3 or even (maybe) as many as 5 different things. I was thinking that I would try to write a function that created a sublist of Items if it matched and then run subsequent searches over the subsequent search strings using this sublist. I am not entirely sure how to store this subset of Items in such a way that I can make searches over it. I guess I have to initialize a variable of type Item, which I can use to add matching Item's to, but I have no idea how to do that....(If it was just a list I could say "sublist = []", what do I use for self defined classes? I Am also usure how to go about creating a function that will accept any number of parameters. Any assistance with these two questions will be greatly appreciated! Thanks! googleboy From popo01 at msn.com Sat Oct 15 22:25:43 2005 From: popo01 at msn.com (John Irby) Date: Sat, 15 Oct 2005 20:25:43 -0600 Subject: Newbie help Message-ID: Francis Girard: Here is the code you are looking for if I read you right: # Michael Dawson - 1/8/03 import random print "\tWelcome to 'Guess My Number'!" print "\nI'm thinking of a number between 1 and 10." # I have randrange set to 10 for debugging. 3 is even faster. print "Try to guess it in under three attempts.\n" # set the initial values counter = 1 # I had to set counter to = 1 for this to work right. the_number = random.randrange(10) + 1 # but it is bug free. guess = int(raw_input("Take a guess: ")) # guessing loop while (guess != the_number): if counter >= 3: # this statement had to go up top print 'Game over! Your 3 tries are up.' break # OKAY! Using break after "game over" is perfect! elif (guess > the_number): print "Lower..." else: print "Higher..." counter += 1 guess = int(raw_input("Take a guess: ")) else: print "You guessed it! The number was", the_number if counter >=2: print "And it only took you", counter, "tries!\n" else: print "and it only took you 1 try!\n" # check this out! # this solution sure took me long enough! What I can't help you with # is how great it would make you feel to do it yourself. # a fellow newbie. -------------- next part -------------- An HTML attachment was scrubbed... URL: From correia_jREMOVECAPS at hotmail.com Fri Oct 21 13:43:33 2005 From: correia_jREMOVECAPS at hotmail.com (J Correia) Date: Fri, 21 Oct 2005 17:43:33 GMT Subject: Searching for txt file and importing to ms access References: Message-ID: <9N96f.38924$Io.6161@clgrps13> "Mark Line" wrote in message news:dj8f1r$do7$1 at nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com... > Hello! > > > I've also managed to connect to my access database, and just print out a > field in a table, but I cant find anywhere on the web that will help me to > import data? Any help would be great?! > > Another method of talking to MS Access is to set up an ODBC datasource... Control Panel > Data Sources (ODBC). Then download and import the mx.ODBC module... this worked a lot faster in my setup than using the win32com route and i find the clear SQL layout simpler to understand. Attached is some sample code I used to quickly get some data from SQL Server, process it, and load into Access, both set up as ODBC data sources. import mx.ODBC.Windows dbc1 = mx.ODBC.Windows.Connect('', user='', password='xxx', clear_auto_commit=0) dbc2 = mx.ODBC.Windows.Connect('', user='', password='xxx', clear_auto_commit=0) # Create cursors on databases. crsr1 = dbc1.cursor() crsr2 = dbc2.cursor() # Get record(s) from SQL Server database. try: crsr1.execute( """ SELECT product_id, image FROM SUP_CATALOGUE_PRODUCT """) except Exception, err: print "*** Error extracting records from SQL Server***" print "Exception:", Exception, "Error:", err sys.exit() else: results = crsr1.fetchall() # fetch the results all at once into a list. if not len(results): # No records found to be processed. print "No records returned from SQL Server table, aborting..." sys.exit() else: # Have records to work with, continue processing print len(results), "records to be updated..." i = 0 for item in results: .... .... < processing of each record goes here.> .... # Now update 1 record in the Access table. try: crsr2.execute( """ UPDATE SUP_CATALOGUE_PRODUCT SET image = '%s' WHERE product_id = %d """ % (new_image, product_id) ) except Exception, err: print "*** Error updating records in MS Access***" print "Exception:", Exception, "Error:", err sys.exit() i += 1 print "All done... records written:", i HTH, JC From my_email_is_posted_on_my_website at munged.invalid Wed Oct 12 18:04:14 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 12 Oct 2005 22:04:14 GMT Subject: Jargons of Info Tech industry References: <1124804082_1011@spool6-east.superfeed.net> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <41hhk195gcipfarnqu85ggs606aqi89ea1@4ax.com> <20051010004218.03171fb6.tengo@DELETEMEecc.lu> Message-ID: On Mon, 10 Oct 2005 00:42:18 +0200, Stefaan A Eeckels wrote or quoted : >"I don't understand that attitude. Don't we want email that has dancing > bears, cute little videos, musical tunes, animated waving hands, sixty > fonts, and looks like it's been done with crayolas? Good grief, man, > think like a three year old!" that excuse could also be used to explain why you have not cracked a book since high school. The same tools that create dancing bears can do a UML diagram. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From sw at wordtech-software.com Sun Oct 23 13:20:38 2005 From: sw at wordtech-software.com (Kevin Walzer) Date: Sun, 23 Oct 2005 13:20:38 -0400 Subject: calling a dylib in python on OS X In-Reply-To: <1130049617.186896.237650@g14g2000cwa.googlegroups.com> References: <1130049617.186896.237650@g14g2000cwa.googlegroups.com> Message-ID: <483b4$435bc667$4275d90a$440@FUSE.NET> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 robspychala at gmail.com wrote: | Hi | | Is there something similar to python's windll for calling DLLs on win32 | but meant for calling dylib's on OS X? | | thanks, | | r.s. | Can you be more specific about what you are trying to do/what dylib you want to call? - -- Cheers, Kevin Walzer, PhD WordTech Software - "Tame the Terminal" http://www.wordtech-software.com sw at wordtech-software.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (Darwin) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDW8ZmJmdQs+6YVcoRAvKPAJ0TUW8hgRN6AOn/nBP1v12kqmLXrQCfc5B1 uVv3uBAz7I/jO7l/htpuTb0= =oXiv -----END PGP SIGNATURE----- From max at alcyone.com Wed Oct 26 04:04:56 2005 From: max at alcyone.com (Erik Max Francis) Date: Wed, 26 Oct 2005 01:04:56 -0700 Subject: a Haskell a Day In-Reply-To: <1130312303.713737.160830@g44g2000cwa.googlegroups.com> References: <1130312303.713737.160830@g44g2000cwa.googlegroups.com> Message-ID: Xah Lee wrote: > This is my learning notes on Haskell. I call it a-Haskell-a-day. Another day, another community to completely piss of, huh, Xah? -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis Never take a stranger's advice / Never let a friend fool you twice -- Florence, _Chess_ From bdesth.quelquechose at free.quelquepart.fr Thu Oct 20 16:50:42 2005 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 20 Oct 2005 22:50:42 +0200 Subject: Popularity of blogging tools used by python programmers In-Reply-To: References: Message-ID: <4357f98c$0$18772$626a14ce@news.free.fr> Stewart Midwinter a ?crit : > I've made a comparison of the relative popularity of blogging tools > used by python programmers. I was surprised by the number of python > developers not using python for their blogs; isn't that like GM > employees driving Toyota cars? > > See my post at: > > http://midtoad.homelinux.org/wp/?p=117 > Could it be say that Python programmers are wise enough to reinvent the wheel ?-) (just kidding...) From kent37 at tds.net Fri Oct 28 14:53:22 2005 From: kent37 at tds.net (Kent Johnson) Date: Fri, 28 Oct 2005 14:53:22 -0400 Subject: Scanning a file In-Reply-To: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> Message-ID: <43627179$1_3@newspeer2.tds.net> pinkfloydhomer at gmail.com wrote: > I want to scan a file byte for byte for occurences of the the four byte > pattern 0x00000100. data = sys.stdin.read() print data.count('\x00\x00\x01\x00') Kent From hancock at anansispaceworks.com Tue Oct 11 21:17:08 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Tue, 11 Oct 2005 20:17:08 -0500 Subject: Python name lookups / Interning strings In-Reply-To: <20051011223606.89640.qmail@web30611.mail.mud.yahoo.com> References: <20051011223606.89640.qmail@web30611.mail.mud.yahoo.com> Message-ID: <200510112017.08618.hancock@anansispaceworks.com> On Tuesday 11 October 2005 05:36 pm, Dave wrote: > What exactly does it mean to "intern" a string? For very simple strings such as "A" and for strings used as identifiers (I think), Python creates a permanent object during byte-code compilation. Thereafter, any time that string value occurs in the program, it will actually be interpreted as a reference to the interned string object with that value. So, if for example, "A" is interned, then statements like: >>> a = "A" >>> b = "A" will result not only in: >>> a == b True but also >>> a is b True Note that since 'a is b' always implies 'a == b', the interpreter needn't do a full value comparison of interned strings, it can stop when it sees they are references to the same object. Whereas, for an un-interned string: >>> a = "I don't think Python will intern this string." >>> b = "I don't think Python will intern this string." >>> >>> a==b True >>> a is b False Now, however, 'a==b' must do an actual string comparison, and is therefore somewhat slower. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From steve at holdenweb.com Sun Oct 23 17:29:55 2005 From: steve at holdenweb.com (Steve Holden) Date: Sun, 23 Oct 2005 22:29:55 +0100 Subject: IDE recommendation please In-Reply-To: <435b627c$0$20493$4fafbaef@reader4.news.tin.it> References: <435b627c$0$20493$4fafbaef@reader4.news.tin.it> Message-ID: Gian Mario Tagliaretti wrote: > microsnot wrote: > > >>I'm new to Python but am wondering what IDE Python developers use? I use >>Mac OS X 10.4.2. I have PythonIDE which comes with MacPython but I don't >>think that has even rudimentary "intellisense". Xcode and Eclipse don't >>seem to support Python out of the box. Suggestions for plugins for Eclipse >>would also be nice. > > > I use wingIDE and as Alex said before is the best python IDE ever... > > cheers I too am a happy Wing IDE user. The debugging features are very convenient. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From lasse at vkarlsen.no Thu Oct 27 07:46:18 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Thu, 27 Oct 2005 13:46:18 +0200 Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: David Schwartz wrote: > Roedy Green wrote: > competing products. (Just as Burger King corporate will not you sell Big > Macs in the same store in which you sell Whoppers.) Rather odd comparison don't you think ? A better comparison would be if Burger King purchases the fries from a factory that says that Burger King has to give out a pack of fries with all meals, regardless of the type of meal, or they are going to raise the price. In other words, you'll be forced to take a pack of fries with your ice cream, salad or what not. Considering that McDonalds have been selling meals with "potato-boats" (don't know the correct english term for it, carved potato pieces fried), they'd have to give you a pack of fries with your meal regardless, even if you want to replace the fries with "potato-boats". Also, in this case Burger King "won't sell you" is not the same as "can't sell you", which seems to be the case with this whole Microsoft discussion. I'm pretty sure you wouldn't be able to easily buy a computer from Microsoft with OS/2 installed or vice versa either and I'm not sure they would be obliged to do so either. However, controlling what an independant outlet is doing, that's different. -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From fakeaddress at nowhere.org Thu Oct 27 05:07:42 2005 From: fakeaddress at nowhere.org (Bryan Olson) Date: Thu, 27 Oct 2005 09:07:42 GMT Subject: Sorting with only a partial order definition In-Reply-To: References: Message-ID: Lasse V?gs?ther Karlsen wrote: > I have a list of items and a "rule" for ordering them. > > Unfortunately, the rule is not complete so it won't define the correct > order for any two items in that list. This is called a "partial ordering". [...] > If there isn't anything built in, does anyone have an idea about how to > go about creating such an ordering function ? Tweaking a cmp-like > function to return 0 for "undefined" didn't seem to work so there must > be a slightly more intelligent solution than that. Perhaps the rules > would have to be checked in a specific order. The usual tools to deal with partial orderings are directed acyclic graphs, and "topological sorting". Try Googling the terms along with "Python". -- --Bryan From mwm at mired.org Thu Oct 27 22:57:03 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 27 Oct 2005 22:57:03 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <86ll0vs1sw.fsf@bhuda.mired.org> <66u633-etj.ln1@news.it.uc3m.es> <7xbr1aewtq.fsf@ruckus.brouhaha.com> <86acgulv5z.fsf@localhost.localdomain> <7xvezi8ypy.fsf@ruckus.brouhaha.com> <86y84ehd3j.fsf@bhuda.mired.org> <86hdb2h750.fsf@bhuda.mired.org> Message-ID: <86zmoufiww.fsf@bhuda.mired.org> "David Schwartz" writes: > "Mike Meyer" wrote in message > news:86hdb2h750.fsf at bhuda.mired.org... > >>> "Ironically, while no one else has so much as compared MS to criminals >>> with >>> guns". I defy you to find *one* place where I complain that MS behavior >>> is >>> equated to the actual use of force where that is not in fact done in >>> precisely the thread I'm replying to. > >> The first one is at: >> >> http://groups.google.com/group/comp.lang.python/msg/8422f41c9fe137b0?dmode=source&hl=en >> >> The original comment was: >> >>>> No, they didn't ask for more than Windows were worth. They tilted the >>>> playing field against MS competitors by causing consumers to pay MS >>>> money for products they didn't receive. In most countries, taking >>>> money from unwilling victims without giving them anything in exchange >>>> is called "theft". >> >> Note that no mention is made of guns or force - just a definition of >> theft. Unless you're so narrowminded that nothing short of pointing a >> gun at someone and demanding money from them is stealing from them, >> there is no way that this can be equated to the actual use of >> force. And if you do believe that definition of stealing, I'll do your >> bookkeeping for free - and I won't steal from you. >> >> Your reply: >> >>> It is not theft if you can simply say "no" to the deal and all that >>>happens is that you don't get the product. Your argument is preposterous. >>>If >>>you accept arguments that equate guns with arguments, the next step is >>>that >>>using a gun is a rational response to an argument one doesn't like. Oh >>>wait, >>>you're already there. >> >> Wherein you accuse me of equating MS's actions with using guns, which >> is *exactly* what I said you do. > > This thread is large and complex, and I can't always know exactly what's > a reply to what reply to what. So what's said in what part of a thread may > carry over to another part of that same thread. So follow the link and read it. I quoted the comment and reply directly to make life easier on the readers. I quoted them exactly in context. That you try and deny they illustrate you doing exactly what I said you do is only to be expected. >> There are lots more examples of you doing this kind of thing. Like I >> said, everytime someone compares MS's behavior with some less >> controversial criminal behavior, you act like they accused MS of >> holding people up at gunpoint. > > They are. Read the quotes. Here they are again: So what? That doesn't change the essential truth of my statement - that you react to *every* comparison of MS's activities with less controversial criminal activity with the "You're comparing them to criminals with guns. I won't discuss that." It really does make me think that you're more interested in protecting MS's reputation than in any discussinon. >>Unless you're so narrowminded that nothing short of pointing a >>gun at someone and demanding money from them is stealing from them, >>there is no way that this can be equated to the actual use of >>force. And if you do believe that definition of stealing, I'll do your >>bookkeeping for free - and I won't steal from you. > You are seriously saying that people in this thread have not > consistently described Microsoft's actions as analogous to an actual use of > force? Have you read any of the thread? Do I need to dig out more quotes? Yes, I've read the thread. It's full of you creating straw men, calling those who disagree with you liars, calling the government crooks, and the like. I'd be interested in seeing *one* quote that compare MS's actions to the "actual use of force." And I want what I gave you - the link to the google groups page the quote came from, and enough context to find it. The quote about the mafia doesn't compare MS's actions to "actual use of force". It compares MS to people who are willing to use force to get their ends. But there is no "actual use of force." > These are all from early in the thread, long before the posts you are > complaining about: > "The choice was go along with MS arm twisting or go out of business." No, this wasn't "long before" the post I quoted; it occured well after it. And while this really does refer to the "actual use of force", anyone even vaguely familiar with common english usage will recognize the phrase "arm twisting" as an idiomatic usage for a being extremely persuasive, with no "actual use of force" taking place. If that's the best you can do, you really haven't got an argument. > "To my way of thinking what MS did was similar to a the only magasine > wholesaler in town telling retailers it had to sell kiddie porn under > the table or pay full retail for all magazines." No "actual use of force" in this one, either. This is a *very* apt comparison. The only real difference between this and what MS did is that it replaces something mildly objectionable - charging people for something they aren't getting - with something very objectionable - selling kiddie porn. > However, you may be right that some of my replies to you may not have > been justified as responses to just what you said. It'd take a lot of > digging through the thread to figure that out. ;) Your replies to *everyone* who compares MS's criminal activities to more obviously criminal activities have been that accues them of equating MS's actions to using a gun - much nastier than simply "the actual use of force" and then refusing to discuss the comparison. The only explanation I can think of is that you are trying to prevent people from realizing that MS is a criminal organization. That you deny doing this is only to be expected, and I'll bet you deny it again. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From martijn at gamecreators.nl Tue Oct 11 05:48:58 2005 From: martijn at gamecreators.nl (martijn at gamecreators.nl) Date: 11 Oct 2005 02:48:58 -0700 Subject: A faster shutil.rmtree or maybe a command. Message-ID: <1129024138.029854.80350@g47g2000cwa.googlegroups.com> H! Sometimes I must delete 2 very big directory's. The directory's have a very large tree with much small file's in it. So I use shutil.rmtree() But its to slow. Is there a faster method ? I use FreeBsd 5.4. --- is it maybe faster to walking in the directy en delete each file? Thanks, GC-Martijn From ericwan78 at yahoo.com Fri Oct 14 16:40:11 2005 From: ericwan78 at yahoo.com (wanwan) Date: 14 Oct 2005 13:40:11 -0700 Subject: confusion between global names and instantiated object variable names Message-ID: <1129322411.776202.314290@g43g2000cwa.googlegroups.com> I'm trying to make a GUI, but for some of the instantiated object variable names, the interpreter is looking at them as global names. Here is an example of what I did: class mygui: def __init__(self, root): self.menubar = Menu(root) # Game Menu self.menu1 = Menu(self.menubar, tearoff=0) self.menu1.add_command(label="Open File", command=donothing) self.menu1.add_separator() self.menu1.add_command(label="Exit", command=root.quit) self.menubar.add_cascade(label="File", menu=self.menu1) # ignoring the rest of the program ... when I run my example, an error shows: "NameError: global name'menubar' is not defined" I wonder why it doesn't work. Isn't that the way to define an object variable? Any response would be appreciated. From mscottschilling at hotmail.com Tue Oct 18 10:42:06 2005 From: mscottschilling at hotmail.com (Mike Schilling) Date: Tue, 18 Oct 2005 14:42:06 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86fyqzzskt.fsf@bhuda.mired.org> <86y84rxryr.fsf@bhuda.mired.org> Message-ID: <2R75f.2005$dO2.1121@newssvr29.news.prodigy.net> "Mike Meyer" wrote in message news:86y84rxryr.fsf at bhuda.mired.org... > "Mike Schilling" writes: >> "Mike Meyer" wrote in message >> news:86fyqzzskt.fsf at bhuda.mired.org... >>> "Mike Schilling" writes: >>>> What matters in generating HTML is which browsers you want to support >>>> and >>>> what they understand. Standards and recommendations are both >>>> irrelevant. >>> Unless, of course, you want to support any compliant browser. >> Since no browser I know of is perfectly compliant (e.g. bug-free), that's >> not a feasible goal. > > I guess you'd say developing any software isn't a feasible goal, > because it'll never be bug-free, will never have bug-free compilers to > compile it, bug-free linkers to link it, bug-free GUI/db/etc libraries > to link with it, bug-free servers to communicate with, and bug-free > operating systems to run it on. Fortunately, most developers aren't > quite that anal, and realize that you can get useful work done in a > less-than-perfect environment. I'm not speaking theroetically. My company (though not me personally) creates browser-based UIs, and one of the biggest expenses has been dealing with IE rendering bugs Given the market share of IE, the fact that something should work, and even does work in Firefox, Opera, etc, is irrelevant. If it breaks IE, we can't use it. When we've had similar issues with C++ compilers, patches have usually been forthcoming, or perhaps optimization has to be turned off on a few source files. In a few areas, though, the solution has been "Don't do that", and again, the fact that the standard supports it is irrelevant. From xah at xahlee.org Sun Oct 30 13:47:58 2005 From: xah at xahlee.org (Xah Lee) Date: 30 Oct 2005 10:47:58 -0800 Subject: learning emacs lisp In-Reply-To: <1130267274.057695.116050@o13g2000cwo.googlegroups.com> References: <1130241817.688203.320540@g44g2000cwa.googlegroups.com> <85br1dydvn.fsf@lola.goethe.zz> <1130246810.318934.123570@g44g2000cwa.googlegroups.com> <1130267274.057695.116050@o13g2000cwo.googlegroups.com> Message-ID: <1130698078.823822.223300@g43g2000cwa.googlegroups.com> well, in the past couple of days i started my own: http://xahlee.org/emacs/notes.html but i'm sure something like it exists. Btw, the elisp intro by Robert J Chassell. At: http://www.gnu.org/software/emacs/emacs-lisp-intro/ is extremely well written. (and so is the elisp reference) Bravo to GNU & Freesoftware Foundation once again. Thank you. PS Fuck unix and unix fuckheads. Fuck asshole Larry Wall. Fuck Python documenation community and their fucking ass lying thru their teeth ignorance fucking shit. (See: http://xahlee.org/UnixResource_dir/writ/gubni_papri.html) Disclaimer: all mention of real person are opinion only. Xah xah at xahlee.org ? http://xahlee.org/ rgb wrote: > > i'm looking for something example based... for senior professional > > programers who may want to pickup some elisp for practical macro. > > Unfortunately the path from any given language to Elisp varies vastly. > For example a Prolog programmer would need far fewer tips than a Cobol > or even a C programmer. It's unlikely you will find something > tailored to your specific experience. > > I'd already written programs in well over 100 languages in the 20 > years before learning Elisp yet I didn't find the intro terribly > tedious until around section 13 (Counting). At that point it switches > focus toward examples of creating functions rather than introducing > syntax and available features. Perhaps starting at section 12 would > suit your learning style better. > > As you probably realize, the language itself is just syntax and the > hard part is learning about all the facilities at your disposal once > you decide to write something. There are a lot of features available > and, although daunting, I think the reference is the best resource > for discovering them. > > This group has also been indispensable to me. From gsakkis at rutgers.edu Fri Oct 14 23:18:39 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Fri, 14 Oct 2005 23:18:39 -0400 Subject: Help with creating a dict from list and range References: <910885da0510140626p2f395ae6rbdf69b62cb55a2@mail.gmail.com> Message-ID: <1129346319.abc03660b95ff66215dd9905db5e4265@teranews> "James Stroud" wrote: > Could be even simpler since enumerate creates tuples anyway: > > dct = dict(x for x in enumerate(description)) > > James > > On Friday 14 October 2005 08:37, Steve Holden wrote: > > >>> dct = dict((x[1], x[0]) for x in enumerate(description)) > > >>> dct > > > > {'second': 1, 'third': 2, 'first': 0} "James Stroud" wrote > Could be even simpler since enumerate creates tuples anyway: > > dct = dict(x for x in enumerate(description)) > > James > > On Friday 14 October 2005 08:37, Steve Holden wrote: > > >>> dct = dict((x[1], x[0]) for x in enumerate(description)) > > >>> dct > > > > {'second': 1, 'third': 2, 'first': 0} Or even simplest :-) dct = dict(enumerate(description)) George From http Thu Oct 6 15:31:53 2005 From: http (Paul Rubin) Date: 06 Oct 2005 12:31:53 -0700 Subject: "no variable or argument declarations are necessary." References: Message-ID: <7xu0fucuhi.fsf@ruckus.brouhaha.com> Brian Quinlan writes: > Without a clear idea of the nature of the proposal, it is impossible > to assess it's costs and benefits. So could a proponent of optional > declarations please provide a more clear proposal? There is no proposal on the table. There's a discussion of how this stuff can work, and whether it's useful. As for how the compiler deals with imported modules, see for example Common Lisp or Haskell or ML--how do they do it? From mvanaswegen at gmail.com Thu Oct 13 08:50:33 2005 From: mvanaswegen at gmail.com (vpr) Date: 13 Oct 2005 05:50:33 -0700 Subject: wxPython question Message-ID: <1129207833.953525.266880@f14g2000cwb.googlegroups.com> Hi Does anyone have some example code to create a wx dialog that apears off screen on the bottom right hand corner and slides up into the screen ? Thanx /vpr From frank at chagford.com Tue Oct 11 05:33:33 2005 From: frank at chagford.com (Frank Millman) Date: 11 Oct 2005 02:33:33 -0700 Subject: Question about StringIO In-Reply-To: <3r1cmeFgbogbU2@uni-berlin.de> References: <1128849763.117104.34370@f14g2000cwb.googlegroups.com> <3qsacmFftrn5U1@uni-berlin.de> <1128940255.694551.318760@g14g2000cwa.googlegroups.com> <3r08l2Fgbm87U1@uni-berlin.de> <1129015921.510133.322350@z14g2000cwz.googlegroups.com> <3r1cmeFgbogbU2@uni-berlin.de> Message-ID: <1129023213.759788.312270@z14g2000cwz.googlegroups.com> Diez B. Roggisch wrote: > > My scripts are used to create the tables in the database. I didn't > > think that DB-API covered that. > > The DB-Api covers executin arbirary SQL - either DDL or DML. It is > surely centered around DML, but that doesn't mean that its not usabel to > issue "create ..." statements. > > >However, even if it did, I don't think > > it would handle differences such as the following. > > > > All that has nocthing to do with teh API - you'd still need your > differentiated DDL - but the communication with the programs would go away. > > Diez I understand. It certainly gives me an alternative approach - I will experiment to see which suits my purpose best. Many thanks for your assistance. Frank From benmorganpowell at gmail.com Fri Oct 28 04:00:25 2005 From: benmorganpowell at gmail.com (benmorganpowell at gmail.com) Date: 28 Oct 2005 01:00:25 -0700 Subject: Spambayes modifications with web services Message-ID: <1130486425.402338.123720@g49g2000cwa.googlegroups.com> In the last few months many personal website owners (such as myself) have found that spammers have been using their domain names to masquerade as valid users to send spam, normally in the form of: JoeMarkBlogs at mydomain.com This new tactic has an annoying problem, which is that the bounced emails end up back with the postmaster at the innocent persons domain. This is normally the first time that the domain owner realises that there is a problem. I am one of those people and currently have nearly 3 thousand bounces in my catch all POP3 box. Solutions I can see to this are one of two things: 1) Delete the email as it arrives and ignore it. Realise that the domain name might end up being blacklisted as a spammer's domain and be done with it, or 2) Fight back! All of the bounced emails contain at least one URI to a spammer website, in a effort to sell "Cheap Meds" or "Faked Rolexes" or similar. The format is usually something like this: http://www.sickmate.info/?a2fb9e415e74beS9cdee919d78Sa6a7d The query part of the URI I believe provides the reference between the email address and the visit. Hence if you visit the website with this link, your email address is saved in a database as one that is a) valid, and b) dumb enough to visit the website. The spammers rely on the fact that some people will visit this website and buy from them. In fact, Q.E.D., some people must buy from these websites via spam, otherwise the spammers would have given up a long time ago*. So, as a web programmer and someone who specialises in getting good results on Google, I realised that I could simply post every spammer website on a Google optimized page, which if searched for on Google would return something like: "WARNING: DO NOT BUY FROM THIS WEBSITE. THE SPAMMER IS A RUSSIAN MAFIA CROOK WHO WILL STEAL YOUR MONEY." ...Or something equally obvious along those lines. In this way we attack the websites that are the link between the spam and the money. The real necessity therefore is to: a) Process the received bounced messages quickly and list them on the website without delay. b) Prevent the spammer using the domain The answer to (b) I cannot find. I thought SPF might help, but it is not a panacea. The answer to (a) I need help with! So, I'm on Windows XP. I use Outlook 2002 and I already have the excellent (and FREE) SpamBayes Outlook add-in** that blocks spam and loves ham. Spambayes is open source and as such I can modify the source code, recompile it and install it afresh. However, the problem is that I'm not a python programmer, and I'm not sure where to start. This is what I want to do, so if anyone would like to direct me, I'd be grateful: 1) Add a menu option to the SpamBayes add-in - "Post Spam Site to Web Service". I'm guessing I can add a new line to the addin.py such as below, but how do I sink the event? self._AddControl(popup, constants.msoControlButton, ButtonEvent, (PostSpamSite, self.manager,), Caption="Post Spam Site to Web Service", Enabled=True, Visible=True, Tag = "SpamBayesCommand.PostSpam") 2) Add a configuration setting, so that the web service location can be set. I'm guessing this is in config.py. Pointers welcome. 4) Add a function to extract all links in a block of text. I have written a good one of these for .NET, but I'm not sure if, or how it would work in Python: string hrefPattern = @"(?(?:(?http(?:s?)|ftp)(?:\:\/\/))" + @"(?[^/\r\n\:]+)?" + @"(?\:\d+)?" + @"(?[^\?#]*)?" + @"(?\?\w*)?" + @"(?\#\w*)?)"; // Regular Expression Regex hrefRegex = new Regex(hrefPattern, RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase); Any help with this welcome. Do I need a specific Python regex library or can I use the .NET regex library in Python? 4) Connect to web service using SOAP and consume that service. Service will provide: a) Authorise (username, password) - returns access b) Submit (domain) - returns success or failure Can I use SOAPpy for this? Can anyone give me any examples or point me in the right direction? 5) Provide another option in the add in to "Scan folder and Post Spam Sites to Web Service", in the same manner as "Filter messages" works now. Can I use filter.py as a model to work from? Summary ================================= I am not a Python programmer per se but have no problem with getting my hands dirty. I have already got the basics of this working as a Windows.Forms application, but running both that and Outlook together is daft. The Spambayes project already does the hard bit in classifying the spam, so it makes sense to hang off the back of it. Has anyone else had similar problems as me with these "phantom" email addresses being using by spammers and would like to work with me on this? Would anyone in the Spambayes team like to have a go at this, or point me in the right direction? Has anyone had a go at hacking around with the SpamBayes source code and knows what I should do? Basically any help is extremely welcome! Regards Ben * There must obviously be enough people out there who can't get an erection or dumb enough to munch pills to get slim rather than endure a bit of excercise. That being said, they will also trust their credit card to a bunch of crooks who even if they send you the pills, will probably sent you rat poison! ** Get the FREE Spambayes Outlook add-in from http://sourceforge.net/projects/spambayes From al at none.fr Sun Oct 9 05:49:36 2005 From: al at none.fr (al) Date: Sun, 09 Oct 2005 11:49:36 +0200 Subject: What about letting x.( ... ? ... ) be equivalent to ( ... x ... ) In-Reply-To: References: Message-ID: <4348e72f$0$11133$626a14ce@news.free.fr> Fredrik Lundh a ?crit : > if you have a fear of introducing new local variables, you have problems > that cannot be solved by syntax. Dear Fredrik, I have read the original messages on fr.comp.lang.python, and I don't understand your answer. It is not about a fear of introducing new local variables, but for me it is an elegant solution to a common problem, to avoid creation of useless variables (what in french we call "variables muettes", like indexes in loops who are just there because some langages level is too low). It also avoid the increase of parenthesis depth, and so the readability is enhanced. And it solve a problem that in all object oriented langages, a method that process 2 or more different classes of objets belongs just to one of those classes. All this kind of problems appears often to me (and in different langages), and contrarily to you, I'm very impressed by the compacity and elegance of the solution. I think it would be nice if implemented in different langages (because it breaks nothing), and firstly Python. Best regards, Al PS : sorry for my approximative english, but my natural langage is french. From eurleif at ecritters.biz Mon Oct 17 13:11:13 2005 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Mon, 17 Oct 2005 17:11:13 GMT Subject: newbie regex In-Reply-To: <1129565047.255804.266190@z14g2000cwz.googlegroups.com> References: <1129565047.255804.266190@z14g2000cwz.googlegroups.com> Message-ID: csselo at gmail.com wrote: > I want to filter some strings,but i don t know how to use compile > method. Why not? > first character must be [a-zA-z] group and others can only be digits or > letters. if re.search('^[a-zA-Z][a-zA-Z0-9]*$', foo): print "Valid string." else: print "Invalid string." From robspychala at gmail.com Sun Oct 23 02:40:17 2005 From: robspychala at gmail.com (robspychala at gmail.com) Date: 22 Oct 2005 23:40:17 -0700 Subject: calling a dylib in python on OS X Message-ID: <1130049617.186896.237650@g14g2000cwa.googlegroups.com> Hi Is there something similar to python's windll for calling DLLs on win32 but meant for calling dylib's on OS X? thanks, r.s. From franz.steinhaeusler at gmx.at Wed Oct 19 04:27:55 2005 From: franz.steinhaeusler at gmx.at (Franz Steinhaeusler) Date: Wed, 19 Oct 2005 10:27:55 +0200 Subject: Any 3state Check Tree Ctrl for wxPython available? References: Message-ID: <6i0cl113dgc8jscj0o265qd6tb78ira3i2@4ax.com> On Mon, 17 Oct 2005 12:14:47 +0200, "Petr Prikryl" wrote: >Hi, > >I am experimenting with wxPython on Windows box. >What I need to implement is a check tree control >with 3 states for each checkbox: unchecked, checked, >gray checked. The status of the checkbox should reflect >the status of the children. When ALL children are checked, >then the status should be checked. When NO children >are checked, the status should be unchecked. When >SOME children are selected, the status should be >checked with gray background. > >I have found something else that could be valuable >after I start understand that: > >http://mitglied.lycos.de/drpython/CheckTreeCtrl.tar > Hello Petr, It is incidentally from my webpage :) I uploaded it once, because I didn't find it anywhere on the web; a person asked for it and I had it on my harddisk. >Anyway, is there something similar with 3 states >available around? To your problem: What about enhancing/deriving from CheckTreeCtrl and exending it? > >Thanks for your time and experience, > >pepr -- Franz Steinhaeusler From pmartin at snakecard.com Fri Oct 21 21:06:05 2005 From: pmartin at snakecard.com (Philippe C. Martin) Date: Sat, 22 Oct 2005 01:06:05 GMT Subject: how to modify text in html form from python References: <0Ra6f.5050$q%.616@newssvr12.news.prodigy.com> <86d5lyu0j8.fsf@bhuda.mired.org> <%Tb6f.5062$q%.3600@newssvr12.news.prodigy.com> <864q7atxcv.fsf@bhuda.mired.org> <86vezqscfq.fsf@bhuda.mired.org> <08f6f.6361$7h7.3176@newssvr21.news.prodigy.com> <86irvqs8cz.fsf@bhuda.mired.org> Message-ID: <1gg6f.6371$7h7.284@newssvr21.news.prodigy.com> Mike, Again, thanks. By plugin I mean the browsers' extensions: ex: http://roachfiend.com/archives/2004/12/08/how-to-create-firefox-extensions/#more-4. IE has the same type or resorts also to activeX components. Right now I know how to program that guy to open a url.... I guess I need to some thinking before I ask more questions. Regards, Philippe Mike Meyer wrote: > "Philippe C. Martin" writes: >> Mike Meyer wrote: >>> I don't know much about plugins. I believe they get started when the >>> page loads, which gives you a chance to do the authentication when you >>> want it done. >> Well not in this case actually: the user triggers the plugin which in >> turn open the url, so the connection is "owned" by the plugin > > I think we don't mean the same thing when we say "plugin". To me, a > plugin is a bit of code that gets executed when the page is rendered > to provide custom content with it's own behavior. Flash is probably > the most popular example. Like I said, I don't know much about > plugins, so they may be usable in other ways. > >>> That won't work very well. HTML goes to the client to display. The >>> server can put data in hidden form elements that code running on the >>> client side can get to - and change - via the document object model >>> (DOM). However, the only way to send the changed data back to the >>> server is to get the client to submit the form. You can automate that, >>> but the results will be disconcerting to the user: they load a page, >>> and it reloads multiple times as the plugin exchanges data with the >>> server. >> Here again, I'm not dying for any page data to be visible: cannot the cgi >> script and the plugin do their business before that ? > > Not if you're using plugin as defined above. Pretty much anything that > happens on the browser end is triggered by things happening in HTML - > which means it has to be displayed. I don't know of any way to > download something to the browser to run without rendering *something* > in the browser window - even if it's only a blank plage. > >>> The problem with this is that the apache<->browser connection isn't >>> "a" connection, it's a series of HTTP request/repsonse >>> pairs. Originally, this implied tearing down and setting up a TCP >>> connection for every request. Modern software will leave the link open >>> and reuse it - but modern software also tends to have multiple >>> connetions open, so it can fetch images and other embedded objects in >>> parallel. >> I'm lost here, better do some more reading > > HTTP is a stateless protocol. Every HTTP request goes the same: the > client sends a request saying what object it wants from the > server. The server reads the request, and sends back the response, > which is a collection of HTTP headers and a string of bytes. There's > lots more details invovled, and various things you can do to enhance > the performance of the system, but functionally they all boil down to > that. > >>> You can make this work, but doing it like that requires making >>> multiple HTTP requests via the browser, which will be >>> disconcerting. I'd recommend taking the browser out of the loop. Have >>> the plugin talk directly to the server to do the >>> authentication. That's what the latest web buzzword (AJAX) does: >>> client-side software makes independent requests of the server (or >>> *any* server) to get data, and possibly updates the document the >>> browser is viewing as a result of that. >> Here I think it's OK as the plugin can "talk" to server prior to the >> browser showing anything. > > If you say so. But certainly not through the browser. > >>> So here's a scenario: the first cgi script gets info from the smart >>> card that puts it in a hidden form element and sends the page to the >>> browser. The plugin - started when the page loads - uses the DOM to >>> get that data, then makes an *independent* HTTP request to the server, >>> thus passing whatever it generated from the data in the form field to >>> a second cgi script. This happens several times, then the plugin >>> changes the HTML form to put whatever the cgi script generated into >>> the form, so that when the user finally submits the form, the third >>> cgi script - the one that handles the submitted form - sees the data >>> from the second script. >>> Actually, the exchanges between the plugin and the server don't need >>> to be HTTP requests. If you've got this working over some other TCP >>> protocol, there's no reason you can't keep doing it that way. >> Maybe that's my clue: can a cgi script, once triggered by a (let's say) >> POST request, use back and forth file transfer with the client ? through >> the _existing_ connection. > > I honestly don't know. HTTP does a strict onetime turnaround - the > client sends, then the server sends, then you're done. There are hooks > in the protocol to allow a connection to be resused, but that's a > different request/response pair, and generally handled by the server, > not the cgi script. After all, the next request from the client may be > for some static file instead of the output of a cgi script. > > Having a cgi script start two-way communications on the connection may > well work. But it won't be HTTP, and I wouldn't be at all surprised if > one or more of the components in some web connections - proxies, > caches, firewalls, etc. - choked on it. You're liable to get > apparently random failures depending on all kinds of exotic things. > > References: <1130364703.849883.109300@z14g2000cwz.googlegroups.com> Message-ID: <1130378894.066463.33530@g43g2000cwa.googlegroups.com> Start here http://www.ibiblio.org/obp/thinkCSpy/ and here http://wiki.python.org/moin/BeginnersGuide bs From christopher.saunter at durham.ac.uk Wed Oct 26 16:59:15 2005 From: christopher.saunter at durham.ac.uk (c d saunter) Date: Wed, 26 Oct 2005 20:59:15 +0000 (UTC) Subject: Using Python to add thumbnails to Explorer References: <1130355747_658@spool6-east.superfeed.net> Message-ID: Hi Roger, Thanks for the info - I was actually interested in custom per file thumbnails rather than icons, but your message sentt me pouring through seemingly relevent parts of the registry - however what I need isn't there. Turns out I need to use a .dll shell extension as per http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ shellcc/platform/shell/programmersguide/shell_int/shell_int_extending/ extensionhandlers/shell_ext.asp Not so simple, and not (directly) a job for Python. Thanks, Chris Roger Upole (rupole at hotmail.com) wrote: : As you guessed, the icon locations are stored in the registry. : There's a key under HKEY_CLASSES_ROOT for each : registered file type, with a default value holding the class name. : Under the class name, there's a DefaultIcon key that gives : the path to the icon. Using python files an an example, you : have HKCR\.py with Default=Python.File, and under : HKCR\Python.File\DefaultIcon, you should have the : path to py.ico. You can use the _winreg module to create : your own entries. : hth : Roger From matthew.garrish at sympatico.ca Sat Oct 8 21:32:55 2005 From: matthew.garrish at sympatico.ca (Matt Garrish) Date: Sat, 8 Oct 2005 21:32:55 -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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> Message-ID: <9r_1f.9763$2F2.1350622@news20.bellglobal.com> "John Bokma" wrote in message news:Xns96E9BE10C8F6Dcastleamber at 130.133.1.4... > Rich Teer wrote: > >> On Sun, 9 Oct 2005, Lasse V?gs?ther Karlsen wrote: >> >>> But trying to keep your email world into a pure text-based >>> no-formatting-whatsoever world, that's a fantasy bubble that is bound to >>> burst, sooner rather than later. >> >> Not here. I've configured my email server to reject HTML emails >> before I even see them, and more often tham not I'll delete any >> others that sneak through the gate. > > Good for you. If I do that, I lose some customers. Your private war is a > joke, and one day you'll wake up. What a waste of energy. > LOL! Maybe this inane thread can finally die now... Matt From steve at holdenweb.com Fri Oct 7 03:36:04 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 07 Oct 2005 08:36:04 +0100 Subject: where to find information about errors/exceptions in socket.py In-Reply-To: <1128663897.741141.241490@f14g2000cwb.googlegroups.com> References: <1128663897.741141.241490@f14g2000cwb.googlegroups.com> Message-ID: mirandacascade at yahoo.com wrote: > Version of python: 2.4 > O/S: Win2K > > I will be writing some python scripts to do some client-side > programming that involves socket.py. I expect that I will be making > calls to the following methods/functions: > > connect_ex() > setsockopt() > sendall() > recv() > close() > > Where can one find information about whether the functions/methods > above return error codes that provide some indication as to whether the > function/method succeeded? Is there an exception class for handling > exceptions raised in socket.py? If so, where can one find information > about it? > > I consulted the docstrings and didn't find much about return codes or > exception classes. Also looked at the Lutz "Programming Python" > text...it devotes several pages to socket programming, but I didn't > observe much with regard to error/exception handling. > I'd suggest reading the documentation myself: http://docs.python.org/lib/module-socket.html regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From scapt at unil.ch Thu Oct 20 05:41:16 2005 From: scapt at unil.ch (=?iso-8859-1?B?U+li?=) Date: 20 Oct 2005 02:41:16 -0700 Subject: Sequence and/or pattern matching References: <1129710091.400262.139440@g14g2000cwa.googlegroups.com> <1h4ocwa.184dksqmnv1q1N%aleaxit@yahoo.com> <1129712258.200656.202440@g43g2000cwa.googlegroups.com> <86fyqxw7ev.fsf@bhuda.mired.org> Message-ID: <1129801276.626944.96230@g44g2000cwa.googlegroups.com> Hi everybody, Thanks for the time taken to answer my question. Unfortunatly, it seems that there's a little confusion about what I want to do. In fact, I don't want to search for a particular path between computers. What I really want is to detect sequences of connection that are repeated along the log. Is it clearer, if not, I will put another exmample ;-) Thank you ! Ps Python community is very nice, I'm glad I learn this language ! From peter at engcorp.com Thu Oct 27 15:19:45 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 27 Oct 2005 15:19:45 -0400 Subject: Counting Threads In-Reply-To: <1130435796.917475.295830@g14g2000cwa.googlegroups.com> References: <1130435220.846203.86320@g44g2000cwa.googlegroups.com> <1130435796.917475.295830@g14g2000cwa.googlegroups.com> Message-ID: David Poundall wrote: > Just sorted (its always the way when you post isn't it) > > But the count isn't doint what I expected. I was after a increment > after every time the class was used ireespective of instance. I have no idea what that last sentence above means... > Instead > I get a count based on the instance usage. > Idea's anyone? Several, interspersed below: > ------------------------------------------------------------------------------------ > class ServerThreads: > """ > Wrapper for thread handling. > Thread ID 0 = Controller > Thread ID 1 = Plant Object 1 > Thread ID 2 = Plant Object 2 > """ > > GlobalThreadCount = 0 Style note: using MixedCaps for variable names doesn't fit conventional Python style. To be conventional you would use "globalThreadCount" here, or just "threadCount" since it's no more "global" than any other class attribute. > def __init__(self): > global GlobalThreadCount And here you definitely don't want "global" since your GlobalThreadCount above is *not* a Python "global". It's a class attribute, and you should reference it as such: > self.Threads = {} > GlobalThreadCount = 0 Change to: ServerThreads.GlobalThreadCount = 0 and access it as such in all other places inside the class. > def launch(self, SubToLaunch, SubsArgs=(), SubsKwargs={}, > AsDeamon=True): > t = Thread(target=SubToLaunch, args = SubsArgs, kwargs = > SubsKwargs) > t.setDaemon(AsDeamon) You appear to know there is a difference in spelling between these two "demons"... but only "daemon" is correct. "Deamon" is a misspelling. > t.start() > self.Threads[len(self.Threads)] = t # Stash the > thread in an instance local > > global GlobalThreadCount > GlobalThreadCount += 1 > print GlobalThreadCount Caution: if you can't guarantee that launch() will be called from only one thread, you have a race condition here since the count could be increased "simultaneously" from multiple threads and you won't get reliable results. You would want to wrap it with a threading.Lock() to protect it in that case. > def globalusagecount(self): > """ > Returns a count figure for how many threads are running in > total > usnig this class. > """ > global GlobalThreadCount > return GlobalThreadCount Style/usage note: although as I mentioned you don't want to use "global" variables anyway, even if you did the above line is unnecessary. You only need to use "global" if you are going to *rebind* the global name (i.e. assign a new value to it), not if you are merely reading the value and returning it, as above. What you wrote would work, it's just not needed or usual. (But, again, using a global at all is wrong anyway.) -Peter From smadim2 at grads.ece.mcmaster.ca Tue Oct 4 14:15:20 2005 From: smadim2 at grads.ece.mcmaster.ca (Mohammed Smadi) Date: Tue, 4 Oct 2005 14:15:20 -0400 (EDT) Subject: closing sockets Message-ID: hi; i am executing program whcih uses a tcp socket. At the end of the program i do s.close() where s is my socket. when i try to run the program again right away i get the following error Traceback (most recent call last): File "asterisk_login.py", line 14, in ? s.bind(("", hp_port)) # do some error checking File "", line 1, in bind socket.error: (98, 'Address already in use') how can i get around that thanks smadi From csheppard91 at gmail.com Sat Oct 8 15:11:27 2005 From: csheppard91 at gmail.com (csheppard91 at gmail.com) Date: 8 Oct 2005 12:11:27 -0700 Subject: new forum -- homework help/chit chat/easy communication Message-ID: <1128798687.305818.66010@g49g2000cwa.googlegroups.com> I've launched a new forum not too long ago, and I invite you all to go there: www.wizardsolutionsusa.com (click on the forum link). We offer all kinds of help, and for those of you who just like to talk, there's a chit chat section just for you...Just remember that forum communication is much easier, safer, and faster. From spammers-go-here at spam.invalid Sat Oct 15 21:02:03 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Sat, 15 Oct 2005 21:02:03 -0400 Subject: Length of read in in python-gpib Message-ID: <4351a665$0$41142$14726298@news.sunsite.dk> python-gpib provides Gpib.py (see end of post) for Linux. I am trying to use the method called read. I usually use it without arguments (the default length being 512). However, I am trying to read in a string with some 16,000 comma separated floating point numbers. So, I have to pass a length parameter much much larger than 512. As is stands, the default read takes in only about 35-40 numbers, so I need about 512/35*16000 ~= 230,000. Not being sure if I could make python read in something that big, I started small - with 1024. This produces an list of numbers that has a malformed first number (I get 88309e-9 instead of something like 6.788309e-9.). Could this be a bug ? Second, does the length need to be a power of two for some reason ? python-gpib is an excellent library, but it suffers from an utter lack of documentation. ------------------------ Gpib.py ----------------------------- import gpib RQS = (1<<11) SRQ = (1<<12) TIMO = (1<<14) class Gpib: def __init__(self,name='gpib0'): self.id = gpib.find(name) def write(self,str): gpib.write(self.id, str) def writebin(self,str,len): gpib.writebin(self.id,str,len) def read(self,len=512): self.res = gpib.read(self.id,len) return self.res def readbin(self,len=512): self.res = gpib.readbin(self.id,len) return self.res def clear(self): gpib.clear(self.id) def wait(self,mask): gpib.wait(self.id,mask) def rsp(self): self.spb = gpib.rsp(self.id) return self.spb def trigger(self): gpib.trg(self.id) def ren(self,val): gpib.ren(self.id,val) def ibsta(self): self.res = gpib.ibsta() return self.res def ibcnt(self): self.res = gpib.ibcnt() return self.res def tmo(self,value): return gpib.tmo(self.id,value) From jack.sankey at gmail.com Tue Oct 11 17:09:07 2005 From: jack.sankey at gmail.com (gurkesaft) Date: 11 Oct 2005 14:09:07 -0700 Subject: scipy.plt legend? In-Reply-To: References: <1129046539.630460.326290@g49g2000cwa.googlegroups.com> Message-ID: <1129064947.475029.78260@g14g2000cwa.googlegroups.com> Thank you, Robert. I noticed how obsolete it is! There is no documentation. Matplotlib freezes my system if I close a plot and make a new one :(. Bah. Windows :) Anyway, I figured out how to make gnuplot.py do my bidding. -Jack From my_email_is_posted_on_my_website at munged.invalid Tue Oct 18 04:42:52 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Tue, 18 Oct 2005 08:42:52 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <43518dc6.95550404@news.oz.net> <11l3fig34u2ln27@corp.supernews.com> Message-ID: On Tue, 18 Oct 2005 08:12:23 GMT, Tim Tyler wrote or quoted : >> - Any ability to automatically generate hits on sender-specified >> servers when the email is read. > >I hadn't though of that one. As well as use in DDOS attacks, that >can help let spammers know if they have reached a human :-| If you think about it, much as you hate spammers you WANT them to have that information. If you never read spam, and they know that, they eventually might stop sending it to you and focus on the nitwits who read it. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From my_email_is_posted_on_my_website at munged.invalid Wed Oct 12 18:34:14 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 12 Oct 2005 22:34:14 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <036lk15rkocgpjjlbdl11vsr82tkrc4bmn@4ax.com> Message-ID: On Mon, 10 Oct 2005 09:35:58 -0700, Alan Balmer wrote or quoted : >And they don't know about attachments? Attachments are geeky kludge. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From deets at nospam.web.de Wed Oct 5 11:06:03 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 05 Oct 2005 17:06:03 +0200 Subject: "no variable or argument declarations are necessary." In-Reply-To: References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> Message-ID: <3qi8erFf252rU1@uni-berlin.de> > This is naive. Testing doesn't guarantee anything. If this is what you > think about testing, then testing gives you a false impression of > security. Maybe we should drop testing. Typechecking is done by a reduced lamda calculus (System F, which is ML-Style), whereas testing has the full power of a turing complete language. So _if_ one has to be dropped, it would certainly be typechecking. Additionally, testing gives you the added benefit of actually using your decelared APIs - which serves documentation purposes as well as securing your design decisions, as you might discover bad design while actually writing testcases. Besides that, the false warm feeling of security a successful compilation run has given many developers made them check untested and actually broken code into the VCS. I've seen that _very_ often! And the _only_ thinng that prevents us from doing so is to enforce tests. But these are more naturally done in python (or similar languages) as every programmer knows "unless the program run sucsessfully, I can't say anything about it" than in a statically typed language where the programmer argues "hey, it compiled, it should work!" Regards, Diez From bear at sonic.net Thu Oct 6 00:51:48 2005 From: bear at sonic.net (Ray Dillinger) Date: Thu, 06 Oct 2005 04:51:48 GMT Subject: check html file size In-Reply-To: References: <1128473042.653989.175990@o13g2000cwo.googlegroups.com> Message-ID: Richard Gration wrote: > ... fucking ... fucking ... fucking ... fucking ... Fucking ... fucking > ... fucking My friend, you can learn to use a far richer vocabulary of obscenities. If your creative flow is blocked by the fear that you can't spell more dirty words correctly, you can dispel this fear with a few evenings of study and preparation. Amaze your friends! Amuse your enemies! Enrich your vocabulary! You can learn the joys of cussing seven times in the same sentence without resorting to repetition! For extra points, and with suitable study, you can even learn to write entire paragraphs of _original_ obscenity! Just imagine how much clearer your point would have been if you'd called him a jizz-licking dogcock grabber! Why insult his code with a vague word like "moronicity" when you could use "steaming pile of entrails" or better yet, "bucket of fermented ballsweat?" wouldn't that have made your technical point much clearer? Now go, and don't attempt obscenity in public again until you learn how. Bear From codecraig at gmail.com Thu Oct 13 09:10:47 2005 From: codecraig at gmail.com (Java and Swing) Date: 13 Oct 2005 06:10:47 -0700 Subject: Pass a tuple (or list) to a C wrapper function In-Reply-To: References: <1129147560.524316.281110@g43g2000cwa.googlegroups.com> <1129152455.3374.20.camel@localhost.localdomain> Message-ID: <1129209047.946591.44780@g49g2000cwa.googlegroups.com> Fredrik, ...I tried using your code... static long *get_long_array(PyObject *data, int *data_size) { int i, size; long* out; PyObject* seq; seq = PySequence_Fast(data, "expected a sequence"); if (!seq) return NULL; size = PySequence_Size(seq); if (size < 0) return NULL; if (data_size) *data_size = size; out = (long*) PyMem_Malloc(size * sizeof(long)); if (!out) { Py_DECREF(seq); PyErr_NoMemory(); return NULL; } for (i = 0; i < size; i++) out[i] = PyInt_AsLong(PySequence_Fast_GET_ITEM(seq, i)); Py_DECREF(seq); if (PyErr_Occurred()) { PyMem_Free(out); out = NULL; } return out; } and I get this error.. C:\project\myapp.c(549) : error C2040: 'get_long_array' : 'long *(struct _object *,int *)' differs in levels of indirection from 'int ()' any idea? Fredrik Lundh wrote: > Jeremy Moles wrote: > > > Probably what you want to do though is just keep the tuple as is and > > iterate over it using the PySequence_* protocol: > > > > http://docs.python.org/api/sequence.html > > I did post a complete and tested example a few days ago, which contained > code that showed how to do this. a complete waste of time, of course. > > From codecraig at gmail.com Wed Oct 5 08:09:21 2005 From: codecraig at gmail.com (Java and Swing) Date: 5 Oct 2005 05:09:21 -0700 Subject: Call C functions from Python In-Reply-To: <11k5rpekldqd29e@corp.supernews.com> References: <1128454231.381256.297280@g47g2000cwa.googlegroups.com> <11k5mpg999eos1f@corp.supernews.com> <1128457689.105158.24700@g44g2000cwa.googlegroups.com> <11k5rpekldqd29e@corp.supernews.com> Message-ID: <1128514161.835258.138730@g44g2000cwa.googlegroups.com> I used, myApp = CDLL("C:...") ...as I saw it in one of the ctypes samples. Anyhow, I tried... myApp = cdll.LoadLibrary("C:\\myapp.dll") myApp.AddNumbers(1, 4) ..I get an error... AttributeError: function 'AddNumbers' not found ...myapp certainly has AddNumbers. Grant Edwards wrote: > On 2005-10-04, Java and Swing wrote: > > ok i got ctypes...now i try > > > >>> from ctypes import * > >>> myApp = CDLL("C:\\myapp.dll") > > I've never seen that sort of usage before. I don't know what > CDLL does, and I can't find it in the docs anywhere. > > Based on my reading of the tutorial, I would have tried eitehr > > myApp = cdll.myapp > or > myApp = cdll.LoadLibrary("C:/myapp.dll") > > > ..now how can I call functions on in myapp.dll? From the > > tutorial I am not sure.. > > Assuming CDLL did something equivalent to cdll.LoadLibrary(), > I'd try: > > myApp.FuncName() > > I've always done it the way it's done in the tutorial: > > mylib = windll.Lib_Name > mylib.myFuncName() > > > i try, dir(cdll.myApp) and dir(myApp)..but don't see my > > functions listed. > > I don't think dir() works on dll's like that. I certainly > don't see it mentioned in the tutorial. What happened when you > tried calling the function the way the tutorial does? > > myapp = cdll.myapp > myapp.MyFunc() > > -- > Grant Edwards grante Yow! Yow! Is my fallout > at shelter termite proof? > visi.com From bonono at gmail.com Sun Oct 23 01:05:38 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 22 Oct 2005 22:05:38 -0700 Subject: best way to replace first word in string? In-Reply-To: References: <1129822003.246170.303920@f14g2000cwb.googlegroups.com> Message-ID: <1130043938.837369.255270@g44g2000cwa.googlegroups.com> interesting. seems that "if ' ' in source:" is a highly optimized code as it is even faster than "if str.find(' ') != -1:' when I assume they end up in the same C loops ? Ron Adam wrote: > Guess again... Is this the results below what you were expecting? > > Notice the join adds a space to the end if the source string is a single > word. But I allowed for that by adding one in the same case for the > index method. > > The big win I was talking about was when no spaces are in the string. > The index can then just return the replacement. > > These are relative percentages of time to each other. Smaller is better. > > Type 1 = no spaces > Type 2 = space at 10% of length > Type 3 = space at 90% of length > > Type: Length > > Type 1: 10 split/join: 317.38% index: 31.51% > Type 2: 10 split/join: 212.02% index: 47.17% > Type 3: 10 split/join: 186.33% index: 53.67% > Type 1: 100 split/join: 581.75% index: 17.19% > Type 2: 100 split/join: 306.25% index: 32.65% > Type 3: 100 split/join: 238.81% index: 41.87% > Type 1: 1000 split/join: 1909.40% index: 5.24% > Type 2: 1000 split/join: 892.02% index: 11.21% > Type 3: 1000 split/join: 515.44% index: 19.40% > Type 1: 10000 split/join: 3390.22% index: 2.95% > Type 2: 10000 split/join: 2263.21% index: 4.42% > Type 3: 10000 split/join: 650.30% index: 15.38% > Type 1: 100000 split/join: 3342.08% index: 2.99% > Type 2: 100000 split/join: 1175.51% index: 8.51% > Type 3: 100000 split/join: 677.77% index: 14.75% > Type 1: 1000000 split/join: 3159.27% index: 3.17% > Type 2: 1000000 split/join: 867.39% index: 11.53% > Type 3: 1000000 split/join: 679.47% index: 14.72% > > > > > import time > def test(func, source): > t = time.clock() > n = 6000000/len(source) > s = '' > for i in xrange(n): > s = func(source, "replace") > tt = time.clock()-t > return s, tt > > def replace_word1(source, newword): > """Replace the first word of source with newword.""" > return newword + " " + " ".join(source.split(None, 1)[1:]) > > def replace_word2(source, newword): > """Replace the first word of source with newword.""" > if ' ' in source: > return newword + source[source.index(' '):] > return newword + ' ' # space needed to match join results > > > def makestrings(n): > s1 = 'abcdefghij' * (n//10) > i, j = n//10, n-n//10 > s2 = s1[:i] + ' ' + s1[i:] + 'd.' # space near front > s3 = s1[:j] + ' ' + s1[j:] + 'd.' # space near end > return [s1,s2,s3] > > for n in [10,100,1000,10000,100000,1000000]: > for sn,s in enumerate(makestrings(n)): > r1, t1 = test(replace_word1, s) > r2, t2 = test(replace_word2, s) > assert r1 == r2 > print "Type %i: %-8i split/join: %.2f%% index: %.2f%%" \ > % (sn+1, n, t1/t2*100.0, t2/t1*100.0) From steve at holdenweb.com Tue Oct 11 07:23:44 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 11 Oct 2005 12:23:44 +0100 Subject: strange import error with Python-2.4.1 In-Reply-To: References: <434B8EDF.3060905@chamonix.reportlab.co.uk> <434B9602.9070001@holdenweb.com> Message-ID: Fredrik Lundh wrote: > Steve Holden wrote: > > >>Can I ask if you are specifying a source encoding in your file with a >>pragma (?) like >> >># -*- coding: iso-8859-15 -*- >> >>I've noticed what appear to be spurious syntax errors from time to time >>on such files, and have been attempting to debug the problem for some >>time without any apparent success. > > > http://www.python.org/sf/1175396 > Thanks! regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From auch-ich-m at g-kein-spam.com Wed Oct 26 04:26:45 2005 From: auch-ich-m at g-kein-spam.com (=?ISO-8859-1?Q?Andr=E9?= Malo) Date: Wed, 26 Oct 2005 10:26:45 +0200 Subject: more than 100 capturing groups in a regex References: <1130160675.270886.208420@z14g2000cwz.googlegroups.com> <1130253162.790086.59130@o13g2000cwo.googlegroups.com> <1130314553.112864.233480@g43g2000cwa.googlegroups.com> Message-ID: * "Iain King" wrote: > Ah, doh! Of course. Oh well then... still, doesn't python's RE > engine support named groups? That would be cumbersome, but would allow > you to go above 100... The named groups are built on top of numbered captures. They are mapped by the parser and the match instance's group method. The regex matcher itself never sees these names. nd From larry.bates at websafe.com Thu Oct 20 10:04:20 2005 From: larry.bates at websafe.com (Larry Bates) Date: Thu, 20 Oct 2005 09:04:20 -0500 Subject: Converting 2bit hex representation to integer ? In-Reply-To: <4356740c$0$41148$14726298@news.sunsite.dk> References: <43567027$0$41144$14726298@news.sunsite.dk> <-_2dndLn4eEm78veRVn-qg@comcast.com> <4356740c$0$41148$14726298@news.sunsite.dk> Message-ID: No you can't convert using str(). Binary data is stored in a Python string object, but it isn't really a string. It is rather just a bunch of bits packed into a string variable. struct.unpack() will unpack those bits into any number of different types of variables and is what you need. Example: import struct s='\x64' values=struct.unpack('b',s) print "values=",values value=(100,) Note: struct.unpack returns a tuple of values. Just get values[0] to get the first one. Larry Madhusudan Singh wrote: > Larry Bates wrote: > > >>Can you give us an example. I don't know what two bit >>hex means (takes at least 4 bits to make a hex digit). > > > Like 64(base 16)=100. > I am referring to 64 in the above. > > >>Now I'm going to try to guess: >> >>If the data is binary then all you need to do is to >>use the struct.unpack module to convert to integer. > > > Doesn't unpack presume that the input is a string ? If so, is it safe to > convert binary data to string using str() ? From davids at webmaster.com Tue Oct 18 01:21:55 2005 From: davids at webmaster.com (David Schwartz) Date: Mon, 17 Oct 2005 22:21:55 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <8b09l1tgavuiu3hmatva34624lvsjn6mtl@4ax.com> Message-ID: "Roedy Green" wrote in message news:8b09l1tgavuiu3hmatva34624lvsjn6mtl at 4ax.com... > On Mon, 17 Oct 2005 19:44:55 -0700, "David Schwartz" > wrote or quoted : >> It is not Microsoft's obligation to be "fair". It is Microsoft's >>obligation to push their vision of the future of computing, one with >>Microsoft's products at the center, using anything short of force or >>fraud. > I think that what they did borders on force/fraud. I don't think any of it bordered on force or fraud. However, their obligation to their shareholders requires them to do anythign that borders on force/fraud so long as it isn't force/fraud. However, the use of things too close to force/fraud often backfires. Microsoft has an obligation to be strategic and look nice where those things beneficially impact the bottom line. It's Bill Gates' job to make his company worth as much as possible. DS From fredrik at pythonware.com Wed Oct 5 09:04:20 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 5 Oct 2005 15:04:20 +0200 Subject: Call C functions from Python References: <1128454231.381256.297280@g47g2000cwa.googlegroups.com><11k5mpg999eos1f@corp.supernews.com><1128457689.105158.24700@g44g2000cwa.googlegroups.com><11k5rpekldqd29e@corp.supernews.com> <1128514161.835258.138730@g44g2000cwa.googlegroups.com> Message-ID: Java and Swing wrote: >I used, myApp = CDLL("C:...") ...as I saw it in one of the ctypes > samples. > > Anyhow, I tried... > > myApp = cdll.LoadLibrary("C:\\myapp.dll") > myApp.AddNumbers(1, 4) > > ..I get an error... > > AttributeError: function 'AddNumbers' not found > > ...myapp certainly has AddNumbers. properly exported? what does dumpbin /exports myapp.pyd say? From lassevk at gmail.com Tue Oct 4 05:55:20 2005 From: lassevk at gmail.com (=?iso-8859-1?q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: 4 Oct 2005 02:55:20 -0700 Subject: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please! In-Reply-To: <43424bee$0$38666$edfadb0f@dread12.news.tele.dk> References: <43424bee$0$38666$edfadb0f@dread12.news.tele.dk> Message-ID: <1128419720.504389.323330@g14g2000cwa.googlegroups.com> While Microsoft and other big software vendors might have a roadmap that ties you very tightly in with their budget, and also changes that roadmap from time to time which breaks your current software, a lot of open source projects have no roadmap at all. This means that a .x.y.2 upgrade might very well kill your software in the same way a 6-7 upgrade with VB might. The biggest reason for this, as far as I can tell, is that open source projects are very much built to integrate with other projects, simply because the source is available and it's thus far easier to integrate them, but that also means that unless you upgrade two integrated projects at the same time, you risk an upgrade in one breaking the other. As an example, Komodo from ActiveState has serious problems (on my 4 computers) debugging functions with Python 2.4.2. Right now I don't know if Python 2.4.2 fixed a bug Komodo depended on or if 2.4.2 introduced a bug breaking Komodo, or if my computer is some freaky thing that just refuses to behave. I'm reinstalling my office computer these days so I'll see what happens then, but until that's done, I've had to go back to 2.4.1 in order to debug properly. With a 6.0 to 7.0 upgrade for a project, I expect problems. Even Microsoft came out and said this new release will definitely break your software projects. The whole point of an upgrade is that something that did X before, does Y now, something different. Preferrably Y = X+1, but sometimes it's radically different. I think a main point in a lot of projects is that unless you have to upgrade, don't. That way you can avoid a lot of problems by default. Now, as for OP, the only way to easily get full support for all the new Microsoft technology when it comes out will probably be to upgrade to the latest and the greatest of the Microsoft tools. I bet the Python community will react quicker than you can turn your head, but the tools will still not be the same as Microsoft. Does it mean they won't be as good ? No, it means they will be different. It means that you probably can't follow Microsoft help when dealing with Python modules. And that, is exactly as it should be. From steve at holdenweb.com Thu Oct 20 03:19:55 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 20 Oct 2005 08:19:55 +0100 Subject: sqlstring -- a library to build a SELECT statement In-Reply-To: References: <1129774730.887128.314960@z14g2000cwz.googlegroups.com> Message-ID: Jason Stitt wrote: > On Oct 19, 2005, at 9:18 PM, grunar at gmail.com wrote: > > > >>My solution is sqlstring. A single-purpose library: to create SQL >>statement objects. These objects (such as sqlstring.Select), represent >>complex SQL Statements, but as Python objects. > > > > > First of all, I like this idea. I've been thinking about doing > something similar but am stuck with SQLObject for the moment. The > ability to construct complex expressions in pieces and then mix and > match them would be killer. > > I think some operator overloading, especially the obvious cases like > ==, is cleaner than using only functions because it lets you order > things normally. But some of the operator choices are non-intuitive. > Personally, I would make something like 'alias' a function or class, > rather than overloading XOR. Not sure about ** for where. > > Using // for 'in' looks really weird, too. It's too bad you can't > overload Python's 'in' operator. (Can you? It seems to be hard-coded > to iterate through an iterable and look for the value, rather than > calling a private method like some other builtins do.) > >>> class inplus(object): ... def __contains__(self, thing): ... print "Do I have a", thing, "?" ... return True ... >>> x = inplus() >>> "Steev" in x Do I have a Steev ? True >>> [...] regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From rrr at ronadam.com Wed Oct 26 19:44:50 2005 From: rrr at ronadam.com (Ron Adam) Date: Wed, 26 Oct 2005 23:44:50 GMT Subject: namespace dictionaries ok? In-Reply-To: <1h4zlsn.15t73ko1d685iuN%aleaxit@yahoo.com> References: <1h4zlsn.15t73ko1d685iuN%aleaxit@yahoo.com> Message-ID: Alex Martelli wrote: > Ron Adam wrote: > ... > >> class namespace(dict): >> def __getattr__(self, name): >> return self.__getitem__(name) > > ... > >>Any thoughts? Any better way to do this? > > > If any of the keys (which become attributes through this trick) is named > 'update', 'keys', 'get' (and so on), you're toast; it really looks like > a nasty, hard-to-find bug just waiting to happen. If you're really > adamant on going this perilous way, you might try overriding > __getattribute__ rather than __getattr__ (the latter is called only when > an attribute is not found "in the normal way"). Thanks Alex, I was wondering what the difference between __getattr__ and __getattribute__ was. > If you think about it, you're asking for incompatible things: by saying > that a namespace X IS-A dict, you imply that X.update (&c) is a bound > method of X; at the same time, you also want X.update to mean just the > same thing as X['update']. Something's gotta give...!-) > > Alex Part of the motivation of this is to try and keep names as names and data as data in my programs. I would use dictionaries for data storage, and namespace_dicts for strictly name/value passing. So some limitations with names are expected just as they would exist anywhere else with object names. Ie.. can't use keywords, and using names of methods can cause objects to break, etc... This seems to be the closest to a generic namespace object so far. class namespace(dict): __getattribute__ = dict.__getitem__ __setattr__ = dict.__setitem__ __delattr__ = dict.__delitem__ Not having any public and/or visible methods of it's own is a good thing here. So you would need to use dict.update(A_namespace, A_dict) in this case. I don't think thats a problem. Maybe a namespace object, (as I am thinking of it), should not have it's own interface, but inherit one from the object it's inserted into? Anyway... this is experimental, and not production code of any sort. ;-) Cheers, Ron From peter at engcorp.com Sun Oct 23 14:58:07 2005 From: peter at engcorp.com (Peter Hansen) Date: Sun, 23 Oct 2005 14:58:07 -0400 Subject: wxpython - passing arg to wx.app OnInit In-Reply-To: <11lnkbipmbgl0d2@corp.supernews.com> References: <11lm687nih0l7ac@corp.supernews.com> <7pGdnfmqQoJJG8beRVn-iA@powergate.ca> <11lnkbipmbgl0d2@corp.supernews.com> Message-ID: <3MydnebVNYW6QMbeRVn-oQ@powergate.ca> Stuart McGraw wrote: > I simplied the my code for posting. In my real program, the > thing being passed is not a command line argument per se, > but the result of signifigant processing dependent on the > command line argument. I do not want to repeat that > processing in the wx.App method. > Would you elaborate on the other ways? In that case, override __init__ something like this: class Application(wx.App): def __init__(self, *pargs, clargs=None, **kwargs): self.clargs = clargs or [] # store reference to args # call parent class initializer wx.App.__init__(self, *pargs, **kwargs) def OnInit(self): # use self.clargs here app = Application(redirect=0, clargs=[dbfn]) or whatever... I just guessed at what you meant to do with dbfn though, but I think the basic idea is clear enough. -Peter From steve at holdenweb.com Thu Oct 13 14:58:25 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 13 Oct 2005 19:58:25 +0100 Subject: installer for amd64 build of python? In-Reply-To: <1129226551.255303.46270@g44g2000cwa.googlegroups.com> References: <1129162224.131305.269060@g49g2000cwa.googlegroups.com> <434E1674.5010201@v.loewis.de> <1129192705.632826.145210@z14g2000cwz.googlegroups.com> <1129225263.705977.181050@o13g2000cwo.googlegroups.com> <1129226551.255303.46270@g44g2000cwa.googlegroups.com> Message-ID: Brett Hoerner wrote: > Trent Mick wrote: > >>Yes. The MS Platform SDK is free and includes a compiler that can target >>x86, ia64 and x64 (the latter is what MS -- and Sun -- are calling >>AMD64). > > > Thanks, looking at their site I can't find a Platform SDK for XP... am > I looking for the Windows 2003 Server SDK...? Seems counter-intuitive > if so, but it does mention you can build 32 and 64-bit apps with it, I > just assumed they would be uh, for Windows Server. > > Thanks again, > Brett > I used the instructions at http://www.vrplumber.com/programming/mstoolkit/ to install the MS Toolkit, but I haven't tried compiling 64-bit code myself, not having any 64-bit hardware. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From allen.cross at gmail.com Mon Oct 3 22:53:08 2005 From: allen.cross at gmail.com (whoopsi) Date: 3 Oct 2005 19:53:08 -0700 Subject: help w/ simple GPIB prog. Message-ID: <1128394388.461568.110390@g47g2000cwa.googlegroups.com> Hi, Could someone give me some simple commands for communicating with GPIB devices. All I want is to aquire values from a multimeter/fiber optic attenuator/and a power meter. Nothing too complex. I was able to do so using Matlab (however, I was using the serail port) and communicating via SCPI language, but now the computer I'm using doesn't have Matlab, so I'm trying to learn with Python. I've downloaded and installed: ActivePython_2.4, pyserial-2.2, and gpib-devices-0.0.4.win32.exe. I have read some beginner's guides to python, but they don't discuss GPIB programming much. I thought I would simply be able to open a port, and send SCPI commands to configure and aquire values. But when I tried to run GPIB .py files from gpib-device-0.0.4 I got an error: "symbol 'ibsta' not found". Doing some searching I found that ibsta was refering to a library for GPIB (I'm assuming some .dll from a driver) and wrapping them???. But these instruments as far as I know don't need drivers. The instruments I'm using are: -PC w/ WIN2k -Keithley 2000 multimeter -HP 8156A optical attenuator -ILXLightwave Fiber Optic Power Meter Essentially what I would like to do is simply run the attenuator through different dB values and measure the voltage using the multimeter. And possibly later integrating the power meter. If you could help me I would appreciate it, and please forgive the above longwindedness. thanks. -Allen From http Fri Oct 14 00:56:39 2005 From: http (Paul Rubin) Date: 13 Oct 2005 21:56:39 -0700 Subject: Python's garbage collection was Re: Python reliability References: <3r6i0uFi3qb8U2@uni-berlin.de> <7xfyr5kfgm.fsf@ruckus.brouhaha.com> <3r6osdFhsfjgU1@uni-berlin.de> <7xvf0168nq.fsf@ruckus.brouhaha.com> <434e7967$1@nntp0.pdx.net> <7xr7apqw1y.fsf@ruckus.brouhaha.com> <434ea2ad$1@nntp0.pdx.net> <7x3bn5s1dm.fsf@ruckus.brouhaha.com> <3r83a5Fi1rt6U1@uni-berlin.de> <7xfyr5qdxh.fsf@ruckus.brouhaha.com> Message-ID: <7xll0wofw8.fsf@ruckus.brouhaha.com> Steve Holden writes: > >>And this presumes an architecture which byte-addresses and only > >> uses "aligned" addresses. > > He was talking about the arachiteecture, for Pete's sake, not a compiler. Yeah, I noticed that, I could have been pedantic about it but chose to just describe how these language implementations work in the real world with zero exceptions that I know of. I guess I should have spelled it out. From http Tue Oct 11 03:26:15 2005 From: http (Paul Rubin) Date: 11 Oct 2005 00:26:15 -0700 Subject: Send password over TCP connection References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> <7xd5md76kd.fsf@ruckus.brouhaha.com> Message-ID: <7xslv87bvs.fsf@ruckus.brouhaha.com> Laszlo Zsolt Nagy writes: > This is a bit offtopic here. I read the RFC and I do not see why SRP > is not vulnerable to dictionary attacks. > If I have a working client software then I can use it to reveal > passwords. Isn't it a dictionary attack? Dictionary attack in this context means an eavesdropper records a session, then compares all the hashed passwords against a word list offline. If the attacker is allowed to make unlimited online queries, then he can guess at SRP passwords too. But the host should notice that and prevent it. From axel at white-eagle.invalid.uk Wed Oct 26 13:45:30 2005 From: axel at white-eagle.invalid.uk (axel at white-eagle.invalid.uk) Date: Wed, 26 Oct 2005 17:45:30 GMT Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: <_gP7f.7988$Ih5.221@fe1.news.blueyonder.co.uk> In comp.lang.perl.misc Steven D'Aprano wrote: >> Heck, I dunno. Like you, I don't even really care all that much. > You don't care that innovation in desktop software has been crippled by > the actions of the monopoly player Microsoft? > In 1988, there were something like ten or a dozen word processors > available to choose from, and they were competing on price and features Yes... I think I used a couple around then. > like crazy. That was then, now there is just MS Office. The most > innovative things Microsoft has added to Office in the last decade? Clippy Er... Open Office, Apple Works. Axel From jamie at jborder.com Thu Oct 13 05:50:19 2005 From: jamie at jborder.com (Jamie Border) Date: Thu, 13 Oct 2005 09:50:19 +0000 (UTC) Subject: Pythot doc problem: lambda keyword... References: <1128925487.783702.198410@f14g2000cwb.googlegroups.com> <1128929786.734783.296990@g44g2000cwa.googlegroups.com> Message-ID: "Pisin Bootvong" wrote: Xah Lee ?????: [...] > Fuck the Python liers and ignorant fuckheads. Motherfucking don't know > shit and yet lying thru their teeth with fanfare. [...] > Xah > xah at xahlee.org > ? http://xahlee.org/ [elided] PB> BTW, you post to the wrong group. No, I think c.l.l is exactly the place to discuss how to play many trumpets through one set of teeth. In fact, I have a box of trumpets lying around somewhere... Open wide, Xah! Jamie From en.karpachov at ospaz.ru Mon Oct 3 12:55:24 2005 From: en.karpachov at ospaz.ru (en.karpachov at ospaz.ru) Date: Mon, 3 Oct 2005 20:55:24 +0400 Subject: "no variable or argument declarations are necessary." In-Reply-To: References: <434084 3b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99 f9f10238681bf68f@teranews> Message-ID: <20051003205524.55ef7a86.jk@ospaz.ru> On Tue, 04 Oct 2005 01:46:49 +1000 Steven D'Aprano wrote: > errors and not rely on the compiler. No compiler will catch this error: > > x = 12.0 # feet > # three pages of code > y = 15.0 # metres > # three more pages of code > distance = x + y > if distance < 27: > fire_retro_rockets() > > And lo, one multi-billion dollar Mars lander starts braking either too > early or too late. Result: a new crater on Mars, named after the NASA > employee who thought the compiler would catch errors. So, I guess, you have a spare Mars lander especially for unit-testing? :) -- jk From dwahler at gmail.com Fri Oct 14 17:18:39 2005 From: dwahler at gmail.com (David Wahler) Date: 14 Oct 2005 14:18:39 -0700 Subject: KeyboardInterrupt being lost? References: Message-ID: <1129324719.428046.225970@f14g2000cwb.googlegroups.com> Operation Latte Thunder wrote: > I have a simple test proggie that isn't behaving like I expect ( found > below ). The script will infinitely run ( as expected ), but seems to > completely ignore control-C's. Shouldn't the interpreter pass along > KeyboardInterrupts and break out of the while loop, or am I missing > something? > > Using python 2.4.2 on linux ( if it matters ) > > -- Script Below -- > > import threading, traceback, time > > class TestThread ( threading.Thread ): > def __init__ ( self ): > threading.Thread.__init__ ( self ) > def run ( self ): > print "Starting..." > while True: > time.sleep ( 1 ) > return > > if __name__ == '__main__': > test = TestThread ( ) > test.start() > print "Started..." > test.join() > > > -- > chris Chris, Thread.join() is implemented using a lock, and the acquisition of a lock is uninterruptible. (See http://docs.python.org/lib/module-thread.html) Therefore, your main thread will block until the other thread terminates or the process is forcibly killed. Even if it could be interrupted, I don't think there's any way to raise that exception in the other thread. (Python's threading support leaves something to be desired when compared to, say, Java.) -- David From matthew.garrish at sympatico.ca Sun Oct 2 11:26:03 2005 From: matthew.garrish at sympatico.ca (Matt Garrish) Date: Sun, 2 Oct 2005 11:26:03 -0400 Subject: [OT] A Moronicity of Guido van Rossum References: <1128003857.930444.47650@g14g2000cwa.googlegroups.com> <1128013745.763757.144280@g44g2000cwa.googlegroups.com> <1128176637.146092.314200@o13g2000cwo.googlegroups.com> <9GS%e.7067$vw6.1891@newsread1.news.atl.earthlink.net> Message-ID: "Lucas Raab" wrote in message news:9GS%e.7067$vw6.1891 at newsread1.news.atl.earthlink.net... > Xah Lee wrote: > > [snip] > >>(they tried, with their limited implementation of lambda and >> shun it like a plaque) > > Can't say I've heard that expression before... > Burns: I'm afraid it's not that simple. As punishment for your desertion, it's company policy to give you the plague. Smithers: Uh, sir, that's the plaque. Matt From jaywgraves at gmail.com Tue Oct 4 18:01:06 2005 From: jaywgraves at gmail.com (jay graves) Date: 4 Oct 2005 15:01:06 -0700 Subject: Mantain IDE colors and paste them in an HTML page References: Message-ID: <1128463266.220423.202960@g44g2000cwa.googlegroups.com> billie wrote: > I tried the export function of scite but it does not generate a proper HTML > code that permit me to copy and paste it into another HTML page. Works OK for me. What exactly is it doing wrong on your side? > Does anyone got any suggestion? I've used Webcpp before. http://webcpp.sourceforge.net/ ... jay From quiteblack at gmail.com Tue Oct 11 21:36:45 2005 From: quiteblack at gmail.com (black) Date: 11 Oct 2005 18:36:45 -0700 Subject: how to execute .exe file ? In-Reply-To: <434BD78C.9030900@websafe.com> References: <1129040197.719729.22460@g44g2000cwa.googlegroups.com> <434BD78C.9030900@websafe.com> Message-ID: <1129081005.496278.304910@z14g2000cwz.googlegroups.com> tks !!! From rupole at hotmail.com Sun Oct 16 11:16:35 2005 From: rupole at hotmail.com (Roger Upole) Date: Sun, 16 Oct 2005 11:16:35 -0400 Subject: odbc errors References: <1129472726.898400.227750@f14g2000cwb.googlegroups.com> Message-ID: <1129476045_3873@spool6-east.superfeed.net> eight02645999 at yahoo.com wrote: > hi > > i have a piece of code: > ... > > def connectdb(sql): > import dbi > import odbc > import sys > try: > s = odbc.odbc('DSN=CONN;UID=user;PWD=pass') > cur = s.cursor() > # cur.execute("set nocount on") > cur.execute(sql) > while 1: > rec = cur.fetchone() > if not rec: break > return rec > except: > print 'error while processing ', sys.exc_type,sys.exc_value > s.close() > cur.close() > s = None > cur = None > > ... > sql = r'update table set col = 'A' where user = "user1"' > connectdb(sql) > > > when i execute it from CGI, i encounter the following : > error while processing dbi.internal-error [MERANT][ODBC Sybase ASE > driver]Invalid cursor state. in FETCH None > > but when i did check the table, the value of col is updated to 'A', > how can i suppress the above error message? or is there some other > things > that are wrong with the code. > thanks > The update is performed as soon as you execute the cursor. No recordset is returned from the update, so you can remove the fetch altogether. hth Roger ----== 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 steve at REMOVETHIScyber.com.au Mon Oct 3 13:08:11 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Tue, 04 Oct 2005 03:08:11 +1000 Subject: "no variable or argument declarations are necessary." References: Message-ID: On Mon, 03 Oct 2005 20:30:35 +0400, en.karpachov wrote: > Some people just don't get the simple fact that declarations are > essentially kind of unit test you get for free (almost), and the compiler > is a testing framework for them. No. Some people just don't get it that declarations aren't almost free, because they cost a lot in human labour, and that they give you practically nothing that your unit testing wouldn't give you anyway. -- Steven. From timothy at open-networks.net Tue Oct 11 19:33:39 2005 From: timothy at open-networks.net (Timothy Smith) Date: Wed, 12 Oct 2005 09:33:39 +1000 Subject: non descriptive error In-Reply-To: References: <4346002C.3080504@open-networks.net><200510070240.56350.hancock@anansispaceworks.com> <4349A55C.90203@open-networks.net> Message-ID: <434C4BD3.3060508@open-networks.net> Fredrik Lundh wrote: >Timothy Smith wrote: > > >>i have reproduced the error in this code block >> >>#save values in edit >>self.FinaliseTill.SaveEditControlValue() >>if >>Decimal(self.parent.TillDetails[self.TillSelection.GetStringSelection()]['ChangeTinBalance'])) >>== Decimal('0'): >>#box must be checked before continuing >>if self.PlacedInSafe.GetValue() != 1: >>self.parent.Popup("You must place the till draw back in the >>safe","Till draw") >>else: >>#finalise the till draw >>if Decimal(self.TillFloat.GetLabel().split('$')[1]) != Decimal('0'): >>Prompt = wx.MessageDialog(self,"""The correct amount has not been >>returned from the till draw float to the main float! >>If you proceed please contact your manager""","Change tin doesn't >>balance!",wx.YES_NO) >>if Prompt.ShowModal() == wx.ID_YES: >>self.Submit() >>else: >>self.parent.Popup('You have an outstanding change tin balance on this >>till','Change tin') >> >>i have NO idea what in there could be making it have such a strange >>error. it just says "error" when you try run it. there nothing terribly >>strange being done. >> >> > >the snippet you posted gives > >$ python script.py > File "script.py", line 2 > self.FinaliseTill.SaveEditControlValue() > ^ >SyntaxError: invalid syntax > >on my python 2.3 install. > >are you sure you don't have some weird sitecustomize file on your >machine? (more likely, it's a wxPython issue. can you reproduce >this without using wxPython ?) > > > > > > > i am still coming across this error it's driving me nuts. usually i can find what's wrong, but it is becoming an increasingly annoying problem. i also get the same problem on a windows machine with the same installed. this time it's nothing to do with the decimal module. help! From mwm at mired.org Sun Oct 16 18:11:40 2005 From: mwm at mired.org (Mike Meyer) Date: Sun, 16 Oct 2005 18:11:40 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: <86y84t159f.fsf@bhuda.mired.org> "Peter T. Breuer" writes: > In comp.os.linux.misc Jeroen Wenting wrote: >> Without Microsoft 90% of us would never have seen a computer more powerful >> than a ZX-81 and 90% of the rest of us would never have used only dumb >> mainframe terminals. > Uh - when microsoft produced dos 1.0, or whatever it was, Just for the record, microsoft didn't "produce" - with the meaning that they created it - dos 1.0; they "produced" - with the meaning that they presented it - after buying it from Seattle Computer Products, where it was known as QDOS, the Quick and Dirty Operating System. MS bought it after promising IBM that MS had an 8088 OS to sell IBM, which was a blatant lie. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From jeremy+complangpython at jeremysanders.net Fri Oct 28 10:37:46 2005 From: jeremy+complangpython at jeremysanders.net (Jeremy Sanders) Date: Fri, 28 Oct 2005 15:37:46 +0100 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> Message-ID: Gerhard H?ring wrote: > pinkfloydhomer at gmail.com wrote: >> I want to scan a file byte for byte [...] >> while True: >> ch = inputFile.read(1) >> [...] But it is very slow. What is the fastest way to do this? Using some >> native call? Using a buffer? Using whatever? > > Read in blocks, not byte for byte. I had good experiences with block > sizes like 4096 or 8192. It's difficult to handle overlaps. The four byte sequence may occur at the end of one block and beginning of the next. You'd need to check for these special cases. Jeremy -- Jeremy Sanders http://www.jeremysanders.net/ From samantha7395 at hotmail.com Thu Oct 20 13:08:12 2005 From: samantha7395 at hotmail.com (Samantha) Date: Thu, 20 Oct 2005 10:08:12 -0700 Subject: Cursor Location Message-ID: Is there any code that would allow a person to click a location on the screen and have that location saved for a future use? For example to imbed a watermark on an image or text, etc. S From sybrenUSE at YOURthirdtower.com.imagination Wed Oct 5 02:00:39 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Wed, 5 Oct 2005 08:00:39 +0200 Subject: Build spoofed IP packets References: Message-ID: billie enlightened us with: > For low level packet building I already used Impacket module but if > I specify a spoofed src address during IP packet creation, module > returns an error. Suggestions? Yes, give us the error. And know that you can't build raw IP packets unless you're root. 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 robinsiebler at gmail.com Wed Oct 19 15:05:24 2005 From: robinsiebler at gmail.com (robinsiebler at gmail.com) Date: 19 Oct 2005 12:05:24 -0700 Subject: Yes, this is a python question, and a serious one at that (moving to Win XP) In-Reply-To: References: Message-ID: <1129748724.890082.70380@g14g2000cwa.googlegroups.com> Try 4NT (http://www.jpsoft.com). It is like cmd on steroids. I've been using it for years and it is the *only* thing that makes powerful batch files possible on Windows. It has a slew of features, including batch file debugging. From ntamas at gmail.com Thu Oct 20 18:39:54 2005 From: ntamas at gmail.com (Tamas Nepusz) Date: 20 Oct 2005 15:39:54 -0700 Subject: KeyboardInterrupt vs extension written in C In-Reply-To: <3rqj7vFhstbuU1@uni-berlin.de> References: <1129814875.226834.10260@g49g2000cwa.googlegroups.com> <3rqj7vFhstbuU1@uni-berlin.de> Message-ID: <1129847994.610270.212810@g14g2000cwa.googlegroups.com> No, that's actually a bit more complicated. The library I'm working on is designed for performing calculations on large-scale graphs (~10000 nodes and edges). I want to create a Python interface for that library, so what I want to accomplish is that I could just type "from igraph import *" in a Python command line and then access all of the functionalities of the igraph library. Now it works, except the fact that if, for example, I start computing the diameter of a random graph of ~100000 nodes and ~200000 edges, I can't cancel it, because the KeyboardInterrupt is not propagated to the Python toplevel (or it isn't even generated until the igraph library routine returns). I would like to allow the user to cancel the computation with the usual Ctrl-C and return to the Python interactive interface. This whole feature is not vital, but it would mean a big step towards user-friendliness. I have access to the source code of igraph as well (since one of my colleagues is developing it), so another possible solution would be to inject some calls into the igraph source code which temporarily cancels the computation and checks whether there's something waiting in the Python interpreter, but I haven't found any function in the API which allows me to do this. Tamas From flupke at nonexistingdomain.com Thu Oct 27 11:31:25 2005 From: flupke at nonexistingdomain.com (flupke) Date: Thu, 27 Oct 2005 15:31:25 GMT Subject: time conversion In-Reply-To: References: Message-ID: Fredrik Lundh wrote: > "flupke" wrote: > > >>Is there an easy to convert following hour notation hh:mm >>to decimals? >>For instance 2 hours and 30 minutes as 2:30 to 2,50 >>I don't really know where to search for this kind of conversion. > > > you mean like > > >>> timestamp = "2:30" > >>> hour, minute = timestamp.split(":") > >>> print int(hour) + int(minute) / 60.0 > 2.5 > > ? > > > > > yep, your sollution is shorter so i'll use that :) Thanks Benedict From benzwt at yahoo.com.tw Mon Oct 3 12:10:54 2005 From: benzwt at yahoo.com.tw (benzwt at yahoo.com.tw) Date: 3 Oct 2005 09:10:54 -0700 Subject: morphological image processing in Python In-Reply-To: References: Message-ID: <1128355854.416660.215260@g49g2000cwa.googlegroups.com> Alexandre Fayolle ??? http://www.mmorph.com/resources.html check this page. Pymorph is a free. > Hello, > > I'm about to start a project which will involve some greyscale image > processing using morphological operators (erosion, dilation, distance > transforms...), and I was wondering if these operators were available in > Python through some open source libraries. > > A quick google search returned pymorphpro[1], which is unfortunately not > free software, and there also seem to be something available in ITK [2]. > Unless I'm mistaken, the PIL does not provide these operations, nore do > Numeric/numarray/scipy. > > Have I missed the one true Python mathematical morphology toolbox? > > Thanks in advance for any advice. > > [1] http://www.mmorph.com/pymorphpro/index.html > [2] http://www.itk.org/ > > -- > Alexandre Fayolle LOGILAB, Paris (France). > http://www.logilab.com http://www.logilab.fr http://www.logilab.org From jimmy at retzlaff.com Fri Oct 7 02:10:22 2005 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Thu, 6 Oct 2005 23:10:22 -0700 Subject: py2exe 0.6.3 released Message-ID: py2exe 0.6.3 released ===================== py2exe is a Python distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation. Console and Windows (GUI) applications, Windows NT services, exe and dll COM servers are supported. Changes in 0.6.3: * First release assembled by py2exe's new maintainer, Jimmy Retzlaff. Code changes in this release are from Thomas Heller and Gordon Scott. * The dll-excludes option is now available on the command line. It was only possible to specify that in the options argument to the setup function before. The dll-excludes option can now be used to filter out dlls like msvcr71.dll or even w9xpopen.exe. * Fix from Gordon Scott: py2exe crashed copying extension modules in packages. Changes in 0.6.2: * Several important bugfixes: - bundled extensions in packages did not work correctly, this made the wxPython single-file sample fail with newer wxPython versions. - occasionally dlls/pyds were loaded twice, with very strange effects. - the source distribution was not complete. - it is now possible to build a debug version of py2exe. Changes in 0.6.1: * py2exe can now bundle binary extensions and dlls into the library-archive or the executable itself. This allows to finally build real single-file executables. The bundled dlls and pyds are loaded at runtime by some special code that emulates the Windows LoadLibrary function - they are never unpacked to the file system. This part of the code is distributed under the MPL 1.1, so this license is now pulled in by py2exe. * By default py2exe now includes the codecs module and the encodings package. * Several other fixes. Homepage: Download from the usual location: Enjoy, Jimmy From larry.bates at websafe.com Mon Oct 3 15:09:28 2005 From: larry.bates at websafe.com (Larry Bates) Date: Mon, 03 Oct 2005 14:09:28 -0500 Subject: Python TNEF (winmail.dat attachment access) library? In-Reply-To: References: Message-ID: Why not write Python class that uses CTypes and make it available as a recipe? From a performance standpoint it is unlikely you can do better than to call the .dll and have it do the work for you. Just a suggestion. -Larry Bates Petri Savolainen wrote: > Hello, > > has anyone seen such a beast? I tried googling, PyPI, Parnassus etc. but > could not find any pure-python code nor extensions to interface with any > of the existing implementations. > > I am thinking about taking the Ruby code I found at > > http://www.zweknu.org/technical/index.rhtml?s=p%7c15 > > and converting that to Python. I have no experience with Ruby so this > will be rather interesting... > > I guess another option would be to use CTypes to plug into some tnef > shared library/DLL. I'd prefer a pure-python route though... > > Any pointers/recommendations appreciated. > > Thanks, > > Petri > From codecraig at gmail.com Wed Oct 5 10:24:31 2005 From: codecraig at gmail.com (Java and Swing) Date: 5 Oct 2005 07:24:31 -0700 Subject: question about output Message-ID: <1128522271.424943.204030@o13g2000cwo.googlegroups.com> i have printed out some numbers and they look like 10944800e 10952560d ...if i want to later assign this type of number to variable how can i do it? for example i can't do... >> x = 10944800e ..since it says "invalid token" on the "e". thanks. From asma61 at dsl.pipex.com Fri Oct 7 02:44:23 2005 From: asma61 at dsl.pipex.com (DaveM) Date: Fri, 07 Oct 2005 07:44:23 +0100 Subject: When someone from Britain speaks, Americans hear a "British accent"... References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kbgj7421kd560@corp.supernews.com> Message-ID: <4h5ck1hkqq0ls83pq0lodkb51tsda4053k@4ax.com> On Fri, 07 Oct 2005 00:33:43 -0000, Grant Edwards wrote: >On 2005-10-06, DaveM wrote: > >>>Frankly, I can't watch Shakespeare or movies like "the full >>>monty" or "trainspotting" because I can't understand a damn >>>word they say. British talk sounds like gibberish to me for the >>>most part. >> >> Not just you. It always amuses me in trips to the US that >> British voices (outside of the movies) are often subtitled, >> while first-generation Americans whose English is. um, >> limited, are not. > >What?!? I've never seen a British voice (inside or outside of >the movies) subtitled -- with the exception of one of a >nightclub scenes in one movie (I think it was Trainspotting) >where the dialog was inaudible because of the music. I noticed this watching news footage rather than imported shows. I haven't seen 'Trainspotting', but I have seen Scottish accents subtitled (unnecessarily) on English TV, to understandable anger across the border - so this isn't uniquely a US phenomenon, to be fair. >For example: In British English one uses a plural verb when the >subject consists of more than one person. Sports teams, >government departments, states, corporations etc. are >grammatically plural. In American, the verb agrees with the >word that is the subject, not how many people are denoted by >that word. > >In sports (thats "sport" for you Brits): Yes. > American: Minnesota is behind 7-0. The Vikings are behind 7-0. > British: Minnesota are behind 7-0. The Vikings are behind 7-0. True. >In politics: > American: The war department has decided to cancel the program. > British: The war department have decided to cancel the program. Not sure about this one. They may be used interchangeably as neither strikes me as sounding "odd". DaveM From no.mail.here.at.here at gmail.com Fri Oct 7 02:54:08 2005 From: no.mail.here.at.here at gmail.com (mike) Date: 6 Oct 2005 23:54:08 -0700 Subject: os.access with wildcards In-Reply-To: References: <1128665933.923295.95580@f14g2000cwb.googlegroups.com> Message-ID: <1128668048.622568.187890@g47g2000cwa.googlegroups.com> thanks Leif. poor question on my part. I had been using glob.glob(path)==[] and was looking for something more readable, hence os.system('[ -e %s ]' % path ) but that doesn't seem like a good idiom for crossplatform. I thought there may either be a way to escape the wildcards, or an alternative to os.access, or .... any other ideas? From mvanaswegen at gmail.com Mon Oct 17 04:35:14 2005 From: mvanaswegen at gmail.com (vpr) Date: 17 Oct 2005 01:35:14 -0700 Subject: wxPython advice Message-ID: <1129538114.173460.176180@g47g2000cwa.googlegroups.com> Hi Guys I have a question re. socketserver and wx. I've written a p2p program using socketserver that's nice and quick. I'd like to give the user a tray applet (part of the p2p service) that will allow the user to activate / deactivate / config and exit the service. However I'm starting to bang my head on the mainloop funtions that manage wx and socket events. Anyone been down this road that can give me some advice Marinus From my_email_is_posted_on_my_website at munged.invalid Tue Oct 25 20:17:40 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 26 Oct 2005 00:17:40 GMT Subject: Microsoft Hatred FAQ References: <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: On Wed, 26 Oct 2005 02:03:36 +1000, Steven D'Aprano wrote, quoted or indirectly quoted someone who said : >You don't care that because of Microsoft's neglect, there are millions of >zombie PCs running their sub-standard OS across the world, sending >hundreds of millions of spam emails? Of course he cares. He is a shill. He licks that hand that feeds him. -- Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching. From lsumnler at uniqueinsuranceco.com Wed Oct 12 21:44:26 2005 From: lsumnler at uniqueinsuranceco.com (LenS) Date: 12 Oct 2005 18:44:26 -0700 Subject: Looking for a Python mentor Message-ID: <1129167866.253155.157850@g43g2000cwa.googlegroups.com> Hello Was wandering if there is any place where some one could go to get mentoring on python coding. I have started coding in python but I am the only one in the shop using it. So there is no one around to look over my code give suggestions on improvement, in style, logic, easier ways of doing things etc. I am not really looking for hand holding as much mentoring. I have purchased about every python book out and have a list a mile long on my internet bookmarks. I believe I have a good grasp of the fundamentals procedurally and I am fighting my way through OOP. I am more at the stage of trying to pull things together into programs that perform real world tasks. At one point I thought I saw some place on one of the web site that did this kind of thing but I can't find it now. Any help or suggestions welcomed Len Sumnler From fredrik at pythonware.com Wed Oct 5 01:56:06 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 5 Oct 2005 07:56:06 +0200 Subject: Help needed in OOP-Python References: Message-ID: Toufeeq Hussain wrote: > I have 3 modules which have class declarations in them and which implement > multiple inheritance. > Traceback (most recent call last): > File "E:\PyPBM\PyPBM\test_case.py", line 7, in ? >TH = constraint.Option1_Rule1() there's no line that says "TH = constraint.Option1_Rule1()" in the code you're posted. looks like you didn't really post the code you tested... From caseyhHAMMER_TIME at istar.ca Thu Oct 20 11:34:17 2005 From: caseyhHAMMER_TIME at istar.ca (Casey Hawthorne) Date: Thu, 20 Oct 2005 15:34:17 GMT Subject: Python vs Ruby References: Message-ID: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> What languages do you know already? What computer science concepts do you know? What computer programming concepts do you know? Have you heard of Scheme? Ruby is a bit Perl like -- so if you like Perl, chances are you might like Ruby. Python is more like Java. I have heard, but have not been able to verify that if a program is about 10,000 lines in C++ it is about 5,000 lines in Java and it is about 3,000 lines in Python (Ruby to?) Roy Smith wrote: >In article , > "Amol Vaidya" wrote: > >> Hi. I am interested in learning a new programming language, and have been >> debating whether to learn Ruby or Python. How do these compare and contrast >> with one another, and what advantages does one language provide over the >> other? I would like to consider as many opinions as I can on this matter >> before I start studying either language in depth. Any help/comments are >> greatly appreciated. Thanks in advance for your help. > >Of all the common scripting languages, Ruby has the highest vowel to >consonant ratio. -- Regards, Casey From davids at webmaster.com Sat Oct 15 18:48:18 2005 From: davids at webmaster.com (David Schwartz) Date: Sat, 15 Oct 2005 15:48:18 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: "Mike Meyer" wrote in message news:86ll0vs1sw.fsf at bhuda.mired.org... > What you call "clever marketing" the DOJ calls "monopolistic > practices". The courts agreed with the DOJ. Having had several large > PC manufacturers refuse to sell me a system without some form of > Windows because MS made it impossible for them to compete if they > didn't agree to do so, I agree with the courts and the DOJ. Go down to your local car dealer and see if you can buy a new car without an engine. DS From Gerald.Klix at klix.ch Thu Oct 20 04:32:38 2005 From: Gerald.Klix at klix.ch (Gerald Klix) Date: Thu, 20 Oct 2005 10:32:38 +0200 Subject: Abstract Methods & Abstract Class References: <20051020065644.GA10206@heaven.kostyrka.org> Message-ID: <000a01c5d550$d49d0f50$e92d200a@ppp5> Isn't class AbstractBase: def method(self): raise NotImplementedError( "abstract method called" ) the right thing to do? Gerald ----- Original Message ----- From: "Andreas Kostyrka" To: "Iyer, Prasad C" Cc: Sent: Thursday, October 20, 2005 8:56 AM Subject: Re: Abstract Methods & Abstract Class > On Thu, Oct 20, 2005 at 12:05:05PM +0530, Iyer, Prasad C wrote: > > > > Do we have something like abstract methods & Abstract class. > > > > So that my class would just define the method. And the implementation > > would be defined by somebody else. > > class AbstractBase: > def method(self): > raise TypeError("abstract method called") > > But basically, Python does not have abstract methods, and usually doesn't > need them. > > Andreas > -- > http://mail.python.org/mailman/listinfo/python-list > From deets at nospam.web.de Thu Oct 13 05:49:01 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 13 Oct 2005 11:49:01 +0200 Subject: Python's garbage collection was Re: Python reliability In-Reply-To: <7xfyr5kfgm.fsf@ruckus.brouhaha.com> References: <3r6i0uFi3qb8U2@uni-berlin.de> <7xfyr5kfgm.fsf@ruckus.brouhaha.com> Message-ID: <3r6osdFhsfjgU1@uni-berlin.de> Paul Rubin wrote: > "Diez B. Roggisch" writes: > >>AFAIK some LISPs do a similar trick to carry int values on >>cons-cells. And by this tehy reduce integer precision to 28 bit or >>something. Surely _not_ going to pass a regression test suite :) > > > Lisps often use just one tag bit, to distinguish between an immediate > object and a heap object. With int/long unification, Python shouldn't > be able to tell the difference between an immediate int and a heap int. That particular implementation used 3 or 4 tag-bits. Of course you are right that nowadays python won't notice the difference, as larger nums get implicitely converted to a suitable representation. But then the efficiency goes away... Basically I think that trying to come up with all sorts of optimizations for rather marginal problems (number crunching should be - if a python domain at all - done using Numarray) simply distracts and complicates the code-base. Speeding up dictionary lookups OTOH would have a tremendous impact (and if I'm n ot mistaken was one of the reasons for the 30% speed increase between 2.2 and 2.3) DIEZ From antonxx at gmx.de Tue Oct 11 09:39:28 2005 From: antonxx at gmx.de (anton) Date: 11 Oct 2005 06:39:28 -0700 Subject: HELP: Searching File Manager written in Python Message-ID: <1129037968.366932.144250@g44g2000cwa.googlegroups.com> Hi, I am googeling some hours now ... still without result. So I have a question: Does somebody know a filemanager: - which looks like Norton Commander/7-Zip Filemanager - where I can add python scripts which I can execute on a selected file I already looked at wxpyatol but its not what I search, and its no more developped. Thanks Stephane From bonono at gmail.com Wed Oct 19 01:54:30 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 18 Oct 2005 22:54:30 -0700 Subject: write a loopin one line; process file paths In-Reply-To: <1129699998.324180.56530@f14g2000cwb.googlegroups.com> References: <1129672592.328278.41490@g14g2000cwa.googlegroups.com> <1129696357.539158.233870@g47g2000cwa.googlegroups.com> <1129699998.324180.56530@f14g2000cwb.googlegroups.com> Message-ID: <1129701270.792327.168620@z14g2000cwz.googlegroups.com> it will be added in 2.5 I beleve. At the moment, you can: predicate and or like : >>> os.paths.exists(something) and "print it is there" or "file not found" I am practicing FP in python and it is in general doable with the help of itertools and add the needed functions as needed, like scanl/scanl1 etc. A few things I don't like about python for FP is that it relies heavily on exception which make these one liners not possible in many case. Example: a=[] a[0] would raise exception I usually prefer None as a special value which can be handled in normal flow(filter out, may be "x is None and something or otherthing"). But the liberal use of Exception force you to structure the program either in a very odd way(test with hasattr/haskey etc. before use) or needs lots of try/except blocks. I am using a python XHTML template Kid which relies on one-liner and found it very difficult. However, if you don't really need one-liner but just FP style to shorten the program, it is fine but I just find the try/except block quite ugly. Then there is the side effect of iterators/generators which unless you know can burn you badly(especially when you are chaining these objects in these multiple map/filter calls), as mentioned in another post. Xah Lee wrote: > Thanks. Here's how the inner loop should be: > > imgPaths2=map(lambda x: (x, re.sub( r"^(.+?)-s(\.[^.]+)$",r"\1\2", x)), > imgPaths) > > though, now i just need something like > > map( lambda x: os.path.exists(s)? x[1]:x[0],impPaths2) > > but Pyhton doesn't support the > test ? trueResult : falseResult > construct. > > (the semantic of this construct, of a conditional that RETURNS A > EXPRESSION, all in one line, is important in functional programing. > Perl supports it. In Mathematica, it's simply the form If[testExpr, > trueExpr, falseExpr]. In lisp, similar: (if testExpr trueExpr > falseExpr) ) > > is there a way to similate it? > > Xah > xah at xahlee.org > ? http://xahlee.org/ > > bonono at gmail.com wrote: > > what do you mean by one line ? Using map/filter, I believe it is > > possible. > > > > Somthing like: > > > > map(lambda (s,f): os.path.exists(f) and f or s, > > map(lambda x: (x, re.replace(x, "-s","")), imgPaths) > > > > My regex is a bit rusty but I hope you got the idea of what I am trying > > to do. If there is a way to make the re return without destroying x, > > the outer map is not needed I believe(that is run it twice, once for > > getting the filename to do the testing, then again based on the testing > > result). > > From jeremy.d.brewer at gmail.com Fri Oct 21 17:30:46 2005 From: jeremy.d.brewer at gmail.com (jbrewer) Date: 21 Oct 2005 14:30:46 -0700 Subject: Python cgi Message-ID: <1129930246.435616.291660@g44g2000cwa.googlegroups.com> I'm currently writing my first CGI script (in Python), and I keep getting an error I don't know how to address. I'm not sure if this is a Python or Apache error, but I suspect it's an Apache config thing. Anyway, in my code I need to upload a file, so in my HTML there's a line like File to upload and in my Python code I try to read the file following the Python docs and the Python Cookbook like form = cgi.FieldStorage() fileitem = form["myfile"] if fileitem.file: # file upload details... else: # print error stuff to page The problem is that the "if fileitem.file" test is never true. After some debugging I discovered that this is because fileitem is returned as type MiniFieldStorage instead of FieldStorage, which is described as "Like FieldStorage, for use when no file uploads are possible." There are other fields in the form that are read just fine. Does anyone know why no file uploads would be possible? I know very little about configuring Apache, unfortunately. Also, I need to run an external program with my CGI script using something like os.system with flags from input forms, which is a major security risk. Is it simply enough to test for flag.isalnum() or should I do more to prevent random programs from being run? I should also do some minimal DOS protection as well, so information on how to do that simply would be appreciated as well. Some system info: Fedora Core 3 Apache 2.0.53 Python 2.3.4 Thanks, Jeremy From jstroud at mbi.ucla.edu Wed Oct 19 15:22:14 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 19 Oct 2005 12:22:14 -0700 Subject: Yes, this is a python question, and a serious one at that (moving to Win XP) In-Reply-To: <1129642964.690532.242710@g49g2000cwa.googlegroups.com> References: <1129574592.754495.72530@g43g2000cwa.googlegroups.com> <1129642964.690532.242710@g49g2000cwa.googlegroups.com> Message-ID: <200510191222.14334.jstroud@mbi.ucla.edu> The OP is obviously a troll. Or he doesn't realize that you can use any shell in OSX as the user default. I used OSX for 4 years and had to go 100% Linux because of my employer. OSX is the best of Linux and Windows--anybody who can't see that has obviously not worked with these three types of operating systems enough and is basing conclusions on limited information...Or is a troll. The OP probably works for microsoft. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From fredrik at pythonware.com Tue Oct 25 04:58:37 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 25 Oct 2005 10:58:37 +0200 Subject: cell and row References: <1d987df30510250150mb4f0f97y79d6e93c0c0d66ff@mail.gmail.com> Message-ID: Shi Mu wrote: >I can not understand the use of "cell" and "row" in the code: > > # convert the matrix to a 1D list > matrix = [[13,2,3,4,5],[0,10,6,0,0],[7,0,0,0,9]] > items = [cell for row in matrix for cell in row] > print items working through the Python tutorial might be a good idea. here's the section on list comprehensions: http://docs.python.org/tut/node7.html#SECTION007140000000000000000 and here's the section on for loops: http://docs.python.org/tut/node6.html#SECTION006200000000000000000 briefly: items = [cell for row in matrix for cell in row] or, slightly edited for clarity: items = [(cell) for row in matrix for cell in row] is the same thing as: items = [] for row in matrix: for cell in row: items.append(cell) except that it's a bit shorter, and a bit more efficient. From mwm at mired.org Sun Oct 9 08:07:38 2005 From: mwm at mired.org (Mike Meyer) Date: Sun, 09 Oct 2005 08:07:38 -0400 Subject: new forum -- homework help/chit chat/easy communication References: <1128798687.305818.66010@g49g2000cwa.googlegroups.com> <1128810677_124183@spool6-east.superfeed.net> Message-ID: <86r7aulwqd.fsf@bhuda.mired.org> Lasse V?gs?ther Karlsen writes: > Fredrik Lundh wrote: > >> "Unlike mainstream component programming, scripts usually >> do not introduce new components but simply "wire" existing >> ones. Scripts can be seen as introducing behavior but no >> new state. /.../ Of course, there is nothing to stop a >> "scripting" language from introducing persistent state -- it >> then simply turns into a normal programming language." >> -- Clemens Szyperski, in "Component Software": > > > That description seems to describe whatever is written more than > whatever it is written in, or in other words, it describes the > difference between a script and a program, not between a scripting > language and a programming language. It also pretty solidly capture what a shell script does. > I think that at one time, scripting languages was something that lived > within other programs, like Office, and couldn't be used by themselves > without running it inside that program, and as thus was a way to add > minor functions and things to that program. That's certainly one kind of scripting language. But I don't think it's ever been the only kind - shells have always been stand-alone applications. What they have in common with your definition is that both types of languages are used to capture user actions for later repetition. And that's what makes a scripting language: it's a language in which one writes "scripts" that describe actions - normally taken by a user - so that a series of them can be performed automatically. For my take on the ontology of scripting languages, see . http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From am_public at email.it Tue Oct 25 09:38:03 2005 From: am_public at email.it (Mattia Adami) Date: 25 Oct 2005 06:38:03 -0700 Subject: security Message-ID: <1130247483.668999.322640@g43g2000cwa.googlegroups.com> Hi to all. I'm intristing in write a plugin for browsers that can execute python code. I know the main problem is security. Many thread were opened about this in the ng. I would know if fork python rewriting some library could avoid problems. I.e. one problem is the possibility to access files. If I rewrite the open() function so that raises exception if the program try to access a file out of a defined directory. I'm sure not a security expert, so please be patient if my question is stupid. Thanks to all. From deets at nospam.web.de Wed Oct 12 17:58:50 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 12 Oct 2005 23:58:50 +0200 Subject: A Tree class, my $0.02 contribution to the python community. In-Reply-To: References: Message-ID: <3r5f8qFh7tufU1@uni-berlin.de> Antoon Pardon wrote: > I don't know. The python dictionary type with its name, seem to refer > to how it is implemented, so I thought Tree was an appropiate name > here as it is implemented as a tree. I too had the impression you're talking about a tree-implementation, not a mapping based on key compare operations. Java calls such a thing TreeMap - so maybe TreeDict would be a suitable name. Diez From mwm at mired.org Sat Oct 29 13:24:19 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 29 Oct 2005 13:24:19 -0400 Subject: Expanding Python as a macro language References: <1130545600.925061.287390@g49g2000cwa.googlegroups.com> <1130592935.839750.322930@g14g2000cwa.googlegroups.com> <1h56rdh.1lgzv2op15fcpN%aleaxit@yahoo.com> Message-ID: <86vezgck3g.fsf@bhuda.mired.org> aleaxit at yahoo.com (Alex Martelli) writes: > ... >> But the problem is that in Linux you can't even send a keystroke to >> a running GUI application! > Actually, if the app is running under X11 you may try to fake out a > keystroke event (with low level calls, but ctypes might let you use it > from Python). Of course, the app WILL be told that the keystroke is > fake, through a special flag if it cares to check for it, for security > reasons; but if the app doesn't specifically defend itself in this way. I'm pretty sure that python-xlib can do this without having to go to low level calls. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From enleverlesO.OmcO at OmclaveauO.com Tue Oct 11 01:11:06 2005 From: enleverlesO.OmcO at OmclaveauO.com (Do Re Mi chel La Si Do) Date: Tue, 11 Oct 2005 07:11:06 +0200 Subject: Why asci-only symbols? References: <86vf04zx0k.fsf@bhuda.mired.org> Message-ID: <434b49ce$0$21693$626a54ce@news.free.fr> Hi ! I agree with you; I will adore capacity to call functions named in Unicode. @-salutations Michel Claveau From eight02645999 at yahoo.com Fri Oct 21 05:34:40 2005 From: eight02645999 at yahoo.com (eight02645999 at yahoo.com) Date: 21 Oct 2005 02:34:40 -0700 Subject: do cc list from smtplib Message-ID: <1129887280.469124.107340@g14g2000cwa.googlegroups.com> hi i have email code: def email(HOST,FROM,TO,SUBJECT,BODY): import smtplib import string, sys body = string.join(( "From: %s" % FROM, "To: %s" % TO, "Subject: %s" % SUBJECT, "", BODY), "\r\n") print body server = smtplib.SMTP(HOST) server.sendmail(FROM, [TO],body) server.quit() is there a way to include CC list for the smtplib module? thanks From mwm at mired.org Thu Oct 13 01:32:03 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 13 Oct 2005 01:32:03 -0400 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <868xx3m2ve.fsf@bhuda.mired.org> <86irw6l1mc.fsf@bhuda.mired.org> Message-ID: <86r7aqugmk.fsf@bhuda.mired.org> Roedy Green writes: > 3. prevent phishing. When PayPal sends you an email, you want to know > for sure it really is from PayPal. This means corporate users at > least will all have digital ids, and all emails will be digitally > signed. That won't prevent phishing, that will just raise the threshhold a little. The first hurdle you have to get past is that most mail agents want to show a human name, not some random collection of symbols that map to a unique address. Even if you do that, most readers aren't going to pay attention to said random collection of symbols. Given that, there are *lots* of tricks that can be used to disguise the signed name, most of which phishers are already using. How many people do you think will really notice that mail from "John Bath, PayPal Customer Service Representative" (john.barth at paypa1.com) isn't really from paypal? Unicode makes things *really* interesting. > 4. status tracking. Unless blocked by the receiver, the sender knows > if his message has been receiveived/read. Got that already. > 5. making it impossible for any incoming email to mount any sort of > attack. the only parts the email software processes are the data > parts. Any enclosed programs must be explicitly installed. The email > software would warn if any code were not digitally signed with proper > certificate to identify the author. How 20th century of you. Making it impossible to send executable code as content is a major step backwards from what we've got now, and you're the last person I would have expected to do that. The solution is to run the code in a sandbox. This is an old technology, and fairly well understood. Except maybe in Redmond. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From amichail at gmail.com Fri Oct 14 20:40:48 2005 From: amichail at gmail.com (Amir Michail) Date: 14 Oct 2005 17:40:48 -0700 Subject: deleting a parameter's name as it is passed to a function Message-ID: <1129336848.353805.176360@o13g2000cwo.googlegroups.com> Hi, I think it would be useful to delete a name of a parameter object as the object is passed to a function: dosomestuff(del a) instead of dosomestuff(a) del a The idea is to garbage collect the object as soon as possible, and this may be sooner than when dosomestuff returns. Amir From egbert.bouwman at hccnet.nl Sun Oct 23 17:25:27 2005 From: egbert.bouwman at hccnet.nl (egbert) Date: Sun, 23 Oct 2005 23:25:27 +0200 Subject: PyGTK color blackout Message-ID: <20051023212527.GA14517@hccnet.nl> Without success I try to understand the color mechanism in PyGTK. It's about the classes Color an Colormap, and their methods and related functions and other paraphernalia. If anyone knows about a tutorial-like systematic description, I will be very grateful. -- Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991 ======================================================================== From hancock at anansispaceworks.com Thu Oct 13 16:18:46 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Thu, 13 Oct 2005 15:18:46 -0500 Subject: Jargons of Info Tech industry In-Reply-To: References: <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <86slv8xdkw.fsf@bhuda.mired.org> Message-ID: <200510131518.46292.hancock@anansispaceworks.com> On Wednesday 12 October 2005 04:37 pm, Roedy Green wrote: > It is a bit like termites. If we don't do something drastic to deal > with spam, the ruddy things will eventually make the entire Internet > unusable. > > the three keys to me are: > > 1. flipping to a digital id based email system so that the sender of > any piece of mail can be legally identified and prosecuted. > If every piece of anonymous email disappeared that would go a long way > to clearing up spam. Let those sending ransom notes, death threats > and hate mail use snail mail. As a second best, correspondents are > identified by permission/identity/encryption keys given to them by > their recipients. Well, that certainly won't accomplish much -- not without a world government, anyway. Much (maybe most) of the spam I receive is international (from Russia, Japan, Southeast Asia, the Middle East, Africa, even the Phillipines). Most of it is also already illegal, so new legislation will certainly make no difference. The only thing you buy with an authentication system is that you can filter out the problems at the ISP or on the uploading side, thus saving a lot of bandwidth. But it would have to be very widely accepted to actually reduce spamming. Now, of course, spammers are also hitting web forms and blogs and other protocols besides e-mail. > 2. flipping to a sender pays system so that the Internet does not > subsidise spam. Then I won't be posting on the Python list anymore, I can assure you. This would chill a lot of the purposes for which email is ideal. > 3. Mail is not transported without prior permission. The receiver can > turn that permission on and off any time he chooses. This is > basically an automated version of what Zaep does where the sender is > not consciously aware of the permission-getting step. Well, this is already happening at the level of my mail client. I gather you have something more centralized in mind? -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From mwm at mired.org Thu Oct 27 15:21:29 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 27 Oct 2005 15:21:29 -0400 Subject: how do i run another script from my python script References: <1130431172.443751.230730@o13g2000cwo.googlegroups.com> Message-ID: <86fyqmix52.fsf@bhuda.mired.org> Daniel Sch?le writes: > Steve already answeared to your question, regaring PHP script > if this would be python script, you could run it by import'ing it That's not very pythonic. Better is to provide a function in the script to run it (say run), then run that in the script iff it's the script is being executed: if __name__ == '__main__': run() Then to use it from another script, you'd do something like: import myscript myscript.run() > or maybe using threading Launching new threads as part of the import process is *dangerous*. There are some nasty bugs lurking there that cause things like your import never finishing. If you need to start a thread in a module, the approach outlined above avoids those bugs. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From iddw at hotmail.com Wed Oct 12 11:09:54 2005 From: iddw at hotmail.com (Dave Hansen) Date: Wed, 12 Oct 2005 15:09:54 GMT Subject: [Info] PEP 308 accepted - new conditional expressions References: <3q4ro9Fd770nU3@individual.net> <3q6oo1Fddg7eU3@individual.net> <7xr7b5zq31.fsf@ruckus.brouhaha.com> Message-ID: <1129129852.92dc41cf1bd445c448e00bd42ec59500@teranews> On Wed, 12 Oct 2005 13:02:20 +0200, Piet van Oostrum wrote: >>>>>> Paul Rubin (PR) wrote: > [...] > >>PR> Yeah, "if C then A else B" is a ancient tradition stretching from >>PR> Algol-60 to OCAML, and who knows what all else in between. I'm not >>PR> sure what Guido saw in the "A if C else B" syntax but it's not a big deal. > >I suspect it is because "if C then A else B" gives problems in the parser >because it would have difficulty to distinguish this in time from the if >statement. This is because the parser doesn't use a very strong formalism. So lose the "if." R = C then A else B I don't think python uses the question mark for anything. Throw that in, if it makes parsing easier: R = C ? then A else B Regards, -=Dave -- Change is inevitable, progress is not. From peter at engcorp.com Thu Oct 13 21:42:09 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 13 Oct 2005 21:42:09 -0400 Subject: 1-liner to iterate over infinite sequence of integers? In-Reply-To: References: Message-ID: Erik Max Francis wrote: > The negative integers are being descriminated against! I demand justice! > > def integers(): > yield 0 > x = 1 > while True: > yield x > yield -x > x += 1 > > ... which is also not a bad demonstration of how the integers are > countably infinite. For some reason I was unable to avoid seeing that one can save a yield there (not that they're a scarce resource, mind you): def integers(): x = 0 while True: yield -x x += 1 yield x I know that shouldn't win any readability awards... -Peter From albalmer at att.net Mon Oct 10 12:41:48 2005 From: albalmer at att.net (Alan Balmer) Date: Mon, 10 Oct 2005 09:41:48 -0700 Subject: Jargons of Info Tech industry References: <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <41hhk195gcipfarnqu85ggs606aqi89ea1@4ax.com> <1128888762.964727.17750@g14g2000cwa.googlegroups.com> Message-ID: On 9 Oct 2005 13:12:43 -0700, riplin at Azonic.co.nz wrote: >> My grandma doesn't put captions in her photo album, >> and she doesn't need captions on her photos in email. > >She doesn't need captions in the album because she will explain the >pictures, at length, every single one of them, to anyone who comes >within grabbing distance. > >> "Here's Johnny with the dog. Here is Johnny with the >> dog again. This one is Johnny on his own. Here is the >> dog. Oh look, it is Johnny with the dog again -- ... > >If your photos are so banal then only people who would recognise the >people would care about them. > >Captions are for people who won't recognise the subject of the photo. >When you send a photo of a house to Granma is she supposed to just >_know_ that it your new house, or the one across the road, or the one >that burnt down last week ? You might try something truly innovative, like including a line in the email that says "Hi, Grandma, here's a picture of our new house." -- Al Balmer Balmer Consulting removebalmerconsultingthis at att.net From nemesis at nowhere.invalid Sat Oct 15 14:23:09 2005 From: nemesis at nowhere.invalid (Nemesis) Date: Sat, 15 Oct 2005 18:23:09 GMT Subject: [ANN] XPN 0.5.5 released References: <20051013194207.1700.5269.XPN@orion.homeinvalid> <1129300207_2667@spool6-east.superfeed.net> <20051014170644.1803.75237.XPN@orion.homeinvalid> <1129316814_3173@spool6-east.superfeed.net> <20051015094021.2058.55430.XPN@orion.homeinvalid> <1129385149_1570@spool6-east.superfeed.net> Message-ID: <20051015173304.1927.10195.XPN@orion.homeinvalid> Mentre io pensavo ad una intro simpatica "Cousin Stanley" scriveva: >> I'd add also config.txt ;-) > > I did but failed to include it in the list I posted .... yes of course. > One small config problem that I haven't figured out > how to deal with .... > > I use a dark background with white foreground text .... > > When posting a reply in the compose/edit window > the cursor is NOT visible .... > > Is there an incantation I can add to the config file > that might render the cursor visible on a dark background ? It's a well known issue, I haven't find a way to change the cursor color yet :-/ I also posted an help request on the pygtk list, but I had no useful replies. -- Famous last words: Don't worry, it's not loaded. |\ | |HomePage : http://nem01.altervista.org | \|emesis |XPN (my nr): http://xpn.altervista.org From mail at eikepreuss.de Tue Oct 25 08:06:20 2005 From: mail at eikepreuss.de (Eike Preuss) Date: Tue, 25 Oct 2005 14:06:20 +0200 Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: <3s6l8mFmj3fjU1@individual.net> David Schwartz wrote: > "Peter T. Breuer" wrote in message > news:okh133-n3l.ln1 at news.it.uc3m.es... > > >>3) there are plenty of other OSs that are developed or could be >>developed but which cannot get a foothold or even manage to be put on >>the shelves because the majority product producer insists on charging >>hardware manufacturers for every box produced, whether or not it carries >>their o/s, and does other nasty things like sabotaging their own >>products so they won't work with a clone o/s. > > > How could he resell an OS that "could be developed"? If nobody wants > these operating systems, then it doesn't hurt him not to be able to sell > them. If people want them, then he could have shown Microsoft the door. Shouldn't it be my right as a seller, to decide that I want to sell an operating system 'that nobody wants' _as well as_ operating systems that 'everybody wants'? So it *hurts* me if I am not able to sell these. That it doesn't hurt me financially doesn't mean that it doesn't hurt me (e.g. my freedom, ideas of morality, whatever). [big snip] EP From en.karpachov at ospaz.ru Tue Oct 11 06:05:42 2005 From: en.karpachov at ospaz.ru (en.karpachov at ospaz.ru) Date: Tue, 11 Oct 2005 14:05:42 +0400 Subject: Batteries Included? In-Reply-To: <7xwtkk7cmu.fsf@ruckus.brouhaha.com> References: <1129010199.291968.142720@g47g2000cwa.googlegroups.com> <7xwtkk7cmu.fsf@ruckus.brouhaha.com> Message-ID: <20051011140542.41312d01.jk@ospaz.ru> On 11 Oct 2005 00:10:01 -0700 Paul Rubin wrote: > Personally I think including a .exe packager in Python would be a > great idea. As a Linux user I can't easily run Windows-specific > utilities like Inno Setup. So I don't have a good way to make .exe's > from my Python code that Windows users can easily run. Having a cross > platform .exe packager included with Python would be useful the same > way cross compilers are useful. I'm using an x86 computer but I can > easily configure gcc to produce ARM code. Why shouldn't my Linux > Python installation be able to produce Windows .exe's? Because you can't run it yourself? If you cannot run the freshly-made exe yourself, why would you want to distrubute it, without even trying? But if you can, then you can run the InnoSetup as well. But, for me, I don't care whether such an option will be included or not. I won't object anyway. -- jk From jstroud at mbi.ucla.edu Thu Oct 20 22:41:21 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Thu, 20 Oct 2005 19:41:21 -0700 Subject: TK question In-Reply-To: <1129860960.909273.68840@g43g2000cwa.googlegroups.com> References: <1129860960.909273.68840@g43g2000cwa.googlegroups.com> Message-ID: <200510201941.21997.jstroud@mbi.ucla.edu> optWin() will create a callable object which is an instance of the class optWin. Calling this callable object will call the __call__() method with the behavior you anticipate. You also need to import Tk from Tkinter and call Tk "Tk" and not "tk". Meditate on the following : from Tkinter import * class optWin: def __init__(self): return None def __call__(self): self.root = Tk() self.root.title("My title") self.root.mainloop() return None ow = optWin() ow() James On Thursday 20 October 2005 19:16, MBW wrote: > class optWin: > > ? ? def __init__(self): > ? ? ? ? return None > > ? ? def __call__(self): > ? ? ? ? self.root = tk() > ? ? ? ? self.root.title("My title") > ? ? ? ? self.root.mainloop() > ? ? ? ? return None -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From caseyhHAMMER_TIME at istar.ca Sun Oct 16 23:00:54 2005 From: caseyhHAMMER_TIME at istar.ca (Casey Hawthorne) Date: Mon, 17 Oct 2005 03:00:54 GMT Subject: The value of Big-O notation is for scale ability and the value of the constant of proportionality! Message-ID: The value of Big-O notation is for scale ability, since quite often a an algorithm used for small N is forgotten about in a large program and not changed when the program has to deal with larger inputs. It's also useful to know the constant of proportionality, for different platforms, for code optimization issues. -- Regards, Casey From davids at webmaster.com Wed Oct 19 02:18:31 2005 From: davids at webmaster.com (David Schwartz) Date: Tue, 18 Oct 2005 23:18:31 -0700 Subject: Microsoft Hatred FAQ References: <86ll0vs1sw.fsf@bhuda.mired.org> <867jcbzdw9.fsf@bhuda.mired.org> <48jbl1honbc8ccfnkuo0bjatmqi5bqfks4@4ax.com> Message-ID: "Roedy Green" wrote in message news:48jbl1honbc8ccfnkuo0bjatmqi5bqfks4 at 4ax.com... > On Tue, 18 Oct 2005 20:34:55 -0700, "David Schwartz" > wrote or quoted : >> As for obligations to community, no, there is no such obligation. An >>executive who devoted his company to his community against his >>shareholders' >>wishes should be fired. The company exists as a vehicle to execute the >>desires of the shareholders. That's why they get to vote on who runs it. > Why should loyalty to company trump all other loyalties -- family, > law, species, community, country, religion ... ? Perhaps you aren't following the thread, but I was talking about the obligations a company has, not the obligations any individual has. And I was talking about obligations *to* individuals. Your criticism would be very appropriate if I said that individuals only owe loyalty to companies. But what I said is that Microsoft (a company) owes an obligation to its shareholders (people). That is, that companies exist purely to benefit people. It is funny that your accusation is based on assuming I said exactly the opposite of what I actually said. DS From free.condiments at gmail.com Fri Oct 14 19:20:55 2005 From: free.condiments at gmail.com (Sam Pointon) Date: 14 Oct 2005 16:20:55 -0700 Subject: wierd threading behavior In-Reply-To: <1129330815.876193.147800@g49g2000cwa.googlegroups.com> References: <1129330815.876193.147800@g49g2000cwa.googlegroups.com> Message-ID: <1129332055.328658.209220@g43g2000cwa.googlegroups.com> thread is a low-level threading module, and start_new is deprecated. Aside from that, thread.start_new(test.()) is syntaxically wrong (a pair of brackets can't follow a dot). However, your example does work for me once I fix the syntax, and it prints hello but then hangs. I can't explain the other results, though - possibly undefined behaviour or more likely me not having much experience with the low-level thread interface. Use threading instead, like so: import threading def test(): print 'Test successful!' def main(): thread = threading.Thread(target = test) thread.start() main() From my_email_is_posted_on_my_website at munged.invalid Tue Oct 18 02:35:57 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Tue, 18 Oct 2005 06:35:57 GMT Subject: Microsoft Hatred FAQ References: <%jV4f.3121$tV6.2659@newssvr27.news.prodigy.net> Message-ID: <2u59l1555jubv8qv09q57qh8m4skei9dqi@4ax.com> On 18 Oct 2005 06:20:56 GMT, John Bokma wrote or quoted : > >That an HTML standard (ISO/IEC 15445:2000) and an HTML recommendation by >w3c (4.01 for example) are two different things, and mixing them up by >calling both standards is a bad thing. Because ... what are the consequences? -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From kenneth.m.mcdonald at sbcglobal.net Thu Oct 6 17:07:15 2005 From: kenneth.m.mcdonald at sbcglobal.net (Kenneth McDonald) Date: Thu, 6 Oct 2005 16:07:15 -0500 Subject: So far (about editing tools) In-Reply-To: <7xr7aypf64.fsf@ruckus.brouhaha.com> References: <48D17FEA-3E2D-46CA-AEB4-86EA1CFACCB1@sbcglobal.net> <7xr7aypf64.fsf@ruckus.brouhaha.com> Message-ID: As I did mention in my original post, Eclipse is indeed bloated. However, in spite of that, I've found it both fast and reliable (much to surprise). The only real problem is learning what functionality (the majority) to ignore. PyDev offers nice integration with Python. If I run a python program from within PyDev, errors are reported on the console, and clicking on an error takes me to the offending line number. Jython is also supported, though I haven't tried it. I personally gave up on Emacs after spending four hours trying to get a perfectly simple keybinding working, and receiving no response from the emacs mailing list--they were apparently as mystified as I. I don't mean to push Eclipse, but I looked at it several times before trying it, and backed off due to the concerns mentioned here. Once I actually sat down with it for about four hours to _concentrate_ on it, though, it rapidly became obvious that it with PyDev really was the best Python solution I'd found. If you do a lot of Python work, it's worth the effort to learn. Ken On 6-Oct-05, at 3:24 PM, Paul Rubin wrote: > Micah Elliott writes: > >> Furthermore, Eclipse requires java and is thusly not provided on any >> linux distro I'm familiar with, which I consider a huge >> roadblock. And >> as mentioned, it's bloated. >> > > It comes with Fedora Core 4 and is compiled with gcj. > > >> I would suspect that the majority of Python programmers write in >> one of >> vim or emacs. Anyone got stats? >> > > I'm a long time emacs bigot but lately I've been editing Python with > IDLE. IDLE leaves a lot to be desired but its integration is very > convenient. > -- > http://mail.python.org/mailman/listinfo/python-list > From donn at u.washington.edu Mon Oct 10 14:47:34 2005 From: donn at u.washington.edu (Donn Cave) Date: Mon, 10 Oct 2005 11:47:34 -0700 Subject: subprocess and non-blocking IO (again) References: <434a80e4_2@news3.prserv.net> Message-ID: In article <434a80e4_2 at news3.prserv.net>, Marc Carter wrote: > I am trying to rewrite a PERL automation which started a "monitoring" > application on many machines, via RSH, and then multiplexed their > collective outputs to stdout. > > In production there are lots of these subprocesses but here is a > simplified example what I have so far (python n00b alert!) > - SNIP --------- > import subprocess,select,sys > > speakers=[] > lProc=[] > > for machine in ['box1','box2','box3']: > p = subprocess.Popen( ('echo '+machine+';sleep 2;echo goodbye;sleep > 2;echo cruel;sleep 2;echo world'), stdout=subprocess.PIPE, > stderr=subprocess.STDOUT, stdin=None, universal_newlines=True ) > lProc.append( p ) > speakers.append( p.stdout ) > > while speakers: > speaking = select.select( speakers, [], [], 1000 )[0] > for speaker in speaking: > speech = speaker.readlines() > if speech: > for sentence in speech: > print sentence.rstrip('\n') > sys.stdout.flush() # sanity check > else: # EOF > speakers.remove( speaker ) > - SNIP --------- > The problem with the above is that the subprocess buffers all its output > when used like this and, hence, this automation is not informing me of > much :) You're using C stdio, through the Python fileobject. This is sort of subprocess' fault, for returning a fileobject in the first place, but in any case you can expect your input to be buffered. You're asking for it, because that's what C stdio does. When you call readlines(), you're further guaranteeing that you won't go on to the next statement until the fork dies and its pipe closes, because that's what readlines() does -- returns _all_ lines of output. If you want to use select(), don't use the fileobject functions. Use os.read() to read data from the pipe's file descriptor (p.stdout.fileno().) This is how you avoid the buffering. > This topic seems to have come up more than once. I am hoping that > things have moved on from posts like this: > http://groups.google.com/group/comp.lang.python/browse_thread/thread/5472ce95e > b430002/434fa9b471009ab2?q=blocking&rnum=4#434fa9b471009ab2 > as I don't really want to have to write all that ugly > fork/dup/fcntl/exec code to achieve this when high-level libraries like > "subprocess" really should have corresponding methods. subprocess doesn't have pty functionality. It's hard to say for sure who said what in that page, after the incredible mess Google has made of their USENET archives, but I believe that's why you see dup2 there - the author is using a pty library, evidently pexpect. As far as I know, things have not moved on in this respect, not sure what kind of movement you expected to see in the intervening month. I don't think you need ptys, though, so I wouldn't worry about it. Donn Cave, donn at u.washington.edu From dietmar at schwertberger.de Tue Oct 4 10:49:04 2005 From: dietmar at schwertberger.de (Dietmar Schwertberger) Date: Tue, 4 Oct 2005 16:49:04 +0200 Subject: help w/ simple GPIB prog. References: <1128394388.461568.110390@g47g2000cwa.googlegroups.com> Message-ID: In article <1128394388.461568.110390 at g47g2000cwa.googlegroups.com>, whoopsi wrote: > I thought I would simply be able to open a port, and send SCPI > commands to configure and aquire values. But when I tried to run GPIB > .py files from gpib-device-0.0.4 I got an error: "symbol 'ibsta' not > found". Doing some searching I found that ibsta was refering to a > library for GPIB (I'm assuming some .dll from a driver) and wrapping > them???. But these instruments as far as I know don't need drivers. Sounds like it's missing the driver for the GPIB board. What kind of GPIB card is it? The driver should be available from the web site of the manufacturer. Regards, Dietmar From frank at chagford.com Tue Oct 11 05:20:24 2005 From: frank at chagford.com (Frank Millman) Date: 11 Oct 2005 02:20:24 -0700 Subject: Question about StringIO In-Reply-To: <3r1ch4FgbogbU1@uni-berlin.de> References: <1128849763.117104.34370@f14g2000cwb.googlegroups.com> <3qsacmFftrn5U1@uni-berlin.de> <1128940255.694551.318760@g14g2000cwa.googlegroups.com> <1129015844.347274.145840@g44g2000cwa.googlegroups.com> <3r1ch4FgbogbU1@uni-berlin.de> Message-ID: <1129022424.781501.254530@g47g2000cwa.googlegroups.com> Diez B. Roggisch wrote: > > Thanks for this pointer. I have read it, but I don't think it applies > > to my situation, as it talks about 'reading' from the child's stdout > > while the child is 'writing' to stderr. > > But that is exactly the point: the psql blocks because you don't read > away the buffered data. Start a thread, read that stdout/stderr and see > if things go smoothly. > > Diez Of course (kicks himself), it is obvious now that you have explained it. I tried your suggestion and it works perfectly. Many thanks Frank From jpablo.romero at gmail.com Fri Oct 21 18:17:48 2005 From: jpablo.romero at gmail.com (Juan Pablo Romero) Date: Fri, 21 Oct 2005 17:17:48 -0500 Subject: fun with lambdas In-Reply-To: <86sluvtshm.fsf@bhuda.mired.org> References: <86sluvtshm.fsf@bhuda.mired.org> Message-ID: Thanks to all I settled with this: def partial1(f,b): return lambda a:f(a,b) def partial2(f,a): return lambda b:f(a,b) Juan Pablo 2005/10/20, Mike Meyer : > Robert Kern writes: > > Juan Pablo Romero wrote: > >> Hello! > >> > >> given the definition > >> > >> def f(a,b): return a+b > >> > >> With this code: > >> > >> fs = [ lambda x: f(x,o) for o in [0,1,2]] > >> > >> or this > >> > >> fs = [] > >> for o in [0,1,2]: > >> fs.append( lambda x: f(x,o) ) > >> > >> I'd expect that fs contains partial evaluated functions, i.e. > >> > >> fs[0](0) == 0 > >> fs[1](0) == 1 > >> fs[2](0) == 2 > >> > >> But this is not the case :( > >> > >> What is happening here? > > > > Namespaces. The functions are looking up o at runtime. In both cases, o > > is bound to the last object in [0,1,2] once the iteration is finished. > > > > Try this (although I'm sure there are better ways): > > > > In [4]: fs = [lambda x, o=o: f(x, o) for o in [0,1,2]] > > > > In [5]: fs[0](0) > > Out[5]: 0 > > > > In [6]: fs[0](1) > > Out[6]: 1 > > > > In [7]: fs[0](2) > > Out[7]: 2 > > Right explanation. Right solution. Wrong examples. He wanted to see: > > >>> fs[0](0) > 0 > >>> fs[1](0) > 1 > >>> fs[2](0) > 2 > >>> > > List comprehensions were purposely designed to mimic for loops, which > (unlike other languages) don't create a new variable for each pass > through the loop. ((They also "leak" the variable to the surrounding > namespace.) So you need to capture the current value of the loop index > somewhere. An alternative (and maybe slightly cleaner) method is: > > >>> def makef(a): > ... return lambda b: a + b > ... > >>> fs = [makef(o) for o in [0, 1, 2]] > >>> fs[0](0) > 0 > >>> fs[1](0) > 1 > >>> fs[2](0) > 2 > >>> > > Generator comprehensions have the same issue: > > >>> fs = list(lambda x: f(o, x) for o in [0, 1, 2]) > >>> fs[0](0) > 2 > >>> fs[1](0) > 2 > >>> fs[2](0) > 2 > >>> > > -- > 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 joerg.schuster at gmail.com Thu Oct 27 03:25:24 2005 From: joerg.schuster at gmail.com (Joerg Schuster) Date: 27 Oct 2005 00:25:24 -0700 Subject: more than 100 capturing groups in a regex In-Reply-To: References: <1130160675.270886.208420@z14g2000cwz.googlegroups.com> <1130312136.411976.118780@o13g2000cwo.googlegroups.com> Message-ID: <1130397924.430152.22760@o13g2000cwo.googlegroups.com> > It's a conflict between python's syntax for regex back > references and > octal number literals. Probably wasn't noticed until way > too late, and > now it will never change. So "reasonable choice" is not a really good description of the phenomenon. From apardon at forel.vub.ac.be Fri Oct 7 06:50:41 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 7 Oct 2005 10:50:41 GMT Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <3qi8erFf252rU1@uni-berlin.de> <3qkdbrFfgga9U1@uni-berlin.de> <3qkn7qFffkl6U1@uni-berlin.de> <3qkr1hFfgj5uU1@uni-berlin.de> <3qmrd2Ffocu8U1@uni-berlin.de> Message-ID: Op 2005-10-07, Diez B. Roggisch schreef : >> Why do you call this a JAVA Object or C void*? Why don't you call >> it a PYTHON object. It is this kind of reaction that IMO tells most >> opponents can't think outside the typesystems they have already >> seen and project the problems with those type systems on what >> would happen with python should it acquire a type system. > > Well, because maybe I wanted you to give you an example of languages > that are statically typed and have such an any construct But since I have no such type system in mind, such an example is useless. > - that, by the > way, is not a piece of inguine imagination of yours, but has been > thought of before, e.g. CORBA (and called there any, too)? It makes no > sense putting python into that context - as it is _not_ statically > typed. Which you should know, after discussing this very subject way too > long. The fact that something else uses the same name, for something doesn't mean it has to be implemented the same way. >>>>Would my suggestion be classified as a statically typed world? >>> >>>See above. >> >> >> Your answer tells more about you then about my suggestion. > > Your answer tells us something too: Just because you don't know anything > about typechecking does not mean that you are in the position to make > assumptions on "how things could work if the people who know stuff > wouldn't be so stupid". That's like saying "cars can't fly because the > stupid engineers lack my sense of imagination." Then argue against my ideas, and not your makings of it. If I just use 'ANY' and you fill that in with C void* like implementation and argue against that, then you are arguing against your own ghosts, but not against what I have in mind. It may very well turn out that my idea is useless, but I will only accept that when someone comes with arguments against my actual idea, and not with arguements against their projection of it. > Just blathering about the possibility of some super-duper-typechecker > and countering criticism or being told about problems in that domain by > making bold statements that this sure could work - provide us with an > implementation. You have not counterd my idea with criticism. You have decorated my idea with how you think it would be implemented (C void*) and argued against that. I don't need to give an implementation to notice, that you jumped to a particular implementation and basicly just countered that implementation, not the idea in general. > Or maybe - just maybe - you could sit back and think about the fact that > lots of people who are way cleverer than you and me have been working on > this subject, and so far haven't found a way. Which doesn't necessarily > mean that there is no way - but certainly its hard, theory-laden work > and won't emerge in a NG discussion by some snide remarks of either you > or anybody else. As far as I'm concerned that was just meant as a matter of fact remark, with no snide intentions. -- Antoon Pardon From juho.schultz at helsinki.fi Tue Oct 4 02:41:34 2005 From: juho.schultz at helsinki.fi (Juho Schultz) Date: Tue, 04 Oct 2005 09:41:34 +0300 Subject: Background process for ssh port forwarding In-Reply-To: References: Message-ID: Jesse Rosenthal wrote: > Hello all, > > I'm writing a script which will backup data from my machine to a server > using rsync. It checks to see if I am on the local network. If I am, it > runs rsync over ssh to 192.168.2.6 using the pexpect module to log in. > That's the easy part. > > Now, when I'm not on the local network, I first want to open up an ssh > connection to do port forwarding, so something like this: > > def hostforward(): > #This is based on the assumption that the passfile is the gnus > #authinfo file, or has a similar format... > f = open(PASS_FILE, "r") > f_list = f.read().split(' ') > f.close() > #Now, we get the entry after "password" (be slicker to make it a > #dictionary, but maybe wouldn't work as well). > pass_index = f_list.index('password') + 1 > forwardpass = f_list[pass_index] > #now we connect > command = 'ssh -l %s -L 2022:%s:22 %s' % \ > (login, my_server, forwarding_server) > connection = pexpect.spawn(command) > connection.expect('.*assword:') > connection.sendline(forwardpass) > > If I end this with 'connection.interact()', I will end up logged in to the > forwarding server. But what I really want is to go on and run rsync to > localhost port 2022, which will forward to my_server port 22. So, how can > I put the ssh connection I set up in hostforward() in the background? > I need to make sure that connection is made before I can run the rsync > command. > > I've looked at threading, but that seems excessive. There must be an > easier way. Whatever I do, though, I'll need to use pexpect to spawn the > processes, since I'll need to log in to ssh servers with a password. > > Thanks for any help. > > --Jesse > > I am not sure I understand you correctly (my english is a bit limited) Can you not use something like: rsync --timeout=5 -e "ssh --with-many-options" From my_email_is_posted_on_my_website at munged.invalid Wed Oct 12 18:09:31 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 12 Oct 2005 22:09:31 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <20051009164202.70f4d3f5.tengo@DELETEMEecc.lu> Message-ID: On Sun, 9 Oct 2005 16:42:02 +0200, Stefaan A Eeckels wrote or quoted : >> > http://mindprod.com/projects.html/mailreadernewsreader.html > >It's gone :-) arghh. try http://mindprod.com/projects/mailreadernewsreader.html -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From http Fri Oct 14 15:25:07 2005 From: http (Paul Rubin) Date: 14 Oct 2005 12:25:07 -0700 Subject: Function to execute only once References: <1129317118.937439.159550@g43g2000cwa.googlegroups.com> Message-ID: <7xbr1ryk8c.fsf@ruckus.brouhaha.com> "PyPK" writes: > now I want execute() function to get executed only once. That is the > first time it is accessed. > so taht when funcc2 access the execute fn it should have same values as > when it is called from func1. There's nothing built into Python for that. You have to program the function to remember whether it's already been called. It sounds like you're trying to avoid performing some side effect more than once. Anyway, there's multiple ways you can do it. The conceptually simplest is probably just use an attribute on the function: tmp = 0 # you want to modify this as a side effect def execute(): global tmp if not execute.already_called: tmp += 1 execute.already_called = True return tmp execute.already_called = False Other ways include using a class instance, using an iterator, etc. Generally too, you might find it cleaner to avoid having side effects like that. Instead, put tmp itself inside a class instance: class Memo: def __init__(self): self.value = 0 # any side effects operate on this self.already_called = False def __call__(self): if not self.already_called: self.already_called = True self.value += 1 return self.value execute = Memo() Now you don't have global state cluttering things up, you can make multiple instances easily, etc. From mscottschilling at hotmail.com Tue Oct 18 15:06:59 2005 From: mscottschilling at hotmail.com (Mike Schilling) Date: Tue, 18 Oct 2005 19:06:59 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86fyqzzskt.fsf@bhuda.mired.org> <86y84rxryr.fsf@bhuda.mired.org> <2R75f.2005$dO2.1121@newssvr29.news.prodigy.net> <86mzl6yfko.fsf@bhuda.mired.org> Message-ID: "Mike Meyer" wrote in message news:86mzl6yfko.fsf at bhuda.mired.org... > "Mike Schilling" writes: >> "Mike Meyer" wrote in message >> news:86y84rxryr.fsf at bhuda.mired.org... >>> "Mike Schilling" writes: >>>> "Mike Meyer" wrote in message >>>> news:86fyqzzskt.fsf at bhuda.mired.org... >>>>> "Mike Schilling" writes: >>>>>> What matters in generating HTML is which browsers you want to support >>>>>> and >>>>>> what they understand. Standards and recommendations are both >>>>>> irrelevant. >>>>> Unless, of course, you want to support any compliant browser. >>>> Since no browser I know of is perfectly compliant (e.g. bug-free), >>>> that's >>>> not a feasible goal. >>> I guess you'd say developing any software isn't a feasible goal, >>> because it'll never be bug-free, will never have bug-free compilers to >>> compile it, bug-free linkers to link it, bug-free GUI/db/etc libraries >>> to link with it, bug-free servers to communicate with, and bug-free >>> operating systems to run it on. Fortunately, most developers aren't >>> quite that anal, and realize that you can get useful work done in a >>> less-than-perfect environment. >> I'm not speaking theroetically. My company (though not me personally) >> creates browser-based UIs, and one of the biggest expenses has been >> dealing >> with IE rendering bugs Given the market share of IE, the fact that >> something should work, and even does work in Firefox, Opera, etc, is >> irrelevant. If it breaks IE, we can't use it. > > Been there, done that, threw out the T-shirt as to ugly to wear. > > Yes, you have to work around bugs in the popular browsers. That hasn't > changed since the first published specs showed up. That doesn't mean > you throw out the standards and only support a trivial set of > browsers. If you're working on a commercial product, it means you support IE (possibly being able to insist on a specific patch level), Foxfire if you can, and ignore the < 1% of the market that won't live with those restrictions. From matt.walsh at gmail.com Mon Oct 24 21:02:00 2005 From: matt.walsh at gmail.com (MBW) Date: 24 Oct 2005 18:02:00 -0700 Subject: Simple server/client application In-Reply-To: <1130200091.651575.221970@z14g2000cwz.googlegroups.com> References: <1130184666.541928.133350@z14g2000cwz.googlegroups.com> <1130187450.794254.60660@z14g2000cwz.googlegroups.com> <1130200091.651575.221970@z14g2000cwz.googlegroups.com> Message-ID: <1130202120.753271.33410@f14g2000cwb.googlegroups.com> thanks both of you, I should have realized what was gonig on Cheers, Matt From steve at holdenweb.com Wed Oct 5 03:58:50 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 05 Oct 2005 08:58:50 +0100 Subject: how to get any available port In-Reply-To: <20051004211115.GC29124@unpythonic.net> References: <20051004211115.GC29124@unpythonic.net> Message-ID: jepler at unpythonic.net wrote: > Apparently, calling bind() with a zero "port" will choose some available port > number, as demonstrated by this program: > > import socket > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.bind(("", 0)) > print s.getsockname() > > Here's how it behaved over several runs: > $ python soc.py > ('0.0.0.0', 34205) > $ python soc.py > ('0.0.0.0', 34206) > $ python soc.py > ('0.0.0.0', 34207) > > I don't know for sure whether this is standard behavior for sockets, or whether > it's a special behavior of linux. > It's been standard behaviour ever since the Berkeley socket interface was defined, as far as I know. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From mwm at mired.org Tue Oct 18 11:55:11 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 18 Oct 2005 11:55:11 -0400 Subject: UI toolkits for Python References: <7xslv56ud1.fsf@ruckus.brouhaha.com> <3ras6oFit2djU1@individual.net> <4350dd34$0$6774$9b4e6d93@newsread4.arcor-online.net> <863bn12k6i.fsf@bhuda.mired.org> <7xslv02aoj.fsf@ruckus.brouhaha.com> <87psq39aur.fsf@wilson.rwth-aachen.de> <7xwtkbud5q.fsf@ruckus.brouhaha.com> <1h4mhm2.1rmv4fh1czi843N%aleaxit@yahoo.com> Message-ID: <86r7aiyg4g.fsf@bhuda.mired.org> aleaxit at yahoo.com (Alex Martelli) writes: > Maybe that's the key difference between the mindset of a > mathematician and that of an engineer -- I consider reaching over > 95% of visitors to be _quite good indeed_, Oh? So you'd consider an SMTP/IMAP/POP/DNS/NFS/etc server that rejected 5% of the systems connecting to be _quite good indeed_? I think I'm glad that the internet wasn't built by people who agreed with that. If you know what you're doing, you can have the best of both worlds for a lot of web applications. Yes, it won't be as rich or functional for the five percent who worry about security (or whatever), but it'll still work. And yes, you can't do it for every application. For those, anyone vaguely competent will add a warning. What surprises me is that marketing types will accept turning away - what's the current internet user base? 200 million? - 10 million potential customers without a complaint. Or maybe they just don't get told that that's what's going on. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From mwm at mired.org Tue Oct 11 11:45:03 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 11 Oct 2005 11:45:03 -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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <86y853mzmr.fsf@bhuda.mired.org> <86mzlil269.fsf@bhuda.mired.org> Message-ID: <86slv8xdkw.fsf@bhuda.mired.org> axel at white-eagle.invalid.uk writes: > I don't know how much spam other people receive but on one account I > hardly receive any as I reserve it for friends and business. On another > I had about 40 spam messages which took all of ten seconds to delete. > Hardly a serious matter. You don't have a spam problem. I get a few thousand spams a day - which get filtered down to a handful. I don't have a spam problem. Jeff Poskanzer, now *he* has a spam problem. He gets a few million spams a day: . For anyone who runs an ISP, spam is chewing up an ever-growing percentage of their bandwidth, and a significant fraction of their staff time. They have a spam problem. But me and you, we don't have a spam problem. At most it's an annoyance. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From codecraig at gmail.com Tue Oct 11 13:38:32 2005 From: codecraig at gmail.com (Java and Swing) Date: 11 Oct 2005 10:38:32 -0700 Subject: Wrapper function Message-ID: <1129052312.444144.142950@g44g2000cwa.googlegroups.com> I am having trouble with a wrapper function... My C code looks like ----------------------- #include #include #include "Python.h" int doStuff(const char *input, const char *d) {...} PyObject *wrap_doStuff(PyObject *, PyObject *args) { int result; char *input = 0; char *d = 0; int ok = PyArg_ParseTuple(args, "ss", &input, &d); if (!ok) return 0; result = doStuff(input, d); return PyBuildValue("i", result); } ...when I try to compile this I get "error C2055: expected formal parameter list, not a type list" and it points to line 31...which is the line "PyObject *wrap_doStuff(...)". I am learning based on the following link: http://wiki.cacr.caltech.edu/danse/index.php/Lots_more_details_on_writing_wrappers any ideas? Note, if I remove the wrapper function, it compiles fine (so its not an issue with Python.h...i don't think), also I am using Visual C++ 6 on Win xp. thanks. From http Thu Oct 6 15:55:45 2005 From: http (Paul Rubin) Date: 06 Oct 2005 12:55:45 -0700 Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86u0fxi7gf.fsf@bhuda.mired.org> <434545b7$0$662$626a14ce@news.free.fr> <86mzlmpo5r.fsf@bhuda.mired.org> Message-ID: <7xpsqictdq.fsf@ruckus.brouhaha.com> Mike Meyer writes: > I think we're using different definitions of statically typed > here. A language that is statically typed doesn't *need* type > inferencing - the types are all declared! Type determines the thypes > by inferenceing them from an examination of the program. I thought static typing simply means the compiler knows the types of all the expressions (whether through declarations or inference) so it can do type checking at compile time: > So, for instance, it can determine that this function: > > def foo(): > return 1 > > Won't ever return anything but an integer. Static typing in this case would mean that re.match('a.*b$', foo()) would get a compile time error, not a runtime error, since re.match expects two string arguments. This can happen through type inference w/o declarations. Note apropos the private variable discussion that CPython can't guarantee that foo() always returns an integer. Something might change foo.func_code.co_code or something like that. > Maybe you're still writing code for a language with declerations? I > never felt that need. Then again, I came to Python from a language > that didn't require declerations: Scheme. I've done a fair amount of Lisp programming and have found the lack of compile-time type checking to cause about the same nuisance as in Python. I also notice that the successors to the old-time Lisp/Scheme communities seem to now be using languages like Haskell. > > Well, in the end, I would really like an *option* at the beginning of a > > module file requiring variable declaration for the module. It would > > satisfy both the ones who want and the ones who don't want that ... > > Nope. It would just change the argument from "Python should have ..." > to "You should always use ..." or "Module foo should use ...". Perl has a feature like that right now, and it doesn't lead to many such arguments. From zanesdad at bellsouth.net Fri Oct 7 07:57:45 2005 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Fri, 07 Oct 2005 07:57:45 -0400 Subject: New Python book In-Reply-To: <43464E24.3050609@acm.org> References: <43464E24.3050609@acm.org> Message-ID: <434662B9.3080004@bellsouth.net> Maurice LING wrote: >I had the opportunity to glance through the book in Borders yesterday. >On the whole, I think it is well covered and is very readable. Perhaps I >was looking for a specific aspect, and I find that threads did not get >enough attention. Looking at the index pages, the topics on threads >(about 4-5 pages) is mainly found in the context of GUI programming. > >maurice > > > I don't have my hard copy of the book, but from memory and grepping over the soft copy, you appear to be correct. Remember, though, that this is a beginning book on Python and *I* would consider threading a more advanced topic. I think putting threading in the context of GUI programming is just about right for an intro book. - jmj From jepler at unpythonic.net Tue Oct 4 17:25:30 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Tue, 4 Oct 2005 16:25:30 -0500 Subject: how to get any available port In-Reply-To: References: <11k5pgpp19v0ec@corp.supernews.com> Message-ID: <20051004212530.GA5929@unpythonic.net> On Tue, Oct 04, 2005 at 05:19:37PM -0400, Mohammed Smadi wrote: > what else would you do? I am using examples from the web and they all > bind to a port at the localhost before connecting to the remote host. [...] the web must be stupider than I thought. Here's how Python's own ftplib connects to an ftp server (dedented for clarity): try: self.sock = socket.socket(af, socktype, proto) self.sock.connect(sa) except socket.error, msg: ... there's no need to call bind() before connect. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From jgrahn-nntq at algonet.se Sat Oct 15 04:45:17 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 15 Oct 2005 08:45:17 GMT Subject: Yes, this is a python question, and a serious one at that (moving to Win XP) References: <434f8a54$0$16641$626a14ce@news.free.fr> Message-ID: On Fri, 14 Oct 2005 12:37:25 +0200, Christophe wrote: > Kenneth McDonald a ?crit : >> For unfortunate reasons, I'm considering switching back to Win XP (from >> OS X) as my "main" system. Windows has so many annoyances that I can ... >> Yes, I know that Cygwin is out there, but last I looked, they still >> went through the Win command-line window, which imposes a lot of >> restrictions. ... > Last time I checked, you could install a native win32gui version of rxvt > with cygwin. This would give you a better terminal window than that > crappy thing you get in XP. Last time /I/ checked (two years ago or so) that rxvt looked nice enough, but was impossible to use in practice. I cannot remember /what/ the problem was -- possibly it was that it could only run CygWin-compiled commands, or something vital only worked with CygWin-compiled commands. Google probably knows more. I wouldn't be surprised if this has improved since then, or if someone else has come up with a serious Win32 terminal. There is surely a need for one! /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From kent37 at tds.net Wed Oct 26 14:27:11 2005 From: kent37 at tds.net (Kent Johnson) Date: Wed, 26 Oct 2005 14:27:11 -0400 Subject: XML Tree Discovery (script, tool, __?) In-Reply-To: <1130350833.334697.60490@g47g2000cwa.googlegroups.com> References: <1130183060.195730.178330@g47g2000cwa.googlegroups.com> <1130189785.358171.307700@o13g2000cwo.googlegroups.com> <1130350833.334697.60490@g47g2000cwa.googlegroups.com> Message-ID: <435fc85e$1_2@newspeer2.tds.net> Istvan Albert wrote: > All I can add to this is: > > - don't use SAX unless your document is huge > - don't use DOM unless someone is putting a gun to your head +1 QOTW From martin.witte at gmail.com Fri Oct 7 03:36:42 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 7 Oct 2005 00:36:42 -0700 Subject: non descriptive error In-Reply-To: References: Message-ID: <1128670602.014619.7160@z14g2000cwz.googlegroups.com> You should tell us more about DutyShift.py, without the code it is very difficult for other people to guess what's going on. From mwm at mired.org Mon Oct 3 16:50:08 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 03 Oct 2005 16:50:08 -0400 Subject: Reply-To header References: <2ECA6FE9-3C8F-4C60-9E89-70CC078B14EF@gmail.com> <7rc0f.11261$Un.585792@phobos.telenet-ops.be> Message-ID: <86oe66jpfj.fsf@bhuda.mired.org> Peter Decker writes: > Setting the default Reply-To: to the list means that 'Reply' sends > just to the list (the desired behavior most of the time), and 'Reply > to all' sends 2 copies. No, it sends one copy to the list, and one copy to the original author. This is the behavior you want. The author may not be subscribed to the list. Such people are most in need of help, and you want the default to be that they get help. There are a number of alternatives for users on the list to avoid getting duplicates. Many lists can be configured to check the headers for other recipients, and to remove them from the list for that message. Many mail readers have functionality to detect and eliminate duplicates - even MS LookOut has that! Personally, I wrote a qmail dot-command to do it long ago. I can make my dot-commands available if anyone wants them. There's also a mail header that's been around for years that tells conforming agents to supress the copy to the author. Some mail readers honor it, others don't. > I'm on several other lists, some of which default replies to the list, > and others which default to the sender. I've *never* seen threads like > this on the former, while such threads appear like clockwork on the > latter. Draw your own conclusion. I see the threads you don't see. Usually started by someone accidently sending a reply that was very much intended to be private to a public list. This should be compared to the badness of hitting the wrong reply when the list is configured properly: only one person gets a copy. That's easily fixed by asking them to forward it to the list, or simply reposting your message, with little or no harm done. My conclusion is that people used to the correct behavior have given up on fixing the internet, and use tools that fix the part of it they can see. When I notice that a list is broken (RFC 2822 says that reply-to is for the *author* of the message; anyone else setting it is doing so in violation of the RFC, and hence broken, no matter how useful it may be), I tell my mailer to ignore reply-to on mail from that list. Similarly, I no longer try and explain to people how long lines violate RFCs and are a pain to read in well-behave mail readers, or why mail readers that wrap text/plain content are broken. Likewise, I restrict my comments on top posting to noting that I've fixed it (or given up on fixing it and deleted the text as useless) when I follow up to such things. Asking people to change their ways because it's better for others is a waste of time - most of the users on the internet these days don't give shit. >> Not that it matters that much to me, since I read practically all >> mailing lists via gmane.org. That turns the lists into newsgroups, where >> the reply button (follow-up, more accurately) does send the reply to the >> newsgroup. > So the answer is to not use the email interface, since the newsgroup > interface actually gets it right! :) Newsreaders only gets it right if it sends copies to posters who aren't subscribed. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From http Sun Oct 9 17:06:20 2005 From: http (Paul Rubin) Date: 09 Oct 2005 14:06:20 -0700 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <5hrik11q3p5ugcjm4hmmgqgq20o8fdrhr9@4ax.com> Message-ID: <7x4q7q2yer.fsf@ruckus.brouhaha.com> Roedy Green writes: > >His reply wasn't exactly clear, but I that he means that wen you use HTM > >mail, you don't have to attach the photo with the email. You can also > >use the HTML to refer to an image somewhere on a webserver. > There is that and also the use of HTML formatting, embedded images, > captioning, rows, borders to make the message look more like a page > from a photo album. That's the worst of all. I certainly don't want my mail reader opening network connections to arbitrary places when I read my mail. I have no willingness at all to reveal my mail reading habits or IP address to everyone who sends me email. If someone wants a return receipt, they can use snail mail and fill out a form at the post office for it. From gandalf at designaproduct.biz Wed Oct 5 09:53:42 2005 From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy) Date: Wed, 05 Oct 2005 15:53:42 +0200 Subject: How to get the output from os.system() into a variable? In-Reply-To: <1128519815.769933.60660@g43g2000cwa.googlegroups.com> References: <1128519815.769933.60660@g43g2000cwa.googlegroups.com> Message-ID: <4343DAE6.4050900@designaproduct.biz> alexLIGO wrote: >Hi, > >I would like to execute some command in python on the bash, e.g. > >os.system('globus-job-run mike4.cct.lsu.edu/jobmanager-pbs -l >/bin/date') > >and want the result of the output in a vector, so something like: > >result=python_command(' command_on_the_bash ') > >Is that possible? And how to do that? > > You can use one of these: the subprocess module: http://docs.python.org/lib/module-subprocess.html the popen2 module: http://docs.python.org/lib/module-popen2.html popen and spawn variants from the os module: http://docs.python.org/lib/os-process.html pexpect (it is not in the standard library): http://pexpect.sourceforge.net/ I believe that if you do not need the extended functionality of "pexpect", then you should start with the "subprocess" module. It is the newest. Les From rrr at ronadam.com Tue Oct 25 12:20:21 2005 From: rrr at ronadam.com (Ron Adam) Date: Tue, 25 Oct 2005 16:20:21 GMT Subject: namespace dictionaries ok? In-Reply-To: References: Message-ID: <9Xs7f.4060$Zd.3377@tornado.tampabay.rr.com> Duncan Booth wrote: > Ron Adam wrote: > >>James Stroud wrote: >> >>>Here it goes with a little less overhead: >>> >>> > > > >>But it's not a dictionary anymore so you can't use it in the same places >>you would use a dictionary. >> >> foo(**n) >> >>Would raise an error. >> >>So I couldn't do: >> >> def foo(**kwds): >> kwds = namespace(kwds) >> kwds.bob = 3 >> kwds.alice = 5 >> ... >> bar(**kwds) #<--- do something with changed items >> > > I agree with Steven D'Aprano's reply, but if you are set on it you could > try this: > > >>>>class namespace(dict): > > def __init__(self, *args, **kw): > dict.__init__(self, *args, **kw) > self.__dict__ = self > > > >>>>n = namespace({'bob':1, 'carol':2, 'ted':3, 'alice':4}) >>>>n.bob > > 1 > >>>>n.bob = 3 >>>>n['bob'] > > 3 > > The big problem of course with this sort of approach is that you cannot > then safely use any of the methods of the underlying dict as they could be > masked by values. > > P.S. James, *please* could you avoid top-quoting. Or worse, the dictionary would become not functional depending on what methods were masked. And this approach reverses that, The dict values will be masked by the methods, so the values can't effect the dictionary methods. But those specific values are only retrievable with the standard dictionary notation. class namespace(dict): __getattr__ = dict.__getitem__ __setattr__ = dict.__setitem__ __delattr__ = dict.__delitem__ n = namespace() n.__getattr__ = 'yes' # doesn't mask __getattr__ method. print n['__getattr__'] -> 'yes' The value is there and __getattr__() still works. But n.__getattr__ returns the method not the value. So is there a way to keep the functionality without loosing the methods? BTW, I agree with Steven concerning data structures. This really isn't a substitute for a data structure. Many keys will not work with this. n.my name = 'Ron' n.(1,2) = 25 n.John's = [ ... ] The use case I'm thinking of is not as a shortcut for data structures, but instead, as a way to keep names as names, and maintaining those names in a group. Thus the namespace association. def foo(**kwds): kwds = namespace(kwds) print kwds.name print kwds.value ... name = 'ron' value = 25 foo( name=name, position=position ) Cheers, Ron From http Tue Oct 4 00:35:01 2005 From: http (Paul Rubin) Date: 03 Oct 2005 21:35:01 -0700 Subject: Controlling who can run an executable References: <1128395422.904212.318930@g44g2000cwa.googlegroups.com> Message-ID: <7x3bnhlx1m.fsf@ruckus.brouhaha.com> "Cigar" writes: > Now that I'm three months into the development of this program, my > client tells me she would like to protect her investment by preventing > her employees from doing the same to her. (Going to the competition > and using her program.) Exactly what is the threat here? Misuse of confidential data, or just the code itself? Does the code do anything that fantastic? Did the employees sign NDA's? Usually this kind of thing is taken care of by legal agreements. Occasionally there are disputes that make the news (Microsoft and Kai-Fu Lee, etc.) but they make the news precisely because they're rare. What is the competitor going to do with this code even if they get it? It's just keeping track of transactions and stuff, right? It's being tailored to one person's specific preferences and requirements, and the competitor's needs will be different and they may as well just use something generic. Your best bet may be to just explain this to the client, that the most valuable thing in a business is relationships; technical secrets aren't nearly as big a deal as some people like to think. Also, is there an office network? Maybe you could run the program on a server that most employees wouldn't have access to. They'd use it through some limited client program or through a web browser. If you really want to do something with a hardware token, I like this stuff: . Assuming you're in the USA, buy from the Canadian distributor since shipping from Germany is very expensive. From carsten at uniqsys.com Mon Oct 3 16:44:47 2005 From: carsten at uniqsys.com (Carsten Haese) Date: Mon, 03 Oct 2005 16:44:47 -0400 Subject: Dynamical loading of modules In-Reply-To: <1128372108.4070.31.camel@dot.uniqsys.com> References: <43418BF5.90504@gmail.com> <1128372108.4070.31.camel@dot.uniqsys.com> Message-ID: <1128372287.4070.33.camel@dot.uniqsys.com> On Mon, 2005-10-03 at 16:41, Carsten Haese wrote: > On Mon, 2005-10-03 at 15:52, Jacob Kroon wrote: > > Hi, I'm having some problems with implementing dynamical module loading. > > First let me > > describe the scenario with an example: > > > > modules/ > > fruit/ > > __init__.py > > apple.py > > banana.py > > > > apple.py defines a class 'Apple', banana defines a class 'Banana'. The > > problem lies in the > > fact that I want to be able to just drop a new .py-file, for instance > > peach.py, and not change > > __init__.py, and it should automatically pickup the new file in > > __init__.py. I've come halfway > > by using some imp module magic in __init__.py, but the problem I have is > > that the instantiated > > objects class-names becomes fruit.apple.Apple/fruit.banana.Banana, whild > > I want it to be > > fruit.Apple/fruit.Banana. > > > > Is there a smarter way of accomplishing what I am trying to do ? > > If someone could give me a small example of how to achieve this I would > > be very grateful. > > How about something like this in fruit/__init__.py: > > import os > > fruit_dir = os.path.dirname(__file__) > fruit_files = [x for x in os.listdir(fruit_dir) if (x[-3:]=='.py' and x!='__init__.py')] > for fruit_file in fruit_files: > module_name = fruit_files[:-3] ^^^^^^^^^^^ This should be fruit_file, of course. > exec "from %s import *" % module_name > > HTH, > > Carsten. From steve at REMOVETHIScyber.com.au Fri Oct 28 19:58:16 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sat, 29 Oct 2005 09:58:16 +1000 Subject: How do I sort these? References: <1130524906.918612.38540@g49g2000cwa.googlegroups.com> <3sfarbFnt8bvU1@uni-berlin.de> <1130532169.033398.155010@g14g2000cwa.googlegroups.com> Message-ID: On Fri, 28 Oct 2005 13:42:49 -0700, KraftDiner wrote: > unzip doesn't seem to work for me... Nor for me: >>> unzip Traceback (most recent call last): File "", line 1, in ? NameError: name 'unzip' is not defined I don't think it exists. But it is easy enough to create: def unzip(L): """Reverse a zip. Expects L to be a list of the form: [(1, 'a'), (2, 'b'), (3, 'c')] and returns: [(1, 2, 3), ('a', 'b', 'c')] Note that unzip(zip(seq1, seq2)) is not quite a null-op, because some type information is lost, e.g. lists and strings are converted into tuples. """ return zip(*L) As you can see, the documentation for unzip is longer than the code itself :-) -- Steven. From grante at visi.com Tue Oct 25 12:37:55 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 25 Oct 2005 16:37:55 -0000 Subject: need some advice on x y plot References: <1129823043.104864.73750@f14g2000cwb.googlegroups.com> <1130253519.330211.92880@o13g2000cwo.googlegroups.com> <11lsl50soghlt8f@corp.supernews.com> <11lsmdg3mmfl9ee@corp.supernews.com> Message-ID: <11lsnr38dmp1q58@corp.supernews.com> On 2005-10-25, Grant Edwards wrote: > It appears that the Gnuplot modules has coerced my data into > single-precision -- thus throwing away most of the resolution > on the x-axis. Passing Gnuplot.Data a Numeric array object is a good work-around. Otherwise, Gnuplot.Data will convert it into a float (single precision) arry. Here's a revised demo that works better: ------------------------------8<------------------------------ import Gnuplot,time,sys,math import Numeric Gnuplot.GnuplotOpts.prefer_fifo_data = 0 def pause(): sys.stdout.write("Press enter to continue: ") sys.stdin.readline() def fgrid(start,stop,count): for i in xrange(count): yield start + ((stop-start)*i)/count start = time.time() xdata = [x for x in fgrid(0,600.0,10)] # two minutes worth ydata = [math.sin(x/100.0) for x in xdata] data = Gnuplot.Data(xdata,ydata,with='linespoints',using=(1,2)) gp = Gnuplot.Gnuplot(debug=1) gp.title('Data starting at %s' % time.asctime(time.gmtime(start+xdata[0]))) # x axis will use default tics (seconds since start of run) gp.plot(data) pause() # same data with x value as Unix timestamps xdata = [x+start for x in xdata] a = Numeric.array(zip(xdata,ydata)) data = Gnuplot.Data(a,with='linespoints',using=(1,2)) gp('set xdata time') gp('set timefmt "%s') gp('set format x "%r"') gp('set xtics 120') gp.plot(data) pause() ------------------------------8<------------------------------ -- Grant Edwards grante Yow! The Korean War must at have been fun. visi.com From http Tue Oct 4 06:32:24 2005 From: http (Paul Rubin) Date: 04 Oct 2005 03:32:24 -0700 Subject: Controlling who can run an executable References: <1128395422.904212.318930@g44g2000cwa.googlegroups.com> <86y85ahs1j.fsf@bhuda.mired.org> <1128421025.598483.240870@z14g2000cwz.googlegroups.com> Message-ID: <7xvf0d4lon.fsf@ruckus.brouhaha.com> "Cigar" writes: > I may have to just put password protection in and if she hangs herself > by 'sharing' the password with underlings she trusts (at the > present)... again that's outside of my control of protecting her. You could have the password automatically change once a month. Give her a master list of passwords and tell her to lock it away. Each month she refers to the list and gives underlings a new password. > Currently this app is running on a stand alone PC. There was a big > concern about hackers getting at her program or data from over the > internet. I complemented her on this level of security. No floppy > drive either. If the app is not being used too often, install it on a laptop and lock the laptop in a drawer when not in use. From csubich.spam.block at spam.subich.block.com Fri Oct 21 14:10:30 2005 From: csubich.spam.block at spam.subich.block.com (Christopher Subich) Date: Fri, 21 Oct 2005 14:10:30 -0400 Subject: Would there be support for a more general cmp/__cmp__ In-Reply-To: References: Message-ID: Antoon Pardon wrote: > It would be better if cmp would give an indication it > can't compare two objects instead of giving incorrect > and inconsistent results. If two objects aren't totally comparable, then using 'cmp' on them is ill-defined to begin with. The Standard Thing To Do is throw an exception; see the Highly Obscure Case of the Complex Numbers. >>>1 == 1j False >>>1 != 1j True >>>1 < 1j Traceback (most recent call last): File "", line 1, in ? TypeError: cannot compare complex numbers using <, <=, >, >= >>>cmp(1j,1j) 0 >>>cmp(1,1j) Traceback (most recent call last): File "", line 1, in ? TypeError: cannot compare complex numbers using <, <=, >, >= So using the well-known case of complex numbers, the semantics are already well-defined. >>> class Incomparable: ... def __cmp__(self,other): ... raise TypeError("cannot compare Incomparables using <, <=, >, >=") ... def __eq__(self,other): ... return self is other ... def __neq__(self,other): ... return self is not other >>> a1 = Incomparable() >>> a2 = Incomparable() >>> a1 == a1 1 # I'm running on python 2.2.3 at the moment, so hence the 1. >>> a2 == a2 1 >>> a1 == a2 0 >>> a1 < a2 Traceback (most recent call last): File "", line 1, in ? File "", line 3, in __cmp__ TypeError: cannot compare Incomparables using <, <=, >, >= >>> cmp(a1,a2) Traceback (most recent call last): File "", line 1, in ? File "", line 3, in __cmp__ TypeError: cannot compare Incomparables using <, <=, >, >= So your use-case is already well-defined, and rather simple. Make __cmp__ raise an exception of your choice, and define rich comparators only for the comparisons that are supported. If, as you say in another post, "some" pairs in D cross D are comparable on an operator but not all of them (and further that this graph is not transitive), then your _ONLY_ choices, no matter your implementation, is to return some possibly inconsistent result (a < b == 1, b < c == 1, a < c == 0) or raise an exception for unapplicable comparisons. This isn't a Python problem; this is a problem from formal mathematics. Personally, I'd favor the "raise an exception" case, which is exactly what will happen if you define rich comparisons and let cmp throw an exception. Operators that assume comparable objects, like sort, also almost always assume a total order -- inconsistent operations can give weird results, while throwing an exception will at least (usually) give some sort of error that can be caught. Another poster mentioned the B-tree example, and that isn't solvable in this case -- B-trees assume a total order, but by their nature aren't explicit about checking for it; inserting a "partial plus exception" order might result in tree failure at weird times. An inconsistent order, however, is even worse -- it would corrupt the tree at the same times. From steve at holdenweb.com Mon Oct 31 19:44:14 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 01 Nov 2005 00:44:14 +0000 Subject: looking for a good python module for MS SQL server In-Reply-To: References: Message-ID: Jarek Zgoda wrote: > Anat napisa?(a): > > >>Does anyone know a good python mudule that works with MS SQL server? > > > Google will yield something, but I prefer adodbapi over specialized > modules. Works good with SQLServer using SSPI auth (others rather not). > Though it does have problems with stored procedures. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From erniedude at gmail.com Mon Oct 31 10:18:31 2005 From: erniedude at gmail.com (Ernesto) Date: 31 Oct 2005 07:18:31 -0800 Subject: Windows - Need to process quotes in string... Message-ID: <1130771911.508820.82030@g49g2000cwa.googlegroups.com> I'm trying to use a $ delimeter, but it doesn't seem to work. Here is the code: launchWithoutConsole("devcon.exe",d'$enable "@USB\VID_0403&PID_6010&MI_00\7&15E4F68&1&0000"$) I want to send the string parameter: enable "@USB\VID_0403&PID_6010&MI_00\7&15E4F68&1&0000" to the program devcon. The argument itself is a string, but has quotes inside too. I've tried it many different ways and I keep getting syntax errors. Thanks, From davids at webmaster.com Mon Oct 31 18:55:57 2005 From: davids at webmaster.com (David Schwartz) Date: Mon, 31 Oct 2005 15:55:57 -0800 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <86acgulv5z.fsf@localhost.localdomain> <7xvezi8ypy.fsf@ruckus.brouhaha.com> <86y84ehd3j.fsf@bhuda.mired.org> <86hdb2h750.fsf@bhuda.mired.org> <86zmoufiww.fsf@bhuda.mired.org> <86oe59e57v.fsf@bhuda.mired.org> <868xwcevke.fsf@bhuda.mired.org> <86br1530w7.fsf@bhuda.mired.org> <867jbt2xyb.fsf@bhuda.mired.org> <863bmh2t7x.fsf@bhuda.mired.org> <86u0ex1cc9.fsf@bhuda.mired.org> Message-ID: "Mike Meyer" wrote in message news:86u0ex1cc9.fsf at bhuda.mired.org... > "David Schwartz" writes: >> You have not disproved that. The closest you've come to a disproof is >> one case where the word "theft" was used (while earlier in the thread, >> actual physical force had been used, but not in that specific spot) where >> the context strongly suggested that it meant theft by force. > Now you're simply lieing. I never discussed force earlier in the > thread. I didn't say that *you* discussed force. I said it "was used". At that time, I was responding to a lot of different people about similar issues, and it is true that things said to me by other people will color my responses to you. I agree that that isn't always fair. >> You are correct that it is possible to steal something without >> actually >> using physical force. But that's not an important difference. The hugely >> important difference, and the one that you and others *are* seeking to >> obliterate, is the difference between inherently unjust actions such as >> force and fraud and actions that are neither forceful nor fraudulent. > And now you change your story again. You've gone from referring to all > other criminal acts as "criminals with guns" to "actual use of force" > to "using force or fraud." It is an interesting debate tactic that rather addressing my claims, you simply note that they're different to the previous ones. Why does it matter whether they're the same or different exactly? >>> The only consistency here has been >>> trying to treat MS's crimes as somehow different from other peoples >>> crimes. >> That's because the only crimes that have come up in this thread are >> Microsoft's crimes (that don't involve force or fraud) and other crimes >> (such as theft, threats of force, and the like) which do. Duh. > Actually, they don't necessarily, but that's relevant. You simply > label *all* crime other than MS's as "criminals with guns" and refuse > to discuss them. No, not at all. If a crime came up that wasn't force or fraud (say, possesion of "illegal" drugs), I would just as much insist that the difference between this type of crime and a crime involving force or fraud be kept in mind. It makes no difference to me who the actor is and all the difference in the world what the action is. >> There were a few narrow cases where Microsoft was actually accused of >> actions that I do consider force or fraud. > That's true. They committed a fraud - by lieing to federal officials > in court - and *you* responded by calling those federal officials > "criminals with guns", and using that to *excuse* MS's criminal acts > in this case. Actually, I wasn't aware of any cases where they actually committed perjury. I was more thinking of cases where they claimed they had no interest in developing a competing product to get advance information when they actually were developing a competing product or cases where they threatened a lawsuit that they knew had no merit. (These are, IMO, fundamentally equivalent to guns, though perhaps lesser in degree.) Morally, lying in court is a tough one. For example, suppose you are in a court case with someone who is definitely lying in court. You are in the right, but it's clear the court won't believe you in the face of the lying and faked evidence. In this case, is lying in court fraud? Or is it justified in defense against an attacker willing to use fraud against you? So this isn't quite in the same category as force or fraud, because the court has the ability to balance credibility and control damage. No such balancing is available against a bullet in flight. The Federal officials do wield force. The purpose of a trial is precisely to determine how force will be used. > Which is more of the same old song and dance from you: treating MS's > criminal acts as somehow different from any other criminals acts. Yes, different from the ones they are different from and the same as the ones they are the same as. There is a huge difference between crimes that involve the use of force, fraud, the threat of force, and the like and crimes that don't. There is a huge difference between crimes that creat real victims and crimes that we have to pretend create notional victims. DS From tim.golden at viacom-outdoor.co.uk Fri Oct 21 10:18:52 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Fri, 21 Oct 2005 15:18:52 +0100 Subject: win32 process information, using win32 extension Message-ID: <9A28C052FF32734DACB0A288A3533991044D227F@vogbs009.gb.vo.local> [Java and Swing] > i need to get information about the processes > running on a windows pc (98, 2k, xp) > i can get the pid's using, win32process.EnumProcesses() > but how can i get the name of the process, path > to process, etc. You can probably do what you want with WMI. You'll have to make sure to install Microsoft's WMI pack (or whatever it's called) on the Win98 machines: http://timgolden.me.uk/python/wmi_cookbook.html#running_processes 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 duncan.booth at invalid.invalid Tue Oct 25 03:46:07 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 25 Oct 2005 07:46:07 GMT Subject: Syntax across languages References: <1130052687.396109.145420@o13g2000cwo.googlegroups.com> <0fkrl15cteikfb09ah670kv9bupr902soi@4ax.com> Message-ID: Tim Roberts wrote: >> >>- Nestable Pascal-like comments (useful): (* ... *) > > That's only meaningful in languages with begin-comment AND end-comment > delimiters. Python has only begin-comment. Effectively, you CAN nest > comments in Python: I believe that the OP is mistaken. In standard Pascal comments do not nest, and you can mix delimiters so, for example: (* this is a comment } Most Pascal implementations require the delimeters to match and allow you to nest comments which use different delimiters, but I'm not aware of any Pascal implementations which would allow you to nest comments with the same delimiter: (* This is not a valid (* comment within a comment. *) *) To this extent Python (if you consider docstrings as a type of comment) does exactly the same thing: """ this is # a docstring! """ # and this is """ a comment """ From steve at myplace.com Mon Oct 10 20:30:59 2005 From: steve at myplace.com (Steve M) Date: Mon, 10 Oct 2005 19:30:59 -0500 Subject: Changing console text color References: <434AF022.5050100@websafe.com> Message-ID: Thank you. I appreciate the help. Steve Larry Bates wrote: > You can use this module to control console windows background and > text colors. > > http://www.effbot.org/zone/console-index.htm > > -Larry Bates > > Steve M wrote: >> Hello, >> >> I've been trying to change the text color on a windows >> console >> program I've been working on with no luck. I should mention that >> I'm a novice so please dummy up your replies. >> >> Thanks-in-Advance >> Steve From dgemic at unknown.ca Sat Oct 15 10:02:39 2005 From: dgemic at unknown.ca (Drazen Gemic) Date: Sat, 15 Oct 2005 16:02:39 +0200 Subject: Microsoft Hatred FAQ In-Reply-To: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> Message-ID: I find this article very much off topic. Send that to some advocacy group, please. DG From mde at micah.elliott.name Mon Oct 3 15:56:06 2005 From: mde at micah.elliott.name (Micah Elliott) Date: Mon, 3 Oct 2005 12:56:06 -0700 Subject: python getopt functionality In-Reply-To: <4341842D.4060905@grads.ece.mcmaster.ca> References: <4341786B.1030901@grads.ece.mcmaster.ca> <4341842D.4060905@grads.ece.mcmaster.ca> Message-ID: <20051003195606.GG10940@kitchen.client.attbi.com> On Oct 03, M.N.A.Smadi wrote: > It is not clear to me if i can define `mandatory' options? That sounds > strange but let say that the command `requires ' a value for -z or > --zoo (either or should be find but one and only one of them MUST be > present). Can i do that with resorting to using if statements? Optik (optparse) adheres to a "Tao of Option Parsing" , which discusses required option arguments. -- Micah Elliott From steve at holdenweb.com Fri Oct 21 12:24:57 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 21 Oct 2005 17:24:57 +0100 Subject: Execute C code through Python In-Reply-To: <11li4h95pnci35b@corp.supernews.com> References: <1129844737.586396.61080@g47g2000cwa.googlegroups.com> <1129861083.010702.6770@g49g2000cwa.googlegroups.com> <1129906892.696582.288010@g43g2000cwa.googlegroups.com> <11li3b2hsa3lhb5@corp.supernews.com> <11li4h95pnci35b@corp.supernews.com> Message-ID: Grant Edwards wrote: > On 2005-10-21, Micah Elliott wrote: > >>On Oct 21, Grant Edwards wrote: >> >>>I'm guessing you're using Windows based on the question. >> >>+1 QOTW. > > > Yow! That's two in one day, what do I win? > If my experience is anything to go by it just means there won't be a weekly URL this week :-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From grante at visi.com Mon Oct 10 15:53:26 2005 From: grante at visi.com (Grant Edwards) Date: Mon, 10 Oct 2005 19:53:26 -0000 Subject: Library functions References: <1128973241.967119.199440@g43g2000cwa.googlegroups.com> Message-ID: <11klhlmas9nfm40@corp.supernews.com> On 2005-10-10, Tuvas wrote: > I am writing a program that mimics a program written in C, but using > Python-supiorior techniques. The C program calles a library function, > non-open source, I only know that it sends it a command > LINUX_CAN_Open() as for a few others as well. I've successfully used the ctypes module to call Windows DLLs (coincidentally it's to send/receive CAN messanges). According to the ctypes docs, you can use it to call functions in Linux libraries as well. -- Grant Edwards grante Yow! Now I can join WEIGHT at WATCHERS! visi.com From hancock at anansispaceworks.com Mon Oct 24 11:04:34 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Mon, 24 Oct 2005 10:04:34 -0500 Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <867jcbzdw9.fsf@bhuda.mired.org> Message-ID: <200510241004.34971.hancock@anansispaceworks.com> On Saturday 22 October 2005 05:44 pm, Tim Tyler wrote: > Microsoft still comes in at number 2 - on: > http://dmoz.org/Society/Issues/Business/Allegedly_Unethical_Firms/ > Few companies are more despised than Microsoft. Wrong URL? No such list appears at that site, although it does link to several different lists and topic-related sites. The two lists I happened to check are years out of date (one was from 1994!) and do not even list Microsoft. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From soretha at aol.com Fri Oct 28 04:39:45 2005 From: soretha at aol.com (yepp) Date: Fri, 28 Oct 2005 10:39:45 +0200 Subject: creating/altering the OpenOffice spredsheet docs References: Message-ID: Andy Leszczynski wrote: > Any idea how to do that the way ActiveX would be used on M$? > Fortunately, NO. You know http://udk.openoffice.org/python/python-bridge.html ?? yepp From jjl at pobox.com Mon Oct 31 19:58:52 2005 From: jjl at pobox.com (John J. Lee) Date: 01 Nov 2005 00:58:52 +0000 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <87ek65kbw5.fsf@lucien.dreaming> <1h5760l.1e2eatkurdeo7N%aleaxit@yahoo.com> <3siakvFohl3aU1@individual.net> <1h57cij.16dkc141lds4s4N%aleaxit@yahoo.com> <1h597yx.wjk2a71spyjhyN%aleaxit@yahoo.com> <3smn47FoolfbU1@individual.net> <3snboiFolt77U1@individual.net> Message-ID: <87sluhji9f.fsf@pobox.com> Paul Watson writes: [...] > How "ill" will things be when large bodies of code cannot run > successfully on a future version of Python or a non-CPython > implementation which does not close files. Might as well put file > closing on exit into the specification. [...] There are many, many ways of making a large body of code "ill". Closing off this particular one would make it harder to get benefit of non-C implementations of Python, so it has been judged "not worth it". I think I agree with that judgement. John From aleaxit at yahoo.com Wed Oct 26 10:42:19 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Wed, 26 Oct 2005 07:42:19 -0700 Subject: Set an environment variable References: <43573022$0$155$edfadb0f@dread16.news.tele.dk> <1129798724.366618.194650@g44g2000cwa.googlegroups.com> <43589205$0$125$edfadb0f@dread16.news.tele.dk> <11lhv31li8sgm0c@corp.supernews.com> <86ll0mu6px.fsf@bhuda.mired.org> <11lifp8r4kipi5c@corp.supernews.com> <868xwmu07g.fsf@bhuda.mired.org> <11liivcbmeops4b@corp.supernews.com> <11lps3jj9a7h62c@corp.supernews.com> Message-ID: <1h4zleu.115juj63s01m9N%aleaxit@yahoo.com> Grant Edwards wrote: > On 2005-10-24, Eric Brunel wrote: > > >> The only think you can export an environment variable to is a > >> child process > > > > Well, you know that, and I know that too. From my experience, > > many people don't... > > True. Using Unix for 20+ years probably warps one's perception > of what's obvious and what isn't. This specific issue is identical in Windows, isn't it? I do not know any OS which does have the concept of "environment variable" yet lets such variables be ``exported'' to anything but a child process. Alex From kent37 at tds.net Mon Oct 24 06:17:18 2005 From: kent37 at tds.net (Kent Johnson) Date: Mon, 24 Oct 2005 06:17:18 -0400 Subject: High Order Messages in Python In-Reply-To: <1130127914.446263.222800@z14g2000cwz.googlegroups.com> References: <1130015536.273136.295800@g43g2000cwa.googlegroups.com> <435bb315$0$15040$ed2619ec@ptn-nntp-reader02.plus.net> <1130118446.643842.178950@g47g2000cwa.googlegroups.com> <1130122476.079450.216280@g47g2000cwa.googlegroups.com> <1h4wiqv.m4hrpogqt6tvN%aleaxit@yahoo.com> <1130127914.446263.222800@z14g2000cwz.googlegroups.com> Message-ID: <435cb299$1_3@newspeer2.tds.net> bonono at gmail.com wrote: > counting that out(regardless whether it is (dis)advantage or not), what > else a block can do but not a named function ? My limited understanding is that the advantage is - simpler syntax - high level of integration into the standard library (*many* methods that take closure arguments). Blocks are used not just for iteration but for the kinds of things shown in the examples to PEP 343 http://www.python.org/peps/pep-0343.html For example to open a file and read from it uses two closures, one to wrap a block with the file open/close, one to iterate lines (from the pickaxe book): File.open("testfile") do |file| file.each_line { |line| puts line } end Kent > > Alex Martelli wrote: > >>bonono at gmail.com wrote: >> >> >>>could someone enlighten me what is the advantage of block over named >>>function ? >>> >>>One thing that I can see a difference may be lexical scope ? >> >>"Yes, but" -- according to the latest Ruby book, the "mixed lexical >>scope" of blocks is a highly controversial notion in the Ruby community; >>so I wouldn't necessarily count it as an _advantage_ of Ruby blocks... >> >> >>Alex > > From __peter__ at web.de Sun Oct 16 13:17:46 2005 From: __peter__ at web.de (Peter Otten) Date: Sun, 16 Oct 2005 19:17:46 +0200 Subject: TypeError: unbound method PrintInput() must be called with test instance as first argument (got test instance instead) References: <1129481319.436107.16950@f14g2000cwb.googlegroups.com> Message-ID: arotem wrote: > Hi, > > I am trying to call an unbound method (PrintInput) with the object > instance as the first argument but getting the following error: > "TypeError: unbound method PrintInput() must be called with test > instance as first argument (got test instance instead)" > > Below is the sample code (test) for this purpose (two files). > > Any help is greatly appreciated. > > Thanks in Advance, Anat > > > Sample Code: > > File 1 - input_file.py: > > #!/usr/bin/env python > from test import * > > CMD = (test.PrintInput, float(2)) > > File 2 - test.py: > > from input_file import * > > class test: > def __init__(self): > _test = 2 > def PrintInput(self, input): > print "Input is = %s"%(input) > > if __name__== "__main__": > print "Unit testing" > inst = test() > print CMD > cmd = CMD[0] > param = CMD[1:] > > cmd(inst,param) # this is the problematic line It is best to avoid situations where you import the main script into modules used by your program. You end up with to copies of (in your example) test.py. and therefore two functionally identical but distinct test classes and that gets you the error message. You can verify that with the following demo: #file script_is_main.py import script_is_main import __main__ print script_is_main is __main__ # False A sound layout would instead be to move the test class into a separate module that is used by both the main script and the test module: # file test.py class Test: def __init__(self): _test = 2 def PrintInput(self, input): print "Input is = %s"%(input) # file input_file.py import test CMD = (test.Test.PrintInput, float(2)) # file main.py #!/usr/bin/env python import input_file import test if __name__== "__main__": print "Unit testing" inst = test.Test() CMD = input_file.CMD print CMD cmd = CMD[0] param = CMD[1:] cmd(inst, param) # this was the problematic line Peter From grante at visi.com Wed Oct 5 15:15:52 2005 From: grante at visi.com (Grant Edwards) Date: Wed, 05 Oct 2005 19:15:52 -0000 Subject: Does python support the expression "a = b | 1"??? References: Message-ID: <11k89j8q8lcgsa5@corp.supernews.com> On 2005-10-05, Wenhua Zhao wrote: > a = b | 1 Yes, Python supports that expression. > a = b if b != nil > else a =1 But that's not what it means. > Is there such expression in python? >>> b=0 >>> b = 0 >>> a = b | 1 >>> a 1 >>> b = 1 >>> a = b | 1 >>> a 1 >>> b = 2 >>> a = b | 1 >>> a 3 >>> I'm not sure what What you mean by "nil", but I would geuess this is the equivalent Python: if b is not None: a = b else: a = 1 -- Grant Edwards grante Yow! .. Do you like at "TENDER VITTLES?"? visi.com From jan.niestadt at gmail.com Tue Oct 25 07:40:14 2005 From: jan.niestadt at gmail.com (Jan Niestadt) Date: 25 Oct 2005 04:40:14 -0700 Subject: cell and row In-Reply-To: References: <1d987df30510250150mb4f0f97y79d6e93c0c0d66ff@mail.gmail.com> Message-ID: <1130240414.896875.160600@f14g2000cwb.googlegroups.com> Because you're inserting items into your existing list instead of a new list. What you probably mean is: b = [] for x in a: b.append(x) which creates a new list b that contains all elements whose length is greater than four. A better way to write this would be: b = [x for x in a if len(x) > 4] From jason at pengale.com Wed Oct 19 21:48:30 2005 From: jason at pengale.com (Jason Stitt) Date: Wed, 19 Oct 2005 20:48:30 -0500 Subject: Having trouble deleting objects from a list... In-Reply-To: <1129770984.225558.284260@g49g2000cwa.googlegroups.com> References: <1129770984.225558.284260@g49g2000cwa.googlegroups.com> Message-ID: On Oct 19, 2005, at 8:16 PM, KraftDiner wrote: > I have a list, and within it, objects are marked for deletion. > However when I iterate through the list to remove objects > not all the marked objects are deleted.. > here is a code portion: > > i = 0 > for obj in self.objList: > if obj.mouseHit: > print 'delete + ' + `i` > self.objList.pop(i) > flag = True > else: > i = i + 1 > print `i` You're mixing two different ways of looping, and they're getting out of sync. 'for obj in self.objList' will keep right on iterating through the list even if you don't increment i. A direct adaptation of your code that should work is: i = 0 while i < len(self.objList): if self.objList[i].mouseHit: self.objList.pop(i) flag = True else: i += 1 Or, shorter and a bit more Pythonic, but not in-place: newObjList = [obj for obj in self.objList if not obj.mouseHit] flag = (len(newObjList) != len(self.objList)) self.objList = newObjList I don't know how the performance of the two would compare. The second involves creating a new list, but Python is supposed to optimize the heck out of list comprehension, and removing items from a list in place isn't free, either. Jason From bokr at oz.net Fri Oct 21 17:22:00 2005 From: bokr at oz.net (Bengt Richter) Date: Fri, 21 Oct 2005 21:22:00 GMT Subject: How to add one month to datetime? References: Message-ID: <43595b53.606924000@news.oz.net> On Fri, 21 Oct 2005 14:01:14 -0700, "Robert Brewer" wrote: >John W wrote: >> I have been trying to figure out how to >> easily add just one month to a datetime >> object? ...I was wondering if there is >> simple way of doing this with built in >> datetime object? > >If you want the same day in the succeeding month, you can try: > > newdate =3D datetime.date(olddate.year, olddate.month + 1, >olddate.day) > >...but as you can see, that will run into problems quickly. See the >"sane_date" function here: >http://projects.amor.org/misc/browser/recur.py for a more robust >solution, where: > > newdate =3D recur.sane_date(olddate.year, olddate.month + 1, >olddate.day) > >will roll over any values which are out-of-bounds for their container. > > The OP will still have to decide whether he likes the semantics ;-) E.g., what does he really want as the date for "one month" after January 30 ? Regards, Bengt Richter From vdavidster at gmail.com Thu Oct 20 12:01:50 2005 From: vdavidster at gmail.com (David Veerasingam) Date: 20 Oct 2005 09:01:50 -0700 Subject: Some more odd behaviour from the Regexp library In-Reply-To: References: <1129777843.892280.302490@g44g2000cwa.googlegroups.com> <86wtk8vofq.fsf@bhuda.mired.org> Message-ID: <1129824110.760645.172330@f14g2000cwb.googlegroups.com> Thanks for all your replies. I guess I've always used .*? as sort of an idiom for a non-greedy match, but I guess it only works if I specify the end point (which I didn't in the above case). e.g. re.search(r'exit: (.*?)$', a) Thanks for pointing that out! David From jmw136 at gmail.com Mon Oct 31 21:50:46 2005 From: jmw136 at gmail.com (John W) Date: Mon, 31 Oct 2005 20:50:46 -0600 Subject: Does Asyncore Send require newline? Message-ID: Hello, I have a test environment that consists of a server and an application that opens an asyncore socket and communicates with it. In my application, on the handle_write call, if I do not append a "\n" to my message the server never gets the message. If I do append it, the server can read the message and act accordingly. So my call looks like this: self.send( message] + "\n") Is this how it was designed? Do you have to send a '\n' to have the data read? I can't find a whole lot of documentation on the send method. If you could offer some help, I would appreciate it. Thanks, John -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Wed Oct 5 05:05:22 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 05 Oct 2005 10:05:22 +0100 Subject: dictionary interface In-Reply-To: References: Message-ID: Antoon Pardon wrote: > Op 2005-10-05, Tom Anderson schreef : > >>On Tue, 4 Oct 2005, Robert Kern wrote: >> >> >>>Antoon Pardon wrote: >>> >>> >>>> class Tree: >>>> >>>> def __lt__(self, term): >>>> return set(self.iteritems()) < set(term.iteritems()) >>>> >>>> def __eq__(self, term): >>>> return set(self.iteritems()) == set(term.iteritems()) >>>> >>>>Would this be a correct definition of the desired behaviour? >>> >>>No. >>> >>>In [1]: {1:2} < {3:4} >>>Out[1]: True >>> >>>In [2]: set({1:2}.iteritems()) < set({3:4}.iteritems()) >>>Out[2]: False >>> >>> >>>>Anyone a reference? >>> >>>The function dict_compare in dictobject.c . >> >>Well there's a really helpful answer. I'm intrigued, Robert - since you >>know the real answer to this question, why did you choose to tell the >>Antoon that he was wrong, not tell him in what way he was wrong, certainly >>not tell him how to be right, but just tell him to read the source, rather >>than simply telling him what you knew? Still, at least you told him which >>file to look in. And if he knows python but not C, or gets lost in the >>byzantine workings of the interpreter, well, that's his own fault, i >>guess. >> >>So, Antoon, firstly, your implementation of __eq__ is, i believe, correct. >> >>Your implementation of __lt__ is, sadly, not. While sets take "<" to mean >>"is a proper subset of", for dicts, it's a more conventional comparison >>operation, which constitutes a total ordering over all dicts (so you can >>sort with it, for example). However, since dicts don't really have a >>natural total ordering, it is ever so slightly arbitrary. >> >>The rules for ordering on dicts are, AFAICT: >> >>- If one dict has fewer elements than the other, it's the lesser >>- If not, find the smallest key for which the two dicts have different >>values (counting 'not present' as a value) >>-- If there is no such key, the dicts are equal >>-- If the key is present in one dict but not the other, the dict in which >>it is present is the lesser >>-- Otherwise, the dict in which the value is lesser is itself the lesser >> >>In code: >> >>def dict_cmp(a, b): >> diff = cmp(len(a), len(b)) >> if (diff != 0): >> return diff >> for key in sorted(set(a.keys() + b.keys())): >> if (key not in a): >> return 1 >> if (key not in b): >> return -1 >> diff = cmp(a[key], b[key]) >> if (diff != 0): >> return diff >> return 0 >> > > > Thanks for the explanation, but you somehow give me too much. > > I have been searching some more and finally stumbled on this: > > http://docs.python.org/ref/comparisons.html > > Mappings (dictionaries) compare equal if and only if their sorted > (key, value) lists compare equal. Outcomes other than equality are > resolved consistently, but are not otherwise defined. > > This seems to imply that the specific method to sort the dictionaries > is unimported (as long as it is a total ordering). So I can use whatever > method I want as long as it is achieves this. > > But that is contradicted by the unittest. If you have a unittest for > comparing dictionaries, that means comparing dictionaries has a > testable characteristic and thus is further defined. > > So I don't need a full implementation of dictionary comparison, > I need to know in how far such a comparison is defined and > what I can choose. > The dict unit tests are probably trying to ensure that the dictionary ordering doesn't change from version to version, which is probably a good idea in case someone (foolishly?) deciess to rely on it. I can't help wondering, though, under what conditions it actually makes sense to compare two dictionaries for anything other than equality. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From __peter__ at web.de Sun Oct 30 04:13:42 2005 From: __peter__ at web.de (Peter Otten) Date: Sun, 30 Oct 2005 10:13:42 +0100 Subject: How do I sort these? References: <1130524906.918612.38540@g49g2000cwa.googlegroups.com> <43642b1b.1315475223@news.oz.net> Message-ID: Bengt Richter wrote: > On Fri, 28 Oct 2005 20:00:42 +0100, Steve Holden > wrote: > >>KraftDiner wrote: >>> I have two lists. >>> I want to sort by a value in the first list and have the second list >>> sorted as well... Any suggestions on how I should/could do this? >>> >> >>> first = [1, 3, 5, 7, 9, 2, 4, 6, 8] >> >>> second = ['one', 'three', 'five', 'seven', 'nine', 'two', 'four', >>'six', 'eight'] >> >>> both = zip(first, second) >> >>> both.sort() >> >>> [b[0] for b in both] >>[1, 2, 3, 4, 5, 6, 7, 8, 9] >> >>> [b[1] for b in both] >>['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'] >> >>> >> >>You mean like this? > ISTM there could be a subtle requirement in the way the OP stated what he > wanted to do. I.e., it sounds like he would like to sort the first list > and have a second list undergo the same shuffling as was required to sort > the first. That's different from having the data of the second participate > in the sort as order-determining data, if equals in the first list are not > to be re-ordered: > > >>> first = [2]*5 + [1]*5 > >>> first > [2, 2, 2, 2, 2, 1, 1, 1, 1, 1] > >>> sorted(first) > [1, 1, 1, 1, 1, 2, 2, 2, 2, 2] > >>> second = [chr(ord('A')+i) for i in xrange(9,-1,-1)] > >>> second > ['J', 'I', 'H', 'G', 'F', 'E', 'D', 'C', 'B', 'A'] > >>> sorted(second) > ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'] > > Now the zipped sort unzipped: > >>> zip(*sorted(zip(first,second))) > [(1, 1, 1, 1, 1, 2, 2, 2, 2, 2), ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', > ['I', 'J')] > > Now suppose we sort the first and use the elements' indices to preserve > order where equal > >>> sorted((f,i) for i,f in enumerate(first)) > [(1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (2, 0), (2, 1), (2, 2), (2, 3), > [(2, 4)] > > Separate out the first list elements: > >>> [t[0] for t in sorted((f,i) for i,f in enumerate(first))] > [1, 1, 1, 1, 1, 2, 2, 2, 2, 2] > > Now select from the second list, by first-element position correspondence: > >>> [second[t[1]] for t in sorted((f,i) for i,f in enumerate(first))] > ['E', 'D', 'C', 'B', 'A', 'J', 'I', 'H', 'G', 'F'] > > Which did the OP really want? ;-) I don't know, but there certainly is no subtle requirement to not provide the key argument: >>> import operator >>> first = [2]*5 + [1]*5 >>> second = list(reversed("ABCDEFGHIJ")) >>> [s for f, s in sorted(zip(first, second))] ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'] >>> [s for f, s in sorted(zip(first, second), key=operator.itemgetter(0))] ['E', 'D', 'C', 'B', 'A', 'J', 'I', 'H', 'G', 'F'] Peter From christopher.saunter at durham.ac.uk Wed Oct 26 12:57:53 2005 From: christopher.saunter at durham.ac.uk (c d saunter) Date: Wed, 26 Oct 2005 16:57:53 +0000 (UTC) Subject: Using Python to add thumbnails to Explorer Message-ID: Greetings All, In Widows Explorer there is a thumbnail view, where you see images as thumbnails. Applications such as MS Office and OpenOffice, when installed, cause their respective filetypes to be previewed as thumbnails as well. Thumbnails are stored in the Thumbs.db hidden file. There my knowledge ends. I'm asuming that aplications install registry keys somewhere that register an invocation that returns a thumbnail for a given file bit this is just a guess. What I'd like to do is write some Python script that can be invoked to add thumbnails for certian file types (my own custom types and things like the .FITS array format.) Googling isn't going anywhere so I am hoping there are some wizards out there with poiters... Specifically any information on how the thumbnail system works would be great! Cheers, Chris From entropy at domain.invalid Mon Oct 24 21:20:14 2005 From: entropy at domain.invalid (entropy) Date: Tue, 25 Oct 2005 01:20:14 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <86k6g59ke6.fsf@bhuda.mired.org> <5y47f.174197$RW.59989@fe2.news.blueyonder.co.uk> Message-ID: davids at webmaster.com wrote... > > Also may I remind you that these newsgroups are international. > > So what? We are talking about a United States' company's actions with > respect to United States laws. There is no reason to make this about > philosophy, politics, law, international relations or any such things. If we > did that, we would wind up on tangents (just like this one!) that have > nothing whatsoever to do with Microsoft. > > Yes, in a discussion about Microsoft, I will make economic or political > statements that aren't 100% valid in every possible imaginable case. But > guess what? They'll be 100% valid for the case we're discussing. > > And you can watch all the replies about how my statement isn't true in > every possible case. Well, guess what? I only care about one case. But I was told recently that the broader discussion is exactly was Usenet if for. ;) From samrobertsmith at gmail.com Fri Oct 14 20:48:59 2005 From: samrobertsmith at gmail.com (Shi Mu) Date: Fri, 14 Oct 2005 17:48:59 -0700 Subject: output Message-ID: <1d987df30510141748v37058d0frab30f0235e0eb9f3@mail.gmail.com> After I run the following python code, I expect to have the printing such as: The year is 2005 However, I got something like: The year is 2005 Fri Oct 14 17:43:31 2005 Fri Oct 14 17:43:31 2005 The year is 2005 What is the reason? The code follows: import time import now class today(now.now): def __init__(self, y = 1970): now.now.__init__(self) def update(self,tt): if len(tt) < 9 : raise TypeError if tt[0] < 1970 or tt[0] > 2038: raise OverflowError self.t = time.mktime(tt) self(self.t) if __name__ == "__main__": n = today() print "The year is", n.year From rupole at hotmail.com Sun Oct 9 23:08:45 2005 From: rupole at hotmail.com (Roger Upole) Date: Sun, 9 Oct 2005 23:08:45 -0400 Subject: Creating internet shortcuts References: <1p9jp8i0al14h$.1xmuz4fyfs4m5.dlg@40tude.net> Message-ID: <1128913971_130673@spool6-east.superfeed.net> Pythoncom doesn't directly support the necessary interfaces, but you can use the Shell COM interfaces to create them. import win32com.client wsh=win32com.client.gencache.EnsureDispatch('wscript.shell') s=wsh.CreateShortcut('c:\\python.url') s.TargetPath='www.python.org' s.Save() hth Roger "Richard Townsend" wrote: > I've seen the python.faqts page: > http://www.faqts.com/knowledge_base/view.phtml/aid/4475/fid/538 on how to > create windows shortcuts using Python. > > Does anyone know if this be adapted to create internet shortcuts on > windows? (as used for Favorites). > > Thank you, > > -- > Richard ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= East/West-Coast Server Farms - Total Privacy via Encryption =--- From nyamatongwe+thunder at gmail.com Thu Oct 13 20:31:17 2005 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Fri, 14 Oct 2005 00:31:17 GMT Subject: win32api.FindFiles Win2003, problem with Short Name In-Reply-To: <1129245942.185252.171220@o13g2000cwo.googlegroups.com> References: <1129245942.185252.171220@o13g2000cwo.googlegroups.com> Message-ID: Frank Borell: > I'm having a problem retrieving the ShortName from a file that was > written by a MAC and only from a Windows 2003 server. > > I realize the file has a space after it, but I can retrieve the short > name from Windows XP and 2000; Does your Windows 2003 machine have short file name support turned off? The NtfsDisable8dot3NameCreation registry option is popular with some administrators. Neil From magneticlemur at gmail.com Wed Oct 12 20:10:24 2005 From: magneticlemur at gmail.com (magneticlemur at gmail.com) Date: 12 Oct 2005 17:10:24 -0700 Subject: installer for amd64 build of python? Message-ID: <1129162224.131305.269060@g49g2000cwa.googlegroups.com> Hi, Does anyone know of an available downloader for an amd64 bit build of (a modern) python? I've done my due diligence search of python docs and mailing archives, and I'm somewhat mystified by the lack of info on this topic. I'm embedding python in a native 64 bit application so python32 using WOW64 is not an option for me. Alternatively, does anyone have experience of using the visual studio files in the PCBuild directory under amd64? Any pointers appreciated, Cheers Mike ------------------------------- Dr Mike Steel Senior Scientist RSoft Design Group www.rsoftdesign.com From apardon at forel.vub.ac.be Thu Oct 20 06:13:15 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 20 Oct 2005 10:13:15 GMT Subject: Would there be support for a more general cmp/__cmp__ References: Message-ID: Op 2005-10-20, Mikael Olofsson schreef : > Antoon Pardon wrote: >> Op 2005-10-20, Duncan Booth schreef : >> >>>Antoon Pardon wrote: >>> >>> >>>>The problem now is that the cmp protocol has no way to >>>>indicate two objects are incomparable, they are not >>>>equal but neither is one less or greater than the other. >>> >>>If that is the case then you implement __eq__ and __ne__ to return >>>True/False and make cmp throw an exception. I don't see any need to extend >>>the cmp protocol. >> >> >> That is not sufficient. There are domains where an order exists, but not >> a total order. So for some couples of elements it is possible to say >> one is less than the other, but not for all such couples. >> >> Your solution wouldn't allow for such a case. > > Wouldn't the full power of rich comparisons be enough? See section 3.3.1 > in Python Reference Manual: > > http://www.python.org/doc/2.4.2/ref/customization.html > > See methods __lt__, __le__, __eq__, __ne__, __gt__, __ge__. Sure, but it would also be rather cumbersome. It is not uncommon that a general compare function which could give you one of four results: one_less_two, one_equal_two, one_greater_two or one_unequal_two, wouldn't differ much from each of those six comparison methods. So you either write about six times the same code or you have to do something like the following: class partial_order: def __compare(self, other): ... return ... def __lt__(self, other): return self.__compare(other) == one_less_two def __le__(self, other): return self.__compare(other) in [one_less_two, one_equal_two] def __eq__(self, other): return self.__compare(other) == one_equal_two def __ne__(self, other): return self.__compare(other) == one_unequal_two def __gt__(self, other): return self.__compare(other) == one_greater_two def __ge__(self, other): return self.__compare(other) in [one_greater_two, one_equale_two] And then you still wouldn't get a usefull result from: delta = cmp(e1, e2) -- Antoon Pardon From steve at holdenweb.com Tue Oct 25 08:39:23 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 25 Oct 2005 13:39:23 +0100 Subject: PDO and database abstraction In-Reply-To: <435E2313.3090504@ghaering.de> References: <1130240852.794081.158320@g47g2000cwa.googlegroups.com> <435E2313.3090504@ghaering.de> Message-ID: Gerhard H?ring wrote: > Luiz Geron wrote: > >>Hi all, >>I'm testing the PDO wrapper to database modules [1] and I'm wondering >>how few things like this there are around. > > > Actually there are several Object-Relation Mappers (ORM) for Python, and > also a few other attempts to provide a more convenient layer on top of > DB-API modules. > > This wiki page has links: > http://wiki.python.org/moin/HigherLevelDatabaseProgramming > > >>My problem, actually, is the paramstyle of modules. > > > That problem exactly what these solutions try to solve, this and > multiple SQL dialects and handling types like date etc. for multiple > backends. > > >>I want to use kinterbasdb in the same code I use >>cx_oracle, for example, but paramstyle changes from one to other, than >>I searched for things like this and found nothing really usefull. The >>problem with PDO is that it was so dificult to find, since a few people >>seems to use it, and I haven't yet figured how to change the paramstyle >>on it, so I want to ask: Do you use a thing like this that you would >>recommend to me? > > > I always wrote my own thin layer on top of DB-API modules and used it to > implement a *specific* database interface for my applications. This > would then have one or more database backends. Actually never more than > two so far. > [ORM stuff ...] Another way is to actually parameterise your queries for the paramstyle according to which packend module you are using. For example, in a current development I have queries that are generated like this: sql = ("SELECT %s FROM %s WHERE %s=%s" % (",".join(f[1] for f in self.FIELDS), table, keyfield, db.pmark)) The "db" module imports one or other of a number of back-end modules, and sets "pmark" to the appropriate parameter marker ("%s" or "?" are the ones I have used: positionals would be a little trickier, now I think of it). Of course you still have to be careful of SQL syntax variations and other backend differences (the usual one being "find the primary key value of the last-inserted row on this connection/cursor"). regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From my_email_is_posted_on_my_website at munged.invalid Wed Oct 12 18:42:31 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 12 Oct 2005 22:42:31 GMT Subject: Jargons of Info Tech industry References: <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> <86zmpjkml4.fsf@bhuda.mired.org> Message-ID: On Sun, 09 Oct 2005 06:32:07 -0400, Mike Meyer wrote or quoted : >Formatted spam can include pictures of words. That's a common spam >tactic - send a multipart/alternative with a text part that look like >a letter from aunt jane - and mention that you're sending a >picture. The picture part is basically a jpeg of a flyer for the spam >companies product. Such a jpg would have a lot more sharp edges than a usual photo. Also you tend to have areas of just two colours. Some edge detecting software might have a go at it. However, my rule of thumb is I would not accept photos from the general public, only from a subset of my correspondendents. That makes a photo a strong spam indicator. Then there are small corporate logos, which are innocuous. Spamnix does not have such a filtering rule. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From vdavidster at gmail.com Wed Oct 19 23:10:43 2005 From: vdavidster at gmail.com (David Veerasingam) Date: 19 Oct 2005 20:10:43 -0700 Subject: Some more odd behaviour from the Regexp library Message-ID: <1129777843.892280.302490@g44g2000cwa.googlegroups.com> Can anyone explain why it won't give me my captured group? In [1]: a = 'exit: gkdfjgfjdfsgdjglkghdfgkd' In [2]: import re In [3]: b = re.search(r'exit: (.*?)', a) In [4]: b.group(0) Out[4]: 'exit: ' In [5]: b.group(1) Out[5]: '' In [6]: b.group(2) IndexError: no such group From dcrespo at gmail.com Fri Oct 28 08:23:00 2005 From: dcrespo at gmail.com (dcrespo) Date: 28 Oct 2005 05:23:00 -0700 Subject: How to replace all None values with the string "Null" in a dictionary In-Reply-To: <4361e8f5$0$32420$636a15ce@news.free.fr> References: <1130444785.353905.85380@g47g2000cwa.googlegroups.com> <4361e8f5$0$32420$636a15ce@news.free.fr> Message-ID: <1130502180.688390.207960@g44g2000cwa.googlegroups.com> > I think it would be time for you to read the Fine Manual... hi, thanks for your answer... I really did it the same way you suggested, but I forgot to tell you that I wanted to get a better way for doing it. By the way, knowing your wisdom, what do I have to install to get the following code work (Win XP, Python 2.4.2) --------------------------------------------- from OpenSSL import SSL import config KEY_FILE = config.SSL_KEY_FILE CERT_FILE = config.SSL_CERT_FILE -------------------------------------------- I've been looking for OpenSSL for python. I found pyOpenSSL, but it requires the OpenSSL library, which I only found on http://www.openssl.org/, but don't know how to install. Other thing is the "config" module... I'm lost. Someone knows? :-S My main purpose is to enable XML-RPC SERVER over an SSL connection. Thanks From davids at webmaster.com Tue Oct 18 20:36:18 2005 From: davids at webmaster.com (David Schwartz) Date: Tue, 18 Oct 2005 17:36:18 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <867jcbzdw9.fsf@bhuda.mired.org> Message-ID: "Aragorn" wrote in message news:Rgg5f.26668$Z96.897128 at phobos.telenet-ops.be... >>>>> Wrong. The only obligation Microsoft has is to their shareholders. >>>> If you genuinely believe that, you are a psychopath. > A psychopath is someone who lacks ethics and/or the ability to respect > his fellow human being. They are quite often narcissistic and perverse > individuals. They make good dictators and successful businessmen. You have provided an excellent refutation. A psychopath would say that Microsoft's executives only obligations are to themselves. A psychopath would not consider obligations to fellow human beings important. Believe it or not, from the point of view of a Microsoft executive, shareholders are fellow human beings. DS From wobsta at gmail.com Wed Oct 5 06:51:36 2005 From: wobsta at gmail.com (wobsta) Date: 5 Oct 2005 03:51:36 -0700 Subject: python plotting with greek symbols within labels recommendations? References: <1128469278.622461.249550@g49g2000cwa.googlegroups.com> Message-ID: <1128509496.658612.279390@o13g2000cwo.googlegroups.com> Hi, michael.s.gilbert at gmail.com wrote: > this message is geared toward those of you in the scientific community. > i'm looking for a python plotting library that can support rendering > greek symbols and other various characters on plot axes labels, etc. I > would prefer something that adheres to tex formatting (as implemented > in latex, matlab, etc and has the form $\alpha$ to represent the greek > character alpha for example). You may want to have a look at PyX (pyx.sourceforge.net), which features a seamless TeX integration for all typesetting tasks and thus allows you to use TeX syntax all over the place. Andr? From james at colannino.org Mon Oct 24 00:42:42 2005 From: james at colannino.org (James Colannino) Date: Sun, 23 Oct 2005 21:42:42 -0700 Subject: output from external commands Message-ID: <435C6642.8020504@colannino.org> Hey everyone. First off, I'm new to the list. I had had a little bit of experience with Perl before discovering Python. The more Python I learn, the more I love it :) I just have a quick question to ask. I know that this is probably a simple question, but I've been googling around, and partly because I'm not sure exactly what to search for, I've been unsuccessful at finding an answer. What I'd like to do is be able to take the output of an external command and assign it as an array of strings. So, for example, in Perl I could do something like: @files = `ls`; So I guess I'm looking for something similiar to the backticks in Perl. Forgive me if I've asked something that's a bit basic for this list. Any help would be greatly appreciated :) Thanks very much in advance. James -- My blog: http://www.crazydrclaw.com/ My homepage: http://james.colannino.org/ From theller at python.net Thu Oct 20 11:09:36 2005 From: theller at python.net (Thomas Heller) Date: Thu, 20 Oct 2005 17:09:36 +0200 Subject: __getattr__, __setattr__ Message-ID: Just wondering about this behaviour, why is it this way? Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> object.__setattr__ >>> object.__getattr__ Traceback (most recent call last): File "", line 1, in ? AttributeError: type object 'object' has no attribute '__getattr__' >>> Thanks, Thomas From grante at visi.com Fri Oct 21 15:04:16 2005 From: grante at visi.com (Grant Edwards) Date: Fri, 21 Oct 2005 19:04:16 -0000 Subject: need some advice on x y plot References: <1129823043.104864.73750@f14g2000cwb.googlegroups.com> <11lfgebn85liq1b@corp.supernews.com> <1129825379.218308.242010@g47g2000cwa.googlegroups.com> <4357d998$1_2@newspeer2.tds.net> <1129831950.926154.196420@g47g2000cwa.googlegroups.com> <1129912485.866312.298390@g47g2000cwa.googlegroups.com> <4359244e$1_2@newspeer2.tds.net> <1129916685.172187.224140@o13g2000cwo.googlegroups.com> Message-ID: <11lietgq0m60f66@corp.supernews.com> On 2005-10-21, nephish at xit.net wrote: > the time is DateTime.DateTime object from a mySQLdb query. the > value is a number anywhere between 0 and 15. the datetime is > formatted like 2005-10-20 08:40:34 > > i could strip it and make a timestamp out of it. but reading > the number of seconds since january of 1970 doesn't make a > neat chart. Pass the data values as floating point numbers (I typically use seconds since the test run started). If you the x tics to be something else, then change them. It's pretty simple to label the x-axis using normal date/time notation. > any suggestions? > > oh, and can you output from Gnuplot to a png or jpeg or > something like that. Is that a question? If so, the answer is yes. > the Gnuplot documentation says that it can make a bitmap png > but i dont know how to do that with the python wrapper. the > docs for this are a little cryptic. still a newbie here. if > you know a good tutorial on this, i would really appreciate > the link. Once you start doing "odd" stuff (e.g. custom labels for the x-axis, output other than X11 or postscript), it's usually simplest to just send normal gnuplot commands. ------------------------------8<------------------------------ import Gnuplot,time,sys,math def pause(): sys.stdout.write("Press enter to continue: ") sys.stdin.readline() def fgrid(start,stop,count): for i in xrange(count): yield start + ((stop-start)*i)/count start = time.time() xdata = [x for x in fgrid(0,600.0,10)] # two minutes worth ydata = [math.sin(x/100.0) for x in xdata] data = Gnuplot.Data(xdata,ydata,with='linespoints') gp = Gnuplot.Gnuplot() gp.title('Data starting at %s' % time.ctime(start+xdata[0])) # x axis will use default tics (seconds since start of run) gp.plot(data) pause() # now let's change x tics to time of day in HH:MM:SS with # ticmarks at 120 second intervals ti = 120.0 startTic = int((start+xdata[0])//ti * ti) endTic = int((start+xdata[-1])//ti * ti) ti = int(ti) ticx = range(startTic,endTic+ti,ti) tics = [(x, time.strftime('%H:%M:%S',time.localtime(x))) for x in ticx] ticstrings = ['"%s" %f' % (t[1],t[0]-start) for t in tics] gp('set xtics (%s)' % ','.join(ticstrings)) gp.plot(data) pause() outfile = 'foo.png' gp('set term png') gp('set out "%s"' % outfile) gp.plot(data) ------------------------------8<------------------------------ -- Grant Edwards grante Yow! ... The waitress's at UNIFORM sheds TARTAR SAUCE visi.com like an 8" by 10" GLOSSY... From my_email_is_posted_on_my_website at munged.invalid Thu Oct 13 01:59:46 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Thu, 13 Oct 2005 05:59:46 GMT Subject: Jargons of Info Tech industry References: <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <868xx3m2ve.fsf@bhuda.mired.org> <86irw6l1mc.fsf@bhuda.mired.org> <86r7aqugmk.fsf@bhuda.mired.org> Message-ID: On Thu, 13 Oct 2005 01:32:03 -0400, Mike Meyer wrote or quoted : >That won't prevent phishing, that will just raise the threshhold a >little. The first hurdle you have to get past is that most mail agents >want to show a human name, not some random collection of symbols that >map to a unique address. Even if you do that, most readers aren't >going to pay attention to said random collection of symbols. Given >that, there are *lots* of tricks that can be used to disguise the >signed name, most of which phishers are already using. How many people >do you think will really notice that mail from "John Bath, PayPal >Customer Service Representative" (john.barth at paypa1.com) isn't really >from paypal? I think it better than you imagine. First of all Mr. Phish will come in as a new communicant begging an audience. That is your first big clue. PayPal is already allowed in. Next if Thawte issues certs, they won't allow Phish names such as Paypol.com just as now for other certs. Mr. Phish is coming in on a different account. Next Mr. Phish had to present his passport etc when he got his Thawte ID. Now Interpol has a much better handle on putting him in jail. He can't repudiate his phishing attempt. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From codecraig at gmail.com Wed Oct 12 16:06:00 2005 From: codecraig at gmail.com (Java and Swing) Date: 12 Oct 2005 13:06:00 -0700 Subject: Pass a tuple (or list) to a C wrapper function Message-ID: <1129147560.524316.281110@g43g2000cwa.googlegroups.com> I have a C function which takes an array of long values.. I understand that I can pass a tuple to a C wrapper function and in the C wrapper function have.. int ok = PyArg_ParseTuple(args, "s(ll)", &a, &b, &c); ..that's great if my tuple only contained two longs..but what if it contained 50 would I have to do.. int ok = PyArg_ParseTuple(args, "s(llllllllllllllllll....ll)", &a, &b, &c, &d...) ?? how can I handle this? From mscottschilling at hotmail.com Thu Oct 27 01:18:59 2005 From: mscottschilling at hotmail.com (Mike Schilling) Date: Thu, 27 Oct 2005 05:18:59 GMT Subject: Microsoft Hatred FAQ References: <3s6l8mFmj3fjU1@individual.net> <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> Message-ID: <7rZ7f.6819$dO2.5775@newssvr29.news.prodigy.net> "David Schwartz" wrote in message news:djpf90$pbm$1 at nntp.webmaster.com... > > There is no different to Microsoft beween a bare computer and one > preloaded with Linux or FreeBSD. One can quickly be converted to other > with minimal cost of effort. In the market, bare PCs really do compete > with Windows PCs. There's a huge difference to the non-techy consumer. One of the buggest reasons Linux has had a reputation of being harder to use than Windows was the fact that Linux had to be installed, while Windows just booted up. From http Wed Oct 5 08:31:28 2005 From: http (Paul Rubin) Date: 05 Oct 2005 05:31:28 -0700 Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> <434245F5.6060500@REMOVEMEcyber.com.au> <7xr7b14lk0.fsf@ruckus.brouhaha.com> <7xu0fx9l7y.fsf@ruckus.brouhaha.com> <7xwtks2tnw.fsf@ruckus.brouhaha.com> Message-ID: <7xek70xhzz.fsf@ruckus.brouhaha.com> Brian Quinlan writes: > Aren't you looking for some of compile-time checking that ensures that > only declared variables are actually used? If so, how does global help? You'd have to declare any variable global, or declare it local, or it could be a function name (defined with def) or a function arg (in the function scope), or maybe you could also declare things like loop indices. If it wasn't one of the above, the compiler would flag it. > >>Your making this feature "optional" contradicts the subject of this > >> thread i.e. declarations being necessary. > > They're necessary if you enable the option. > > OK. Would it work on a per-module basis or globally? Whatever perl does. I think that means per-module where the option is given as "use strict" inside the module. > > def do_add(x->str, y->str): > > return '%s://%s' % (x, y) > > def do_something(node->Node): > > if node.namespace == XML_NAMESPACE: > > return do_add('http://', node.namespace) > > elif node.namespace == ... > > Wouldn't an error be generated because XML_NAMESPACE is not declared? XML_NAMESPACE would be declared in the xml.dom module and the type info would carry over through the import. > And I notice that you are not doing any checking that "namespace" is a > valid attribute of the node object. Aren't the typos class of error > that you are looking to catch just as likely to occur for attributes > as variables? The node object is declared to be a Node instance and if the Node class definition declares a fixed list of slots, then the compiler would know the slot names and check them. If the Node class doesn't declare fixed slots, then they're dynamic and are looked up at runtime in the usual way. From dellaq at ml1.net Fri Oct 21 21:26:00 2005 From: dellaq at ml1.net (dellaq at ml1.net) Date: 21 Oct 2005 18:26:00 -0700 Subject: How to add one month to datetime? References: <43595b53.606924000@news.oz.net> Message-ID: <1129944360.034151.228030@o13g2000cwo.googlegroups.com> Bengt Richter wrote: > The OP will still have to decide whether he likes the semantics ;-) > E.g., what does he really want as the date for "one month" after January 30 ? > > Regards, > Bengt Richter When dealing with bonds a common convention is to return the same day in the succeeding month if it is valid otherwise return the last day of that month. However, if the original date is the last day of the month, then the last day of the succeeding month should always be returned. This snippet adds an arbitrary number of months (positive or negative) according to that convention. OneDay = datetime.timedelta(days=1) def addMonth(date, n=1): # add n+1 months to date then subtract 1 day # to get eom, last day of target month q,r = divmod(date.month+n, 12) eom = datetime.date(date.year+q, r+1, 1) - OneDay if date.month != (date+OneDay).month or date.day >= eom.day: return eom return eom.replace(day=date.day) Regards, John Dell'Aquila From exarkun at divmod.com Tue Oct 18 18:37:48 2005 From: exarkun at divmod.com (Jp Calderone) Date: Tue, 18 Oct 2005 18:37:48 -0400 Subject: write a loopin one line; process file paths In-Reply-To: <1129672592.328278.41490@g14g2000cwa.googlegroups.com> Message-ID: <20051018223748.27584.778467958.divmod.quotient.775@ohm> On 18 Oct 2005 14:56:32 -0700, Xah Lee wrote: >is there a way to condense the following loop into one line? There is. exec('696d706f72742072652c206f732e706174680a0a696d6750617468733d5b75272f55736572732f742f7765622f506572696f6469635f646f736167655f6469722f6c616e63692f74342f6f682f4453434e323035396d2d732e6a7067272c0a75272f55736572732f742f7765622f506572696f6469635f646f736167655f6469722f6c616e63692f74342f6f682f4453434e323036326d2d732e6a7067272c0a75272f55736572732f742f7765622f506572696f6469635f646f736167655f6469722f6c616e63692f74342f6f682f4453434e323039376d2d732e6a7067272c0a75272f55736572732f742f7765622f506572696f6469635f646f736167655f6469722f6c616e63692f74342f6f682f4453434e323039396d2d732e6a7067272c0a75272f55736572732f742f7765622f49636f6e735f6469722f69636f6e5f73756d2e676966275d0a0a23206368616e67652074686520696d616765207061746820746f207468652066756c6c2073697a656420696d6167652c206966206974206578697374730a2320746861742069732c20696620696d61676520656e647320696e202d732e6a70672c2066696e64206f6e6520776974686f75742074686520272d73272e0a74656d703d696d6750617468735b3a5d0a696d6750617468733d5b5d0a666f72206d795061746820696e2074656d703a0a20202020703d6d79506174680a20202020286469724e616d652c2066696c654e616d6529203d206f732e706174682e73706c6974286d7950617468290a202020202866696c65426173654e616d652c2066696c65457874656e73696f6e293d6f732e706174682e73706c69746578742866696c654e616d65290a2020202069662872652e7365617263682872272d7324272c66696c65426173654e616d652c72652e5529293a0a202020202020202070323d6f732e706174682e6a6f696e286469724e616d652c66696c65426173654e616d655b303a2d325d29202b2066696c65457874656e73696f6e0a20202020202020206966206f732e706174682e657869737473287032293a20703d70320a20202020696d6750617468732e617070656e642870290a0a74656d703d5b5d0a7072696e7420696d6750617468730a'.decode('hex')) Jp From iainking at gmail.com Thu Oct 27 08:46:45 2005 From: iainking at gmail.com (Iain King) Date: 27 Oct 2005 05:46:45 -0700 Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: <1130417205.892409.230580@g14g2000cwa.googlegroups.com> David Schwartz wrote: > Roedy Green wrote: > > > On Sun, 16 Oct 2005 16:31:41 GMT, Roedy Green > > wrote, quoted or > > indirectly quoted someone who said : > > >> I used to be a retailer of custom computers. MS used a dirty trick > >> to compete with IBM's OS/2. They said to me as a retailer. You must > >> buy a copy of our OS for EVERY machine you sell. The alternative is > >> to pay full retail for the OSes. > > > Through intimidation, MS managed to control the entire retail computer > > market in Vancouver BC to the extent you could not buy even the most > > stripped down computer without having to buy a copy of Windows with > > it, whether you wanted it or not. > > > > You might not want it because you bought OS/2. > > > > You might not want it because you already owned Windows from your > > older machine you were upgrading. > > > > You might not want it because somebody stole your machine and they did > > not steal all your software masters. > > Tell me, can you buy a new car without seats? Guess what, you have to > buy those seats whether you want them or not. > > Try to start a business selling competing seats for a new car. Your > seats may be cheaper, better, but how can you possibly compete when people > have to pay for factory car seats whether they want them or not? > > The real reason PCs were not available without Windows was because not > enough people wanted them that way to justify setting up a business to > provide them that way, and Microsoft was not going to let a business > parasitically use Windows to build a business that touted the advantages of > competing products. (Just as Burger King corporate will not you sell Big > Macs in the same store in which you sell Whoppers.) > > DS Don't you see how your metaphor doesn't work? It would only be fitting if Microsoft OWNED the outlet. Places which sell Whoppers are Burger King franchises, so of course they aren't going to sell Big Mac's. PC hardware stores do not belong to microsoft. There just isn't any correlation. Iain From wolfgang.keller.nospam at gmx.de Mon Oct 17 06:01:14 2005 From: wolfgang.keller.nospam at gmx.de (Wolfgang Keller) Date: Mon, 17 Oct 2005 12:01:14 +0200 Subject: UI toolkits for Python References: Message-ID: > With OS X compatibility you tend to come across with the > fact that many "OS X compatible" things are actually X11 > things. X11 certainly looks different from Aqua (the native > interface). But imho, Gnome _does_ "look and feel" quite Mac-ish in the sense that its ergonomics has certain things in common with the Mac, even more with the old MacOS classic than with the pretty "gadget-ish" Aqua interface. For example, with its hierarchical multi-column listview, Nautilus "looks" and "feels" perfectly like the old MacOS classic Finder, something that lots of long-time Mac users miss a lot on MacOS X. Another example is MDI (or "windows inside windows"), which is a no-no on the Mac (and afaik not supported by GTK), or multi-pains (sic!). As a long-time Mac user (since system 6.0.x), I did like a lot the GUI of WingIDE (which uses GTK) because it allows me to switch from a multi-pain layout to a multi-window layout. > GTK is an example of this. There is an Aqua version of > GTK, but it seems to be rather outdated. There's a new effort for a "aqua-native" implementation: http://micke.hallendal.net/archives/2005/10/gtk-macosx.html > The newer versions > run on X11 but installing them may be just laborious or > then plain pain depending on your luck. And you still need > the X11 installed. One advantage of an X11 application is, obviously, the possibility to use it from a different computer without the requirement to install it there. "Hey, my Mac can do that for free, while your Windows needs an expensive "Server" license.!" >;-> Shhh, don't tell them about Cygwin... > So, if you are looking for something that looks like Mac > and works like Mac, do not touch anything with X11. As a long-time Mac user, I somewhat disagree, see above. :-) To me, a GTK application with a really well-thought ergonomic user interface is a lot more Mac-ish than a pile of "aqua-native" visual gadgetry. Sincerely, Wolfgang Keller From mcfletch at rogers.com Mon Oct 17 12:40:21 2005 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Mon, 17 Oct 2005 12:40:21 -0400 Subject: graphic memory & animation In-Reply-To: <009d01c5d2f0$3c634590$0a01a8c0@NEWLAT> References: <009d01c5d2f0$3c634590$0a01a8c0@NEWLAT> Message-ID: <4353D3F5.8040509@rogers.com> Peres wrote: > Thanks a lot for your answer, Fredrik, > Slow means more than 20ms to erase the screen. After double buffering > it improved a lot , of course (16 ms) but I'll need a faster speed. > I program 2D animated sequences on a PC. Do you think OpenGL is the > correct direction to take? If so is it easy to interface with Python > (it seems PyOpenGL is not freeware...) PyOpenGL has a BSD-style license, that's about as 'free' as one can get in the freeware sense. Just a note, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From scott.daniels at acm.org Thu Oct 13 11:14:29 2005 From: scott.daniels at acm.org (Scott David Daniels) Date: Thu, 13 Oct 2005 08:14:29 -0700 Subject: Python's garbage collection was Re: Python reliability In-Reply-To: <7xvf0168nq.fsf@ruckus.brouhaha.com> References: <3r6i0uFi3qb8U2@uni-berlin.de> <7xfyr5kfgm.fsf@ruckus.brouhaha.com> <3r6osdFhsfjgU1@uni-berlin.de> <7xvf0168nq.fsf@ruckus.brouhaha.com> Message-ID: <434e7967$1@nntp0.pdx.net> Paul Rubin wrote: > "Diez B. Roggisch" writes: (about tag bits) >>... Basically I think that trying to come up with all sorts of >> optimizations for rather marginal problems (number crunching >> should be - if a python domain at all - done using Numarray) > I don't think it's necessarily marginal. Tagged ints can be kept in > registers, which means that even the simplest code that does stuff > with small integers becomes a lot more streamlined, easing the load on > both the Python GC and the cpu's memory cache.... But the cost on modern computers is more problematic to characterize. Current speeds are due to deep pipelines, and a conditional in the INCREF code would blow a pipeline. On machines with a conditional increment instruction (and a C (or whatever) compiler clever enough to use it, saving the write saves dirty cache in the CPU, but most of today's CPU/compiler combos will flush the pipeline, killing a number of pending instructions. > Right now with the bytecode interpreter, it probably doesn't matter, > but with Pypy generating native machine code, this kind of thing can > make a real difference. You are right that Pypy is the place to experiment with all of this. That project holds a lot of promise for answering questions that seem to otherwise degenerate into "Jane, you ignorant slut" (for non-US readers, this is a reference to an old "Saturday Night Live" debate skit where the debate always degenerated into name-calling). --Scott David Daniels scott.daniels at acm.org From rune.strand at gmail.com Wed Oct 12 05:15:43 2005 From: rune.strand at gmail.com (Rune Strand) Date: 12 Oct 2005 02:15:43 -0700 Subject: Adding a __filename__ predefined attribute to 2.5? In-Reply-To: <3r3u8kFhhsqmU1@uni-berlin.de> References: <1129098667.336115.303060@g47g2000cwa.googlegroups.com> <1129103007.870187.101790@g44g2000cwa.googlegroups.com> <3r3u8kFhhsqmU1@uni-berlin.de> Message-ID: <1129108543.596435.200600@g47g2000cwa.googlegroups.com> Excuse me, do you suffer from a bad hair-day? I didn't say it is platform independant. It's ok for my use on Linux and Windows. If you cannot imagine any other usecase for a __filename__ attribute, that's your problem, not mine. From pkilambi at gmail.com Fri Oct 14 13:31:20 2005 From: pkilambi at gmail.com (pkilambi at gmail.com) Date: 14 Oct 2005 10:31:20 -0700 Subject: Searching files in directories Message-ID: <1129311080.579292.112990@g47g2000cwa.googlegroups.com> can anyone help me with this... I want to search for a list for files in a given directory and if it exists copy them to destination directory so what i am looking for is : file = 'file1.txt' source_directory = '/tmp/source/' destination_directory = '/tmp/destination/' so If the file exists in source_directory cp that file to the destination_directory.. hope I am clear From cowie.rob at gmail.com Mon Oct 3 12:17:52 2005 From: cowie.rob at gmail.com (Rob Cowie) Date: 3 Oct 2005 09:17:52 -0700 Subject: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please! In-Reply-To: References: Message-ID: <1128356272.091514.63180@g44g2000cwa.googlegroups.com> Perhaps with the time saved by using Python instead of C# or some such, you could help to improve adodbapi.py, ensuring support for the next version of MS SQLServer, although that might be of little help in the short term. Just a thought. Also, have a gander at http://www.object-craft.com.au/projects/mssql/ I have no knowledge of it, but it may prove useful to you. From malte.clasen at arcor.de Sat Oct 15 06:42:57 2005 From: malte.clasen at arcor.de (Malte Clasen) Date: Sat, 15 Oct 2005 12:42:57 +0200 Subject: UI toolkits for Python In-Reply-To: <3ras6oFit2djU1@individual.net> References: <7xslv56ud1.fsf@ruckus.brouhaha.com> <3ras6oFit2djU1@individual.net> Message-ID: <4350dd34$0$6774$9b4e6d93@newsread4.arcor-online.net> Claudio Grondi wrote: > What is that complex, that it can't be solved using an Internet Browser as a > GUI? Nothing, but session management isn't trivial with http interfaces. You have to deal with the back button of the browsers, bookmarks to pages that result from posted forms, users leaving the application without notice, etc.. And if you want to implement dialogs like the Photoshop image resizing with automatic calculation of some widget data based on other widgets (e.g. interlocked width and height), you have to rely on JavaScript which isn't as platform independent as it should be and sometimes deactivated due to security issues. But if that doesn't bother you, you might want to have a look at http://qooxdoo.sourceforge.net/ , "an advanced open-source javascript based toolkit." Malte From pmartin at snakecard.com Fri Oct 21 19:49:16 2005 From: pmartin at snakecard.com (Philippe C. Martin) Date: Fri, 21 Oct 2005 23:49:16 GMT Subject: how to modify text in html form from python References: <0Ra6f.5050$q%.616@newssvr12.news.prodigy.com> <86d5lyu0j8.fsf@bhuda.mired.org> <%Tb6f.5062$q%.3600@newssvr12.news.prodigy.com> <864q7atxcv.fsf@bhuda.mired.org> <86vezqscfq.fsf@bhuda.mired.org> Message-ID: <08f6f.6361$7h7.3176@newssvr21.news.prodigy.com> Mike Meyer wrote: > > I don't know much about plugins. I believe they get started when the > page loads, which gives you a chance to do the authentication when you > want it done. Well not in this case actually: the user triggers the plugin which in turn open the url, so the connection is "owned" by the plugin > > That won't work very well. HTML goes to the client to display. The > server can put data in hidden form elements that code running on the > client side can get to - and change - via the document object model > (DOM). However, the only way to send the changed data back to the > server is to get the client to submit the form. You can automate that, > but the results will be disconcerting to the user: they load a page, > and it reloads multiple times as the plugin exchanges data with the > server. > Here again, I'm not dying for any page data to be visible: cannot the cgi script and the plugin do their business before that ? > > The problem with this is that the apache<->browser connection isn't > "a" connection, it's a series of HTTP request/repsonse > pairs. Originally, this implied tearing down and setting up a TCP > connection for every request. Modern software will leave the link open > and reuse it - but modern software also tends to have multiple > connetions open, so it can fetch images and other embedded objects in > parallel. > I'm lost here, better do some more reading > You can make this work, but doing it like that requires making > multiple HTTP requests via the browser, which will be > disconcerting. I'd recommend taking the browser out of the loop. Have > the plugin talk directly to the server to do the > authentication. That's what the latest web buzzword (AJAX) does: > client-side software makes independent requests of the server (or > *any* server) to get data, and possibly updates the document the > browser is viewing as a result of that. > Here I think it's OK as the plugin can "talk" to server prior to the browser showing anything. > So here's a scenario: the first cgi script gets info from the smart > card that puts it in a hidden form element and sends the page to the > browser. The plugin - started when the page loads - uses the DOM to > get that data, then makes an *independent* HTTP request to the server, > thus passing whatever it generated from the data in the form field to > a second cgi script. This happens several times, then the plugin > changes the HTML form to put whatever the cgi script generated into > the form, so that when the user finally submits the form, the third > cgi script - the one that handles the submitted form - sees the data > from the second script. > > Actually, the exchanges between the plugin and the server don't need > to be HTTP requests. If you've got this working over some other TCP > protocol, there's no reason you can't keep doing it that way. > Maybe that's my clue: can a cgi script, once triggered by a (let's say) POST request, use back and forth file transfer with the client ? through the _existing_ connection. > A word of warning: authentication protocols are fragile; they tend to > stop being resistant to attacks after even relatively minor changes, > so you want to be very carefull about changing the protocol. Web-based > things are very open. You can't really do much to prevent the client > end from doing *whatever they want* with the HTML you send them, or > you generate for them on the fly. This also has serious security > implications. Think carefully about what happens when the user pulls > one of your forms out of the browser history, or bookmarks a > page. Then make sure you get a thorough audit of the resulting > system/protocol done by people who know what they're doing. > Even if the data when seen, there would not be any security breach as the cards have the keys + algo to understand the data. I realy just need of few tens of bytes to go back and forth (I'm frustrated ;-) Thanks Philippe > Message-ID: wrote in message news:1129823043.104864.73750 at f14g2000cwb.googlegroups.com... If the x-axis is time, gnuplot will plot it correctly but it will connect *all* the datapoints and scale the x-axis so that everything will fit on the graph. Is it the autoscaling or conneting that what you think is wrong? Getting a fixed-size x-axis is a configuration option. I think one simply passes a range to the axis one wants to scale. I cannot remember exactly, how though. > one of you guys know a charting app that will do this ? or is there > some other way i could do it? RRDTool is excellent at storing & plotting time series data. It will not "connect" missing data points but has the limitation that the sample rate must be known when creating the database and generally adhered to. Missed samples are NAN's. You have to "tell" gnuplot what to plot and what not to plot. I think you can add more than one data series to the same plot, providing the "gap" where data is unavaliable. Else you have to "pad" it with zeros or some other appropriate null value. From jepler at unpythonic.net Thu Oct 20 20:48:37 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Thu, 20 Oct 2005 19:48:37 -0500 Subject: os.makedirs should not succeed when the directory already exists (was Re: Python Doc Error: os.makedirs) In-Reply-To: <1129739176.881283.8910@f14g2000cwb.googlegroups.com> References: <1129685449.372717.56900@z14g2000cwz.googlegroups.com> <1129739176.881283.8910@f14g2000cwb.googlegroups.com> Message-ID: <20051021004836.GB16725@unpythonic.net> On Wed, Oct 19, 2005 at 09:26:16AM -0700, Dr. Who wrote: > The fact that the directory already exists is irrelevant to the function...it > still failed to create the directory. That's not true. Imagine that os.makedirs() is used inside tempfile.mkdtemp() (I looked, and it isn't) and the proposed behavior (do not raise an exception when the directory already exists) is adopted. In this case, there is a race condition between you and the attacker who guesses the next directory you will attempt to make. If he calls mkdir() before you do, then your os.makedirs() returns successfully (instead of raising an exception) and you place your files into a location that is under the control of someone else. If the attacker then makes the directory setuid himself, that files created in the directory are owned by him. Now, he can view and change the contents of these files. This can lead to a local priviledge escalation. Errors should never pass silently. Unless explicitly silenced. -- from the Zen of Python ('import this') ... and wanting them to do so may introduce a security bug in your software. If you know more about your users and their environments than I do (for instance, that none of them will ever use a multi-user computer system) maybe you should choose to wrap os.makedirs with something that silences EEXIST. But I'm glad Python does the secure thing and treats EEXIST as a failure by default. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From ptb at oboe.it.uc3m.es Wed Oct 26 20:28:46 2005 From: ptb at oboe.it.uc3m.es (Peter T. Breuer) Date: Thu, 27 Oct 2005 02:28:46 +0200 Subject: Microsoft Hatred FAQ References: <3s6l8mFmj3fjU1@individual.net> <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> Message-ID: In comp.os.linux.misc Roedy Green wrote: > 3. Maytag makes the machines. In the computer instance, we at CMP > custom build the computers. Microsoft have no business telling me what > to do when they supplied only one component. I could not even sell a > BARE computer. I'm a bit curious about this. If I were a business person, I would simply have created two busineses (two accounts, etc.). One business sells only machines with MS on and pays the MS tax on all its machines. One business sells only machines without MS on and pays the MS tax on none of its machines. What's up with that? Peter From gandalf at designaproduct.biz Tue Oct 11 10:54:19 2005 From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy) Date: Tue, 11 Oct 2005 16:54:19 +0200 Subject: Send password over TCP connection In-Reply-To: References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> <1128979760.251637.316480@o13g2000cwo.googlegroups.com> Message-ID: <434BD21B.3000407@designaproduct.biz> >If you're saying that people have no choice but to trust that their >passwords, stored in the clear on the server of some idiot who didn't >know better, are safe from casual administrator observation and safe >from hackers stealing the password file, then you shouldn't be allowed >anywhere near a supposedly secure system... > > Of course I would not say this. :-) >If you're just saying that one has to trust that the server you are >talking to at this instant in time is really the one you thought it was, >then that's an entirely different issue and I agree. > > Not just this. "one has to trust that the server you are talking to at this instant in time is really the one you thought it was" - this is just authentication. I'm saying that even if the authentication is secure and the server is really the one that you wanted to talk with, the server can still be vulnerable to other kinds of attacks. Since users are storing data on the server, they need to trust in its security. Storing the clear passwords is not a good idea, I agree. But having a secure authentication method and not storing clear passwords doesn't automatically mean that the server is secured. :-) I'm sorry, I was not clear. I think we were talking about the same thing. Les From timr at probo.com Sat Oct 15 18:30:41 2005 From: timr at probo.com (Tim Roberts) Date: Sat, 15 Oct 2005 22:30:41 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: "Jeroen Wenting" wrote: > >Microsoft isn't evil, they're not a monopoly either. >If they were a monopoly they'd have 100% of the market and there'd be no >other software manufacturers at all. This is wrong. The dictionary definition of a monopoly is when a manufacturer has all or nearly all of a market. Microsoft DOES have a monopoly on PC operating systems. That, in itself, is not necessarily illegal. However, Microsoft then USED that monopoly power to stifle their competition, and that IS illegal. Part of their behavior really escape me. The whole thing about browser wars confuses me. Web browsers represent a zero billion dollar a year market. Why would you risk anything to own it? >Without Microsoft 90% of us would never have seen a computer more powerful >than a ZX-81 and 90% of the rest of us would never have used only dumb >mainframe terminals. Utter hogwash. Computer hardware would still have followed the path it did. I suspect we'd all be using WordPerfect or AbiWord on some kind of Unix clone, and I also suspect application integration wouldn't be as commonplace as it now is, but it's silly to credit Microsoft with the ubiquity of powerful computers. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From daniel.dittmar at sap.corp Thu Oct 6 10:48:28 2005 From: daniel.dittmar at sap.corp (Daniel Dittmar) Date: Thu, 06 Oct 2005 16:48:28 +0200 Subject: Absolultely confused... In-Reply-To: References: Message-ID: Jeremy Moles wrote: > So, here is my relevant code: > > PyArg_ParseTuple(args, "O!", &PyType_vector3d, &arg1) > > And here ismy error message: > > argument 1 must be pylf.core.vector3d, not pylf.core.vector3d > It looks as if two PyType_vector3d exist in your system - the one that created the object passed to your routine - the one in your extension code As PyType_vector3d probably comes from a shared object/DLL - does your code accesses really the same shared object that is also loaded by the Python interpreter? It could be that you linked with a specific file, but Python loads something different from $PYTHONPATH - on Windows, you couldn't simply import a variable from a DLL, you had to call a special routine to get the pointer One possible portable solution: in your module initialization - import pylf.core - create an object of type vector3d - use your knowledge about the inner structure of Python objects and get the pointer to the PyType from the object - store it in a module static variable TypeVector3D - pass that variable to PyArg_ParseTuple Browse the Python Extension API, maybe partts or all of this are already available. There's still a problem left when pylf.core gets reloaded (rare, but possible). I assume the shared object also gets reloaded, which means that the type objects gets loaded to a new address and PyArg_ParseTuple will complain again. I'm not sure if there is a solution to this, because there still could be objects create from the old module. Maybe you should just check the type yourself by comparing the class names buried in the PyType. You could cache one or two type pointers to speed this up. Daniel From moondusterone at comcast.net Tue Oct 11 20:37:27 2005 From: moondusterone at comcast.net (moondusterone) Date: Tue, 11 Oct 2005 19:37:27 -0500 Subject: Newbie needs help. Setting PYTHONDOCS to read HTML. References: <1128995462.893750.155420@o13g2000cwo.googlegroups.com> <1129070730.596978.199710@g49g2000cwa.googlegroups.com> Message-ID: Yes it did. And it worked! Thank you! ____________ moondusterone "Brett Hoerner" wrote in message news:1129070730.596978.199710 at g49g2000cwa.googlegroups.com... > That's because the Python docs come zipped up within a folder, for > example: > > python_docs.tar.bz2 has a folder inside it called Python-Docs-2.4.2. > > You need to have C:\Python24\Python-Docs-2.4.2\ as the value if thats > where that folder is, or wherever you unzipped it. I, personally, just > took all the directories out of Python-Docs-2.4.2 and put them in > C:\Python24\Doc and then added C:\Python24\Doc as the value for > PYTHONDOCS. > > Hope that made sense. > From hgk at et.uni-magdeburg.de Tue Oct 11 11:12:31 2005 From: hgk at et.uni-magdeburg.de (Hans Georg Krauthaeuser) Date: Tue, 11 Oct 2005 17:12:31 +0200 Subject: searching python/gui developper in germany Message-ID: Dear all, for the measurements in our labs we have developed python scripts that are pretty fine for our needs. Basically, we have classes and call the appropriate methods from the command line (or by other scripts). So, we don't have any GUI. Now, an external customer want to use our software and -- as you can imagine -- we want a pretty GUI. So, we are looking for someone who can develop such a pretty GUI for us (of course for money). OS is Windows (XP). We are not fixed to a special toolkit -- it just should look nice and do the job. Best would be someone from our region (Magdeburg, Germany). If someone is interested: contact me by email, please. Best regards Hans Georg Krauthaeuser From fredrik at pythonware.com Wed Oct 5 11:35:19 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 5 Oct 2005 17:35:19 +0200 Subject: Call C functions from Python References: <1128454231.381256.297280@g47g2000cwa.googlegroups.com><1128522414.964010.65970@g14g2000cwa.googlegroups.com> <1128525560.469712.214380@f14g2000cwb.googlegroups.com> Message-ID: "Java and Swing" wrote: >i dont have a myapp.pyd ...i have myapp.c, or are u suggesting I dump > the dll? if that's what you're trying to import, yes. > or the swig generated python file? > the swig generated python file only has .py and .pyc. huh? if you have a swig-generated python file, why are you using ctypes? From __peter__ at web.de Mon Oct 31 03:19:10 2005 From: __peter__ at web.de (Peter Otten) Date: Mon, 31 Oct 2005 09:19:10 +0100 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <867jbxfpvb.fsf@bhuda.mired.org> <1h55ri3.1hzntdk1dtxpa7N%aleaxit@yahoo.com> <43632812.1249162210@news.oz.net> <4363b997.1286415918@news.oz.net> <436541ce.1390422241@news.oz.net> Message-ID: Bengt Richter wrote: > I still smelled a bug in the counting of substring in the overlap region, > and you motivated me to find it (obvious in hindsight, but aren't most ;-) > > A substring can get over-counted if the "overlap" region joins > infelicitously with the next input. E.g., try counting 'xx' in 10*'xx' > with a read chunk of 4 instead of 1024*1024: > > Assuming corrections so far posted as I understand them: > > >>> def byblocks(f, blocksize, overlap): > ... block = f.read(blocksize) > ... yield block > ... if overlap>0: > ... while True: > ... next = f.read(blocksize-overlap) > ... if not next: break > ... block = block[-overlap:] + next > ... yield block > ... else: > ... while True: > ... next = f.read(blocksize) > ... if not next: break > ... yield next > ... > >>> def countsubst(f, subst, blksize=1024*1024): > ... count = 0 > ... for block in byblocks(f, blksize, len(subst)-1): > ... count += block.count(subst) > ... f.close() > ... return count > ... > > >>> from StringIO import StringIO as S > >>> countsubst(S('xx'*10), 'xx', 4) > 13 > >>> ('xx'*10).count('xx') > 10 > >>> list(byblocks(S('xx'*10), 4, len('xx')-1)) > ['xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xx'] > > Of course, a large read chunk will make the problem either > go away > > >>> countsubst(S('xx'*10), 'xx', 1024) > 10 > > or might make it low probability depending on the data. [David Rasmussen] > First of all, this isn't a text file, it is a binary file. Secondly, > substrings can overlap. In the sequence 0010010 the substring 0010 > occurs twice. Coincidentally the "always overlap" case seems the easiest to fix. It suffices to replace the count() method with def count_overlap(s, token): pos = -1 n = 0 while 1: try: pos = s.index(token, pos+1) except ValueError: break n += 1 return n Or so I hope, without the thorough tests that are indispensable as we should have learned by now... Peter From chrisgarland67 at hotmail.com Tue Oct 4 14:10:05 2005 From: chrisgarland67 at hotmail.com (Cigar) Date: 4 Oct 2005 11:10:05 -0700 Subject: Controlling who can run an executable In-Reply-To: <1128432188.408503.309280@f14g2000cwb.googlegroups.com> References: <1128395422.904212.318930@g44g2000cwa.googlegroups.com> <1128432188.408503.309280@f14g2000cwb.googlegroups.com> Message-ID: <1128449405.776337.251380@g44g2000cwa.googlegroups.com> Istvan Albert wrote: > >was using to track clients and transactions. He couldn't demonstrate > >the program for one reason or another because it was protected in a way > >that neither could circumvent. (She didn't remember how it was > >protected, she had hired this person a long time ago.) > > I'd venture to guess that neither of the people above knew much about > programming. So do the same, create a security measure that protects > against this level of 'threat'. I could ask her, "If you can't break it is that good enough security?" > As others have pointed out the simplest way would be to detect the > presence of a hidden file, or some hardcoded system value, mac address > etc. Obscure this step even more by encrypting some of the information > so that one can't just simply view it in a hex editor. > > Istvan. From john at castleamber.com Sun Oct 16 10:51:48 2005 From: john at castleamber.com (John Bokma) Date: 16 Oct 2005 14:51:48 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: Steven D'Aprano wrote: > On Sun, 16 Oct 2005 05:26:51 +0000, John Bokma wrote: > >> Steven D'Aprano wrote: >> >>> On Sun, 16 Oct 2005 00:47:09 +0000, John Bokma wrote: >>> >>>> Ok, let me spell it out for you: If all your applications are web >>>> based, and the OS shouldn't matter, why do Linux distributions >>>> matter? It doesn't matter which one you use to run, for example, >>>> OpenOffice. Yet people pick a certain distribution. Why? Well, one >>>> reason is that people like to belong to a group. So even if it >>>> really doesn't matter which OS you are going to use to access a web >>>> application, or even which browser, people will pick a certain >>>> browser, and a certain OS, just because. >>> >>> Dude, do you think that Microsoft gives a rat's tail[1] for what a >>> handful of computer enthusiasts and geek programmers pick? >> >> So you missed the point again. > > "Again"? > > What exactly *is* your point? You seem to be oscillating from > "Microsoft doesn't care what browser people use" I didn't write that. > to "Microsoft cares > deeply what browser people use". I don't understand what you are > trying to say. Neither that. I wrote: People *care* what OS they are using. Hence, even if there is a standard web platform for applications, and it doesn't matter what you use, people still will prefer MS over others. Even if they can't see any difference. I already wrote: look at CDs. There are several factories producing CDs. There are labels put on the same batch of CDs. So one can buy brand X, and brand Y, but basically you buy CDs made by factory Z, batch W. And yet people make a great deal about how much better X is compared to Y for burning CDs. So even if the OS doesn't matter from a technical viewpoint (which I don't see happen soon), people are able to attach matters to their choice. It's like those cookies that every year get more tastier, better, etc. >> So basically you're saying that even if web based applications become >> the shit, everybody keeps running Microsoft? So I am right :-) > > No. My point is, IF web-based apps become popular, and back in the > 1990s people thought that they would, Some did, some didn't. I didn't. I always said the Notworking computer was just that: not working. > and they would run on any > browser, then you could run your browser on any operating system on > any hardware. That's what Microsoft wanted to stop, by gluing the > browser to the OS. And how exactly was that going to work? >> Ah, sure, you really think that a business is going to run office >> applications on a web server? Are they already moving to Linux with >> OpenOffice (free as in speech?). > > As I said, back in the 90s that's what people thought, including > Microsoft. So, you have contacts in high places, or you make it up? *I* didn't think that back in the 90s, and I remember quite a lot of people didn't think it either. The diskless Networking computer had quickly a harddisc added, and I, and many others said: what's the difference? How much does a harddisc save and how much costs does it add not having it? The picture was clear to me, and others back then: thin clients are not happening. The whole PC idea is that you can shop your hardware, put it in a computer, and have your own *Personal* computer. > As for OpenOffice, yes, there is a slow migration away from MS Office. Yup, like the slow migration away from MS as an OS. > If you are in the US, the UK or Australia, you probably won't have > noticed it, I am in Mexico, am Dutch, and have been living in NZ for 2 years. The only companies who say that it's going to happen are the ones that do Linux support (go figure). > since it is a tiny trickle in those countries. But in the > emerging IT markets of Asia (especially China), Europe and South > America, that trickle has become a steady stream. I am in Latin America, and it's not happening here as far as I know. > Especially now that Gartner has claimed that migrating from current > versions of Office to Office 12 will cost ten times more for training > alone than migrating to OpenOffice, I think we can expect to see that > trickle start gushing in the next twelve months or so. LOL, well, I am not going to hold my breath. >>> That is why MS >>> decided to bundle IE with Windows and (try to) kill off Netscape as >>> a competitor. >> >> So and when exactly do we see the web based office? > > Rumour has it that Google is preparing to do exactly that. Yeah, rumours. > Personally, I don't see the point. I would never use a web-based > office suite, but then I don't even like web mail. Yes, I agree with you. But, like I explained in a related thread somewhere else some time ago, a web based office will get users. As I said, I live in Mexico. Most people here don't have money for a PC (and no, they are not going to buy those miracle machines like AMD is promising), so they go to Internet cafes when they need one. Students I know already rely a lot on Hotmail, Gmail, etc, to store and exchange their homework. They edit it in an Internet cafe, email it, etc. So I am sure that in Mexico, people might going to switch to web based office. > What's more important these days from Microsoft's strategic planning > is multimedia. And advertising, which is quite related of course. > Yes, they want -- need -- to keep control of the office > suite, Office gives them something like 1/2 their revenue. But for the > long-term, they want to lock folks into their proprietary > Internet-based multimedia systems (e.g. streaming wmv over mms) > because they think that this will give them control of a very > lucrative business. I can't really disagree with them. Yup, I don't see MS disappear very soon now, nor do I see major shifts (like desktop to network) happening very soon. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From qwweeeit at yahoo.it Thu Oct 6 19:04:32 2005 From: qwweeeit at yahoo.it (qwweeeit at yahoo.it) Date: 6 Oct 2005 16:04:32 -0700 Subject: dcop module under Python 2.4 Message-ID: <1128639872.036312.76620@g44g2000cwa.googlegroups.com> Hi all, at the end I upgraded to 2.4, but now I am not able to load dcop module (part of the Python-KDE3 bindings). Any help? Bye. From __peter__ at web.de Sat Oct 29 14:36:12 2005 From: __peter__ at web.de (Peter Otten) Date: Sat, 29 Oct 2005 20:36:12 +0200 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <867jbxfpvb.fsf@bhuda.mired.org> <1h55ri3.1hzntdk1dtxpa7N%aleaxit@yahoo.com> <43632812.1249162210@news.oz.net> <4363b997.1286415918@news.oz.net> Message-ID: Bengt Richter wrote: > What struck me was > > >>>?gen?=?byblocks(StringIO.StringIO('no'),1024,len('end?')-1) > >>>?[gen.next()?for?i?in?xrange(10)] > ['no',?'no',?'no',?'no',?'no',?'no',?'no',?'no',?'no',?'no'] Ouch. Seems like I spotted the subtle cornercase error and missed the big one. Peter From robin at reportlab.com Tue Oct 18 14:10:53 2005 From: robin at reportlab.com (Robin Becker) Date: Tue, 18 Oct 2005 19:10:53 +0100 Subject: override a property In-Reply-To: <1129647504.536405.156280@g43g2000cwa.googlegroups.com> References: <1129647504.536405.156280@g43g2000cwa.googlegroups.com> Message-ID: <43553AAD.1020708@chamonix.reportlab.co.uk> Kay Schluehr wrote: > Robin Becker wrote: > >>Is there a way to override a data property in the instance? Do I need to create >>another class with the property changed? >>-- >>Robin Becker > > > It is possible to decorate a method in a way that it seems like > property() respects overridden methods. The decorator cares > polymorphism and accesses the right method. > > def overridable(f): > def __wrap_func(self,*args,**kwd): > func = getattr(self.__class__,f.func_name) > if func.func_name == "__wrap_func": > return f(self,*args,**kwd) > else: > return func(self,*args,**kwd) > return __wrap_func > > > class A(object): > def __init__(self, x): > self._x = x > > @overridable > def get_x(self): > return self._x > > x = property(get_x) > > class B(A): > > def get_x(self): > return self._x**2 > > class C(B):pass > > >>>>a = A(7) >>>>a.x > > 7 > >>>>b = B(7) >>>>b.x > > 49 > >>>>c = C(7) >>>>c.x > > 49 > I thought that methods were always overridable. In this case the lookup on the class changes the behaviour of the one and only property. -- Robin Becker From steve at holdenweb.com Wed Oct 5 12:35:05 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 05 Oct 2005 17:35:05 +0100 Subject: change a value to NULL? In-Reply-To: <1128529216.608027.227010@o13g2000cwo.googlegroups.com> References: <1128529216.608027.227010@o13g2000cwo.googlegroups.com> Message-ID: Brett Hoerner wrote: > I'm not sure what you mean, really, do you need an official Python > "Null" value? Try None? > > In [6]: myCells = ['Mary', 'Bob', None, 'Joe'] > > In [7]: for cell in myCells: > ...: if cell: > ...: print cell > ...: else: > ...: print "NULL VALUE" > ...: > Mary > Bob > NULL VALUE > Joe > > -- > > As far as having a Null value to put into the DB, most (SQL) DB's I've > used have a specific SQL command like "INSERT INTO ROW VALUE NULL()", > kind of like the SQL DATE(), etc. I'm really rusty on my syntax etc > right now btw so don't copy and paste that. :P > And besides that, Excel is a spreadsheet not a database :-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From my_email_is_posted_on_my_website at munged.invalid Mon Oct 17 20:48:30 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Tue, 18 Oct 2005 00:48:30 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <86vezwzmlt.fsf@bhuda.mired.org> Message-ID: On Mon, 17 Oct 2005 02:25:18 -0400, Mike Meyer wrote or quoted : > >Actually, *any* company with a defacto monopoly pulling such a stunt >would be found in violation of the law. Such companies operate under >different legal rules than other companies. This was true when IBM was >the company that was dancing with the DOJ, and it'll be true long >after MS is nothing more than a memory. I don't know if anyone has >spelled this out to MS, but IBM was told so in no uncertain terms. MS would still be dancing with the DOJ hand Gates not bribed Bush to pull the plug on the prosecution. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From johnnyandfiona at hotmail.com Wed Oct 12 03:37:52 2005 From: johnnyandfiona at hotmail.com (Johnny Lee) Date: 12 Oct 2005 00:37:52 -0700 Subject: A problem while using urllib In-Reply-To: References: <1129024641.113182.74420@g49g2000cwa.googlegroups.com> <1h49slu.1gaj0nnmdk5ghN%aleax@mail.comcast.net> <1129089078.852454.153800@f14g2000cwb.googlegroups.com> Message-ID: <1129102671.990994.43590@f14g2000cwb.googlegroups.com> Steve Holden wrote: > Johnny Lee wrote: > > Alex Martelli wrote: > > > >>Johnny Lee wrote: > >> ... > >> > >>> try: > >>> webPage = urllib2.urlopen(url) > >>> except urllib2.URLError: > >> > >> ... > >> > >>> webPage.close() > >>> return True > >>>---------------------------------------------------- > >>> > >>> But every time when I ran to the 70 to 75 urls (that means 70-75 > >>>urls have been tested via this way), the program will crash and all the > >>>urls left will raise urllib2.URLError until the program exits. I tried > >>>many ways to work it out, using urllib, set a sleep(1) in the filter (I > >>>thought it was the massive urls crashed the program). But none works. > >>>BTW, if I set the url from which the program crashed to base url, the > >>>program will still crashed at the 70-75 url. How can I solve this > >>>problem? thanks for your help > >> > >>Sure looks like a resource leak somewhere (probably leaving a file open > >>until your program hits some wall of maximum simultaneously open files), > >>but I can't reproduce it here (MacOSX, tried both Python 2.3.5 and > >>2.4.1). What version of Python are you using, and on what platform? > >>Maybe a simple Python upgrade might fix your problem... > >> > >> > >>Alex > > > > > > Thanks for the info you provided. I'm using 2.4.1 on cygwin of WinXP. > > If you want to reproduce the problem, I can send the source to you. > > > > This morning I found that this is caused by urllib2. When I use urllib > > instead of urllib2, it won't crash any more. But the matters is that I > > want to catch the HTTP 404 Error which is handled by FancyURLopener in > > urllib.open(). So I can't catch it. > > > > I'm using exactly that configuration, so if you let me have that source > I could take a look at it for you. > > regards > Steve > -- > Steve Holden +44 150 684 7255 +1 800 494 3119 > Holden Web LLC www.holdenweb.com > PyCon TX 2006 www.python.org/pycon/ I've sent the source, thanks for your help. Regrads, Johnny From elbertlev at hotmail.com Thu Oct 20 00:09:06 2005 From: elbertlev at hotmail.com (elbertlev at hotmail.com) Date: 19 Oct 2005 21:09:06 -0700 Subject: Python vs Ruby In-Reply-To: <1129778582.411476.259500@o13g2000cwo.googlegroups.com> References: <1129778582.411476.259500@o13g2000cwo.googlegroups.com> Message-ID: <1129781346.035866.16660@g43g2000cwa.googlegroups.com> Languages are very similar but Python has more cale avaliable. Much more. From rdm at rcblue.com Wed Oct 5 18:11:20 2005 From: rdm at rcblue.com (Dick Moores) Date: Wed, 05 Oct 2005 15:11:20 -0700 Subject: New Python book Message-ID: <6.2.1.2.2.20051005150954.0741e1d0@rcblue.com> (Sorry, my previous post should not have had "Tutor" in the subject header.) Magnus Lie Hetland's new book, _Beginning Python: From Novice to Professional_ was published by Apress on Sept. 26 (in the U.S.). My copy arrived in the mail a couple of days ago. Very much worth a look, IMHO. But what do the experts here think? Dick Moores rdm at rcblue.com From onurb at xiludom.gro Thu Oct 20 04:48:30 2005 From: onurb at xiludom.gro (bruno modulix) Date: Thu, 20 Oct 2005 10:48:30 +0200 Subject: Python vs Ruby In-Reply-To: References: Message-ID: <435759e1$0$4297$626a54ce@news.free.fr> Amol Vaidya wrote: > Hi. I am interested in learning a new programming language, and have been > debating whether to learn Ruby or Python. How do these compare and contrast > with one another, and what advantages does one language provide over the > other? I would like to consider as many opinions as I can on this matter > before I start studying either language in depth. Any help/comments are > greatly appreciated. Thanks in advance for your help. The main point about "advantages" is that Python has a larger community, a larger choice of libraries, and is somewhat more mature (which is not surprising since Python is a little bit older than Ruby). Else, both are hi-level highly dynamic object oriented languages, both are fun to program with, and both are easy to get started with. So the best thing to do is to give both a try and go with the one that fits your brain. -- 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 gsakkis at rutgers.edu Fri Oct 14 13:59:54 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Fri, 14 Oct 2005 13:59:54 -0400 Subject: NYLUG meeting: The Python Object Model with Alex Martelli & Google(open bar and food!) References: Message-ID: <1129312792.c8c0370da34fd63e5cace1fe6133aff9@teranews> "Ron Guerin" wrote: > The New York Linux User's Group invites you to a special presentation > by Alex Martelli of Google, on the Python Object Model. This > presentation will be held at P.J. Clarke's Sidecar, rather than our > usual location, and Google is picking up the tab for an hour and a half > of open bar and food. Additionally, if you're looking for a job as a > Python developer, bring your resume. > > Please RSVP at http://rsvp.nylug.org to attend, as seating is limited. > > - Ron What date is it ? It isn't mentioned at the web site either. George From wholcomb at gmail.com Fri Oct 21 13:33:25 2005 From: wholcomb at gmail.com (Will) Date: 21 Oct 2005 10:33:25 -0700 Subject: subprocess exiting in an incomprehensible fashion Message-ID: <1129916005.543449.305390@g44g2000cwa.googlegroups.com> I have this bit of code: #!/usr/bin/python import subprocess calc = subprocess.Popen("dc", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) max = 5 for value in range(1, max): calcout, calcerr = calc.communicate("%d\n" % value) print("Post Communicate Value %d: %s (%s) [%d]" % (value, calcout, calcerr, calc.returncode)) if value > 1: calcout, calcerr = calc.communicate("*\n") calcout, calerr = calc.communicate("p\n") print("Value: %d = %d" % (calcout, reduce(lambda x,y: x * y, range(1, max)))) calc.communicate("q\n") status = calc.wait() print "Exited with: %d" % status ### End Code After the first number is input, the subprocess is exiting after the first communicate. I do not understand why. I have tried to accomplish the same thing with os.popen and popen2.Popen. I can't get anything to work and I am having a difficult time finding examples that include both redirected input and output from a subprocess. I am wanting to do work with a more complicated program, but was looking to get something simple working first. Any help would be much appreciated. I have been hunting quite a bit for he answer to no avail. Will Holcomb From arve.knudsen at gmail.com Tue Oct 25 14:46:25 2005 From: arve.knudsen at gmail.com (arve.knudsen at gmail.com) Date: 25 Oct 2005 11:46:25 -0700 Subject: How to statically link Python with ncurses and readline? In-Reply-To: <435e78d1$0$2680$9b622d9e@news.freenet.de> References: <1130263338.291061.50210@g49g2000cwa.googlegroups.com> <435e78d1$0$2680$9b622d9e@news.freenet.de> Message-ID: <1130265985.862970.185070@g47g2000cwa.googlegroups.com> Well, I implied that _curses.so and readline.so disappeared as one would expect, dependencies on libncurses.so and libreadline.so instead showing up in Python itself. It's very strange that this happens with ncurses and readline, when both db and Tcl/Tk got linked in with no fuss. Anyway, I built static-only (.a) versions of readline and ncurses, which did the trick. Arve From onurb at xiludom.gro Tue Oct 25 04:22:02 2005 From: onurb at xiludom.gro (bruno modulix) Date: Tue, 25 Oct 2005 10:22:02 +0200 Subject: Hi All - Newby In-Reply-To: <435ddd20$1@news1.veridas.net> References: <435ddd20$1@news1.veridas.net> Message-ID: <435deb2c$0$652$626a14ce@news.free.fr> Ask wrote: > G'day All, > (snip) Welcome here... > I must admit to much confusion regarding some of the basics, but I'm sure > time, reading, and good advice will get rid of that. at this stage, it's > just working through some examples and getting my head around things. As an > example, if I create a window, I've been unable to force it to be a certain > size, and put a button (widget) at (say) 20,40 (x & y). Is window formatting > possible? As you say, Python runs on a lot of platforms. It also allow the use of a lot of GUI toolkits. So "windows formatting" isn't a Python problem - it's specific to to toolkit you're using. Since we don't know which you're using, there's no way to answer your question. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From jadedgamer at hotmail.com Sun Oct 16 03:57:11 2005 From: jadedgamer at hotmail.com (Tor Iver Wilhelmsen) Date: 16 Oct 2005 09:57:11 +0200 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: John Bokma writes: > No, it's a recommendation, an advise, nothing else. It is a de facto standard instead of a de jure standard. Sort of how the SMTP "recommendation" is the de facto standard for internet mail instead of ISO-MOTIS (built on the X.400 spec). From carsten at uniqsys.com Tue Oct 4 09:00:10 2005 From: carsten at uniqsys.com (Carsten Haese) Date: Tue, 04 Oct 2005 09:00:10 -0400 Subject: Dynamical loading of modules In-Reply-To: <43427640.3010707@holdenweb.com> References: <43418BF5.90504@gmail.com> <1128372108.4070.31.camel@dot.uniqsys.com> <1128372287.4070.33.camel@dot.uniqsys.com> <1128428782.4070.42.camel@dot.uniqsys.com> <43427640.3010707@holdenweb.com> Message-ID: <1128430810.4070.55.camel@dot.uniqsys.com> On Tue, 2005-10-04 at 08:32, Steve Holden wrote: > Carsten Haese wrote: > > On Mon, 2005-10-03 at 17:37, Steve Holden wrote: > > > >>Carsten Haese wrote: > >> > >>>On Mon, 2005-10-03 at 16:41, Carsten Haese wrote: > >>> > >>> > >>>>On Mon, 2005-10-03 at 15:52, Jacob Kroon wrote: > >>>> > >>>> > >>>>>Hi, I'm having some problems with implementing dynamical module loading. > >>>>>First let me > >>>>>describe the scenario with an example: > >>>>> > >>>>>modules/ > >>>>> fruit/ > >>>>> __init__.py > >>>>> apple.py > >>>>> banana.py > >>>>> > >>>>>apple.py defines a class 'Apple', banana defines a class 'Banana'. The > >>>>>problem lies in the > >>>>>fact that I want to be able to just drop a new .py-file, for instance > >>>>>peach.py, and not change > >>>>>__init__.py, and it should automatically pickup the new file in > >>>>>__init__.py. I've come halfway > >>>>>by using some imp module magic in __init__.py, but the problem I have is > >>>>>that the instantiated > >>>>>objects class-names becomes fruit.apple.Apple/fruit.banana.Banana, whild > >>>>>I want it to be > >>>>>fruit.Apple/fruit.Banana. > >>>>> > >>>>>Is there a smarter way of accomplishing what I am trying to do ? > >>>>>If someone could give me a small example of how to achieve this I would > >>>>>be very grateful. > >>>> > >>>>How about something like this in fruit/__init__.py: > >>>> > >>>>import os > >>>> > >>>>fruit_dir = os.path.dirname(__file__) > >>>>fruit_files = [x for x in os.listdir(fruit_dir) if (x[-3:]=='.py' and x!='__init__.py')] > >>>>for fruit_file in fruit_files: > >>>> module_name = fruit_files[:-3] > >>> > >>> ^^^^^^^^^^^ This should be fruit_file, of course. > >>> > >>> > >>> > >>>> exec "from %s import *" % module_name > >>>> > >> > >>Wouldn't > >> > >> __import__(module_name) > >> > >>be better. > > > > > > I don't see how a working example that meets the OP's requirements can > > be constructed using __import__, but that may easily be due to my lack > > of imagination. How would you do it? > > > I was simply suggesting that you replace the exec statement with a call > to __import__(). Wouldn't that work? Not the way I tried it by simply replacing my line with your line. (If it matters, I'm on python 2.2 here.) First of all, the __import__ variant doesn't see the submodules unless I add fruit_dir to sys.path. Secondly, the OP's requirements are that the classes that the submodules implement be imported into fruit's namespace, and I don't see how to make __import__ do that. Regards, Carsten Haese. From eight02645999 at yahoo.com Sat Oct 29 23:21:20 2005 From: eight02645999 at yahoo.com (eight02645999 at yahoo.com) Date: 29 Oct 2005 20:21:20 -0700 Subject: query a port Message-ID: <1130642480.233982.197760@g49g2000cwa.googlegroups.com> hi in python, how do one query a port to see whether it's up or not? thanks From zanesdad at bellsouth.net Wed Oct 26 15:06:57 2005 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Wed, 26 Oct 2005 15:06:57 -0400 Subject: Problem ... with threads in Python In-Reply-To: <000601c5da56$291323d0$a6b07856@cosmin> References: <000601c5da56$291323d0$a6b07856@cosmin> Message-ID: <435FD3D1.4070607@bellsouth.net> Negoescu Constantin wrote: > Hello. > > I know that Python is */not fully threadsafe/*. Unlike Java, where > threading was considered to be so important that it is a part of the > syntax, in Python threads were laid down at the altar of Portability. > But, i really have to finish a project which uses multiple threads in > Python, and i shouldn't use the time.sleep() function. > Is there any posibility to use multiple threads without using the > time.sleep() function ? And if so, what that way should be ? > > Best regards, > _Cosmin You might want to give us a little more detail on what you're trying to accomplish and how you're using sleep() so we'll be able to help you better. Are you trying to use sleep() as a synchronization mechanism between threads? - jmj From ivoras at fer.hr Tue Oct 11 07:42:36 2005 From: ivoras at fer.hr (Ivan Voras) Date: Tue, 11 Oct 2005 13:42:36 +0200 Subject: Let My Terminal Go In-Reply-To: <8664s4zfvv.fsf@bhuda.mired.org> References: <1129010288.251817.147690@z14g2000cwz.googlegroups.com> <8664s4zfvv.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > The easy way to do all these things - from C, anyway - is with > daemon(3). That isn't wrapped as part of the Python library. The > easiest way to solve your problem may be write a wrapper for that > call. If daemon exists on enough systems, submitting your wrapper as a > patch to the os modulee would be appropriate. I think the deamon() library call only exists on the BSDs. Anyway, there it is implemented with a fork() call and some additional code to close std descriptors, so there's no practical difference between calling deamon() and fork() by yourself... From onurb at xiludom.gro Mon Oct 24 04:19:18 2005 From: onurb at xiludom.gro (bruno modulix) Date: Mon, 24 Oct 2005 10:19:18 +0200 Subject: [OT] Python vs Ruby In-Reply-To: <43593468$1@nntp0.pdx.net> References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> <4358d9f6$0$19694$626a14ce@news.free.fr> <43593468$1@nntp0.pdx.net> Message-ID: <435c9906$0$14034$636a15ce@news.free.fr> Scott David Daniels wrote: > bruno modulix wrote: > >> ... Another language that failed to make it to the mainstream but is >> worth giving a try is Smalltalk - the father of OOPLs (Simula being the >> GrandFather). > > I would say Simula is the forefather of modern OOPLs, and Smalltalk is > the toofather. Err... I'm afraid I don't understand this last word (and google have not been of much help here) -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From leasun at gmail.com Sun Oct 23 12:08:45 2005 From: leasun at gmail.com (leasun) Date: 23 Oct 2005 09:08:45 -0700 Subject: bsddb version? Message-ID: <1130083725.481400.323330@g14g2000cwa.googlegroups.com> Anybody knows which version bsddb is released with py2.3 and py2.4? Thanks. From peter at engcorp.com Tue Oct 25 04:38:55 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 25 Oct 2005 04:38:55 -0400 Subject: more than 100 capturing groups in a regex In-Reply-To: <1130225565.592108.197670@z14g2000cwz.googlegroups.com> References: <1130160675.270886.208420@z14g2000cwz.googlegroups.com> <1130225565.592108.197670@z14g2000cwz.googlegroups.com> Message-ID: Joerg Schuster wrote: > I just want to use more than 100 capturing groups. If someone told me > that it is very unlikely for Python to get rid of the said limitation, > I would recode part of my program in C++ using pcre. It is very unlikely for Python to get rid of the said limitation. -Peter From prince_amir86 at yahoo.com Wed Oct 5 08:12:08 2005 From: prince_amir86 at yahoo.com (Brandon K) Date: Wed, 05 Oct 2005 07:12:08 -0500 Subject: Help with chaos math extensions. In-Reply-To: References: <43433982.8080008@yahoo.com> Message-ID: <4343C318.3090902@yahoo.com> Here's the Script it was being used in (forgive it if it seems a bit messy, i have been tinkering with variables and such to try different ideas and haven't really cleaned it up). import ctest import Tkinter import threading hue_map = ("#FFFFFF","#FEFEFF","#FDFDFF","#FCFCFF","#FBFBFF","#FAFAFF","#F9F9FF","#F8F8F8","#F7F7FF","#F6F6F6","#EEEEFF","#DDDDFF","#CCCCFF","#BBBBFF","#AAAAFF","#9999FF","#8888FF",\ "#7777FF","#6666FF","#5555FF","#4444FF","#3333FF","#2222FF","#1111FF","#0000FF") class Mandelbrot_Set(Tkinter.Canvas): def __init__(self,master,iters): Tkinter.Canvas.__init__(self,master) self.dims = {'x':500,'y':500} self.config(height=self.dims['y'],width=self.dims['x']) self.r_range = (-2.0,2.0) self.i_range = (-2.0,2.0) self.iters = iters self.prec = {'r':1.*(self.r_range[1]-self.r_range[0])/(self.dims['x']),'i':1.*(self.i_range[1]-self.i_range[0])/self.dims['y']} self.escapemap = ctest.escapeMap(-1j,self.iters,(self.dims['x'],self.dims['y']),(self.r_range[0],self.r_range[1]),(self.i_range[0],self.i_range[1])) self.select = False self.select_event = (0,0) self.sbox = None self.bind("",self.selection_box) self.bind("",self.select_update) self.t_draw = threading.Thread(target=self.draw) self.t_draw.start() def draw(self): for j in range(self.dims['y']): i = 0 while i < self.dims['x']: cur = 0; try: color = self.escapemap[j][i] while self.escapemap[j][i+cur] == color: cur+=1 except IndexError: break; hue_step = 1.*len(hue_map)/self.iters if color == -1: f = "#000000" else: f = hue_map[int(hue_step*color)] self.create_line(i,j,i+cur,j,fill=f) i+=cur def selection_box(self,event): if not self.select: self.select_event = (event.x,event.y) self.select = True else: self.r_range = self.new_range(event.x,self.select_event[0]) self.i_range = self.new_range(event.y,self.select_event[1]) print self.r_range,self.i_range self.select = False self.delete(Tkinter.ALL) self.t_draw.run() self.select_update(event) def new_range(self,x,y): if x > y: return (y,x) else: return (x,y) def select_update(self,event): if not self.select: return else: if self.sbox != None: self.delete(self.sbox) self.sbox = self.create_rectangle(self.select_event[0],self.select_event[1],event.x,event.y,fill=None,outline="#000000") else: self.sbox = self.create_rectangle(self.select_event[0],self.select_event[1],event.x,event.y,fill=None,outline="#000000") if __name__ == "__main__": root = Tkinter.Tk() c = Mandelbrot_Set(root,50) c.pack() root.mainloop() The error occurs in the instantiation of the Mandelbrot_Set object. Additionally in little mini timing scripts such as import time import ctest t = time.time() c = ctest.escapeMap(-1j,100,(500,500)) print time.time()-t this will crash it too however I found that just opening up the interpreter and typing import ctest ctest.escapeMap(-1j,100,(50,50)) #50 yields much smaller output than 500x500 it generates a 2d tuple fine. So the error seems really obscure to me, and I don't understand it. > Brandon Keown wrote: > > >> I have programmed a fractal generator (Julia Set/Mandelbrot Set) in >> python in the past, and have had good success, but it would run so >> slowly because of the overhead involved with the calculation. I >> recently purchased VS .NET 2003 (Win XP, precomp binary of python >> 2.4.2rc1) to make my own extensions. I was wondering if anyone could >> help me figure out why I'm getting obscure memory exceptions (runtime >> errors resulting in automatic closing of Python) with my extension. It >> seems to run okay if imported alone, but when accompanied in a list of >> instructions such as a function it crashes. >> > > a short script or interpreter session that illustrates how to get the errors > would help. > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mscottschilling at hotmail.com Thu Oct 20 18:07:51 2005 From: mscottschilling at hotmail.com (Mike Schilling) Date: Thu, 20 Oct 2005 22:07:51 GMT Subject: Microsoft Hatred FAQ References: <867jcbzdw9.fsf@bhuda.mired.org> <4vcbl1dkek9kr86embmgrj70vk945t99ho@4ax.com> <35jbl1dprs4v1o87i0tapc2husjqiqm6fi@4ax.com> <4355ea72$1_3@news.melbourne.pipenetworks.com> Message-ID: "Steven D'Aprano" wrote in message news:pan.2005.10.20.13.46.50.253609 at REMOVETHIScyber.com.au... > On Thu, 20 Oct 2005 13:17:14 +0000, axel wrote: > >> Employees have *no* obligations towards the shareholders of a company. >> They are not employed or paid by the shareholders, they are employed >> by the company itself which is a separate legal entity. >> >> It is a different matter for the board of directors of a company. > > The board of directors are also employees of the company. That's why the > company can fire them. The relationships are a bit more complex than that: The shareholders elect a Board of Directors to represent their interests. The board then hires a management staff, which reports to them. The management staff hires other employees, who report (directly or indirectly) to management. An employee who refuses to act as directed, claiming that he's thinking of the shareholders' interests, can be fired for cause. His only recourse would be to become a shareholder (not hard), and then get the attention of either the board or a large block of shareholders (much harder). If management is actually breaking the law (say by Enron-like looting) rather than simply making decisions he considers suboptimal, he can also go to the authorities, but he does this in his capacity as private citizen; his status as employee gives him no additional rights or responsibilities in this respect. As Axel says, a regular employee has no direct obligations towards the shareholders. From mystilleef at gmail.com Tue Oct 11 06:32:45 2005 From: mystilleef at gmail.com (Mystilleef) Date: 11 Oct 2005 03:32:45 -0700 Subject: Let My Terminal Go In-Reply-To: <1129010288.251817.147690@z14g2000cwz.googlegroups.com> References: <1129010288.251817.147690@z14g2000cwz.googlegroups.com> Message-ID: <1129026765.635156.109690@g43g2000cwa.googlegroups.com> Hello, Thanks to all the responders and helpers on the group. I'm learning everyday. Thanks From steven.bethard at gmail.com Fri Oct 21 13:34:05 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Fri, 21 Oct 2005 11:34:05 -0600 Subject: classmethods, class variables and subclassing In-Reply-To: <4357EE59.1000005@bakerjaffe.plus.com> References: <4357EE59.1000005@bakerjaffe.plus.com> Message-ID: Andrew Jaffe wrote: > Hi, > > I have a class with various class-level variables which are used to > store global state information for all instances of a class. These are > set by a classmethod as in the following (in reality the setcvar method > is more complicated than this!): > > class sup(object): > cvar1 = None > cvar2 = None > > @classmethod > def setcvar1(cls, val): > cls.cvar1 = val > > @classmethod > def setcvar2(cls, val): > cls.cvar2 = val > > @classmethod > def printcvars(cls): > print cls.cvar1, cls.cvar2 > > > I can then call setcvar on either instances of the class or the class > itself. > > Now, the problem comes when I want to subclass this class. If I override > the setcvar1 method to do some new things special to this class, and > then call the sup.setcvar1() method, it all works fine: > > class sub(sup): > cvar1a = None > > @classmethod > def setcvar1(cls, val, vala): > cls.cvar1a = vala > sup.setcvar1(val) > > @classmethod > def printcvars(cls): > print cls.cvar1a > sup.printcvars() > > This works fine, and sets cvar and cvar2 for both classes. > > However, if I *don't* override the setcvar2 method, but I call > sub.setcvar2(val) directly, then only sub.cvar2 gets set; it is no > longer identical to sup.cvar1! > > In particular, > sub.setcvar1(1,10) > sub.setcvar2(2) > sub.printcvars() > prints > 10 > 1 None > > i.e. sub.cvar1, sub.cvar1a, sub.cvar2= 1 10 2 > but sup.cvar1, cvar2= 1 None I'm not sure if I understand your goal here, but you can get different behavior using super(). py> class sup(object): ... cvar1 = None ... cvar2 = None ... @classmethod ... def setcvar1(cls, val): ... cls.cvar1 = val ... @classmethod ... def setcvar2(cls, val): ... cls.cvar2 = val ... @classmethod ... def printcvars(cls): ... print cls.cvar1, cls.cvar2 ... py> class sub(sup): ... cvar1a = None ... @classmethod ... def setcvar1(cls, val, vala): ... cls.cvar1a = vala ... super(sub, cls).setcvar1(val) ... @classmethod ... def printcvars(cls): ... print cls.cvar1a ... super(sub, cls).printcvars() ... py> sub.setcvar1(1, 10); sub.setcvar2(2); sub.printcvars() 10 1 2 py> sup.printcvars() None None I'm not sure what you want sup.printcvars() to print afterwards. If you want it to print out "1 2" instead of "None None", then what you're trying to do is to set every cvar in every superclass. You'll need to be explicit about this, perhaps something like: py> class sup(object): ... cvar1 = None ... cvar2 = None ... @classmethod ... def setcvar1(cls, val): ... for cls in cls.mro()[:-1]: # search through superclasses ... cls.cvar1 = val ... @classmethod ... def setcvar2(cls, val): ... for cls in cls.mro()[:-1]: # search through superclasses ... cls.cvar2 = val ... @classmethod ... def printcvars(cls): ... print cls.cvar1, cls.cvar2 ... py> class sub(sup): ... cvar1a = None ... @classmethod ... def setcvar1(cls, val, vala): ... for cls in cls.mro()[:-2]: # search through superclasses ... cls.cvar1a = vala ... super(sub, cls).setcvar1(val) ... @classmethod ... def printcvars(cls): ... print cls.cvar1a ... super(sub, cls).printcvars() ... py> sub.setcvar1(1, 10); sub.setcvar2(2); sub.printcvars() 10 1 2 py> sup.printcvars() 1 2 That is, if you want the cvar set on every superclass, you need an assignment statement for every superclass. There's probably a way to factor out the for-loop so you don't have to write it every time, but I haven't thought about it too much yet. Perhaps an appropriate descriptor in the metaclass... STeVe From peter at engcorp.com Sat Oct 15 23:52:06 2005 From: peter at engcorp.com (Peter Hansen) Date: Sat, 15 Oct 2005 23:52:06 -0400 Subject: How to get a raised exception from other thread In-Reply-To: <1129434185.879062.61600@o13g2000cwo.googlegroups.com> References: <1129326320.914350.171460@o13g2000cwo.googlegroups.com> <1129434185.879062.61600@o13g2000cwo.googlegroups.com> Message-ID: themightydoyle at gmail.com wrote: > I also need an answer to this problem. What _is_ the problem? We're still waiting for a clear description from the OP as to what the problem really is. How would you describe what _your_ problem is? > I'm using windows. Throwing an > exception in thread B from thread A using a callback function. > > The function runs, but the thread never actually catches the exception. > The try/except block is in the run() method (over-riden from the > Thread class) Rather than force us all to guess what you are doing wrong, maybe it would be better if you posted a small amount of code that shows the problem. Exceptions raised in threads can definitely be caught in the run() method if the code is written correctly, so that is not in itself an issue. -Peter From kerysso at gmail.com Sun Oct 23 03:33:41 2005 From: kerysso at gmail.com (kery) Date: 23 Oct 2005 00:33:41 -0700 Subject: IDE recommendation please References: <1h4usyj.1ndvf691bu0zvuN%aleaxit@yahoo.com> Message-ID: <1130052821.015256.9630@g49g2000cwa.googlegroups.com> Alex Martelli wrote: > microsnot wrote: > > > ... > > On the Mac, I think the XCode integration you get with PyObjC is > probably best. I know there are plugins for Eclipse but haven't tried > any personally, so it's hard to make suggestions (I'm a dinosaur, and I > prefer to develop with GVim + a command-line tool, such as Python's own > interactive mode...). I'm not sure if BlackAdder (simplest and fastest > to learn) and WingIDE (probably THE one most powerful Python IDE) work > on the Mac (shame on me, as a Python AND Mac enthusiast, for not having > tried them...), but they're surely worth investigating. Ditto for > ActiveState's Komodo tool... > > > Alex Any suggestions for Linux, specifically SuSE or perhaps Red Hat? Thanks in advance, Kery From codecraig at gmail.com Tue Oct 11 14:30:12 2005 From: codecraig at gmail.com (Java and Swing) Date: 11 Oct 2005 11:30:12 -0700 Subject: Wrapper function In-Reply-To: References: <1129052312.444144.142950@g44g2000cwa.googlegroups.com> <3r2c91FhamghU1@uni-berlin.de> <1129053625.591216.116340@z14g2000cwz.googlegroups.com> Message-ID: <1129055412.329565.232630@o13g2000cwo.googlegroups.com> So, I write the C code...as shown previously. Then, I do something like... c:\> python >> from distutils.core import setup, Extension >> >>setup( >> name="DLLTester", >> ext_modules = [Extension("DLLTester", ["test.c"])] >> ) c:\> python setup.py build_ext -i ..is that it? If so, then it's ok that I get those 2 errors when trying to build in visual c++? thanks Robert Kern wrote: > Java and Swing wrote: > > > When I compile, I get two warnings..which are ok. Then when I build my > > DLL I get.. > > > > Linking... > > Creating library Release/MyDLL.lib and object Release/MyDLL.exp > > test.obj : error LNK2001: unresolved external symbol _PyBuildValue > > Release/MyDLL.dll : fatal error LNK1120: 1 unresolved externals > > Error executing link.exe. > > > > MyDLL.dll - 2 error(s), 0 warning(s) > > > > ..Any ideas? > > Are you using distutils to build your extension module? You should be. > > -- > 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 ggrp1.20.martineau at dfgh.net Wed Oct 5 17:43:02 2005 From: ggrp1.20.martineau at dfgh.net (Martin Miller) Date: 5 Oct 2005 14:43:02 -0700 Subject: replacments for stdio? References: <1127477278.036977.189230@g44g2000cwa.googlegroups.com> <1127670588.872596.117560@o13g2000cwo.googlegroups.com> <1128079278.563621.8310@g47g2000cwa.googlegroups.com> Message-ID: <1128548582.759883.326290@g47g2000cwa.googlegroups.com> Ido, I tried Bryan Olson's code [on Windows] from his last post to the "Catching stderr output from graphical apps" thread , and it seemed to work for stdout as well as stderr output. To enable its use with stdout, all I had to do was un-comment the last line in Bryan's post, namely > # sys.stdout = ErrorPipe() and the any stdout output starting would appear in a separate window. Since it's based on Tkinter, and from what Bryan said in his post, I believe it's a fairly portable solution. [Nice work, Bryan!] Best, -Martin Ido.Yehieli at gmail.com wrote: > Thanks martin, > I'll give it a shot as soon as i get back from work! From mrmaple at gmail.com Fri Oct 14 17:06:05 2005 From: mrmaple at gmail.com (Jim) Date: 14 Oct 2005 14:06:05 -0700 Subject: MS Word Outline -> reStructuredText script? In-Reply-To: <1129322010.339492.319420@g49g2000cwa.googlegroups.com> References: <1129319634.407351.27080@z14g2000cwz.googlegroups.com> <1129322010.339492.319420@g49g2000cwa.googlegroups.com> Message-ID: <1129323965.137194.173250@g49g2000cwa.googlegroups.com> I'll look into that. I also found that Open Office can read the .doc file and then saveAs a DocBook xml file. I think DocUtils can parse and write both DocBook and reStructured text, but It'll take me some time to experiment with it. David Mertz has an article that shows reSt -> DocBook, I just need to do the opposite. http://www-128.ibm.com/developerworks/library/x-matters24/?ca=dnt-45 -Jim From stefan.behnel-n05pAM at web.de Wed Oct 12 07:07:35 2005 From: stefan.behnel-n05pAM at web.de (Stefan Behnel) Date: Wed, 12 Oct 2005 13:07:35 +0200 Subject: wrapping single classes in an extension module Message-ID: Hi! In a project, I'm providing an API that is made up by augmenting XML DOM elements with tag specific attributes and methods. These actually operate on the DOM and fulfill the need of making the DOM API more user friendly and domain specific. I currently use PyXML/4DOM and I'm considering moving the project to a different package of XML tools that (in addition to XPath) supports RelaxNG, XSLT, etc. out-of-the-box. My preferred candidate would be lxml (based on libxml2, which supports basically all XML standards), but it is backed by classes written in C, which effectively prohibits my current approach of sticking methods into objects generated by the parser API (the __slots__ problem). I guess I'd have to go for a more general wrapper for the XML API that /replaces/ the respective objects (Elements) by my own subclasses whereever they may occurr, i.e. as return values of various functions, as content of containers that are being passed around, etc. This looks like a lot of work to me... Therefore my question: Can anyone imagine a simpler way of approaching this problem? My main interest is to extend the API of XML handling by my domain specific one to make usable through the same objects. Thanks in advance, Stefan From robert.kern at gmail.com Tue Oct 4 20:41:15 2005 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 04 Oct 2005 17:41:15 -0700 Subject: dictionary interface In-Reply-To: References: Message-ID: Tom Anderson wrote: > On Tue, 4 Oct 2005, Robert Kern wrote: > >>Antoon Pardon wrote: >> >>> class Tree: >>> >>> def __lt__(self, term): >>> return set(self.iteritems()) < set(term.iteritems()) >>> >>> def __eq__(self, term): >>> return set(self.iteritems()) == set(term.iteritems()) >>> >>>Would this be a correct definition of the desired behaviour? >> >>No. >> >>In [1]: {1:2} < {3:4} >>Out[1]: True >> >>In [2]: set({1:2}.iteritems()) < set({3:4}.iteritems()) >>Out[2]: False >> >>>Anyone a reference? >> >>The function dict_compare in dictobject.c . > > Well there's a really helpful answer. Well, *I* thought it was. Maybe not "really" helpful, but certainly a healthy start. > I'm intrigued, Robert - since you > know the real answer to this question, why did you choose to tell the > Antoon that he was wrong, not tell him in what way he was wrong, certainly > not tell him how to be right, but just tell him to read the source, rather > than simply telling him what you knew? Because I *didn't* know. I *still* don't know. I just know that the implementation of __lt__ was wrong as I demonstrated by applying the given algorithm to real dictionaries. I *do* know where to find that information: the source. So I told him absolutely everything that I knew on the subject. I couldn't tell him anything more except by trudging through the details of the source myself, but I'm not particularly interested in learning those details myself, so I didn't bother. What do you want? Personalized Python tutorials delivered by candygram? A detailed comparison of the various partial ordering schemes that could have been used? My first born son? > Still, at least you told him which > file to look in. Yes, I figured it was the polite, helpful thing to do. Apparently, I shouldn't have bothered. > And if he knows python but not C, or gets lost in the > byzantine workings of the interpreter, well, that's his own fault, i > guess. It's certainly not 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 danb_83 at yahoo.com Mon Oct 31 23:20:37 2005 From: danb_83 at yahoo.com (Dan Bishop) Date: 31 Oct 2005 20:20:37 -0800 Subject: Why the nonsense number appears? References: <1130749726.707175.293040@g43g2000cwa.googlegroups.com> Message-ID: <1130818837.615748.151150@g14g2000cwa.googlegroups.com> Steve Horsley wrote: > Ben O'Steen wrote: > > On Mon, October 31, 2005 10:23, Sybren Stuvel said: > >> Ben O'Steen enlightened us with: > >>> Using decimal as opposed to float sorts out this error as floats are > >>> not built to handle the size of number used here. > >> They can handle the size just fine. What they can't handle is 1/1000th > >> precision when using numbers in the order of 1e10. > > > > I used the word 'size' here incorrectly, I intended to mean 'length' > > rather than numerical value. Sorry for the confusion :) > > Sybren is right. The problem is not the length or the size, it's > the fact that 0.039 cannot be represented exactly in binary, in > just the same way that 1/3 cannot be represented exactly in > decimal. They both give recurring numbers. If you truncate those > recurring numbers to a finite number of digits, you lose > precision. And this shows up when you convert the inaccurate > number from binary into decimal representation where an exact > representation IS possible. That's A source of error, but it's only part of the story. The double-precision binary representation of 0.039 is 5620492334958379 * 2**(-57), which is in error by 1/18014398509481984000. By contrast, Johnny Lee's answer is in error by 9/262144000, which is more than 618 billion times the error of simply representing 0.039 in floating point -- a loss of 39 bits. The problem here is catastrophic cancellation. 1130748744.500 ~= 4742703982051328 * 2**(-22) 1130748744.461 ~= 4742703981887750 * 2**(-22) Subtracting gives 163578 * 2**(-22), which has only 18 significant bits. From fredrik at pythonware.com Sun Oct 2 02:44:48 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 2 Oct 2005 08:44:48 +0200 Subject: Background process for ssh port forwarding References: Message-ID: Jesse Rosenthal wrote: > If I end this with 'connection.interact()', I will end up logged in to the > forwarding server. But what I really want is to go on and run rsync to > localhost port 2022, which will forward to my_server port 22. So, how can > I put the ssh connection I set up in hostforward() in the background? > I need to make sure that connection is made before I can run the rsync > command. $ man ssh ... -f Requests ssh to go to background just before command execution. This is useful if ssh is going to ask for passwords or passphrases, but the user wants it in the background. This implies -n. The recommended way to start X11 programs at a remote site is with something like ssh -f host xterm. ... From appumail at gmail.com Thu Oct 6 05:40:14 2005 From: appumail at gmail.com (Murugesh) Date: Thu, 06 Oct 2005 15:10:14 +0530 Subject: Help-log in to a web page In-Reply-To: References: Message-ID: <6x61f.11$nq6.8@news.oracle.com> Murugesh wrote: > > Laszlo Zsolt Nagy wrote: > >> Murugesh wrote: >> >>> Hi all, >>> I'm a newbie to python.I need to login to a webpage after supplying >>> usename and password. >>> >>> import urllib sock = urllib.urlopen("http://xop-pc.main.com") >>> htmlSource = sock.read() >>> sock.close() print >>> htmlSource >>> In the above code how can i supply username and password to that URL. >>> Thanks for you time. >>> >>> >> xop-pc.main.com is not an existing site. >> Can you tell me what kind of authentication method it is using? >> If that is the "basic authentication" (defined the standard HTTP >> protocol) then you need to read this: >> >> http://docs.python.org/lib/urlopener-objs.html >> >> Basically, you need to subclass URLopener or FancyURLopener, and >> overwrite its "prompt_user_passwd" method. >> That method will be then called whenever the server needs >> authentication. >> >> Here is a template for you (untested): >> >> >> from urllib import FancyURLOpener >> class MyOpener(FancyURLOpener): >> def prompt_user_passwd(host,realm): >> return ('myusername','mypassword') >> >> opener = MyOpener({}) >> f = opener.open("http://xop-pc.main.com") >> try: >> html_source = f.read() >> finally: >> f.close() >> >> >> >> Best, >> >> Les >> >> > > I tried to view the source,it has, > .... > .... > src="/em/cabo/images /t.gif" height="80"> align="center" border="0" cellspacing="2" cellpadding="0"> >
title="Required" class="xc">* *User Name pan> width="12"> id="username" class="x4" onkeypress="return > _submitOnEnter(event, 'User');" name="j_username" size="30" > type="text" value="myadmin">
nowrap> class="xc">* Password width="12"> name="j_password" size="30*" autocomplete="off" type="p > ... > ... > > Thanks > Amen > * > * > >> Les, I tried your code and it hangs.I believe the authentication is different from the standard one. Any help will be appreciated. Thanks Amen >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From claird at lairds.us Thu Oct 6 07:08:09 2005 From: claird at lairds.us (Cameron Laird) Date: Thu, 06 Oct 2005 11:08:09 GMT Subject: Can Python replace TCL/Expect References: <1128578298.778640.313900@g49g2000cwa.googlegroups.com> Message-ID: <6ncf13-2ps.ln1@lairds.us> In article , Robert Kern wrote: >xinchenvn at gmail.com wrote: >> Hi >> >> I'm learning Python. I don't know whether Python can do something like >> Expect can do. If yes, please show me how to do it. >> I want to do something automatically: open connection to a ftp server, >> get the welcome message on the screen (not in the packet). I can do it >> easily with Expect but I still don't have any idea with Python. >> If possible, can you introduce me some book or website that I can get >> infor about automation programming with Python > >You'll probably want to take a look at pexpect: > > http://pexpect.sourceforge.net/ . . . 1. Yes. 2. While Pexpect indeed "can do something like Expect", it does NOT have all the facilities and polish of the latter. 3. But very, VERY few of Expect's users are aware of more than a handful of Expect's functions, let alone use them, so it's fair to say that Pexpect does everything Expect does, within the realm of ordinary use. 4. But it sort-of doesn't matter anyway, because, if the goal is (as appears in this case) to work with ftp, there are better ways to work, anyway . From sjsobol at JustThe.net Sat Oct 15 22:17:18 2005 From: sjsobol at JustThe.net (Steve Sobol) Date: Sat, 15 Oct 2005 19:17:18 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> Message-ID: Xah Lee wrote: > Answer: so did the German population thought Jews are morons by > heritage, to the point that Jews should be exterminated from earth. > Apparently, the entire German population cannot be morons, they must be > right. Y'know, I'm Jewish, I have friends who are Holocaust survivors, and I still think you're a complete asshole for even attempting to compare anything Microsoft does to what Hitler did. It trivializes the Holocaust. Fuck off. Please. (There, I said "please.") -- Steve Sobol, Professional Geek 888-480-4638 PGP: 0xE3AE35ED Company website: http://JustThe.net/ Personal blog, resume, portfolio: http://SteveSobol.com/ E: sjsobol at JustThe.net Snail: 22674 Motnocab Road, Apple Valley, CA 92307 From mcfletch at rogers.com Thu Oct 6 20:05:01 2005 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Thu, 06 Oct 2005 20:05:01 -0400 Subject: Merging sorted lists/iterators/generators into one stream of values... In-Reply-To: References: Message-ID: <4345BBAD.9060104@rogers.com> Lasse V?gs?ther Karlsen wrote: >I need to merge several sources of values into one stream of values. All >of the sources are sorted already and I need to retrieve the values from >them all in sorted order. > >In other words: >s1 = [10, 20, 30, 40, 50] >s2 = [15, 25] >s3 = [17, 27, 37] > >for value in ???(s1, s2, s3): > print value > >will print out 10, 15, 17, 20, 25, 27, 30, 37, 40, 50 in that order. > >The sources are cursors retrieving data from several databases, not from >the same server, and there's a potential for a large number of rows from >several of the sources. As such, any method that would load it all into >memory and sort it is no good as it would too much memory. > >Is there a function or whatnot in Python that will do what I want? I >have come up with my own method but since it uses generators I'm not >sure how much overhead there is. Additionally, since the values >retrieved from the cursors will be dictionaries of "fieldname":value >pairs, the method would either need to handle that construct (and be >told what fieldname to sort on), or be able to take a function object to >use for the comparison operation. > >Basically, I'll use my own function for this unless someone can point me >to something that is already available. Couldn't seem to find anything >in the builtin modules but I didn't find glob.glob when I was looking >for how to find filenames either so who knows what it's called :) > >Since I need to deal with a variable list of sources (that is, 2 in one >application, 3 in another and 4-5 in a third), a simple 2-source method >isn't enough but if it's better than what I do for 2 sources then I can >make a wrapper for it, since that's what I do anyway. > > I doubt you'll find a prebuilt one, it's fairly easy to create your own, after all. Generators are fairly fast constructs in Python, btw. Here's what I whipped up in a few minutes: def firstIter( value ): it = iter( value ) try: return it.next(), it except StopIteration, err: return None, None def inorder( comparision, *args ): iterators = [ [value,it] for (value,it) in [ firstIter( arg ) for arg in args ] if it is not None ] iterators.sort() while iterators: yield iterators[0][0] try: value = iterators[0][0] = iterators[0][1].next() except StopIteration, err: iterators.pop(0) else: if len(iterators) > 1 and comparision( value, iterators[1][0]) == 1: iterators.sort() continue if __name__ == "__main__": s1 = [10, 20, 30, 40, 50] s2 = [15, 25] s3 = [17, 27, 37] s4 = [] for value in inorder(cmp, s1, s2, s3, s4): print value Anyway, have fun, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From rvtol+news at isolution.nl Sun Oct 9 15:53:52 2005 From: rvtol+news at isolution.nl (Dr.Ruud) Date: Sun, 9 Oct 2005 21:53:52 +0200 Subject: Jargons of Info Tech industry References: <1124804082_1011@spool6-east.superfeed.net> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <41hhk195gcipfarnqu85ggs606aqi89ea1@4ax.com> <2dadnfArEfWwvdTeRVnzvA@telenor.com> <0trik1ldrtvuhsdvoai4a7h34q7la1pehl@4ax.com> Message-ID: Roedy Green: > (Note that the most > common spam is the Nigerian con and variants which comes as a > non-formatted message.) Don't think that that is true for everybody. For example not for people that are behind central filters that already cope with common spam. -- Affijn, Ruud "Gewoon is een tijger." From codecraig at gmail.com Mon Oct 24 13:38:43 2005 From: codecraig at gmail.com (jas) Date: 24 Oct 2005 10:38:43 -0700 Subject: Read/Write from/to a process In-Reply-To: <1130174674.759464.197470@z14g2000cwz.googlegroups.com> References: <1130163642.868252.148070@g44g2000cwa.googlegroups.com> <1130174259.472124.114790@f14g2000cwb.googlegroups.com> <1130174674.759464.197470@z14g2000cwz.googlegroups.com> Message-ID: <1130175523.594766.207770@g49g2000cwa.googlegroups.com> What about having a thread which reads from subprocess.Popen()'s stdout...instead of read/write, read/write. just always read, and write when needed? any comments on that idea? jas wrote: > actually, i can't check for ">" only because if you a dir, a line can > end with a > but is not the end of the output > > jas wrote: > > Thanks, that is certainly a start. As you mentioned, the "cd" could is > > an issue. > > > > Perhaps checking to see if the line ends with ">" is sufficient? > > > > Dennis Lee Bieber wrote: > > > On 24 Oct 2005 07:20:42 -0700, "jas" declaimed the > > > following in comp.lang.python: > > > > > > > Hi, > > > > I would like to start a new process and be able to read/write from/to > > > > it. I have tried things like... > > > > > > > > import subprocess as sp > > > > p = sp.Popen("cmd.exe", stdout=sp.PIPE) > > > > p.stdin.write("hostname\n") > > > > > > > > however, it doesn't seem to work. I think the cmd.exe is catching it. > > > > > > One: you didn't read any of the "returned" output... > > > > > > Two: the output only seems to be available upon EOF, which means the > > > spawned command processor has to exit first... Though you CAN read one > > > character at a time, and then have to build lines and expected prompt > > > strings... > > > > > > > > > This seems to work: > > > -=-=-=-=-=-=-=-=- > > > import subprocess > > > import os > > > > > > PROMPT = os.getcwd() + ">" > > > > > > def getLine(proc): > > > ld = [] > > > while True: > > > c = proc.stdout.read(1) > > > if c == "\r": continue #skip Windows > > > if c != "\n": ld.append(c) #save all but > > > if c is None or c == "\n" or c == ">": break > > > ln = "".join(ld) > > > return ln > > > > > > p = subprocess.Popen("cmd.exe", stdout=subprocess.PIPE, stdin = > > > subprocess.PIPE) > > > > > > print "**** START of captured output" > > > while True: > > > ln = getLine(p) > > > print ln > > > if ln == PROMPT: break > > > print "**** END of captured output" > > > > > > p.stdin.write("ipconfig\n") > > > print "**** START of captured output" > > > while True: > > > ln = getLine(p) > > > print ln > > > if ln == PROMPT: break > > > print "**** END of captured output" > > > > > > p.stdin.write("dir\n") > > > print "**** START of captured output" > > > while True: > > > ln = getLine(p) > > > print ln > > > if ln == PROMPT: break > > > print "**** END of captured output" > > > > > > p.stdin.write("exit\n") > > > -=-=-=-=-=-=-=-=-=- > > > E:\UserData\Dennis Lee Bieber\My Documents>python script1.py > > > **** START of captured output > > > Microsoft Windows XP [Version 5.1.2600] > > > (C) Copyright 1985-2001 Microsoft Corp. > > > > > > E:\UserData\Dennis Lee Bieber\My Documents> > > > **** END of captured output > > > **** START of captured output > > > ipconfig > > > > > > Windows IP Configuration > > > > > > > > > Ethernet adapter Local Area Connection: > > > > > > Connection-specific DNS Suffix . : > > > IP Address. . . . . . . . . . . . : 192.168.1.100 > > > Subnet Mask . . . . . . . . . . . : 255.255.255.0 > > > IP Address. . . . . . . . . . . . : fe80::211:11ff:fee1:f303%4 > > > Default Gateway . . . . . . . . . : 192.168.1.1 > > > > > > Tunnel adapter Teredo Tunneling Pseudo-Interface: > > > > > > Connection-specific DNS Suffix . : > > > IP Address. . . . . . . . . . . . : > > > 3ffe:831f:4004:1956:0:fbde:bd0a:e50b > > > IP Address. . . . . . . . . . . . : fe80::5445:5245:444f%5 > > > Default Gateway . . . . . . . . . : :: > > > > > > Tunnel adapter Automatic Tunneling Pseudo-Interface: > > > > > > Connection-specific DNS Suffix . : > > > IP Address. . . . . . . . . . . . : fe80::5efe:192.168.1.100%2 > > > Default Gateway . . . . . . . . . : > > > > > > E:\UserData\Dennis Lee Bieber\My Documents> > > > **** END of captured output > > > **** START of captured output > > > dir > > > Volume in drive E is Data > > > Volume Serial Number is 2626-D991 > > > > > > Directory of E:\UserData\Dennis Lee Bieber\My Documents > > > > > > 10/24/2005 09:23 AM > > > . > > > 10/24/2005 09:23 AM > > > .. > > > 07/25/2005 10:39 PM > > > .metadata > > > 10/06/2005 09:54 AM > > > Ada Progs > > > 08/13/2005 02:01 PM > > > Agent Data > > > 10/21/2005 09:29 AM 421,820 apress_offer.pdf > > > 07/03/2005 11:36 AM 132 cp.py > > > 07/17/2005 12:25 PM > > > Cyberlink > > > 07/06/2005 09:32 AM 102,400 db1.mdb > > > 07/26/2005 12:20 AM 26,614 eclipse_code.xml > > > 10/24/2005 01:08 AM > > > Eudora > > > 06/24/2005 08:50 PM 667 fake_oosums.ads > > > 06/24/2005 08:50 PM 695 fake_oosums.ali > > > 09/06/2005 09:01 PM > > > Genealogy > > > 07/13/2005 10:56 PM > > > HomeSite > > > 05/08/2005 01:05 PM > > > Investing > > > 10/21/2005 10:04 PM > > > Java Progs > > > 08/04/2005 10:13 PM 162 main.py > > > 10/11/2005 10:43 PM > > > My Downloads > > > 05/01/2005 10:31 AM > > > My eBooks > > > 04/22/2005 12:09 AM > > > My Music > > > 07/10/2005 11:43 AM > > > My Pictures > > > 06/29/2005 11:55 PM > > > My PSP Files > > > 05/23/2005 09:30 AM > > > My Videos > > > 05/01/2005 12:49 PM > > > Office Documents > > > 06/27/2005 03:19 PM 7,961,778 > > > org.eclipse.jdt.doc.user.I20050627-1435.pdf > > > 06/27/2005 03:19 PM 6,791,109 > > > org.eclipse.platform.doc.user.I20050627-1435.pdf > > > 10/11/2005 10:52 PM 56 oth_tsr_rm_750.ram > > > 07/20/2005 09:32 AM 108,457 parkerred15yc.jpg > > > 09/03/2005 10:36 PM > > > Python Progs > > > 10/20/2005 10:38 PM > > > Quicken > > > 07/10/2005 12:09 PM 3,356,248 results.xml > > > 06/11/2005 12:03 PM 935 Scout_Ship Database.lnk > > > 07/03/2005 12:38 PM > > > Scout_Ship My Documents > > > 10/24/2005 09:23 AM 971 Script1.py > > > 09/25/2005 12:40 PM 1,107 Script1_old.py > > > 08/28/2005 11:47 AM > > > SimpleMu Logs > > > 06/24/2005 08:56 PM 1,201 student_pack.ads > > > 06/24/2005 08:49 PM 1,144 student_pack.ads.0 > > > 06/24/2005 08:56 PM 1,342 student_pack.ali > > > 08/02/2005 11:39 PM 4,096 t.DOC > > > 06/20/2005 10:11 AM 104 t.rx > > > 08/05/2005 08:41 PM 66,452 Untitled-1.tif > > > 08/05/2005 08:41 PM > > > VCheck > > > 10/03/2005 02:58 AM > > > Visual Studio > > > 10/03/2005 02:51 AM > > > Visual Studio 2005 > > > 21 File(s) 18,847,490 bytes > > > 25 Dir(s) 267,162,845,184 bytes free > > > > > > E:\UserData\Dennis Lee Bieber\My Documents> > > > **** END of captured output > > > > > > E:\UserData\Dennis Lee Bieber\My Documents> > > > > > > -=-=-=-=-=-=-=-=- > > > > > > Note that my "getLine()" has to return on either a real EOL, OR on > > > the end of a command prompt ("stuff>"). I also had to initialize the > > > prompt at the start. If someone issued a "cd" command to the subprocess, > > > the prompt would be all out of sequence, and the code would hang. > > > > > > You'll also note that the prompt /ends/ a capture sequence, and the > > > next command is the start of the /next/ capture sequence. > > > > > > -- > > > > ============================================================== < > > > > wlfraed at ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG < > > > > wulfraed at dm.net | Bestiaria Support Staff < > > > > ============================================================== < > > > > Home Page: < > > > > Overflow Page: < From saint.infidel at gmail.com Fri Oct 28 12:16:57 2005 From: saint.infidel at gmail.com (infidel) Date: 28 Oct 2005 09:16:57 -0700 Subject: xml-rpc - adodb - None type - DateTime type In-Reply-To: <1130504075.327403.236240@o13g2000cwo.googlegroups.com> References: <1130504075.327403.236240@o13g2000cwo.googlegroups.com> Message-ID: <1130516217.672739.218850@g49g2000cwa.googlegroups.com> > I can replace all None values with the string 'Null', there's no > problem, but I can't detect the DateTime type object I retrieve from > the database. > > I have something like this: > def xmlrpc_function(): > conn = adodb.NewADOConnection('postgres') > conn.Connect(host,user,password,database) > rs = conn.Exec("select * from table") > result = [] > i = 0 > while not rs.EOF: > row = rs.GetRowAssoc(False) > for key, value in row.items(): > if value==None: > row[key]='Null' > result.append(row) > i = i + 1 > rs.MoveNext() > rs.Close() > > print result > return result > > The problem here is that if row[key] == etc...>, then I don't know what to do for detect it and make the > appropriate change to string. > > Console output: > [{'name': 'Null', 'date': at 1515f60>}] > > If you consult the python manual, you'll see that there's no 'DateTime' > type object, so I can't do something like: > > if value==DateTimeType: > ... > > I only need to know which type of data is a field for make the change > according to what can I pass through the xml-rpc. Well, there is the possibility of passing null values through xml-rpc. I believe there is an optional keyword argument in some of the xmlrpclib functions to allow it. Basically it translates None to in the xml. The DateTime type must be defined somewhere. Is it an adodb type? If so, you could do something like this: if type(value) == adodb.DateTime: ... From pmartin at snakecard.com Fri Oct 21 09:05:20 2005 From: pmartin at snakecard.com (Philippe C. Martin) Date: Fri, 21 Oct 2005 13:05:20 GMT Subject: http/urlib pos/get question (newbie) References: Message-ID: I have found what I needed ... in one of my books :E) regards, Philippe Philippe C. Martin wrote: > Hi, > (I am _very_ new to web programming) > > I am writing a client module (browser plugin) and server module (Python > CGI) that need to exchange information. > > I want the transaction to be intiated when the client accesses the link. > > I need data to go back and forth between the client and the server (cgi > script) with no impact on what the browser shows. > > In the end (when I get the above to work), the server will say OK and the > actual page will appear or NOK and an ERROR page will appear. > > > I'm pretty clear (I think) as to what to do on the javascript (client) > side (XMLHttp) but am not certain if my cgi script must "urlib.open" its > own link in order to open the pipe on its side (there'll be some HTML > GET/POST tag I assume but where is the pipe/socket ?) > > Thanks, > > Philippe From dr.addn at gmail.com Wed Oct 5 05:11:43 2005 From: dr.addn at gmail.com (adDoc's networker Phil) Date: Wed, 5 Oct 2005 02:11:43 -0700 Subject: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please! In-Reply-To: References: Message-ID: <8fd4a2fe0510050211q1b1afba9l88fa2e4bcf256c30@mail.gmail.com> On 10/4/05, Cameron Laird wrote: > > > Python IS "a dot net language" . > . that is the site it was born at; but microsoft has actively adopted it here: IronPython 0.9.2 (9/22/2005) [@] http://www.microsoft.com/downloads/details.aspx?FamilyID=2C649E9E-CF43-41E0-9E22-6E6438924CAA&displaylang=en#additionalInfo Overview IronPython is the codename for an alpha release of the Python programming language for the .NET platform. It supports an interactive interpreter with fully dynamic compilation . It is well integrated with the rest of the framework and makes all .NET libraries easily available to Python programmers. . the active dev site [@] http://www.gotdotnet.com/workspaces/workspace.aspx?id=ad7acff7-ab1e-4bcb-99c0-57ac5a3a9742 . the IronPython mailing list [@] http://lists.ironpython.com/listinfo.cgi/users-ironpython.com -- American Dream Documents http://www.geocities.com/amerdreamdocs/home/ "(real opportunity starts with real documentation) -------------- next part -------------- An HTML attachment was scrubbed... URL: From max at alcyone.com Tue Oct 18 21:40:05 2005 From: max at alcyone.com (Erik Max Francis) Date: Tue, 18 Oct 2005 18:40:05 -0700 Subject: how best to split into singleton and sequence In-Reply-To: References: Message-ID: Randy Bush wrote: > so, i imagine what is happening is the lhs, t,l, is really > (t, (l)), i.e. only two items. > > so how should i have done this readably and simply? Your question isn't at all clear. You're trying to assign a 4-element tuple to two elements. That generates a ValueError. Did you want to only split once at most? Then it's s.split('|', 1). Did you want to assign the first element to the first variable and the rest to the next? Then it's x = s.split('|'); a, b = x[0], x[1:]. -- 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's funny when you think about it / How coincidence rules -- Anggun From luismgz at gmail.com Tue Oct 4 10:35:52 2005 From: luismgz at gmail.com (Luis M. Gonzalez) Date: 4 Oct 2005 07:35:52 -0700 Subject: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please! In-Reply-To: <1128432576.708995.19060@f14g2000cwb.googlegroups.com> References: <1128428885.390019.304730@g43g2000cwa.googlegroups.com> <1128432576.708995.19060@f14g2000cwb.googlegroups.com> Message-ID: <1128436552.877409.296480@g47g2000cwa.googlegroups.com> If you read again my comment, I said "almost" an static version of Python for .NET. That means that it's not a Python implementation, but another language. It takes a lot from python though, and it is aknowledeged by its creator in the first paragraph of its homepage. And if you still feel the need to argue, please don't do it with me, do it with Guido Van Rossum himself, who said that Boo is 95% Python, but statically typed... http://aws.typepad.com/aws/2005/01/amazon_devcon_g_5.html Although he makes clear that he doesn't want python to become Boo. So, we can safely say that Boo is "almost" a static python implementation. Wether you like or not, is another problem, but please, do not insist with your reiterative anti-boo ranting. I'm not a Boo evangelist and I don't think I'm perpetuating any "nonsense". I just made a simple comment in reply to an specific question, and I think this comment is very pertinent. From __peter__ at web.de Sun Oct 30 03:51:39 2005 From: __peter__ at web.de (Peter Otten) Date: Sun, 30 Oct 2005 09:51:39 +0100 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <1130614532.765771.288960@g43g2000cwa.googlegroups.com> <4363f91d$0$2089$edfadb0f@dtext02.news.tele.dk> Message-ID: David Rasmussen wrote: > None of the solutions presented in this thread is nearly as fast as the > > print file("filename", "rb").read().count("\x00\x00\x01\x00") Have you already timed Scott David Daniel's approach with a /large/ blocksize? It looks promising. Peter From joerg.schuster at gmail.com Wed Oct 26 03:35:36 2005 From: joerg.schuster at gmail.com (Joerg Schuster) Date: 26 Oct 2005 00:35:36 -0700 Subject: more than 100 capturing groups in a regex In-Reply-To: References: <1130160675.270886.208420@z14g2000cwz.googlegroups.com> <1130253162.790086.59130@o13g2000cwo.googlegroups.com> Message-ID: <1130312136.411976.118780@o13g2000cwo.googlegroups.com> > if you want to know why 100 is a reasonable and non-random choice, I > suggest checking the RE documentation for "99 groups" and the special > meaning of group 0. I have read everything I found about Python regular expressions. But I am not able to understand what you mean. What is so special about 99? From hauck at gseos.com Tue Oct 25 14:30:49 2005 From: hauck at gseos.com (Tommytrojan) Date: 25 Oct 2005 11:30:49 -0700 Subject: Weird import behavior In-Reply-To: References: <1130260282.027302.49370@g44g2000cwa.googlegroups.com> Message-ID: <1130265049.927710.155050@g44g2000cwa.googlegroups.com> Duncan, thanks for your quick reply. I guess I should have included the output. I thought I was clear in the error description. The problem is that I never assign to 'string'. I only reference it (as the error message correctly states). If you comment out the import statement in the except clause the program runs fine. Now notice that the exception hander never gets executed! Any explanation? From nil at dev.nul Sun Oct 16 08:41:06 2005 From: nil at dev.nul (Christian Stapfer) Date: Sun, 16 Oct 2005 14:41:06 +0200 Subject: Comparing lists References: <1128930699.799657.146210@g47g2000cwa.googlegroups.com> <1128952417.0544cc73190bbbd4e683448c137969c8@teranews> <434ba977@nntp0.pdx.net> <1129216693.445956.155490@g47g2000cwa.googlegroups.com> Message-ID: "Ron Adam" wrote in message news:cTp4f.16180$ae.11317 at tornado.tampabay.rr.com... > Christian Stapfer wrote: > >> This discussion begins to sound like the recurring >> arguments one hears between theoretical and >> experimental physicists. Experimentalists tend >> to overrate the importance of experimental data >> (setting up a useful experiment, how to interpret >> the experimental data one then gathers, and whether >> one stands any chance of detecting systematic errors >> of measurement, all depend on having a good *theory* >> in the first place). Theoreticians, on the other hand, >> tend to overrate the importance of the coherence of >> theories. In truth, *both* are needed: good theories >> *and* carefully collected experimental data. >> >> Regards, >> Christian > > An interesting parallel can be made concerning management of production vs > management of creativity. > > In general, production needs checks and feedback to insure quality, but > will often come to a stand still if incomplete resources are available. > > Where as creativity needs checks to insure production, but in many cases > can still be productive even with incomplete or questionable resources. > The quality may very quite a bit in both directions, but in creative > tasks, that is to be expected. > > In many ways programmers are a mixture of these two. I think I and Steven > use a style that is closer to the creative approach. I get the feeling > your background may be closer to the production style. This diagnosis reminds me of C.G. Jung, the psychologist, who, after having introduced the concepts of extra- and introversion, came to the conclusion that Freud was an extravert whereas Adler an introvert. The point is that he got it exactly wrong... As to the value of complexity theory for creativity in programming (even though you seem to believe that a theoretical bent of mind can only serve to stifle creativity), the story of the discovery of an efficient string searching algorithm by D.E.Knuth provides an interesting case in point. Knuth based himself on seemingly quite "uncreatively theoretical work" (from *your* point of view) that gave a *better* value for the computuational complexity of string searching than any of the then known algorithms could provide. Regards, Christian -- ?It is no paradox to say that in our most theoretical moods we may be nearest to our most practical applications.? - Alfred North Whitehead [and those "practical applications" will likely be most "creative" ones..] From dcrespo at gmail.com Mon Oct 10 14:36:51 2005 From: dcrespo at gmail.com (dcrespo) Date: 10 Oct 2005 11:36:51 -0700 Subject: Send password over TCP connection In-Reply-To: References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> Message-ID: <1128969410.983804.248920@g44g2000cwa.googlegroups.com> I think you said the same as me: Client: Password = "password" h = Hash(Password) h is "GddTHww90lze7vnmxG" (whatever) Sends h over the network to the server. h is a string, so this approach is simply vulnerable. SRP seems to be very good, but because I don't know it well, I think I'll delay it for a while. Thank you From davids at webmaster.com Mon Oct 17 01:36:53 2005 From: davids at webmaster.com (David Schwartz) Date: Sun, 16 Oct 2005 22:36:53 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: "Tor Iver Wilhelmsen" wrote in message news:ufyr1990k.fsf at hotmail.com... > "David Schwartz" writes: >> How is that better? Nothing in your car depends upon what tires you >> have >> on. But all of the rest of the software on your computer is dependent >> upon >> your choice of OS. > Which cars let you install another engine as easily as you can install > a new operating system? Admit the analogy sucks, like all car-computer > analogies invariably do. What? If you install a new operating system, all your existing software stops working. You would encounter precisely analogous problems if you replaced your car's engine. The transmission might no longer fit, for example. I'm not sure why this analogy matters, but it does seem to be pretty accurate. >> I don't really know why and I don't particularly care. I think it has >> a >> lot to do with support costs and may also have to do with the type of >> deals >> Microsoft offers. > Microsoft apologists always assume that training cost for Windows > users are zero, that people "know" Windows from the start. If that was > true, there would not be a multi-million market in Windows user > support. I neither said nor assumed that. The fact is, they have to support Windows because it's what most of their users want. So whatever that costs, they have to pay it. I think it's pretty low, actually, only because their solution to any problem is to reinstall. Yes, that works, but it does kind of screw over the user. On the other hand, supporting Linux is not something they have to do to stay competitive. The market for Linux desktops is small. It's better served by niche companies that can grab a larger share of the smaller market. >> The point is, they do. And there's nothing unusual, immoral, or >> problemmatic about it. If you don't think the total package is worth the >> total package price, buy elsewhere. > But when Microsoft were doing their illegal arm-wringing of dealers, > there was no "elsewhere" to go. There were always other places to go. There was never a time in this story when you couldn't buy computer components, without an OS, and put together your own computer. As for it being illegal, it was illegal only because if was Microsoft doing it. There's nothing illegal about a car dealer not selling a car without an engine. And the only reason it was illegal for Microsoft was because Microsoft was deemed to have a monopoly, and the only reason they were deemed to have a monopoly (well, not the only, but a major reason) was that the market was defined as "desktop operating systems for x86 computers". DS From bokr at oz.net Tue Oct 25 20:48:15 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 26 Oct 2005 00:48:15 GMT Subject: Read/Write from/to a process References: <1130163642.868252.148070@g44g2000cwa.googlegroups.com> <1130174259.472124.114790@f14g2000cwb.googlegroups.com> <1130242940.918480.65020@f14g2000cwb.googlegroups.com> Message-ID: <435ec58d.961797972@news.oz.net> On Tue, 25 Oct 2005 17:32:28 GMT, Dennis Lee Bieber wrote: >On 25 Oct 2005 05:22:20 -0700, "jas" declaimed the >following in comp.lang.python: > >> So it seems there is no good way to handle "interactive" processes on >> windows using python. By interactive I mean processes/commands that >> require user interaction, such as telnet or del (to delete a file or >> directory sometimes you need to confirm with a yes or no), date, etc. >> > telnetlib includes an "expect" method... > >> os.system gives the exact behavior, but you can't redirec the output. >> pexpect isn't supported on windows. Even with subprocess you can't >> handle all/most cases..since you have to do things like look for he >> prompt. > > That applies to any OS... If you have no IPC signalling mechanism >that the other process has completed an output phase and is now waiting >for input, you must scan for whatever is the "current" prompt. Even an >"expect" module is "expecting" to find something you had to specify in >advance. > > Heck... How do YOU recognize that an application running in a >command window is waiting for input? > > I suspect you do it by reading the output text and recognizing that >the cursor is on a line that looks like a prompt. The main difference is >that you have cognitive understanding of what IS the prompt, and can >recognize the differences between, say an [abort, retry, exit] prompt >and c:\junk> prompt. To programmatically handle this situation, you have >to code the logic to recognize the two possible prompts. > If I were going to do something on windows, I think I would look at creating a cmd.exe process and see if I could get ahold of its console by way of the windows console-related api, or I might try to write a limited shell of my own, but I'm not going to do it just for fun ;-) NT and descendants have all sorts of stuff for waiting for things and communicating etc. if you want to get down to the raw stuff, e.g., ---- GetQueuedCompletionStatus QuickInfo Overview Group The GetQueuedCompletionStatus function attempts to dequeue an I/O completion packet from a specified input/output completion port. If there is no completion packet queued, the function waits for a pending input/output operation associated with the completion port to complete. The function returns when it can dequeue a completion packet, or optionally when the function times out. If the function returns because of an I/O operation completion, it sets several variables that provide information about the operation. BOOL GetQueuedCompletionStatus( HANDLE CompletionPort, // the I/O completion port of interest LPDWORD lpNumberOfBytesTransferred, // to receive number of bytes transferred during I/O LPDWORD lpCompletionKey, // to receive file's completion key LPOVERLAPPED * lpOverlapped, // to receive pointer to OVERLAPPED structure DWORD dwMilliseconds // optional timeout value ); Parameters CompletionPort Handle to the input/output completion port of interest. Use the CreateIoCompletionPort function to create I/O completion ports. lpNumberOfBytesTransferred Points to a variable that the function sets to the number of bytes transferred during an I/O operation that has completed and is causing the function to return. lpCompletionKey Points to a variable that the function sets to the completion key value associated with the file handle whose I/O operation has completed and is causing the function to return. A completion key is a per-file key that is specified in a call to CreateIoCompletionPort. lpOverlapped Points to a variable that the function sets to the address of the OVERLAPPED structure that was specified when an input/output operation that has completed was started. The following functions can be used to start input/output operations that complete using I/O completion ports. You must pass the function an OVERLAPPED structure and a file handle associated (by a call to CreateIoCompletionPort) with an I/O completion port to invoke the I/O completion port mechanism: ? ConnectNamedPipe ? DeviceIoControl ? LockFileEx ? ReadFile ? TransactNamedPipe ? WaitCommEvent ? WriteFile Even if both of the preceding conditions (passing the function a file handle associated with a completion port and a valid OVERLAPPED structure) are met, an application can prevent completion port notification. To do this, specify a valid event handle for the hEvent member of the OVERLAPPED structure, and set the low order bit of that event handle. A valid event handle whose low order bit is set keeps I/O completion from being queued to the completion port. dwMilliseconds Specifies the number of milliseconds that the caller is willing to wait for an input/output completion packet to appear at the I/O completion port. If a completion packet doesn't appear within the specified time, the function times out, returns FALSE, and sets *lpOverlapped to NULL. Timing out is optional. If dwMilliseconds is -1, the function will never time out. If dwMilliseconds is zero and there is no I/O operation to dequeue, the function will timeout immediately. Return Value The GetQueuedCompletionStatus function's return value is TRUE if the function dequeues an I/O completion packet for a successful I/O operation from the completion port. The function stores valid values into the variables pointed to by lpNumberOfBytesTransferred, lpCompletionKey, and lpOverlapped. The function's return value is FALSE, and *lpOverlapped is set to NULL, if the function does not dequeue an I/O completion packet from the completion port. The function does not store valid values into the variables pointed to by lpNumberOfBytesTransferred and lpCompletionKey. To get extended error information, call GetLastError. The function's return value is FALSE, and *lpOverlapped is not NULL, if the function dequeues an I/O completion packet for a failed I/O operation from the completion port. The function stores valid values into the variables pointed to by lpNumberOfBytesTransferred, lpCompletionKey, and lpOverlapped. To get extended error information, call GetLastError. Remarks The Win32 I/O system can be instructed to send I/O completion notification packets to input/output completion ports, where they are queued up. The CreateIoCompletionPort function provides a mechanism for this. When you perform an input/output operation with a file handle that has an associated input/output completion port, the I/O system sends a completion notification packet to the completion port when the I/O operation completes. The I/O completion port places the completion packet in a first-in-first-out queue. The GetQueuedCompletionStatus function retrieves these queued I/O completion packets. A server application may have several threads calling GetQueuedCompletionStatus for the same completion port. As input operations complete, the operating system queues completion packets to the completion port. If threads are actively waiting in a call to this function, queued requests complete their call. You can call the PostQueuedCompletionStatus function to post an I/O completion packet to an I/O completion port. The I/O completion packet will satisfy an outstanding call to the GetQueuedCompletionStatus function. See Also ConnectNamedPipe, CreateIoCompletionPort, DeviceIoControl, LockFileEx, OVERLAPPED, ReadFile, PostQueuedCompletionStatus, TransactNamedPipe, WaitCommEvent, WriteFile, ---- And then there is the console stuff, ---- Following are the functions used to access a console. AllocConsole CreateConsoleScreenBuffer FillConsoleOutputAttribute FillConsoleOutputCharacter FlushConsoleInputBuffer FreeConsole GenerateConsoleCtrlEvent GetConsoleCP GetConsoleCursorInfo GetConsoleMode GetConsoleOutputCP GetConsoleScreenBufferInfo GetConsoleTitle GetLargestConsoleWindowSize GetNumberOfConsoleInputEvents GetNumberOfConsoleMouseButtons GetStdHandle HandlerRoutine PeekConsoleInput ReadConsole ReadConsoleInput ReadConsoleOutput ReadConsoleOutputAttribute ReadConsoleOutputCharacter ScrollConsoleScreenBuffer SetConsoleActiveScreenBuffer SetConsoleCP SetConsoleCtrlHandler SetConsoleCursorInfo SetConsoleCursorPosition SetConsoleMode SetConsoleOutputCP SetConsoleScreenBufferSize SetConsoleTextAttribute SetConsoleTitle SetConsoleWindowInfo SetStdHandle WriteConsole WriteConsoleInput WriteConsoleOutput WriteConsoleOutputAttribute WriteConsoleOutputCharacter ---- And that is a miniscule piece of it all. For sychronizing, there ought to be something in: --- Following are the functions used in synchronization. CreateEvent CreateMutex CreateSemaphore DeleteCriticalSection EnterCriticalSection GetOverlappedResult InitializeCriticalSection InterlockedDecrement InterlockedExchange InterlockedIncrement LeaveCriticalSection MsgWaitForMultipleObjects OpenEvent OpenMutex OpenSemaphore PulseEvent ReleaseMutex ReleaseSemaphore ResetEvent SetEvent WaitForMultipleObjects WaitForMultipleObjectsEx WaitForSingleObject WaitForSingleObjectEx BTW, """ The CreateFile function creates, opens, or truncates a file, pipe, communications resource, disk device, or console. It returns a handle that can be used to access the object. It can also open and return a handle to a directory. """ So it seems likely someone has put together most of the pieces already, just maybe not wrapped in a python API ;-) Regards, Bengt Richter From steven.bethard at gmail.com Mon Oct 24 11:59:43 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Mon, 24 Oct 2005 09:59:43 -0600 Subject: Tricky Areas in Python In-Reply-To: <1h4xfdx.azxzrkhr5xukN%aleaxit@yahoo.com> References: <1130097286.772836.94930@g44g2000cwa.googlegroups.com> <1h4wbvb.1dblc4317zeuw2N%aleaxit@yahoo.com> <435CA1DE.2060101@REMOVEMEcyber.com.au> <1h4xfdx.azxzrkhr5xukN%aleaxit@yahoo.com> Message-ID: <9vmdnZBDS6NwmcDeRVn-3w@comcast.com> Alex Martelli wrote: > >>> class Base(object) >>> def getFoo(self): ... >>> def setFoo(self): ... >>> foo = property(getFoo, setFoo) >>> >>> class Derived(Base): >>> def getFoo(self): .... >> [snip] > the solution, in Python 2.4 and earlier, is to use > one extra level of indirection: > def __getFoo(self): return self.getFoo() > def getFoo(self): ... > foo = property(__getFoo) > so the name lookup for 'getFoo' on self happens when you access s.foo > (for s being an instance of this here-sketched class) and overriding > works just as expected. Another solution (for those of you scoring at home) would be to use a property-like descriptor that delays the name lookup until the time of the method call, e.g. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/442418 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/408713 STeVe From grante at visi.com Sat Oct 8 15:55:54 2005 From: grante at visi.com (Grant Edwards) Date: Sat, 08 Oct 2005 19:55:54 -0000 Subject: new forum -- homework help/chit chat/easy communication References: <1128798687.305818.66010@g49g2000cwa.googlegroups.com> Message-ID: <11kg92ams62oo9f@corp.supernews.com> On 2005-10-08, csheppard91 at gmail.com wrote: > I've launched a new forum not too long ago, and I invite you all to go > there: www.wizardsolutionsusa.com (click on the forum link). We offer > all kinds of help, and for those of you who just like to talk, there's > a chit chat section just for you...Just remember that forum > communication is much easier, safer, and faster. I disagree 100% with that last assertion. Usenet is much, much, easier, safer and faster. -- Grant Edwards grante Yow! BARRY... That was at the most HEART-WARMING visi.com rendition of "I DID IT MYWAY" I've ever heard!! From john at castleamber.com Sun Oct 16 23:18:48 2005 From: john at castleamber.com (John Bokma) Date: 17 Oct 2005 03:18:48 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: Steven D'Aprano wrote: > On Sun, 16 Oct 2005 14:57:19 +0000, John Bokma wrote: > >> As soon as products can't evolve >> much more, the producers will find ways to make them even better >> compared to last week. > > So once a product can't evolve any more, then it will suddenly > start evolving much more. > > Riiiiight. Yup, maybe you should do some shopping instead of letting others do it for you. And you will notice that almost every X months the cookies of brand X are just improved a bit more. > Well, I think that's just demonstrated the quality of John's reasoning > ability. I am sorry if it's all beyond you. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From hancock at anansispaceworks.com Tue Oct 25 11:10:39 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Tue, 25 Oct 2005 10:10:39 -0500 Subject: [OT] Re: output from external commands In-Reply-To: <200510241904.52917.bulliver@badcomputer.org> References: <435C6642.8020504@colannino.org> <200510241904.52917.bulliver@badcomputer.org> Message-ID: <200510251010.39092.hancock@anansispaceworks.com> On Monday 24 October 2005 09:04 pm, darren kirby wrote: > quoth the Fredrik Lundh: > > (using either on the output from glob.glob is just plain silly, of course) > > Silly? Sure. os.listdir() is more on point. Never said I was the smartest. > However, I will defend my post by pointing out that at the time it was the > only one that actually included code that did what the OP wanted. I think Mr. Lundh's point was only that the output from glob.glob is already guaranteed to be strings, so using either '%s'%f or str(f) is superfluous. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From chrisgarland67 at hotmail.com Mon Oct 3 23:10:22 2005 From: chrisgarland67 at hotmail.com (Cigar) Date: 3 Oct 2005 20:10:22 -0700 Subject: Controlling who can run an executable Message-ID: <1128395422.904212.318930@g44g2000cwa.googlegroups.com> I am developing a program for a client. She runs a shop where her clients bring in items for sale or short term buyback. Development of the program has been going great but she's mentioned that there is a 'feature' coming up in the next couple of weeks that she'd like me to implement that has me a bit worried. My client has told me a story of how she hired someone from a competing store and that person had brought a copy of the program her competition was using to track clients and transactions. He couldn't demonstrate the program for one reason or another because it was protected in a way that neither could circumvent. (She didn't remember how it was protected, she had hired this person a long time ago.) Now that I'm three months into the development of this program, my client tells me she would like to protect her investment by preventing her employees from doing the same to her. (Going to the competition and using her program.) What my client cannot prevent: - access to the .exe What my client is looking to prevent: - running of the exe by un-authorized individuals. Ideas I've had to prevent someone from running the app: - ask for a password every time the program is run. (I wonder how quickly they will complain about this, not very secure once everyone eventually finds out what the password is) - make a little hardware dongle and check to see if it's on the parallel port. (old idea) - check for an encrypted flash drive and try to read an encrypted file from it. (new idea) - buy the client a Microsoft Fingerprint Keyboard and figure out if it will make the clients life easier (two minutes of research showed this idea has multiple problems) What I want: - the simplest thing that could possibly work! I guess my problem isn't really a python problem. This is a scenario that any developer in any language might face where an executable should only be run by approved individuals. c.l.p searches I've tried: 'protecting code' - details how to make python files 'unreadable' 'preventing execution' - best one here details encrypting a root password Thanks From pwatson at redlinepy.com Mon Oct 31 09:13:26 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Mon, 31 Oct 2005 08:13:26 -0600 Subject: Scanning a file In-Reply-To: <1h597yx.wjk2a71spyjhyN%aleaxit@yahoo.com> References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <87ek65kbw5.fsf@lucien.dreaming> <1h5760l.1e2eatkurdeo7N%aleaxit@yahoo.com> <3siakvFohl3aU1@individual.net> <1h57cij.16dkc141lds4s4N%aleaxit@yahoo.com> <1h597yx.wjk2a71spyjhyN%aleaxit@yahoo.com> Message-ID: <3smn47FoolfbU1@individual.net> Alex Martelli wrote: ... >>>>gc.garbage > > [<__main__.a object at 0x64cf0>, <__main__.b object at 0x58510>] > > So, no big deal -- run a gc.collect() and parse through gc.garbage for > any instances of your "wrapper of file" class, and you'll find ones that > were forgotten as part of a cyclic garbage loop and you can check > whether they were explicitly closed or not. > > > Alex Since everyone needs this, how about building it in such that files which are closed by the runtime, and not user code, are reported or queryable? Perhaps a command line switch to either invoke or suppress reporting them on exit. Is there any facility for another program to peer into the state of a Python program? Would this be a security problem? From steve at holdenweb.com Thu Oct 20 17:17:28 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 20 Oct 2005 22:17:28 +0100 Subject: classmethods, class variables and subclassing In-Reply-To: <4357EE59.1000005@bakerjaffe.plus.com> References: <4357EE59.1000005@bakerjaffe.plus.com> Message-ID: Andrew Jaffe wrote: > Hi, > > I have a class with various class-level variables which are used to > store global state information for all instances of a class. These are > set by a classmethod as in the following (in reality the setcvar method > is more complicated than this!): > > class sup(object): > cvar1 = None > cvar2 = None > > @classmethod > def setcvar1(cls, val): > cls.cvar1 = val > > @classmethod > def setcvar2(cls, val): > cls.cvar2 = val > > @classmethod > def printcvars(cls): > print cls.cvar1, cls.cvar2 > > > I can then call setcvar on either instances of the class or the class > itself. > > Now, the problem comes when I want to subclass this class. If I > override the setcvar1 method to do some new things special to this > class, and then call the sup.setcvar1() method, it all works fine: > > class sub(sup): > cvar1a = None > > @classmethod > def setcvar1(cls, val, vala): > cls.cvar1a = vala > sup.setcvar1(val) > > @classmethod > def printcvars(cls): > print cls.cvar1a > sup.printcvars() > > This works fine, and sets cvar and cvar2 for both classes. > > However, if I *don't* override the setcvar2 method, but I call > sub.setcvar2(val) directly, then only sub.cvar2 gets set; it is no > longer identical to sup.cvar1! > > In particular, > sub.setcvar1(1,10) > sub.setcvar2(2) > sub.printcvars() > prints > 10 > 1 None > > i.e. sub.cvar1, sub.cvar1a, sub.cvar2= 1 10 2 > but sup.cvar1, cvar2= 1 None > > since sup.cvar2 has never been set, and this is what sup.printcvars() > looks for. > > This behavior is "expected", but is it desirable? > > For my application, at least, I think the problem really comes in the > printcvars method: is there any way to call the overridden > sup.printcvars() but with, effectively, cls=sub? > > Thanks for reading this far! > > Andrew > > > Andrew > > > > > This seems like a bug > > Is this expected behavior, or a bug (or both -- it is expected but > probably not what is wanted!)? You are experiencing this problem because you are using hard-wired class names. Try using (for example) self.__class__. That way, even if your method is inheroted by a subclass it will use the class of the object it finds itself a method of. No need to use classmethods. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From alainpoint at yahoo.fr Fri Oct 7 10:33:22 2005 From: alainpoint at yahoo.fr (alainpoint at yahoo.fr) Date: 7 Oct 2005 07:33:22 -0700 Subject: Python interpreter bug In-Reply-To: <1128694740.418262.95470@g44g2000cwa.googlegroups.com> References: <1128686833.994339.295780@f14g2000cwb.googlegroups.com> <1128692705.964188.5720@z14g2000cwz.googlegroups.com> <1128694740.418262.95470@g44g2000cwa.googlegroups.com> Message-ID: <1128695602.718637.144720@g43g2000cwa.googlegroups.com> In fact, i want to sort the list based on the 'allocated attribute' and at the same time, test membership based on the id attribute. __cmp__ logically implies an ordering test, not an identity test. These two notions seems to be confounded in python which is unfortunate. Two objects could have the same rank while still being different. Alain From steve at REMOVETHIScyber.com.au Sun Oct 9 06:32:30 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 09 Oct 2005 20:32:30 +1000 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> Message-ID: On Sun, 09 Oct 2005 00:03:05 +0200, Lasse V?gs?ther Karlsen wrote: > Now, if you want to get into a big huff because someone you knows use a > font that is "slightly oversized" because of Windows, then I think you > missed the point of the email altogether, which was probably to convey a > message. Talk about missing the point, pun intended. The point isn't that there is some tiny difference in font sizes. It is that small font sizes which are just readable under Windows are unreadably small on Linux and Mac. If you want to convey a message, it helps if the recipient can actually read the damn thing without having to get out a magnifying glass. -- Steven. From malvert at telenet.be Wed Oct 12 09:28:33 2005 From: malvert at telenet.be (malv) Date: 12 Oct 2005 06:28:33 -0700 Subject: searching python/gui developper in germany References: Message-ID: <1129123713.193715.60780@g14g2000cwa.googlegroups.com> Hans Georg Krauthaeuser wrote: > Dear all, > > for the measurements in our labs we have developed python scripts that > are pretty fine for our needs. Basically, we have classes and call the > appropriate methods from the command line (or by other scripts). So, we > don't have any GUI. > > Now, an external customer want to use our software and -- as you can > imagine -- we want a pretty GUI. > > So, we are looking for someone who can develop such a pretty GUI for us > (of course for money). OS is Windows (XP). We are not fixed to a special > toolkit -- it just should look nice and do the job. > > Best would be someone from our region (Magdeburg, Germany). > > If someone is interested: contact me by email, please. > > Best regards > Hans Georg Krauthaeuser http://www.die-offenbachs.de/detlev/eric3.html If you run SuSE9.3 or SuSE 10.0, everything is there. Simply install eric or eric3. There is also a great gui design utility in the installation. You'll be going in no time. malv From paniq at paniq-dot-org.no-spam.invalid Sat Oct 15 09:10:08 2005 From: paniq at paniq-dot-org.no-spam.invalid (paniq) Date: 15 Oct 2005 13:10:08 GMT Subject: p2exe using wine/cxoffice References: Message-ID: <4350ffb0$0$52182$892e7fe2@authen.white.readfreenews.net> the problem you have comes from a badly wrapped imagehlp. i could solve it by starting winecfg (distributed with recent wine releases) and adding imagehlp as native,builtin. of course you need a native dll to get this working. From fredrik at pythonware.com Wed Oct 5 03:29:34 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 5 Oct 2005 09:29:34 +0200 Subject: Help needed in OOP-Python References: Message-ID: Toufeeq Hussain wrote: > My coding is really really bad,that's why I changed the names to more human > readable form(Module1,2.. etc). the problem is that when you do that (and post using a tool that's not smart enough to preserve leading whitespace), anyone who wants to help will basically have to recreate your program -- and once they've done that, chances are that they won't get the same error as you do. consider this: $ python test.py Traceback (most recent call last): File "test.py", line 1, in ? import module3 File "module3.py", line 4, in ? class Option1_Rule1(declaration.Option1): NameError: name 'declaration' is not defined oops. looks like you forgot to rename something. that's easy to fix. $ python test.py Traceback (most recent call last): File "test.py", line 3, in ? Test_Case = module3.Option1_Rule1() File "module3.py", line 6, in __init__ module2.Option1.__init__(self) File "module2.py", line 5, in __init__ module1.OptionClass.__init__('Blah Blah','OR0001','0000','0000') TypeError: unbound method __init__() must be called with OptionClass instance as first argument (got str instance instead) aha. that sure looks like a bug. when you call the baseclass init method, you must pass in the object instance as the first argument. that's easy to fix. $ python test.py Traceback (most recent call last): File "test.py", line 4, in ? Test_Case.Option1_constraint() AttributeError: Option1_Rule1 instance has no attribute 'Option1_constraint' oops. looks like I got the indentation wrong when I fixed up that module. that's easy to fix. $ python test.py condition satisfied Traceback (most recent call last): File "test.py", line 4, in ? Test_Case.Option1_constraint() File "module3.py", line 11, in Option1_constraint self.FOO_warning.Fire() AttributeError: Option1_Rule1 instance has no attribute 'FOO_warning' FOO_warning? there's no FOO_warning anywhere in the code. ::: so, after four attempts, I've found four problems, three of which was present in your posted code, but I still haven't seen the problem you reported: Traceback (most recent call last): File "test_case.py", line 7, in ? TH = constraint.Option1_Rule1() File "constraint.py", line 13, in __init__ declaration.Option1.__init__(self) TypeError: __init__() takes no arguments (1 given) which, in itself, looks like you've forgotten the self argument in some init method somewhere (but the code you posted doesn't have that problem). if you want to post code, 1) try to reduce the problem to as little code as you possibly can, and 2) make sure that the code you post really has the problem you're seeing... (i.e. run it at least once before you post it) From grante at visi.com Fri Oct 7 10:18:21 2005 From: grante at visi.com (Grant Edwards) Date: Fri, 07 Oct 2005 14:18:21 -0000 Subject: When someone from Britain speaks, Americans hear a "British accent"... References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kbgj7421kd560@corp.supernews.com> <4h5ck1hkqq0ls83pq0lodkb51tsda4053k@4ax.com> Message-ID: <11kd0td8spouu96@corp.supernews.com> On 2005-10-07, DaveM wrote: >>For example: In British English one uses a plural verb when the >>subject consists of more than one person. Sports teams, >>government departments, states, corporations etc. are >>grammatically plural. In American, the verb agrees with the >>word that is the subject, not how many people are denoted by >>that word. >> >>In sports (thats "sport" for you Brits): > > Yes. > >> American: Minnesota is behind 7-0. The Vikings are behind 7-0. >> British: Minnesota are behind 7-0. The Vikings are behind 7-0. > > True. > >>In politics: > >> American: The war department has decided to cancel the program. >> British: The war department have decided to cancel the program. > > Not sure about this one. They may be used interchangeably as neither strikes > me as sounding "odd". It could be that both are used in British English and I only notice the "have" usage. In US English it's always "has" because "deptartment" is considered singular: "departement has" and "departements have" For some reason I find this sort of thing fascinating enough to have download the entire "story of English" series off Usenet... -- Grant Edwards grante Yow! Yow! Now we can at become alcoholics! visi.com From spammers-go-here at spam.invalid Wed Oct 12 15:53:37 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Wed, 12 Oct 2005 15:53:37 -0400 Subject: Force flushing buffers References: <4345b6e8$0$49009$14726298@news.sunsite.dk> Message-ID: <434d699f$0$49009$14726298@news.sunsite.dk> skip at pobox.com wrote: > > Madhusudan> How do I flush the buffer and force python to write the > Madhusudan> buffers to the files ? I intend to put this inside the > loop. > > f = open("somefile", "w") > f.write("foo") > f.flush() > > Skip Thanks !! From dudufigueiredo at gmail.com Mon Oct 31 15:06:45 2005 From: dudufigueiredo at gmail.com (dudufigueiredo at gmail.com) Date: 31 Oct 2005 12:06:45 -0800 Subject: Rename files with numbers In-Reply-To: References: <1130776390.085587.116270@g43g2000cwa.googlegroups.com> <1130784747.373637.108040@g14g2000cwa.googlegroups.com> Message-ID: <1130789205.862429.10090@g43g2000cwa.googlegroups.com> Micah, thanks a lot, but my focus is to learn how to acess a folder and rename all files in this folder. Somyhing like this: def renamer(folder, band): folder = #place to act archive = #file to transform rest = archive[3:] print band + " -", rest.capitalize() And than just do this: renamer('C:\My Shared Folder\Rubber Soul', 'The Beatles') And than pyhton alter all files in my folder. Is it possible? I'm a beginer, for now, i just want to let the spaces and apostrophes as they are... From sxn02 at yahoo.com Mon Oct 17 15:20:10 2005 From: sxn02 at yahoo.com (Sori Schwimmer) Date: Mon, 17 Oct 2005 12:20:10 -0700 (PDT) Subject: Upgrading 2.4.1 to 2.4.2 Message-ID: <20051017192011.28785.qmail@web50206.mail.yahoo.com> Hi, I have Python 2.4.1 and have downloaded 2.4.2. Is there a way to avoid installing everything and, instead, just upgrade? Thanks, Sorin __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com From fredrik at pythonware.com Tue Oct 4 01:49:02 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 4 Oct 2005 07:49:02 +0200 Subject: Where to find python c-sources References: <433e7898$0$49766$ed2e19e4@ptn-nntp-reader04.plus.net><43417009$0$15070$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: Peter Hansen wrote: > Sorry, but this defense is less than weak. Using "python > socketmodule.c" you actually get the right answer as the third result, > while with the even-more-obvious-to-a-rookie "socketmodule.c" you get it > as the *first* result. using just "python" gives you a link to the source code download page as part of the first result. From steve at holdenweb.com Mon Oct 24 15:15:48 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 24 Oct 2005 20:15:48 +0100 Subject: Would there be support for a more general cmp/__cmp__ In-Reply-To: <200510241159.53032.jstroud@mbi.ucla.edu> References: <200510241159.53032.jstroud@mbi.ucla.edu> Message-ID: James Stroud wrote: > On Monday 24 October 2005 04:33, Steve Holden wrote: > >>Well in that case it's time to declare Principia Mathematica obsolete. >>The real numbers are a two-dimensional field, and you are proposing to >>define an ordering for it. > > > I wasn't a math major, but don't you mean "the complex numbers are a two > dimensional field"? > Correct. > If you mean real numbers, please do explain. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From tim.golden at viacom-outdoor.co.uk Wed Oct 26 13:36:29 2005 From: tim.golden at viacom-outdoor.co.uk (Tim G) Date: 26 Oct 2005 10:36:29 -0700 Subject: Windows vs Linux [was: p2exe using wine/cxoffice] In-Reply-To: References: Message-ID: <1130348189.729657.311500@o13g2000cwo.googlegroups.com> Thomas Heller wrote: > FYI, if you don't know this already: You also can resize the console without > going through the properties menu with 'mode con cols=... lines=...'. Good grief! I haven't used "mode con" in years; forgotten it even existed! Thanks for bringing that back, Thomas. TJG From albalmer at att.net Mon Oct 10 12:55:20 2005 From: albalmer at att.net (Alan Balmer) Date: Mon, 10 Oct 2005 09:55:20 -0700 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> Message-ID: On Sun, 09 Oct 2005 00:03:05 +0200, Lasse V?gs?ther Karlsen wrote: >In any case, html email is here to stay. Or perhaps I should remove html >and say "richly formatted", whatever that might mean in the future. > >But trying to keep your email world into a pure text-based >no-formatting-whatsoever world, that's a fantasy bubble that is bound to >burst, sooner rather than later. > >Deal with it. And you're calling other people control freaks! Sorry to burst *your* bubble, but no one has to "deal with it." For centuries, intelligent people have managed to convey information using plain text, and they'll manage for the foreseeable future. I'm surprised that you can bring yourself to write articles in such a humble venue as Usenet. -- Al Balmer Balmer Consulting removebalmerconsultingthis at att.net From petr at tpc.cz Tue Oct 18 17:55:48 2005 From: petr at tpc.cz (McBooCzech) Date: 18 Oct 2005 14:55:48 -0700 Subject: Dealing with Excel References: <1129670191.061006.146320@g47g2000cwa.googlegroups.com> Message-ID: <1129672548.082627.35180@g47g2000cwa.googlegroups.com> Robert Hicks wrote: > I need to pull data out of Oracle and stuff it into an Excel > spreadsheet. What modules have you used to interface with Excel and > would you recommend it? It is possible to control Excel directly from the Python code (you do not need to write Excel macros within the Excel). It works flawlessly for me. My code goes for example: import win32api from win32com.client import Dispatch xlApp = Dispatch("Excel.Application") xlApp.Visible=0 xlApp.Workbooks.Add() . . === snip === It is helpful to find values of VBA (Visual Basic for Applications) constants on the Internet or in the Excel documentation and this constants values assign as Python constants with the same names as in VBA in the code. For example: xlToLeft = 1 xlToRight = 2 xlUp = 3 xlDown = 4 xlThick = 4 xlThin = 2 xlEdgeBottom=9 Than you can use exactly the same code as in your Excel macros (including formating etc.). === snip === xlApp.Range(xlApp.Selection, xlApp.Selection.End(xlToRight)).Select() xlApp.Range(xlApp.Selection, xlApp.Selection.End(xlDown)).Select() xlApp.Selection.NumberFormat = "# ##0" xlApp.Selection.HorizontalAlignment = xlRight xlApp.Selection.IndentLevel = 1 === snip === HTH Petr Jakes From david at jotax.com Tue Oct 25 11:51:08 2005 From: david at jotax.com (David Poundall) Date: 25 Oct 2005 08:51:08 -0700 Subject: Tricky import question. In-Reply-To: <1130253287.721535.322370@g47g2000cwa.googlegroups.com> References: <1130247555.359770.169070@o13g2000cwo.googlegroups.com> <1130253287.721535.322370@g47g2000cwa.googlegroups.com> Message-ID: <1130255468.174460.227300@f14g2000cwb.googlegroups.com> This worked ... def my_import(name): mod = __import__(name) components = name.split('.') for comp in components[1:]: mod = getattr(mod, comp) return mod for reasons given here... http://www.python.org/doc/2.3.5/lib/built-in-funcs.html From fgeiger at datec.at Sat Oct 15 03:11:17 2005 From: fgeiger at datec.at (Franz GEIGER) Date: Sat, 15 Oct 2005 09:11:17 +0200 Subject: MS Word Outline -> reStructuredText script? References: <1129319634.407351.27080@z14g2000cwz.googlegroups.com> Message-ID: Jim wrote: > Hi, > > I'm using reStructuredText as a format for some group documentation, > and often my co-workers take notes during meetings in Word's outline > mode. Does anyone already have a python script that will convert from > Word (or the Open Office file format version of a word document) to > reStructured Text? Not a direct answer to your problem, but: Have a look at Leo! Leo is an outstanding outliner, written in Python. I do all formatting with reST and the convert it into LATEX and/or HTML. Everything's built in already, either in Python or in Leo. Perhaps you can convert your co-workers using Leo? > > If not I've got a fun project ahead of me. > > Thanks, > -Jim HTH Franz GEIGER From chris at kateandchris.net Tue Oct 18 13:00:37 2005 From: chris at kateandchris.net (Chris Lambacher) Date: Tue, 18 Oct 2005 13:00:37 -0400 Subject: Yes, this is a python question, and a serious one at that (moving to Win XP) In-Reply-To: References: <434f8a54$0$16641$626a14ce@news.free.fr> Message-ID: <20051018170037.GA27125@kateandchris.net> The shell that comes with MSys (from the MinGW guys). Is pretty good, although it does have a bit of a problem with stdout output before a process exits, ie it will hold back output until the process exits. As a bonus, the file system is a little more sane, and if you are interested in compiling software that is not open source, you are not tied to the Cygwin DLL which is GPLed. I have given up on Cygwin in favour of the tools that come with MSys because they seem slightly better suited to the windows environment. -Chris On Sat, Oct 15, 2005 at 08:45:17AM +0000, Jorgen Grahn wrote: > On Fri, 14 Oct 2005 12:37:25 +0200, Christophe wrote: > > Kenneth McDonald a ?crit : > >> For unfortunate reasons, I'm considering switching back to Win XP (from > >> OS X) as my "main" system. Windows has so many annoyances that I can > ... > >> Yes, I know that Cygwin is out there, but last I looked, they still > >> went through the Win command-line window, which imposes a lot of > >> restrictions. > ... > > Last time I checked, you could install a native win32gui version of rxvt > > with cygwin. This would give you a better terminal window than that > > crappy thing you get in XP. > > Last time /I/ checked (two years ago or so) that rxvt looked nice enough, > but was impossible to use in practice. I cannot remember /what/ the problem > was -- possibly it was that it could only run CygWin-compiled commands, or > something vital only worked with CygWin-compiled commands. Google probably > knows more. > > I wouldn't be surprised if this has improved since then, or if someone else > has come up with a serious Win32 terminal. There is surely a need for one! > > /Jorgen > > -- > // Jorgen Grahn \X/ algonet.se> R'lyeh wgah'nagl fhtagn! > -- > http://mail.python.org/mailman/listinfo/python-list From fumanchu at amor.org Fri Oct 21 02:20:17 2005 From: fumanchu at amor.org (Robert Brewer) Date: Thu, 20 Oct 2005 23:20:17 -0700 Subject: sqlstring -- a library to build a SELECT statement References: <1129774730.887128.314960@z14g2000cwz.googlegroups.com> Message-ID: Tim Roberts wrote: "grunar at gmail.com" wrote: > > > >An Example: > > > >>>> import sqlstring > >>>> model = sqlstring.TableFactory() > >>>> print model.person > >SELECT > >person.* > >FROM > >[person] person > > The [bracket] syntax is unique to Microsoft. > Everyone else, including Microsoft SQL Server, > uses "double quotes" to protect special characters > in identifiers. Except MySQL (at least 4.1), which uses backticks. http://dev.mysql.com/doc/refman/4.1/en/legal-names.html Robert Brewer System Architect Amor Ministries fumanchu at amor.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From belred at gmail.com Wed Oct 19 23:18:12 2005 From: belred at gmail.com (Bryan) Date: Wed, 19 Oct 2005 20:18:12 -0700 Subject: Python vs Ruby In-Reply-To: References: Message-ID: Amol Vaidya wrote: > Hi. I am interested in learning a new programming language, and have been > debating whether to learn Ruby or Python. How do these compare and contrast > with one another, and what advantages does one language provide over the > other? I would like to consider as many opinions as I can on this matter > before I start studying either language in depth. Any help/comments are > greatly appreciated. Thanks in advance for your help. > > why don't you do what i did? download ruby and spend a day or two reading "programming ruby" from www.ruby-lang.org/en. the download python and spend a day or two reading the python tuturial from www.python.org. they are very similar languages and it's going to come down to your personal perference. for me personally, ruby did not fit in my brain and python did. i used the "how many times did i have to flip back to a previous page in the manual/tutorial and reread a section" test. with ruby, once i got about one third of the way through the manual, i had to constantly reread previous sections. with python, not once did i need to reread a previous section. therefore, python was the obvious choice for me. bryan From davids at webmaster.com Tue Oct 25 07:49:55 2005 From: davids at webmaster.com (David Schwartz) Date: Tue, 25 Oct 2005 04:49:55 -0700 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: "Peter T. Breuer" wrote in message news:okh133-n3l.ln1 at news.it.uc3m.es... > 3) there are plenty of other OSs that are developed or could be > developed but which cannot get a foothold or even manage to be put on > the shelves because the majority product producer insists on charging > hardware manufacturers for every box produced, whether or not it carries > their o/s, and does other nasty things like sabotaging their own > products so they won't work with a clone o/s. How could he resell an OS that "could be developed"? If nobody wants these operating systems, then it doesn't hurt him not to be able to sell them. If people want them, then he could have shown Microsoft the door. You are responding to an argument that was specifically about the effect of this particular arrangement on this particular business. This third case was not one that he could find himself in. In fact, it's case 1 for him. > Sorry - that's not legal, fair, just, or good for the market. It means > that anybody with a 51% share of the market automatically gets 100%. That's just absolutely absurd. If some OS had 51% of the market, plenty of other distributors and manufacturers would gladly take other 49%. > Stop this apologism now. "Apologism"? Merriam-Webster says: "The word you've entered isn't in the dictionary. Click on a spelling suggestion below or try again using the search box to the right." Dictionary.com says: "No entry found for apologism." Fortunately I finally found what you mean, from http://www.absoluteastronomy.com/encyclopedia/a/ap/apologism.htm which says: Apologism is the metaphysical philosophy that argues that it is wrong for humans to attempt to alter the conditions of life in the mortal sphere of influence. It is opposed to the idea that absolute "progress" is a desirable goal for the pursuit of human endeavors. I'm not sure how I've said it's wrong for people to try to alter the conditions of life. I strongly believe that progress is a desirable goal. In fact, thanks to you, I now know that I am a meliorist. Never knew there was a word for it and never knew there were people who weren't. But then I found what I think you meant, "Apologetics is the field of study concerned with the systematic defense of a position. Someone who engages in apologetics is called an apologist." So perhaps you are asking me to stop systematically defending my position. Don't worry, my defense is not and has not been systematic. DS From steve at holdenweb.com Mon Oct 17 06:56:30 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 17 Oct 2005 11:56:30 +0100 Subject: How to get a raised exception from other thread In-Reply-To: References: <1129326320.914350.171460@o13g2000cwo.googlegroups.com> <1129434185.879062.61600@o13g2000cwo.googlegroups.com> <1129434873.307336.112030@g47g2000cwa.googlegroups.com> <1129438147.182266.196790@g44g2000cwa.googlegroups.com> <1h4knsn.1tihnpm15d5y4lN%aleaxit@yahoo.com> Message-ID: Antoon Pardon wrote: > Op 2005-10-17, Alex Martelli schreef : > >> wrote: >> >> >>>Nevermind. I found a better solution. I used shared memory to create >>>a keep-alive flag. I then use the select function with a specified >>>timeout, and recheck the keep-alive flag after each timeout. >> >>Definitely a better architecture. Anyway, one supported way for a >>thread to raise an exception in a different thread is function >>thread.interrupt_main(), which raises a KeyboardInterrupt in the *main* >>thread (the one thread that's running at the beginning of your program). >> >>There's also a supported, documented function to raise any given >>exception in any existing thread, but it's deliberately NOT directly >>exposed to Python code -- you need a few lines of C-coded extension (or >>pyrex, ctypes, etc, etc) to get at the functionality. This small but >>non-null amount of "attrition" was deliberately put there to avoid >>casual overuse of a facility intended only to help in very peculiar >>cases (essentially in debuggers &c, where the thread's code may be buggy >>and fail to check a keep-alive flag correctly...!-). > > > I find this rather arrogant. It is not up to the developers of python > to decide how the users of python will use the language. If someone > has use of specific functionality he shouldn't be stopped because his > use is outside the intentions of the developers. > The developers have to support (at no cost) what the users do, so if they want to make use of certain features inaccessible to users who are likely to go wrong then that's up to them. > Just suppose you are writing a chess program. You let the program > "think" while it is the users move, but this thinking has to be > interrupted and some cleanup has to be made after the users move > has made a lot of this thinking obsolete by his move. Such code > could be mixture of loops and recursion that makes use of a simple > flag to end it all, unpractical. Use of an exception raised from > somewhere else would IMO in this case be an acceptable choice. > In *your* opinion, possibly. In my opinion it would seem to make more sense to have the worker thread code examine a shared flag and raise an exception at some convenient point in its calculation cycle. Otherwise you have to write the worker thread to be capable of handling asynchronous signals, which is a notoriously difficult task. I presume this is why Alex commented that he thought the OP's "better solution" was "definitely a better architecture." > Why should the coder of this software have to go through this > deliberate set up attrition, to get at this functionality, just > because it wasn't intented to be used in such a way by the > developers? > Because otherwise people who know no better will use the feature for purposes where it's not the best way to achieve the required functionality, leading to yet more endless discussions about why "it doesn't work". Asynchronous signalling between threads is an accident waiting to happen in the hands of an inexperienced programmer. > As far as I know, pyrex and ctypes weren't intended to get > at the Python/C api. But they didn't create extra hurdles > for those who could use it that way. > This seems like a complete non sequitur to me. Let's stick to the point. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From python-url at phaseit.net Tue Oct 25 21:34:05 2005 From: python-url at phaseit.net (Cameron Laird) Date: Wed, 26 Oct 2005 01:34:05 +0000 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Oct 26) Message-ID: QOTW: "Using Unix for 20+ years probably warps one's perception of what's obvious and what isn't." -- Grant Edwards "... windoze users--despite their unfortunate ignorance, they are people too." -- James Stroud "The Widget Construction Kit (WCK) is an extension API that allows you to implement custom widgets in pure Python." A typical recent enhancemennt is slightly more efficient anti-aliased drawing under Windows: http://online.effbot.org/2005_10_01_archive.htm#20051022 Mike Meyer and others demonstrate the paranoia and propensity to abstraction of the experienced when thinking about something as simple as replacement of one string for another: http://groups.google.com/group/comp.lang.python/browse_thread/thread/98f0d93332748af9/ Similarly, Bengt Richter illustrates that "a month" is a far more complicated idea than first appears: http://groups.google.com/group/comp.lang.python/browse_thread/thread/68b08f36ca516aa2/ "The deadline for PyCon 2006 submissions is now only a week away." http://www.python.org/pycon/2006/cfp Is there a good way to manage Python installations on multiple (Windows) hosts? There are several: http://groups.google.com/group/comp.lang.python/browse_thread/thread/1343f89416f8f783/ ======================================================================== 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 There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. 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 lycka at carmen.se Tue Oct 11 10:56:21 2005 From: lycka at carmen.se (Magnus Lycka) Date: Tue, 11 Oct 2005 16:56:21 +0200 Subject: Best way to share a python list of objects In-Reply-To: <1128736534.695525.255410@g43g2000cwa.googlegroups.com> References: <1128736534.695525.255410@g43g2000cwa.googlegroups.com> Message-ID: kyle.tk wrote: > So I have a central list of python objects that I want to be able to > share between different process that are possibly on different > computers on the network. Some of the processes will add objects to > list and another process will be a GUI that will view objects in the > list. I want this all to happen in real-time (e.g once a processes adds > an object to the list the GUI will see it.) > > What would be the best way to accomplish this. Some of my ideas: > - An XML file r/w-able by all processes > - Send pickled objects between all processes and each keeps it own list > locally > - A ascii type protocol akin to ftp the hands out all the info to the > processes > > Any other ideas? What would work the best Relational database are useful for sharing data in a controlled way. A better option for arbirary Python objects might be ZODB with ZEO. http://www.zope.org/Wikis/ZODB/FrontPage http://www.zope.org/Wikis/ZODB/FrontPage/guide/index.html From nospam at here.com Wed Oct 5 12:13:50 2005 From: nospam at here.com (Matt Feinstein) Date: Wed, 05 Oct 2005 12:13:50 -0400 Subject: Python Newbie References: <1128526724.904832.278270@z14g2000cwz.googlegroups.com> Message-ID: <5su7k1lt4o18637u4lp0u11fqntb5rig24@4ax.com> On 5 Oct 2005 08:38:44 -0700, norm at normgoertzen.com wrote: >Hi, > >I'm learning Python now and I'm really pleased with everything so far, >however, at some point I'll want to develop a Windows application (no >other OS at this point). The question are: > 1. What toolkit is best for Windows development? > 2. Which toolkits can I exclude from consideration? > 3. What toolkit is most popular for Windows development? > 4. Are there any impartial reviews of these packages anywhere? You have to give us a clue about what you mean by 'best'. Matt Feinstein -- There is no virtue in believing something that can be proved to be true. From xah at xahlee.org Tue Oct 18 23:58:04 2005 From: xah at xahlee.org (Xah Lee) Date: 18 Oct 2005 20:58:04 -0700 Subject: write a loopin one line; process file paths In-Reply-To: References: <1129672592.328278.41490@g14g2000cwa.googlegroups.com> <1129675636.740977.151760@z14g2000cwz.googlegroups.com> Message-ID: <1129694284.783396.197680@f14g2000cwb.googlegroups.com> Peter Hansen wrote: > Xah Lee wrote: > > If you think i have a point, ... > > You have neither that, nor a clue. Dear Peter Hansen, My messages speak themselfs. You and your cohorts's stamping of it does not change its nature. And if this is done with repetitiousness, it gives away your nature. It is not necessary to shout against me. But if you must refute (and that is reasonable), try to put content into your posts. (see Philosophies of Netiquette at http://xahlee.org/UnixResource_dir/writ/phil_netiquette.html) If you deem fit, create a alt.fan.XahLee, and spare the rest of Python community of your politics. I appreciate your fandom. Xah xah at xahlee.org ? http://xahlee.org/ From sigzero at gmail.com Tue Oct 18 17:16:31 2005 From: sigzero at gmail.com (Robert Hicks) Date: 18 Oct 2005 14:16:31 -0700 Subject: Dealing with Excel Message-ID: <1129670191.061006.146320@g47g2000cwa.googlegroups.com> I need to pull data out of Oracle and stuff it into an Excel spreadsheet. What modules have you used to interface with Excel and would you recommend it? Robert From Danielnord15 at yahoo.se Tue Oct 4 02:43:31 2005 From: Danielnord15 at yahoo.se (Svennglenn) Date: 3 Oct 2005 23:43:31 -0700 Subject: Controlling who can run an executable References: <1128395422.904212.318930@g44g2000cwa.googlegroups.com> Message-ID: <1128408211.276386.94100@z14g2000cwz.googlegroups.com> > What I want: > - the simplest thing that could possibly work! > Have the program check for a file hidden somewhere on the computer. For instance, if the file dummyfile.dll doesn't exist in the windows/system32 folder the program just doesn't start. And when you install the program on her computer just add this file. And if anyone copies the program the can't run it on any other computer because they doesn't know the name of the file that's needed to start the program. How about that? From mscottschilling at hotmail.com Tue Oct 18 15:02:51 2005 From: mscottschilling at hotmail.com (Mike Schilling) Date: Tue, 18 Oct 2005 19:02:51 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <%jV4f.3121$tV6.2659@newssvr27.news.prodigy.net> Message-ID: "John Bokma" wrote in message news:Xns96F3DB7684BFcastleamber at 130.133.1.4... > "Mike Schilling" wrote: > >> "John Bokma" wrote in message > > [ w3c "standard" v.s. ISO ] > >> You haven't said why you thinbk "standards" are more valuable than >> "recommendations". We apparently both agree they're no more likely to be >> observed, so what is the reason? > > That an HTML standard (ISO/IEC 15445:2000) and an HTML recommendation by > w3c (4.01 for example) are two different things, and mixing them up by > calling both standards is a bad thing. Sorry, that's non-responsive. Now, once more, why are standards" *more valuable* than "recommendations"? From prince_amir86 at yahoo.com Thu Oct 6 10:08:20 2005 From: prince_amir86 at yahoo.com (Brandon K) Date: Thu, 06 Oct 2005 09:08:20 -0500 Subject: Help with chaos math extensions. In-Reply-To: References: <43433982.8080008@yahoo.com> <4343BC8E.1060702@yahoo.com> Message-ID: <1128607857_115243@spool6-east.superfeed.net> Well, I didn't buy it JUST to compile python extensions, I'm looking to write C++ apps as well, I just use python for a lot of math and science simulations, and I got VS .NET at heavy discount since I'm a student. > Brandon K wrote: >> In case you missed it, I said I have windows XP. Windows XP >> pre-compiled python binaries are built on VS .NET 2003. In order to >> build extensions, you need the compiler the interpreter was built on, >> or at least that is what is reported to me by calling setup.py. If I >> was using linux, which I currently am not, it'd be a different story. >> Additionally, GCC isn't available for windows XP, only MinGW, the >> port, and I don't know that much about it to use it running on a >> Windows platform. Furthermore, I was asking for help on an extension, >> not an economical question about my programming environment. >> >> Thanks >> >>> >>> On Oct 4, 2005, at 10:25 PM, Brandon Keown wrote: >>> >>>> I have programmed a fractal generator (Julia Set/Mandelbrot Set) >>>> in python in the past, and have had good success, but it would run >>>> so slowly because of the overhead involved with the calculation. I >>>> recently purchased VS .NET 2003 (Win XP, precomp binary of python >>>> 2.4.2rc1) to make my own extensions. >>> >>> Why did you need to purchase anything when gcc is available for free? >>> > Since gcc isn't an option, the logical way to proceed would be to do > what others have done and install the Microsoft Toolkit compiler, > available from their web site for the outrageous price of nothing. I can > vouch that it really does compile extensions for Python 2.4 on Windows, > having done that myself. > > See > > http://www.vrplumber.com/programming/mstoolkit/ > > regards > Steve ----== Posted via Newsgroups.com - Usenet Access to over 100,000 Newsgroups ==---- Get Anonymous, Uncensored, Access to West and East Coast Server Farms! ----== Highest Retention and Completion Rates! HTTP://WWW.NEWSGROUPS.COM ==---- From email at christoph-haas.de Thu Oct 20 16:50:56 2005 From: email at christoph-haas.de (Christoph Haas) Date: Thu, 20 Oct 2005 22:50:56 +0200 Subject: get a copy of a string leaving original intact In-Reply-To: <2387F0EED10A4545A840B231BBAAC722607F6A@slcimail1.slcgov.com> References: <2387F0EED10A4545A840B231BBAAC722607F6A@slcimail1.slcgov.com> Message-ID: <200510202250.56620.email@christoph-haas.de> On Thursday 20 October 2005 22:43, Bell, Kevin wrote: > I need to copy a file, say "abc-1.tif" to another directory, but if it's > in there already, I need to transfer it named "abc-2.tif" but I'm going > about it all wrong. What a coincidence... I stepped about this today: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/442460 Looks close to what you are trying. Kind Regards Christoph -- ~ ~ ".signature" [Modified] 1 line --100%-- 1,48 All From robert.h.boyd at gmail.com Thu Oct 27 10:26:41 2005 From: robert.h.boyd at gmail.com (Robert Boyd) Date: Thu, 27 Oct 2005 10:26:41 -0400 Subject: Question: New editions of Python books? Message-ID: Hi, Are any new editions in the works for either "Python Essential Reference" or "Python in a Nutshell"? I'm holding off buying one or the other existing editions, although my library overdue fines for them would have paid for them by now! Thanks, Rob -------------- next part -------------- An HTML attachment was scrubbed... URL: From prince_amir86 at yahoo.com Wed Oct 5 07:44:14 2005 From: prince_amir86 at yahoo.com (Brandon K) Date: Wed, 05 Oct 2005 06:44:14 -0500 Subject: Help with chaos math extensions. In-Reply-To: References: <43433982.8080008@yahoo.com> Message-ID: <4343BC8E.1060702@yahoo.com> In case you missed it, I said I have windows XP. Windows XP pre-compiled python binaries are built on VS .NET 2003. In order to build extensions, you need the compiler the interpreter was built on, or at least that is what is reported to me by calling setup.py. If I was using linux, which I currently am not, it'd be a different story. Additionally, GCC isn't available for windows XP, only MinGW, the port, and I don't know that much about it to use it running on a Windows platform. Furthermore, I was asking for help on an extension, not an economical question about my programming environment. Thanks > > > On Oct 4, 2005, at 10:25 PM, Brandon Keown wrote: >> >> I have programmed a fractal generator (Julia Set/Mandelbrot Set) >> in python in the past, and have had good success, but it would run so >> slowly because of the overhead involved with the calculation. I >> recently purchased VS .NET 2003 (Win XP, precomp binary of python >> 2.4.2rc1) to make my own extensions. > > Why did you need to purchase anything when gcc is available for free? > > > --- > Andrew Gwozdziewycz > apgwoz at gmail.com > http://ihadagreatview.org > http://plasticandroid.org > > > > From franz.steinhaeusler at gmx.at Wed Oct 12 09:10:51 2005 From: franz.steinhaeusler at gmx.at (Franz Steinhaeusler) Date: Wed, 12 Oct 2005 15:10:51 +0200 Subject: IDLE dedent/unindent key bindings for non-us keybord? References: Message-ID: On Wed, 12 Oct 2005 14:58:18 +0200, "Adriaan Renting" wrote: >You could try using the Qscintilla based Eric3 IDE, it uses Ctrl-i and Ctrl-Shift-i. > That is possible. But what has it to do with the original post? Apart from that, in Idle you can bind them it to Ctrl-i and Ctrl-Shift-i also. -- Franz Steinhaeusler From my_email_is_posted_on_my_website at munged.invalid Tue Oct 4 13:14:45 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Tue, 04 Oct 2005 17:14:45 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: <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> On Tue, 23 Aug 2005 08:32:09 -0500, l v wrote or quoted : >I think e-mail should be text only. I disagree. Your problem is spam, not HTML. Spam is associated with HTML and people have in Pavlovian fashion come to hate HTML. But HTML is not the problem! That is like hating all choirs because televangelists use them. HTML allows properly aligned table, diagrams, images, use of colour/fonts to encode speakers. emphasis, hyperlinks. I try to explain Java each day both on my website on the plaintext only newsgroups. It is so much easier to get my point across in HTML. Program listings are much more readable on my website. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From sxanth at cs.teiath.gr Tue Oct 11 06:01:34 2005 From: sxanth at cs.teiath.gr (sxanth at cs.teiath.gr) Date: Tue, 11 Oct 2005 13:01:34 +0300 Subject: Idle bytecode query on apparently unreachable returns Message-ID: <1129024894.434b8d7e3f8b4@tilemachos.teiath.gr> >What puzzles me, though, are bytecodes 17, 39 and 42 - surely these aren't >reachable? Does the compiler just throw in a default 'return None' >epilogue, with routes there from every code path, even when it's not >needed? If so, why? Hi. pyc (http://freshmeat.net/projects/pyc) can already remove that unused code since June. As for "why", I guess that there is a lot of room for optimizing the bytecode but it's a PITA doing all of it in the current internal compiler. And so developers simply don't care about it. Maybe the ast-branch would make it easier to start generating optimal bytecode. On the other hand, the 'compiler module' produces bad bytecode (for example it miscalculates the 'stacksize' of functions and as a result the generated functions are slow), it doesn't use LIST_APPEND, and it doesn't even do the simple peephole optimizations of the intenal compiler! In the latest version 0.8 to-be-released, pyc does many more bytecode optimizations that give a +5% to pystone and it can also bring generator expressions and decorators to python 2.3. [OT] 0.8 is stuck on the conditional. We can bring the conditional expression from the __future__ to users of 2.3/2.4 but I'm not sure people really like the "T if C else F" syntax over "C ? T : F". The argument: "python uses 'and'/'or' instead of &&/|| and therefore it should also use 'if-else' instead of '?:'", just doesn't apply. And generally this is one of those things that you will never find the argument that proves which is the right choice. In these cases you do what you *LIKE* more. Perhaps a vote would be in order considering the this-or-that nature of the conditional expression :) st. ---------------------------------------------------------------- This message was sent through the TEI of ATHENS by means of NOC. From m.barenco at gmail.com Tue Oct 11 14:50:24 2005 From: m.barenco at gmail.com (m.barenco at gmail.com) Date: 11 Oct 2005 11:50:24 -0700 Subject: dictionnaries and lookup tables In-Reply-To: References: <1129053992.141269.149840@z14g2000cwz.googlegroups.com> Message-ID: <1129056624.073937.207160@g44g2000cwa.googlegroups.com> >Sure they're implemented. Oops, my apologies. Just to build up on that, when I run: #start of listing import random A={1:None,2:None,"hello":None,(1,2,3):None} def dictcomp(n): for i in range(n): B=A.copy() C=A.copy() b=random.uniform(0,1) c=random.uniform(0,1) B[b]=None C[c]=None res=((B>C)==(b>c)) print res, dictcomp(1000) #end of listing I get 1000 True's on the output, which suggests that key-wise ordering is implemented in some guise. The question is: how do I access that? Thanks Martino From steve at holdenweb.com Mon Oct 3 18:06:00 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 03 Oct 2005 23:06:00 +0100 Subject: Reply-To header In-Reply-To: References: <2ECA6FE9-3C8F-4C60-9E89-70CC078B14EF@gmail.com> <7rc0f.11261$Un.585792@phobos.telenet-ops.be> <86oe66jpfj.fsf@bhuda.mired.org> Message-ID: Roel Schroeven wrote: > Mike Meyer wrote: > >>Peter Decker writes: >> >> >>>Setting the default Reply-To: to the list means that 'Reply' sends >>>just to the list (the desired behavior most of the time), and 'Reply >>>to all' sends 2 copies. >> >> >>No, it sends one copy to the list, and one copy to the original >>author. This is the behavior you want. The author may not be >>subscribed to the list. Such people are most in need of help, and you >>want the default to be that they get help. > > > Is that really the desired behaviour? IMO the least you can do if you're > searching for help is subscribing to the mailing list on which you're > looking for help. Me and many others don't like to receive replies > directly instead of via the mailing list; it's of no use, since we're > subscribed to the mailing list anyway. > > Just reply to the mailing list, and subscribe to it if you want to > receive replies. Avoids duplicates without all kinds mail filters. Only > disadvantage is that by subscribing to the mailing list, you receive all > posts to the list, not just the replies to your own post. But that's not > a big disadvantage. On the contrary; one can easily learn something from > them. > ... if one has time to do anything but curse and delete them ! regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From nnorwitz at gmail.com Wed Oct 19 00:41:23 2005 From: nnorwitz at gmail.com (Neal Norwitz) Date: 18 Oct 2005 21:41:23 -0700 Subject: make: circular dependency for Modules/signalmodule.o In-Reply-To: <4354a3f4$0$28047$5a62ac22@per-qv1-newsreader-01.iinet.net.au> References: <4354a3f4$0$28047$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <1129696883.760079.323170@g49g2000cwa.googlegroups.com> James Buchanan wrote: > Hi group, > > I'm preparing Python 2.4.2 for the upcoming Minix 3.x release, and I > have problems with make. configure runs fine and creates the makefile, > but right at the end ends with an error about a circular dependency in > Modules/signalmodule.o. I've never heard of this problem. The Makefile is generated by configure so this is possibly a configure issue. In my (generated) Makefile, signalmodule.o is listed in MODOBJS, but not in SIGNAL_OBJS. Maybe your signalmodule.o is listed in both? Search through the Makefile for signalmodule and see what you can find. Mine has two long lines for the rules which cause signalmodule.c to be compiled. Modules/signalmodule.o: $(srcdir)/Modules/signalmodule.c; $(CC) $(PY_CFLAGS) -c $(srcdir)/Modules/signalmodule.c -o Modules/signalmodule.o Modules/signalmodule$(SO): Modules/signalmodule.o; $(LDSHARED) Modules/signalmodule.o -o Modules/signalmodule$(SO) Good luck, n From zhu_dave at yahoo.com Thu Oct 13 19:04:49 2005 From: zhu_dave at yahoo.com (Dave) Date: Thu, 13 Oct 2005 16:04:49 -0700 (PDT) Subject: Profiling results Message-ID: <20051013230449.38319.qmail@web30607.mail.mud.yahoo.com> Hello All, I'm trying to profile a Python program using gprof, but I don't understand some of the results, especially what some of the functions do. For example, _moncount, mcount, _PyEval_EvalFrame take too much time. What are they for? Any ideas? Thank you for your help! __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com From johnnyandfiona at hotmail.com Fri Oct 21 02:28:15 2005 From: johnnyandfiona at hotmail.com (Johnny Lee) Date: 20 Oct 2005 23:28:15 -0700 Subject: Question on class member in python In-Reply-To: References: <1129537638.714752.120290@g49g2000cwa.googlegroups.com> <1129613041.473285.84800@g44g2000cwa.googlegroups.com> <1h4mjg9.1n5khr7pjy1zN%aleaxit@yahoo.com> Message-ID: <1129876095.937498.277630@z14g2000cwz.googlegroups.com> It looks like there isn't a last word of the differrences.... From mrbmahoney at gmail.com Thu Oct 20 01:39:04 2005 From: mrbmahoney at gmail.com (B Mahoney) Date: 19 Oct 2005 22:39:04 -0700 Subject: Expat - how to UseForeignDTD Message-ID: <1129786744.782887.80130@z14g2000cwz.googlegroups.com> I have a simple Kid template document: ... (snip) This runs as expected but now I would like to load a DTD without tampering with this xml file In the expat parser __init__ after setting other handlers for parser, I have added: parser.ExternalEntityRefHandler = self._ExternalEntityRefHandler parser.UseForeignDTD(1) (also tried True) Which I understand at some point will call self._ExternalEntityRefHandler with None for args and I must have code to get this other dtd. I have done regular ExternalEntityRefHandlers before. As required, these two lines occur before my Parse() call. Perhaps I misunderstand the sequence, or need something more in my xml file, but my _ExternalEntityRefHandler is never called. The process behaves as if I never added these two lines. Help? From free.condiments at gmail.com Sat Oct 8 11:02:18 2005 From: free.condiments at gmail.com (Sam Pointon) Date: 8 Oct 2005 08:02:18 -0700 Subject: Function decorator that caches function results In-Reply-To: References: Message-ID: <1128783738.588723.200130@g43g2000cwa.googlegroups.com> What about not storing args at all? Something like this: def cache_function(func, args_list): cache = {} def cached_result(*args, **kwargs): kwargs.update(dict(zip(args_list, args))) if kwargs in cache: return cache[kwargs] result = func(**kwargs) cache[kwargs] = result return result return cached_result args_list is a list of all the argument names, so that they can be converted into keyword arguments. From usenet.filter at gmail.com Sat Oct 8 11:19:43 2005 From: usenet.filter at gmail.com (Stephan) Date: 8 Oct 2005 08:19:43 -0700 Subject: List performance and CSV Message-ID: <1128784783.256285.24680@z14g2000cwz.googlegroups.com> Hello, I'm working on a simple project in Python that reads in two csv files and compares items in one file with items in another for matches. I read the files in using the csv module, adding each line into a list. Then I run the comparision on the lists. This works fine, but I'm curious about performance. Here's the main part of my code: ###### file1 = open("CustomerList.csv") CustomerList = csv.reader(file1) Customers = [] #Read in the contents of the CSV file into memory for CustomerRecord in CustomerList: Customers.append(CustomerRecord) #not shown here: the second file CustomersToMatch #is loaded in a similar manner #loop through each record and find matches on column 2 #breaking out of inner loop when a match is found for loop1 in range(len(CustomersToMatch)): for loop2 in range(len(Customers)): if (CustomersToMatch[loop1][2] == Customers[loop2][2]) : CustomersToMatch[loop1][1] = Customers[loop2][1] break ###### With this code, it takes roughly 10 minutes on a 2Ghz x86 box to compare two lists of 20,000 records. Is that good? Out of curiousity, I tried psyco and saw no difference. Is there a better Python synax to use? Thanks, -Stephan From no.mail.here.at.here at gmail.com Fri Oct 7 13:29:25 2005 From: no.mail.here.at.here at gmail.com (mike) Date: 7 Oct 2005 10:29:25 -0700 Subject: os.access with wildcards In-Reply-To: References: <1128665933.923295.95580@f14g2000cwb.googlegroups.com> <1128701207.675536.126370@z14g2000cwz.googlegroups.com> Message-ID: <1128706165.298211.148680@g44g2000cwa.googlegroups.com> No need to apologize for continuing to waste your time, self.plonk. Get a life, though, and you'll be happier. As to your question, well, not before you apologize for thread crapping. As for your possible solutions, if you consider any of yours to be "readable", then i have no interest in coding with you. And for if glob.glob(path): I had already posted that work around. From shitizb at yahoo.com Fri Oct 14 20:32:34 2005 From: shitizb at yahoo.com (Shitiz Bansal) Date: Fri, 14 Oct 2005 17:32:34 -0700 (PDT) Subject: How to get a raised exception from other thread In-Reply-To: <1129326880.3372.68.camel@localhost.localdomain> Message-ID: <20051015003234.96963.qmail@web53810.mail.yahoo.com> Threads can share the same memory space. Hence a very neat way to achieve the objective. > For example: > > --------------- > programA.py > --------------- > > import programB Exception=0; > thread = programB.MakeThread() > thread.start() if (Exception): raise SomeException() > --------------- > programB.py > --------------- > import threading, time > > class SomeException(Exception): > pass > > class MakeThread(threading.Thread): > def __init__(self): > threading.Thread.__init__(self) > > def run(self): > i = 0 > while 1: > print i > i += 1 > time.sleep(1) #wait a second to continue > if i>10: omit this ->raise SomeException() instead: if i>10: Exception=1 or whatever > Sounds cool? shitiz Jeremy Moles wrote: On non-Windows system there are a ton of ways to do it--this is almost a whole field unto itself. :) (D-BUS, fifos, sockets, shmfs, etc.) In Windows, I wouldn't have a clue. I guess this is a hard question to answer without a bit more information. :) On Fri, 2005-10-14 at 14:45 -0700, dcrespo wrote: > Hi all, > > How can I get a raised exception from other thread that is in an > imported module? > > For example: > > --------------- > programA.py > --------------- > > import programB > > thread = programB.MakeThread() > thread.start() > > --------------- > programB.py > --------------- > import threading, time > > class SomeException(Exception): > pass > > class MakeThread(threading.Thread): > def __init__(self): > threading.Thread.__init__(self) > > def run(self): > i = 0 > while 1: > print i > i += 1 > time.sleep(1) #wait a second to continue > if i>10: > raise SomeException() > > > Thanks > > Daniel > -- http://mail.python.org/mailman/listinfo/python-list --------------------------------- Yahoo! Music Unlimited - Access over 1 million songs. Try it free. -------------- next part -------------- An HTML attachment was scrubbed... URL: From istvan.albert at gmail.com Tue Oct 4 09:29:36 2005 From: istvan.albert at gmail.com (Istvan Albert) Date: 4 Oct 2005 06:29:36 -0700 Subject: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please! In-Reply-To: <1128428885.390019.304730@g43g2000cwa.googlegroups.com> References: <1128428885.390019.304730@g43g2000cwa.googlegroups.com> Message-ID: <1128432576.708995.19060@f14g2000cwb.googlegroups.com> Disclaimer: this is not a flame against Boo. It just boggles my mind that a language that describes itself as "python inspired syntax" keeps being touted as: > Luis M. Gonzalez wrote: > Boo (which could be considered almost an static version of Python for .NET) Boo is *nothing* like a static version of Python. Stop perpetuating this nonsense. From mail at tuxipuxi.org Sun Oct 9 06:17:36 2005 From: mail at tuxipuxi.org (Michael Goettsche) Date: Sun, 9 Oct 2005 12:17:36 +0200 Subject: Daisy Daisy, give me your answer do In-Reply-To: <1128807595.122982.310790@o13g2000cwo.googlegroups.com> References: <1128802217.156887.234490@g43g2000cwa.googlegroups.com> <1128807595.122982.310790@o13g2000cwo.googlegroups.com> Message-ID: <200510091217.36591.mail@tuxipuxi.org> On Saturday 08 October 2005 23:39, Xah Lee wrote: > Dear Michael Goettsche, > > why don't you lead the pack to be on-topic for a change, huh? > > Xah > Because you are a moron. Unsubscribe from this list please and never come back. From kent37 at tds.net Fri Oct 21 08:54:43 2005 From: kent37 at tds.net (Kent Johnson) Date: Fri, 21 Oct 2005 08:54:43 -0400 Subject: ANN: Beginning Python (Practical Python 2.0) In-Reply-To: References: Message-ID: <4358e30c$1_3@newspeer2.tds.net> Magnus Lie Hetland wrote: > I guess it has actually been out for a while -- I just haven't > received my copies yet... Anyways: My book, "Beginning Python: From > Novice to Professional" (Apress, 2005) is now out. Apress is offering a $10 rebate if you purchase the book before October 30. See for example http://www.bookpool.com/sm/159059519X Kent From mde at micah.elliott.name Mon Oct 31 17:31:08 2005 From: mde at micah.elliott.name (Micah Elliott) Date: Mon, 31 Oct 2005 14:31:08 -0800 Subject: Rename files with numbers In-Reply-To: <20051031220841.GF2575@kitchen.client.attbi.com> References: <1130776390.085587.116270@g43g2000cwa.googlegroups.com> <1130784747.373637.108040@g14g2000cwa.googlegroups.com> <1130789205.862429.10090@g43g2000cwa.googlegroups.com> <20051031220841.GF2575@kitchen.client.attbi.com> Message-ID: <20051031223108.GG2575@kitchen.client.attbi.com> On Oct 31, Micah Elliott wrote: > Now I need to go beautify my collection. :-) While a fun exercise, there are probably already dozens (or thousands?) of utilities in existence that do this and much more. -- _ _ ___ |V|icah |- lliott http://micah.elliott.name mde at micah.elliott.name " " """ From steve at REMOVETHIScyber.com.au Mon Oct 17 09:01:39 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 17 Oct 2005 23:01:39 +1000 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <1129491006.021102.43920@g14g2000cwa.googlegroups.com> <86zmp8zsjk.fsf@bhuda.mired.org> Message-ID: On Mon, 17 Oct 2005 00:17:03 -0400, Mike Meyer wrote: > Yup. When NS was the 800 lb gorilla When was this? When did Netscape have a monopoly in any market? Netscape was never the 800 lb gorilla. > on they acted like MS, When did Netscape executives perjure themselves in court? When did Netscape commit fraud? Astro-turfing? Patent infringement? Theft of code? If you really wanted to compare apples with apples (no pun intended), IBM and Microsoft would be the two to compare. IBM had an effective monopoly once, and they acted like Microsoft, although even they never had the gall to just ignore the court's rulings as Microsoft has done, and continues to do. Twenty years ago, Microsoft were the knights in shining armour going to save Apple Macintosh from the Big Blue evil empire. But that was then, this is now, and unlike IBM, Microsoft hasn't yet learnt about karma. -- Steven. From list at notmyisp.pl Fri Oct 7 06:24:09 2005 From: list at notmyisp.pl (Tomasz Lisowski) Date: Fri, 07 Oct 2005 12:24:09 +0200 Subject: non descriptive error In-Reply-To: References: Message-ID: <43464cc9$1@news.home.net.pl> Timothy Smith wrote: > i try to run my app and i get this > > %python DutyShift.py > error > > > thats it. thats the error. mya pp was previously working, and i did make > some fairly large changes to it, but i'd expect a more descriptive > message then just "error". anyidea where i need to start looking? It seems to me, like a result of a "print" statement, exexcuted somewhere (maybe in the except: clause). You may look for lines similar to: print "error" Tomasz Lisowski From jhu at metrigenix.com Fri Oct 28 16:05:11 2005 From: jhu at metrigenix.com (James Hu) Date: Fri, 28 Oct 2005 16:05:11 -0400 Subject: drag/move image from staticBitmap control? Message-ID: <90DEA7ED93F71A4580CEDF76A02682EA03ACDA@torexch.metrigenix.com> Hi, all gurus, I have an application to show bitmap image on one wx.staticBitmap control area, I can display part of the image, or the whole image(detail is unclear), But I would like to use mouse to drag/move the image inside thewx.staticBitmap control when only part image on the screen, just like maps.google does, is it possible to do that? Any sample code or any idea or suggestion are appreciated! Have a nice weekend! James -------------- next part -------------- An HTML attachment was scrubbed... URL: From stewart.midwinter at gmail.com Fri Oct 14 09:30:28 2005 From: stewart.midwinter at gmail.com (stewart.midwinter at gmail.com) Date: 14 Oct 2005 06:30:28 -0700 Subject: UI toolkits for Python In-Reply-To: References: <33765778-7F70-438D-8020-1FEC94CE1FA9@sbcglobal.net> Message-ID: <1129296627.990153.78290@g47g2000cwa.googlegroups.com> sure it is, but since this is a Python list, you'd also need PyQt to go along with it, and there's no version of PyQt yet compatible with Qt4. From aleaxit at yahoo.com Sun Oct 23 20:54:20 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 23 Oct 2005 17:54:20 -0700 Subject: Tricky Areas in Python References: <1130097286.772836.94930@g44g2000cwa.googlegroups.com> Message-ID: <1h4wbvb.1dblc4317zeuw2N%aleaxit@yahoo.com> PyPK wrote: > What possible tricky areas/questions could be asked in Python based > Technical Interviews? I like to present code that seems like it should work, but has some kind of relatively subtle problem, either of correctness in some corner case, or of performance, etc -- and I ask them what they would say if they were to code-review that code, or how they would help a student who came to them with that code and complaints about it not working, &c. This tells me whether they have real-world Python experience, and how deep, or whether they've carefully studied the appropriate areas of "Python in a Nutshell" and the Cookbook (and I'm biased enough to think that the second kind of preparation is almost as good as the first kind...;-). Not sure whether you think this count as "tricky"... they're typically problems that do come up in the real world, from (e.g.): for string_piece in lots_of_pieces: bigstring += string_piece (a typical performance-trap) to for item in somelist: if isbad(item): somelist.remove(item) (with issues of BOTH correctness and performance), to class Sic: def getFoo(self): ... def setFoo(self): ... foo = property(getFoo, setFoo) to class Base(object) def getFoo(self): ... def setFoo(self): ... foo = property(getFoo, setFoo) class Derived(Base): def getFoo(self): .... and so on, and so forth. If a candidate makes short work of a couple of these, and I've been asked to focus my part of the interview solely on Python coding, I may branch out into more advanced stuff such as asking for an example use case for a closure, a custom descriptor, or an import hook, for example -- those are the cases in which I'm trying to decide if, on a scale of 1 to 5, the candidate's Python competence is about 4 or well over 4 (I would not consider having no idea of why one might want to code a custom descriptor to be at all "disqualifying" -- it would just mean I'd rate the candidate 4 out of five, instead of 4.5 or more, for Python coding competence). Alex From grunar at gmail.com Thu Oct 20 11:59:35 2005 From: grunar at gmail.com (grunar at gmail.com) Date: 20 Oct 2005 08:59:35 -0700 Subject: sqlstring -- a library to build a SELECT statement In-Reply-To: References: <1129774730.887128.314960@z14g2000cwz.googlegroups.com> <1129784130.596225.174860@z14g2000cwz.googlegroups.com> Message-ID: <1129823975.023490.287440@g43g2000cwa.googlegroups.com> > >> Using // for 'in' looks really weird, too. It's too bad you can't > >> overload Python's 'in' operator. (Can you? It seems to be hard-coded > >> to iterate through an iterable and look for the value, rather than > >> calling a private method like some other builtins do.) > >> > > > > // was a bit of a stretch. I'd initially thought it for the "where" > > clause, becuase it's lower precedence than ** (I think), and really > > late at night // kind of looks like a W. I decided against it because > > it looks to close to a comment in some other languages. > > > > Python "in" clause doesn't seem exploitable in any way--probably a > > good > > thing. I did add a "in_" method (name is arguable), which does the > > same thing, also a not_in. > > What about modifying the overloaded == to produce 'in' if the right- > hand side is a list? Then you can more easily generate statements > dynamically: > > def makeCond(name): > return someOtherCond & (model.table.name == name) > > makeCond("foo") > makeCond(["foo", "bar"]) > > And it doesn't require two different functions. > > As long as there is no case where you might actually want to test if > a column value equals a list, it should work. Is there? Some DBs > support an Array type, but in general that might be better handled > with an Array class, anyway. This is a great idea, and should be the default behaviour for lists. It does present a problem if the right hand expression is a SELECT object, though. Both of these are valid syntax: id = (select max(id) from table) id in (select id from table) Also, SQLite allows for column in table_name syntax. I've never seen that before, but I wanted to support that, there'd be no way of knowing in vs. ==. On this line of thought, what about the += operator? That might be more intuative than //. I could even use -= for not in. Runar From mrosenstihl at macnews.de Tue Oct 11 19:04:09 2005 From: mrosenstihl at macnews.de (Markus Rosenstihl) Date: Wed, 12 Oct 2005 01:04:09 +0200 Subject: Nicer way of strip and replace? References: <7xpsqb6839.fsf@ruckus.brouhaha.com> Message-ID: On 2005-10-11 23:45:46 +0200, Paul Rubin said: > Markus Rosenstihl writes: >> This looks ugly (I htink) and I wonder if there is a nicer way to >> strip commata and change the comma to a dot already when reading in. >> Or should i do it with a shell script before processing in python? > > First of all you should just set your locale to use comma instead > of dot as the numeric decimal, instead of translating commas to dots. Yes that is true, but most of the time I use a dot as numerical decimal. > > Second, for the field separation, see if you can configure the csv > module to do it for you. indeed, it did it correctly by default: read_file = csv.reader(open('2005_08_Rechnung_4963184011.dat', 'r'), delimiter="\t") for row in read_file: rechnung.append(row) From dietz at rouge.phys.lsu.edu Wed Oct 5 10:11:15 2005 From: dietz at rouge.phys.lsu.edu (alexLIGO) Date: 5 Oct 2005 07:11:15 -0700 Subject: How to get the output from os.system() into a variable? In-Reply-To: References: <1128519815.769933.60660@g43g2000cwa.googlegroups.com> Message-ID: <1128521475.136191.165780@f14g2000cwb.googlegroups.com> Hi, thank you very much for your tipps. I get it to work! Alexander From steve at REMOVETHIScyber.com.au Sun Oct 23 18:50:57 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 24 Oct 2005 08:50:57 +1000 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <86k6g59ke6.fsf@bhuda.mired.org> <3EI6f.43974$MF6.5922@fe1.news.blueyonder.co.uk> <86irvo861u.fsf@bhuda.mired.org> Message-ID: On Sun, 23 Oct 2005 13:52:38 -0700, David Schwartz wrote: > The court's determination of the relevent > market, on wich all of their other decisions were predicated, was arbitrary > and bizarre, and the law did not provide any notice of how the market would > be determined. You keep saying that, as if people could do their word processing and run their financial accounting software on the micro-controllers of microwave ovens or the computer in their car engine. The market of desktop PC is a perfectly obvious and natural market. You are the one insisting on arbitrarily lumping together who knows what other products in with the desktop PC. I say "who knows" for a reason -- the only two examples you have come up with were Apple Macintoshes and desktop PCs running Linux (both less than 5% of the market *now*, and even less back when the court was investigating Microsoft). Making your position even more bizarre, both of these products were recognised by the court as part of the market in question, both were recognised as potential competing products put at risk due to Microsoft's illegal behaviour. > In the sense of interchangeability, almost all operating systems are > monopolies. You don't know what the word monopoly actually means in either law or economics, do you? What you have written is a perfectly grammatical sentence that makes no sense whatsoever. If OSes are monopolies, then they are NOT interchangeable -- but you state in the very next sentence that they are. > And if you go by application, Windows, Linux, and FreeBSD > are all interchangeable -- there is nothing significant you can do on > one that you can't do on the other. Try telling that to a business that needs to do computerised book-keeping of wages and payroll. -- Steven. From zanesdad at bellsouth.net Tue Oct 18 10:43:04 2005 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Tue, 18 Oct 2005 10:43:04 -0400 Subject: global interpreter lock In-Reply-To: <1129623917.257410.294060@g43g2000cwa.googlegroups.com> References: <1129623917.257410.294060@g43g2000cwa.googlegroups.com> Message-ID: <435509F8.7030108@bellsouth.net> Tommy.Ryding at gmail.com wrote: >I just need confirmation that I think right. > >Is the files thread_xxx.h (xxx = nt, os2 or whatever) responsible for >the >global interpreter lock in a multithreaded environment? > >I'm currently writing my own thread_VW for VxWorks, thats why I'm >asking. > >//Tommy > > > Someone can correct me if I'm wrong, but the lock actually lives in ceval.c, around here: 802 PyThread_release_lock(interpreter_lock); 803 804 /* Other threads may run now */ 805 806 PyThread_acquire_lock(interpreter_lock, 1); This was taken from what appears to be a 2.4.1 release rather than a CVS checkout. It looks like the PyThread_type_lock is defined in the thread_xxx.h files, though. HTH, - jmj From http Thu Oct 13 17:45:53 2005 From: http (Paul Rubin) Date: 13 Oct 2005 14:45:53 -0700 Subject: Jargons of Info Tech industry References: <1124804082_1011@spool6-east.superfeed.net> <11ktbum1ira9le4@corp.supernews.com> <11ktl11e426b41d@corp.supernews.com> Message-ID: <7xslv56qge.fsf@ruckus.brouhaha.com> gordonb.mrv0t at burditt.org (Gordon Burditt) writes: > I'm not sure that you can disable Javascript from reading cookies > from other sites while allowing Javascript to read cookies from the > site it came from on all browsers. Javascript is not supposed to be able to read cross-site cookies. It's bad but it's not THAT bad. There was an MSIE bug that allowed reading other sites' cookies but it was correctly considered a horrendous security breach and it was fixed quickly after discovery. It caused a big fire drill where I was working at the time of the incident. We had to write a special ActiveX control to protect our cookie info until the browser patch went out. From codecraig at gmail.com Wed Oct 12 12:15:52 2005 From: codecraig at gmail.com (Java and Swing) Date: 12 Oct 2005 09:15:52 -0700 Subject: C Wrapper Function, crashing Python? In-Reply-To: References: <1129122046.417746.100120@g47g2000cwa.googlegroups.com> <1129123866.536068.69520@g43g2000cwa.googlegroups.com> Message-ID: <1129133752.747652.246050@g49g2000cwa.googlegroups.com> thanks for the tip, however even when I do not free aString or bString, i'm still crashing at the malloc in the c function, not the wrapper. Bernhard Herzog wrote: > "Java and Swing" writes: > > > static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { > [...] > > char *aString = 0; > > char *bString = 0; > [...] > > int ok = PyArg_ParseTuple(args, "sss", &in, &aString, &bString); > [...] > > free(aString); > > free(bString); > > aString and bString are pointers to memory managed by the strings in > your args tuple. You must not free them! The memory is automatically > managed by Python. > > Bernhard > > -- > Intevation GmbH http://intevation.de/ > Skencil http://skencil.org/ > Thuban http://thuban.intevation.org/ From jepler at unpythonic.net Mon Oct 24 14:47:14 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Mon, 24 Oct 2005 13:47:14 -0500 Subject: Extention String returning In-Reply-To: <1130178503.498003.175810@f14g2000cwb.googlegroups.com> References: <1130178503.498003.175810@f14g2000cwb.googlegroups.com> Message-ID: <20051024184713.GB16962@unpythonic.net> I think that you want to use return PyString_FromStringAndSize(buf, 8); Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From alex_f_il at hotmail.com Mon Oct 31 09:28:06 2005 From: alex_f_il at hotmail.com (alex_f_il at hotmail.com) Date: 31 Oct 2005 06:28:06 -0800 Subject: need start point for getting html info from web In-Reply-To: <1130724071.688187.59230@g47g2000cwa.googlegroups.com> References: <1130724071.688187.59230@g47g2000cwa.googlegroups.com> Message-ID: <1130768886.337891.97140@g44g2000cwa.googlegroups.com> You can easily do it with SW Explorer Automation (http://home.comcast.net/~furmana/SWIEAutomation.htm). The program creates an automation API for any Web application which uses HTML and DHTML and works with Microsoft Internet Explorer. The Web application becomes programmatically accessible from any .NET language. The tool has Visual Table Data Extractor. It allows visually define the table structure. The table becomes accessible from the code as DataTable class. You can develop the extraction script in hours with the tool. From no at spam Wed Oct 26 22:25:08 2005 From: no at spam (D H) Date: Wed, 26 Oct 2005 21:25:08 -0500 Subject: NEWBIE In-Reply-To: <1130367819.973474.85660@g49g2000cwa.googlegroups.com> References: <1130364703.849883.109300@z14g2000cwz.googlegroups.com> <1130367819.973474.85660@g49g2000cwa.googlegroups.com> Message-ID: beliavsky at aol.com wrote: > brenden wrote: > >>hey everyone....i'm new to all this programming and all this stuff and >>i just wanted to learn how to do it... >> >>does anyone think they can teach me how to work with python? > > > Don't waste readers' time with such vague and broad requests. Instead, > post a specific question, for example showing a small fragment of > Python code that does not work as you expect. Or ask how to do XYZ in > Python, if you are unable to find the answer using Google. > > "Newbie" by itself is always a bad subject line. Having a specific > question should help you form a better title for your message. As you can see, you won't find help here. You will get a lot of great advice and help on the python-tutor list, which is for beginners such as yourself: http://mail.python.org/mailman/listinfo/tutor From vvoipio at kosh.hut.fi Sun Oct 9 16:04:01 2005 From: vvoipio at kosh.hut.fi (Ville Voipio) Date: Sun, 9 Oct 2005 23:04:01 +0300 (EEST) Subject: wxPython in a PDA Message-ID: Does anyone know of an inexpensive PDA which would run wxPython? The availability of a conventional (wired) Ethernet would be nice, as well (e.g., using a CF adapter). TIA, - Ville -- Ville Voipio, Dr.Tech., M.Sc. (EE) From xah at xahlee.org Sat Oct 8 16:10:17 2005 From: xah at xahlee.org (Xah Lee) Date: 8 Oct 2005 13:10:17 -0700 Subject: Daisy Daisy, give me your answer do Message-ID: <1128802217.156887.234490@g43g2000cwa.googlegroups.com> there is a MacPerl program posted in 1998 that uses Mac's speech synth to sing Daisy Bell. See: http://bumppo.net/lists/macperl/1998/11/msg00412.html can anyone modify it so it runs out of the box on today's OS X? PS i'm posting this also in python and lisp group, i hope it'd be some general interest. For some background of this song, see http://xahlee.org/Periodic_dosage_dir/sanga_pemci/daisy_bell.html i'm interested in getting versions that can sing the song in Windows, Mac, Linux using whatever speech synth each OS may provide. Thanks. Xah xah at xahlee.org ? http://xahlee.org/ From my_email_is_posted_on_my_website at munged.invalid Sun Oct 9 03:21:37 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sun, 09 Oct 2005 07:21:37 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> Message-ID: <85hhk1d9ife3gvk6co97ra03u4hah7o8i8@4ax.com> On 8 Oct 2005 23:39:27 GMT, John Bokma wrote or quoted : >Yeah, yeah, and 640K is enough for everybody. Same song, different tune. For how long. Surely attachments are a stop gap. Can you imagine people sharing images that way 100 years from now? Why should we wait for the future? The problems blocking easy to use photo sharing are not technological but social. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From trentm at ActiveState.com Thu Oct 13 13:47:04 2005 From: trentm at ActiveState.com (Trent Mick) Date: Thu, 13 Oct 2005 10:47:04 -0700 Subject: installer for amd64 build of python? In-Reply-To: <1129225263.705977.181050@o13g2000cwo.googlegroups.com> References: <1129162224.131305.269060@g49g2000cwa.googlegroups.com> <434E1674.5010201@v.loewis.de> <1129192705.632826.145210@z14g2000cwz.googlegroups.com> <1129225263.705977.181050@o13g2000cwo.googlegroups.com> Message-ID: <20051013174704.GB19251@ActiveState.com> [Brett Hoerner wrote] > As an aside to this, are there any freely available C compilers for > Windows that can compile 64-bit binaries? I find nothing for Cygwin or > MinGW... Yes. The MS Platform SDK is free and includes a compiler that can target x86, ia64 and x64 (the latter is what MS -- and Sun -- are calling AMD64). Trent -- Trent Mick TrentM at ActiveState.com From matthew.garrish at sympatico.ca Sun Oct 23 21:02:59 2005 From: matthew.garrish at sympatico.ca (Matt Garrish) Date: Sun, 23 Oct 2005 21:02:59 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <86k6g59ke6.fsf@bhuda.mired.org> <3EI6f.43974$MF6.5922@fe1.news.blueyonder.co.uk> <86irvo861u.fsf@bhuda.mired.org> Message-ID: <5pW6f.1670$ki7.76729@news20.bellglobal.com> "David Schwartz" wrote in message news:djh3ue$otu$1 at nntp.webmaster.com... > > "Matt Garrish" wrote in message > news:EVT6f.1507$ki7.59085 at news20.bellglobal.com... > >>> A right is a scope of authority. That is, a sphere within which one's >>> decision is sovereign. > >> Then why were you claiming that a government can infringe on a person's >> rights if those rights are not codified or even accepted by those people? >> The idea of inalienable rights for anyone in a Western society only >> exists if you believe that the rights of Western societies are >> inalienable and should be respected everywhere. There is a huge arrogance >> in that assumption, though, and once you enter a jurisdiction that does >> not hold your rights to be inalienable they are no longer your rights. >> >> You can have generally agreed upon rights, but as you note, those rights >> can only be hoped for if the systems exist to enforce them. Once those >> systems erode, you no longer have rights only hopes. The more you allow >> those systems to be eroded, the less you can expect your rights to exist. > > This would suggest that rogue governments can't infringe on the rights > of their people because those people have no rights since their societies > don't recognize any. This is another principle I reject at its roots. Your > rights exist whether or not others choose to respect them. > I'd say to that that you're confusing a belief with a right. A belief doesn't become a right until society acknowledges it as such and puts measures in place to ensure it. If people are perfectly happy living under communist rule, who are you to tell them they must have the right to own property? If that society later acknowledges that it wants the right to own property then the government (in an ideal society) should respond accordingly. If the society demands a right and governments denies it, only then are the people's rights being oppressed (which may be what you were originally saying now that I look back, but I read it at first as the citizen's not ackowledging the right either). The counter-argument is that oppressive socities work to prevent their citizens from expressing their desire for rights or selectively apply them, which is all true. Without just laws and the instruments of justice to enforce them, however, you cannot correct the problem. There is still an acknowledgement on the part of society that things are wrong, and societal problems eventually come to a head when the time is right else we wouldn't be where we are and still not be where we need to go. I'm not claiming that the world is an easy place to live in... : ) Matt From Tommy.Ryding at gmail.com Tue Oct 18 04:25:17 2005 From: Tommy.Ryding at gmail.com (Tommy.Ryding at gmail.com) Date: 18 Oct 2005 01:25:17 -0700 Subject: global interpreter lock Message-ID: <1129623917.257410.294060@g43g2000cwa.googlegroups.com> I just need confirmation that I think right. Is the files thread_xxx.h (xxx = nt, os2 or whatever) responsible for the global interpreter lock in a multithreaded environment? I'm currently writing my own thread_VW for VxWorks, thats why I'm asking. //Tommy From aleaxit at yahoo.com Mon Oct 24 11:09:12 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 24 Oct 2005 08:09:12 -0700 Subject: Tricky Areas in Python References: <1130097286.772836.94930@g44g2000cwa.googlegroups.com> <1h4wbvb.1dblc4317zeuw2N%aleaxit@yahoo.com> <435CA1DE.2060101@REMOVEMEcyber.com.au> Message-ID: <1h4xfdx.azxzrkhr5xukN%aleaxit@yahoo.com> Steven D'Aprano wrote: ... > my hard-won ignorance, and admit that I don't see the > problem with the property examples: > > > class Sic: > > def getFoo(self): ... > > def setFoo(self): ... > > foo = property(getFoo, setFoo) Sorry for skipping the 2nd argument to setFoo, that was accidental in my post. The problem here is: class Sic is "classic" ("legacy", "old-style") so property won't really work for it (the setter will NOT trigger when you assign to s.foo and s is an instance of Sic). > > to > > class Base(object) > > def getFoo(self): ... > > def setFoo(self): ... > > foo = property(getFoo, setFoo) > > > > class Derived(Base): > > def getFoo(self): .... > > Unless the answer is "Why are you using setters and > getters anyway? This isn't Java you know." Nope, that's not a problem -- presumably the "..." bodies DO something useful, and they do get nicely dressed in attribute syntax. The problem, as others have indicated, is that overriding doesn't work as one might expect -- the solution, in Python 2.4 and earlier, is to use one extra level of indirection: def __getFoo(self): return self.getFoo() def getFoo(self): ... foo = property(__getFoo) so the name lookup for 'getFoo' on self happens when you access s.foo (for s being an instance of this here-sketched class) and overriding works just as expected. This can be seen as the simplest possible use case for the "Template Method" Design Pattern, btw;-) Alex From steve at holdenweb.com Fri Oct 7 04:01:21 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 07 Oct 2005 09:01:21 +0100 Subject: When someone from Britain speaks, Americans hear a "British accent"... In-Reply-To: <4h5ck1hkqq0ls83pq0lodkb51tsda4053k@4ax.com> References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kbgj7421kd560@corp.supernews.com> <4h5ck1hkqq0ls83pq0lodkb51tsda4053k@4ax.com> Message-ID: DaveM wrote: > On Fri, 07 Oct 2005 00:33:43 -0000, Grant Edwards wrote: [...] > >>For example: In British English one uses a plural verb when the >>subject consists of more than one person. Sports teams, >>government departments, states, corporations etc. are >>grammatically plural. In American, the verb agrees with the >>word that is the subject, not how many people are denoted by >>that word. >> >>In sports (thats "sport" for you Brits): > OK, so how do you account for the execresence "That will give you a savings of 20%", which usage is common in America? There aren't any universal rules, except possibly "British people speak English while Americans don't". Nowadays relatively few people on either side of the Atlantic even know the difference between a collective noun and a plural, so there's little hope of them being able to correctly apply any rule there might be (and yes, I split that infinitive just to annoy any pedants who may be reading). > > Yes. > > >>American: Minnesota is behind 7-0. The Vikings are behind 7-0. >> British: Minnesota are behind 7-0. The Vikings are behind 7-0. > > > True. > > >>In politics: > > >> American: The war department has decided to cancel the program. >> British: The war department have decided to cancel the program. > > > Not sure about this one. They may be used interchangeably as neither strikes > me as sounding "odd". > Then again, there's room for infinite disagreement about these topics. I mentioned a while ago that I disliked the English on a bumper sticker I liked, which read "Some village in Texas is missing their idiot". Several people defended this, saying that a village could use the plural possessive "their". I personally found it odd (and essentially non-grammatical) not because either the singular or plural forms should be mandated but because this one manages to mix them up. So "Some village in Texas are missing their idiot" would be better (though it sounds like the kind of thing only the idiot alluded to would say), while my preferred choice would be "Some village in Texas is missing its idiot". Then again, what can you expect from a country whose leader pronounces "nuclear" as though it were spelled "nucular"? I suppose it's only a matter of time before they change the spelling just like they did with "aluminium". tongue-in-cheek-ly y'rs - steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From renting at astron.nl Tue Oct 25 04:22:24 2005 From: renting at astron.nl (Adriaan Renting) Date: Tue, 25 Oct 2005 10:22:24 +0200 Subject: Microsoft Hatred FAQ Message-ID: >>>"David Schwartz" 10/25/05 9:44 am >>> % %"Peter T. Breuer" wrote in message %news:2n3133-19g.ln1 at news.it.uc3m.es... % %>> Essentially, Microsoft asked for exclusive arrangements. That is, %>>arrangements wherein you could not sell competing products if you wished %>>to %>>sell Microsoft products. That's not even remotely unusual. % %>It soitenly is, stanley. In case you hadn't noticed, the shops sell %>more than one kind of washing powder. % % Your argument is nonsensical. Because you can find one category of goods %that don't have the property I'm talking about it follows that the property %is unusual?! % % Operating systems are not like washing powder at all. Try to sell both %Big Macs and Whoppers in one store. Heck, try to sell Craftsman tools %without being a Sears. Microsoft gets to decide whether they sell their %operating systems software like washing powder or like burgers, not you. % The thing it, that under certain circumstances, defined by law, it becomes illegal to ask for exclusive arrangements. One of these is if you have a monopoly. Another is the way the Mob asks for "protection money". IANAL, so I don't know the exact wording, but sometime in the past the USA representative bodies/government decided that under certain conditions it is illegal. (and others like my own country) The in the 2000-2004 lawsuit it was proven that these conditions applied to MS. It happened before (Standard oil, American Tobacco Company, AT&T). I'm unsure if your point is that antitrust laws should not exist, or that they should not apply to MS. If you think those laws should not exist, I suggest you investigate why they were created, and maybe write your representative in your government to change this. If you think they should not apply to MS, but you in general agree with them, then I think you should investigate why the laws were found to apply to MS. Interesting information can be found here: http://en.wikipedia.org/wiki/Antitrust From petri.savolainen at iki.fi Mon Oct 3 06:43:37 2005 From: petri.savolainen at iki.fi (Petri Savolainen) Date: Mon, 03 Oct 2005 11:43:37 +0100 Subject: Python TNEF (winmail.dat attachment access) library? Message-ID: Hello, has anyone seen such a beast? I tried googling, PyPI, Parnassus etc. but could not find any pure-python code nor extensions to interface with any of the existing implementations. I am thinking about taking the Ruby code I found at http://www.zweknu.org/technical/index.rhtml?s=p%7c15 and converting that to Python. I have no experience with Ruby so this will be rather interesting... I guess another option would be to use CTypes to plug into some tnef shared library/DLL. I'd prefer a pure-python route though... Any pointers/recommendations appreciated. Thanks, Petri From pmartin at snakecard.com Mon Oct 17 22:03:18 2005 From: pmartin at snakecard.com (Philippe C. Martin) Date: Tue, 18 Oct 2005 02:03:18 GMT Subject: A Logging System for Python Message-ID: Dear all, I have been looking for a logging system and have come across http://www.red-dove.com/python_logging.html. As the site refers to PEP 282, I assume this package is a potential contender for integration in the Python distribution. Am I correct and if so is there any trend to include it in Python 2.5 ? Regards, Philippe From usenet at eikepreuss.de Wed Oct 26 04:35:01 2005 From: usenet at eikepreuss.de (Eike Preuss) Date: Wed, 26 Oct 2005 10:35:01 +0200 Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: <3s8t89FmdnriU1@individual.net> David Schwartz wrote: >> >>But if *every* vendor has to make that same choice, there is no place for >>that other 5% to go to buy another operating system. So the other >>operating system(s) die off. And those 5% become customers of Microsoft >>since there's no other choice left. And *that* is where the legal >>problems start: they gained market share by preventing consumers from >>finding competing products. > > > Right, except that's utterly absurd. If every vendor takes their tiny > cut of the 95%, a huge cut of the 5% is starting to look *REALLY* good. > Sure, that would be true if the market would be / would have been really global. In practice if you have a shop you have a limited 'region of influence'. Optimally you are the only shop in this region that sells the stuff, or perhaps there are a few shops that compete with you. Lets say in your region are two shops competing with you, and you must decide wether to sell product A (95%) or B (5%), but you may not sell both. Decision 1: Sell A, share the 95% of the local market with two -> about 32% of the local market for all of you, if all perform equally good Decision 2: Sell B -> you get the 5% of the market, the others 47% each This calculation is probably still a very bad approximation of the truth, but things are definitely not as easy as you state them. EP From david at jotax.com Thu Oct 27 13:56:32 2005 From: david at jotax.com (David Poundall) Date: 27 Oct 2005 10:56:32 -0700 Subject: Counting Threads In-Reply-To: <1130435220.846203.86320@g44g2000cwa.googlegroups.com> References: <1130435220.846203.86320@g44g2000cwa.googlegroups.com> Message-ID: <1130435792.701474.235570@g47g2000cwa.googlegroups.com> Just sorted (its always the way when you post isn't it) But the count isn't doint what I expected. I was after a increment after every time the class was used ireespective of instance. Instead I get a count based on the instance usage. Idea's anyone? # ------------------------------------------------------------------------------------ class ServerThreads: """ Wrapper for thread handling. Thread ID 0 = Controller Thread ID 1 = Plant Object 1 Thread ID 2 = Plant Object 2 """ GlobalThreadCount = 0 def __init__(self): global GlobalThreadCount self.Threads = {} GlobalThreadCount = 0 def launch(self, SubToLaunch, SubsArgs=(), SubsKwargs={}, AsDeamon=True): t = Thread(target=SubToLaunch, args = SubsArgs, kwargs = SubsKwargs) t.setDaemon(AsDeamon) t.start() self.Threads[len(self.Threads)] = t # Stash the thread in an instance local global GlobalThreadCount GlobalThreadCount += 1 print GlobalThreadCount def globalusagecount(self): """ Returns a count figure for how many threads are running in total usnig this class. """ global GlobalThreadCount return GlobalThreadCount def stop(self,ThreadID): t = self.Threads[ThreadID] t.stop() self.Threads.clear[ThreadID] def count(self): """ Returns alist of how many threads are running in the instance """ return len(self.Threads) def runningkeys(self): """ Returns a llist of all running Keys """ return self.Threads.keys def allOK(self): """ Returns a list of all threads that are down if any) """ ThreadsDown = [] for t in self.Threads: if not self.Threads[t].isAlive: ThreadsDown.append(t) return ThreadsDown From my_email_is_posted_on_my_website at munged.invalid Thu Oct 27 08:11:36 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Thu, 27 Oct 2005 12:11:36 GMT Subject: Microsoft Hatred FAQ References: <4ua533-60t.ln1@news.it.uc3m.es> Message-ID: <5mg1m1ls1m030esk5sonu9rmncc8l4vsgm@4ax.com> On Thu, 27 Oct 2005 04:07:50 -0700, "David Schwartz" wrote, quoted or indirectly quoted someone who said : > That is a bit questionable, I admit. It is questionable because the >intent is pretty obviously to get the individuals more interested in being >nice to you than looking out for the interests of their employers when they >make their purchasing decisions. I don't think this was as reprehensible as what MS did. For a start, everyone could refuse the trip if they wanted without dire consequences. They could also refuse to go out partying each night with the salesmen. They could refrain from alcohol (as I did). Even though I don't think in most cases the salesmen went so far as to purchase hookers or lap dancers, they did after the evening's revelry know something about the client that potentially could be very embarrasing if it were revealed to a spouse, without the tiniest hint of a threat to do so. -- Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching. From jari.aalto at cante.net Sat Oct 15 12:43:36 2005 From: jari.aalto at cante.net (Jari Aalto) Date: Sat, 15 Oct 2005 19:43:36 +0300 Subject: how to improve simple python shell script (to compile list of files) References: Message-ID: "Fredrik Lundh" writes: > Jari Aalto wrote: > | > Please suggest comments how can I make this script to work | > from bash. > > replace it with a call to the compileall module? > > $ python -mcompileall [directory...] Thanks, but that will not work. The files are gathered from discrete places and I'd need advice why the simple -c options does not accept the code inside parentheses. Are there some restrictions in Python to use only "all in one line"? I mean: python -c "command; command ...; command; ..." Jari From fredrik at pythonware.com Thu Oct 13 06:06:05 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 13 Oct 2005 12:06:05 +0200 Subject: Adding a __filename__ predefined attribute to 2.5? References: <1129098667.336115.303060@g47g2000cwa.googlegroups.com><1129103007.870187.101790@g44g2000cwa.googlegroups.com> <1129150883.303899.259570@g43g2000cwa.googlegroups.com> Message-ID: Rune Strand wrote: >> those modules are already imported when Python gets to your code, so >> the only "overhead" you're saving is a little typing. > > I don't understand this. Could you please elaborate? - if sys or os > are not imported for any other causes how are they already imported? because they are imported for Python's own purposes, together with lots of other stuff: > python Python 2.4.2 >>> import sys >>> sys.modules.keys() ['copy_reg', 'locale', '__main__', 'site', '__builtin__', 'encodings', 'os.path' , 'encodings.cp437', 'encodings.codecs', 'ntpath', 'UserDict', 'encodings.except ions', 'nt', 'stat', 'zipimport', 'warnings', 'encodings.types', '_codecs', 'enc odings.cp1252', 'sys', 'codecs', 'types', '_locale', 'signal', 'linecache', 'enc odings.aliases', 'exceptions', 'os'] (sys is a built-in module, btw, so the cost of importing that is always close to zero) > It may be lousy, but it requires no imports. And, as I said in the > answer to Steve, I _know_ there are many ways to achieve this, > including yours. But in your rush to pin-point lousy code, you didn't > read that, I suppose. you know, being clueless is one thing, but being both clueless and arrogant is not a good way to get anywhere. I suggest spending more time learning things (start with the language reference), and less time picking fights that leads no- where. From jepler at unpythonic.net Mon Oct 10 21:40:35 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Mon, 10 Oct 2005 20:40:35 -0500 Subject: pyparallel and MAKE controller board for CRYDOM AC/DC switches In-Reply-To: References: Message-ID: <20051011014035.GA21569@unpythonic.net> Recalling the parallel pinout, pin 3 is data bit 2. Have you tried def BIT(x): return 1< From c.peres2 at wanadoo.fr Mon Oct 10 04:21:48 2005 From: c.peres2 at wanadoo.fr (Peres) Date: Mon, 10 Oct 2005 10:21:48 +0200 Subject: 2D graphics Message-ID: <006a01c5cd73$a91c1450$0a01a8c0@NEWLAT> Hello, As a Python beginner, I feel a bit lost among all possible libraries... so I wondered whether soemone could help me find my way... I just need to generate animated sequences of 2D primitives (dots and lines), as fast as possible, checking the computer clock for the time elapsed for each image, and checking the mouse click. Thanks a lot in advance for your help! Valerie, a grateful Pythonner -------------- next part -------------- An HTML attachment was scrubbed... URL: From rrr at ronadam.com Sun Oct 9 12:34:56 2005 From: rrr at ronadam.com (Ron Adam) Date: Sun, 09 Oct 2005 16:34:56 GMT Subject: Function decorator that caches function results In-Reply-To: References: Message-ID: Fredrik Lundh wrote: > Ron Adam wrote: > > >>In effect, 'cache' and 'fn' are replaced by the objects they reference >>before the cached_result function is returned. > > > not really; accesses to "free variables" always go via special cell objects > (rather than direct object references), and the compiler uses special byte > codes for all accesses to such objects. > > this snippet illustrates the differences: > > def func1(): > return a > > def func2(a): > return a > > def wrapper(a): > def func3(): > return a > return func3 > > def decode(func): > import dis > print func.__name__ + ":" > dis.dis(func) > print "co_freevars =", func.func_code.co_freevars > print "func_closure =", func.func_closure > print > > decode(func1) > decode(func2) > decode(wrapper(10)) > > if you run this on a recent version of Python, you get something like: > > func1: > 2 0 LOAD_GLOBAL 0 (a) > 3 RETURN_VALUE > co_freevars = () > func_closure = None > > func2: > 5 0 LOAD_FAST 0 (a) > 3 RETURN_VALUE > co_freevars = () > func_closure = None > > func3: > 9 0 LOAD_DEREF 0 (a) > 3 RETURN_VALUE > co_freevars = ('a',) > func_closure = (,) > > note the use of LOAD_DEREF for the variable access. > > Other opcodes include STORE_DEREF (that updates a local variable > through a cell, used inside the "defining" scope), and MAKE_CLOSURE > (which sets up the function object for functions that actually uses > nested scopes; this is where the func_closure attribute is initialized). > > (now, if I weren't limited to plain text, I could have drawn a nice little > diagram for you, but that's an entirely different thread...) > > Thanks Fred, That's something useful to know when working with decorators I think. And it should answer Stevens question too. Abstract terminology is great once you already know the things and concepts it refers to. But if you don't, finding where the abstract connects to reality is sometimes not easy. There's nothing better than a good example to illistrate the concept. ;-) Cheers, Ron From belred at gmail.com Wed Oct 12 02:02:55 2005 From: belred at gmail.com (Bryan) Date: Tue, 11 Oct 2005 23:02:55 -0700 Subject: bizarro world (was Re: Python Doc Problem Example: sort() (reprise)) In-Reply-To: References: <1128937897.500935.254770@o13g2000cwo.googlegroups.com> <1129033426.009136.256600@g47g2000cwa.googlegroups.com> <1129071507.829655.252340@g44g2000cwa.googlegroups.com> Message-ID: mr. xah... would you be willing to give a lecture at pycon 2006? i'm sure you would draw a huge crowd and a lot of people would like to meet you in person... thanks. From bokr at oz.net Thu Oct 6 17:55:37 2005 From: bokr at oz.net (Bengt Richter) Date: Thu, 06 Oct 2005 21:55:37 GMT Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> <434245F5.6060500@REMOVEMEcyber.com.au> <7xr7b14lk0.fsf@ruckus.brouhaha.com> <7xu0fx9l7y.fsf@ruckus.brouhaha.com> <4344b80d.3321657210@news.oz.net> Message-ID: <43459965.3379345391@news.oz.net> On 6 Oct 2005 06:44:41 GMT, Antoon Pardon wrote: >Op 2005-10-06, Bengt Richter schreef : >> On 5 Oct 2005 09:27:04 GMT, Duncan Booth wrote: >> >>>Antoon Pardon wrote: >>> >>>> It also is one possibility to implement writable closures. >>>> >>>> One could for instace have a 'declare' have the effect that >>>> if on a more inner scope such a declared variable is (re)bound it >>>> will rebind the declared variable instead of binding a local name. >>> >>>That is one possibility, but I think that it would be better to use a >>>keyword at the point of the assigment to indicate assignment to an outer >>>scope. This fits with the way 'global' works: you declare at (or near) the >>>assignment that it is going to a global variable, not in some far away part >>>of the code, so the global nature of the assignment is clearly visible. The >>>'global' keyword itself would be much improved if it appeared on the same >>>line as the assignment rather than as a separate declaration. >>> >>>e.g. something like: >>> >>>var1 = 0 >>> >>>def f(): >>> var2 = 0 >>> >>> def g(): >>> outer var2 = 1 # Assign to outer variable >>> global var1 = 1 # Assign to global >> >> IMO you don't really need all that cruft most of the time. E.g., what if ':=' >> meant 'assign to variable wherever it is (and it must exist), searching according >> to normal variable resolution order (fresh coinage, vro for short ;-), starting with >> local, then lexically enclosing and so forth out to module global (but not to builtins).' > >Just some ideas about this > >1) Would it be usefull to make ':=' an expression instead if a > statement? Some people would think so, but some would think that would be tempting the weak ;-) > >I think the most important reason that the assignment is a statement >and not an expression would apply less here because '==' is less easy >to turn into ':=' by mistake than into = > >Even if people though that kind of bug was still too easy > >2) What if we reversed the operation. Instead of var := expression, > we write expression =: var. > >IMO this would make it almost impossible to write an assignment >by mistake in a conditional when you meant to test for equality. It's an idea. You could also have both, and use it to differentiate pre- and post-operation augassign variants. E.g., alist[i+:=2] # add and assign first, index value is value after adding alist[i=:+2] # index value is value before adding and assigning Some people might think that useful too ;-) Hm, I wonder if any of these variations would combine usefully with the new short-circuiting expr_true if cond_expr else expr_false ... Sorry I'll miss the flames, I'll be off line a while ;-) Regards, Bengt Richter From apardon at forel.vub.ac.be Thu Oct 6 07:18:43 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 6 Oct 2005 11:18:43 GMT Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <3qi8erFf252rU1@uni-berlin.de> <3qkdbrFfgga9U1@uni-berlin.de> Message-ID: Op 2005-10-06, Diez B. Roggisch schreef : >> Sure, But allow me this silly analogy. >> >> Going out on a full test-drive will also reveal your tires are flat. >> So if you one has to be dropped, a full test drive or a tire check >> it would certainly be the tired check. But IMO the tire check >> is still usefull. > > But you could write it as test - including not only a look (which > resembles the limited capabilities of typechecking), but testing the air > pressure, looking at the tyre type and see that it won't match the rainy > conditions... > >> Hey, I'm all for testing. I never suggested testing should be dropped >> for declarations > > The testing is IMHO more valuable than typechecking. The latter one > actually _limits_ me. See e.g. the java IO-Api for a very bloated way of > what comes very naturally with python. Duck-typing at it's best. But typechecking doesn't has to be java like. I can't help but feel that a lot of people have specific typechecking systems in mind and then conclude that the limits of such a symtem are inherent in typechecking itself. IMO a good type system doesn't need to limit python in any way. -- Antoon Pardon From roy at panix.com Fri Oct 21 22:10:20 2005 From: roy at panix.com (Roy Smith) Date: Fri, 21 Oct 2005 22:10:20 -0400 Subject: Python vs Ruby References: <1129776956.254389.188040@z14g2000cwz.googlegroups.com> <89DF2CF9-408E-4D9E-8E43-003D23006C24@pengale.com> Message-ID: Robert Boyd wrote: > As if Plone, Zope, and (non-Python) Shibboleth weren't getting me > enough funny looks. And I haven't even started telling co-workers > about Django. A couple of years ago, a head-hunter asked me if I knew Plone. I figured he was just being an idiot and didn't know how to spell PL/1. Silly me :-) From viktor.marohnic at gmail.com Tue Oct 25 07:56:02 2005 From: viktor.marohnic at gmail.com (Viktor Marohnic) Date: 25 Oct 2005 04:56:02 -0700 Subject: overiding assignment in module Message-ID: <1130241362.081637.105410@g14g2000cwa.googlegroups.com> Hello. I would to do something like this. container = [] p1 = point() l1 = line() and i would like to override = method of the module so that its puts all objects into container. how i can do something like that. thanks for help, viktor. From samrobertsmith at gmail.com Tue Oct 25 02:55:32 2005 From: samrobertsmith at gmail.com (Shi Mu) Date: Mon, 24 Oct 2005 23:55:32 -0700 Subject: pickle Message-ID: <1d987df30510242355k66dca1e9p6e3e1df9c2c6e981@mail.gmail.com> I got a sample code and tested it but really can not understand the use of pickle and dump: >>> import pickle >>> f = open("try.txt", "w") >>> pickle.dump(3.14, f) >>> pickle.dump([1,2,3,4], f) >>> f.close() From tim.peters at gmail.com Tue Oct 18 16:07:35 2005 From: tim.peters at gmail.com (Tim Peters) Date: Tue, 18 Oct 2005 16:07:35 -0400 Subject: wierd threading behavior In-Reply-To: References: <1129330815.876193.147800@g49g2000cwa.googlegroups.com> Message-ID: <1f7befae0510181307p6b2ad9a2w1b2e44edb5a55241@mail.gmail.com> [Qun Cao] >> import thread >> def main(): >> thread.start_new(test.()) >> >> def test(): >> print 'hello' >> >> main() >> " >> this program doesn't print out 'hello' as it is supposed to do. >> while if I change main() [Neil Hodgson] > The program has exited before the thread has managed to run. It is > undefined behaviour whether secondary threads survive main thread > termination but it looks like they don't on your system. In fact, they don't on most systems. > Use the threading module and call join to wait for all threads to > complete before exiting the program. That's a different story: threads from the `thread` module have entirely OS-specific behavior when Python shuts down. Python knows a lot more about threads from the newer `threading` module, & uses an atexit() hook to ensure that the Python interpreter does _not_ go away while a threading.Thread is still running(*). IOW, Python does the join() for you for threading.Thread threads -- there's no need to do it yourself. (*) Unless you explicitly mark it as a daemon thread. From bokr at oz.net Mon Oct 31 12:02:18 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 31 Oct 2005 17:02:18 GMT Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <867jbxfpvb.fsf@bhuda.mired.org> <1h55ri3.1hzntdk1dtxpa7N%aleaxit@yahoo.com> <43632812.1249162210@news.oz.net> <4363b997.1286415918@news.oz.net> <436541ce.1390422241@news.oz.net> Message-ID: <436645a8.1456944885@news.oz.net> On Mon, 31 Oct 2005 09:19:10 +0100, Peter Otten <__peter__ at web.de> wrote: >Bengt Richter wrote: > >> I still smelled a bug in the counting of substring in the overlap region, >> and you motivated me to find it (obvious in hindsight, but aren't most ;-) >> >> A substring can get over-counted if the "overlap" region joins >> infelicitously with the next input. E.g., try counting 'xx' in 10*'xx' >> with a read chunk of 4 instead of 1024*1024: >> >> Assuming corrections so far posted as I understand them: >> >> >>> def byblocks(f, blocksize, overlap): >> ... block = f.read(blocksize) >> ... yield block >> ... if overlap>0: >> ... while True: >> ... next = f.read(blocksize-overlap) >> ... if not next: break >> ... block = block[-overlap:] + next >> ... yield block >> ... else: >> ... while True: >> ... next = f.read(blocksize) >> ... if not next: break >> ... yield next >> ... >> >>> def countsubst(f, subst, blksize=1024*1024): >> ... count = 0 >> ... for block in byblocks(f, blksize, len(subst)-1): >> ... count += block.count(subst) >> ... f.close() >> ... return count >> ... >> >> >>> from StringIO import StringIO as S >> >>> countsubst(S('xx'*10), 'xx', 4) >> 13 >> >>> ('xx'*10).count('xx') >> 10 >> >>> list(byblocks(S('xx'*10), 4, len('xx')-1)) >> ['xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xxxx', 'xx'] >> >> Of course, a large read chunk will make the problem either >> go away >> >> >>> countsubst(S('xx'*10), 'xx', 1024) >> 10 >> >> or might make it low probability depending on the data. > >[David Rasmussen] > >> First of all, this isn't a text file, it is a binary file. Secondly, >> substrings can overlap. In the sequence 0010010 the substring 0010 >> occurs twice. The OP didn't reply to my post re the above for some reason http://groups.google.com/group/comp.lang.python/msg/dd4125bf38a54b7c?hl=en& > >Coincidentally the "always overlap" case seems the easiest to fix. It >suffices to replace the count() method with > >def count_overlap(s, token): > pos = -1 > n = 0 > while 1: > try: > pos = s.index(token, pos+1) > except ValueError: > break > n += 1 > return n > >Or so I hope, without the thorough tests that are indispensable as we should >have learned by now... > Unfortunately, there is such a thing as a correct implementation of an incorrect spec ;-) I have some doubts about the OP's really wanting to count overlapping patterns as above, which is what I asked about in the above referenced post. Elsewhere he later reveals: [David Rasmussen] >> If you must know, the above one-liner actually counts the number of >> frames in an MPEG2 file. I want to know this number for a number of >> files for various reasons. I don't want it to take forever. In which case I doubt whether he wants to count as above. Scanning for the particular 4 bytes would assume that non-frame-marker data is escaped one way or another so it can't contain the marker byte sequence. (If it did, you'd want to skip it, not count it, I presume). Robust streaming video format would presumably be designed for unambigous re-synching, meaning the data stream can't contain the sync mark. But I don't know if that is guaranteed in conversion from file to stream a la HDLC or some link packet protocol or whether it is actually encoded with escaping in the file. If framing in the file is with length-specifying packet headers and no data escaping, then the filebytes.count(pattern) approach is not going to do the job reliably, as Lasse was pointing out. Requirements, requirements ;-) Regards, Bengt Richter From bokr at oz.net Mon Oct 31 22:11:32 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 01 Nov 2005 03:11:32 GMT Subject: Reuse base-class implementation of classmethod? References: <9By9f.17396$65.522385@twister1.libero.it> Message-ID: <4366d5d7.1493855220@news.oz.net> On Tue, 01 Nov 2005 00:24:37 GMT, "Giovanni Bajo" wrote: >Hello, > >what's the magic needed to reuse the base-class implementation of a >classmethod? > >class A(object): > @classmethod > def foo(cls, a,b): > # do something > pass > >class B(A): > @classmethod > def foo(cls, a, b): > A.foo(cls, a, b) # WRONG! > >I need to call the base-class classmethod to reuse its implementation, but I'd >like to pass the derived class as first argument. >-- >Giovanni Bajo > > Maybe define a funny-class-method decorator? (nothing below tested beyond what you see ;-) >>> def funnycm(m): ... return property(lambda cls: m.__get__(type(cls), type(type(cls)))) ... >>> class A(object): ... @funnycm ... def foo(cls, a, b): ... print cls, a, b # do something ... >>> class B(A): ... pass # just inherit ... >>> a=A() >>> a.foo(1,2) 1 2 >>> b=B() >>> b.foo(1,2) 1 2 Or more directly, a custom descriptor (with dynamic method replacement for good measure ;-) >>> class funnycm(object): ... def __init__(self, f): self._f = f ... def __get__(self, inst, cls=None): ... return self._f.__get__(inst is None and cls or type(inst)) ... def __set__(self, inst, m): self._f = m # replace method ... >>> class A(object): ... @funnycm ... def foo(cls, a, b): ... print cls, a, b # do something ... >>> class B(A): ... pass # just inherit ... >>> a=A() >>> a.foo(1,2) 1 2 >>> b=B() >>> b.foo(1,2) 1 2 >>> A.foo(3,4) 3 4 >>> B.foo(3,4) 3 4 >>> a.foo = lambda cls, *args: repr(args) >>> a.foo('what','now','then?') "('what', 'now', 'then?')" >>> b.foo('eh?') "('eh?',)" >>> B.foo() '()' Vary to taste ;-) Regards, Bengt Richter From steve at holdenweb.com Sun Oct 2 05:51:47 2005 From: steve at holdenweb.com (Steve Holden) Date: Sun, 02 Oct 2005 10:51:47 +0100 Subject: Problems posting with urlencode In-Reply-To: References: <5HN%e.61089$mb4.14795@tornado.rdc-kc.rr.com> Message-ID: Fredrik Lundh wrote: > Joseph Chase wrote: > > >>When I go and view the inserted record, the record exists, but the field >>values are null. It is my thinking that the backend needs the "id" value >>for each input value; how do I add that data to the urlencode() call? > > > since the id isn't part of the form data set: > > http://www.w3.org/TR/REC-html40/interact/forms.html#form-data-set > > that's a bit unlikely. > > printing the params string might help you figure out what's > missing. > If there's no chance of putting any debug statements into the processing script you might consider using a proxy or submitting to a local server to ensure that you are submitting what you think. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From running.bare at gmail.com Sat Oct 1 17:03:44 2005 From: running.bare at gmail.com (Running Bare) Date: Sat, 01 Oct 2005 17:03:44 -0400 Subject: OT: Phases of the moon [was Re: A Moronicity of Guido van Rossum] References: <1128003857.930444.47650@g14g2000cwa.googlegroups.com> <1128013745.763757.144280@g44g2000cwa.googlegroups.com> <1128015868.201617.153240@g14g2000cwa.googlegroups.com> <0001HW.BF63479501083049F0407550@news.individual.de> <3q7tg9Fdleo3U1@individual.net> Message-ID: Ulrich Hobelmann writes: > When TV is turned off by a power failure, lots of people that > usually never have sex start making love, and lots of people that > usually use contraception lose their minds and forget about it. > > 9 months later more babies are born, unless that's also a myth. http://www.snopes.com/pregnant/blackout.htm "Despite initial reports of New York City hospitals' seeing a dramatic increase in the number of births nine months after the 1965 blackout, later analyses showed the birth rate during that period to be well within the norm." From adelagon at gmail.com Thu Oct 27 05:30:13 2005 From: adelagon at gmail.com (Alvin A. Delagon) Date: Thu, 27 Oct 2005 17:30:13 +0800 Subject: SOAPpy module In-Reply-To: References: Message-ID: <43609E25.4020908@gmail.com> Hello fellow pythonista's! I would like to ask if there's any good people who had experience in using the SOAPpy module. I'm currently rewriting a SOAP client that is written in PERL which uses the SOAP::Lite module. I managed to fetch the XML response from the server but I'm getting XML parser errors. I turned on the SOAP debug mode so that I could check the Incoming SOAP message and it was ok. >:o Has anyone experienced this? I'm googling like crazy these past few weeks just to find a solution to this predicament. Thank you in advance! :-) From johnnyandfiona at hotmail.com Fri Oct 28 06:03:31 2005 From: johnnyandfiona at hotmail.com (Johnny Lee) Date: 28 Oct 2005 03:03:31 -0700 Subject: How to translate python into C In-Reply-To: <1130493304.961498.226200@g47g2000cwa.googlegroups.com> References: <1130491053.787273.201650@g44g2000cwa.googlegroups.com> <1130493304.961498.226200@g47g2000cwa.googlegroups.com> Message-ID: <1130493811.719479.160450@z14g2000cwz.googlegroups.com> Szabolcs Nagy wrote: > python creates bytecode (like java classes) > > > you cannot translate python directly to c or machine code, but there > are some projects you probably want to look into > > > Pypy is a python implemetation in python and it can be used to > translate a python scrip to c or llvm code. (large project, work in > progress) > http://codespeak.net/pypy/dist/pypy/doc/news.html > > > Shedskin translates python code to c++ (not all language features > supported) > http://shed-skin.blogspot.com/ > > > Pyrex is a nice language where you can use python and c like code and > it translates into c code. (it is useful for creating fast python > extension modules or a python wrapper around an existing c library) > http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/ Thanks, Szabolcs. In fact, I want to reproduce a crush on cygwin. I used a session of python code to produce the crush, and want to translate it into C and reproduce it. Is the tools provided by you help with these issues? Of coz, I'll try them first. :) Regards, Johnny From aleax at mail.comcast.net Sat Oct 8 03:09:30 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Sat, 8 Oct 2005 00:09:30 -0700 Subject: Extending Python References: <1128533901.767470.279220@z14g2000cwz.googlegroups.com> Message-ID: <1h4371j.fuys6u9p47htN%aleax@mail.comcast.net> Micah Elliott wrote: > On Oct 05, Tuvas wrote: > > I am looking for a good tutorial on how to extend python with C > > code. I have an application built in C that I need to be able to use > > in Python. I have searched through various sources, starting of > > course with the Python site itself, and others, but I felt a bit > > lacking from the Python site, it seems it was only made for those > > who installed the source distribution, as for the other people... > > Anyways, thanks for the help! > > I have no experience with this, but I see that Alex Martelli's "Python > In A Nutshell" has quite a few pages on the subject. I also covered the same subject in a more tutorial (but less deep and extended) way in articles for "Py" magazine, but I don't know if those old issues of it are still in print. Alex From jjl at pobox.com Mon Oct 3 13:26:51 2005 From: jjl at pobox.com (John J. Lee) Date: 03 Oct 2005 18:26:51 +0100 Subject: Where to find python c-sources References: <433e7898$0$49766$ed2e19e4@ptn-nntp-reader04.plus.net> Message-ID: [Tor Erik S?nvisen] > socketmodule.c, but I can't locate this file... Where should I look? [John, finding 'socketmodule.c' responds well to "I'm Feeling Lucky"] > Does google vary in its results across the globe? [Michael] > The search terms might be obvious to you, but it simply means your google-fu > is strong, and the strong should help the weak. (or not attack them at > least...) You believe that Tor is dumb enough not to think of searching for "socketmodule.c" when, um, searching for socketmodule.c? John From andrea_gavana at tin.it Thu Oct 13 15:58:26 2005 From: andrea_gavana at tin.it (Andrea Gavana) Date: Thu, 13 Oct 2005 21:58:26 +0200 Subject: [PIL]: Question On Changing Colour Message-ID: <008001c5d030$79890e40$5b923652@Gavana> Hello Terry, > new_hue # your 'basic color', just the hue part > rgb_base # color from the basic button image > rgb_new # the new color you want to replace rgb_base with > > rgb_new = hsv_to_rgb( (new_hue,) + rgb_to_hsv(rgb_base)[1:]) thanks a lot for your suggestion! However, either I did not understand it correctly or I am doing something stupid in my code. Here is a small example: from colorsys import * # that is the old colour --> GREY rgb_old = (0.7, 0.7, 0.7) # Transform the new colour in HSV hsv_old = rgb_to_hsv(rgb_old[0], rgb_old[1], rgb_old[2]) # this is the new colour --> BLUE rgb_new = (0.0, 0.0, 1.0) # Transform the new colour in HSV hsv_new = rgb_to_hsv(rgb_new[0], rgb_new[1], rgb_new[2]) # I take only the Hue part of the new colour new_hue = hsv_new[0] # Get the new colour rgb_new = hsv_to_rgb(new_hue, hsv_old[1], hsv_old[2]) print rgb_old print rgb_new print rgb_old == rgb_new This prints: (0.69999999999999996, 0.69999999999999996, 0.69999999999999996) (0.69999999999999996, 0.69999999999999996, 0.69999999999999996) True So, no matter what colour I choose as a "new" colour, the Hue part of the new colour doesn't change in RGB. In other words, leaving the old value for "Saturation" and "Value" makes the presence of the "Hue" part useless. But why in the world does this happen? If a colour is defined by 3 values, changes in every single value should change the colour too... Ah, thanks God for the existence of RGB ;-) Thanks a lot for every suggestion. Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.virgilio.it/infinity77 -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwm at mired.org Tue Oct 25 16:08:02 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 25 Oct 2005 16:08:02 -0400 Subject: security References: <1130247483.668999.322640@g43g2000cwa.googlegroups.com> Message-ID: <86d5lt4axp.fsf@bhuda.mired.org> "Mattia Adami" writes: > Hi to all. > I'm intristing in write a plugin for browsers that can execute python > code. > I know the main problem is security. Many thread were opened about this > in the ng. > I would know if fork python rewriting some library could avoid > problems. I.e. one problem is the possibility to access files. If I > rewrite the open() function so that raises exception if the program try > to access a file out of a defined directory. > I'm sure not a security expert, so please be patient if my question is > stupid. People who *are* security experts have looked into modifying Python to make it secure, and given up on the project as unrealistic. Generally, taking an existing project that wasn't designed with security in mind and making it secure is hard. Not impossible, but not easy. You might consider using Jython and jythonc to produce objects to run in the JVM. Not only was that designed with security in mind, but most browsers come with a JVM already installed. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From fredrik at pythonware.com Mon Oct 10 14:06:51 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 10 Oct 2005 20:06:51 +0200 Subject: unable to import os References: Message-ID: Kim Nguyen wrote: > Fredrik Lundh,I replaced mtime = os.stat(Path + file_name)[os.path.stat.ST_MTIME] > with mtime = nt.stat("q.py") per your suggested, then ran it from IDLE 2.4.2. Here is > the message I got oh, sorry, that was an example that accidentally slipped through. I somehow expected you to realize that if you wanted to stat some other file, you would pass in another filename. From joeyjwc at gmail.com Thu Oct 27 05:52:05 2005 From: joeyjwc at gmail.com (Joey C.) Date: 27 Oct 2005 02:52:05 -0700 Subject: Setting a Limit to the Maximum Size of an Upload In-Reply-To: References: <1130147553.883353.141410@g14g2000cwa.googlegroups.com> <1130232152.429900.109710@g44g2000cwa.googlegroups.com> Message-ID: <1130406725.833382.119660@g44g2000cwa.googlegroups.com> Yes, I see that now. I tried your method and it seemed to work fine until I tried printing the filesize out. def checkfilesize(thefile): # Check the Size of the File global filesize thefile.seek(0,2) filesize = thefile.tell() thefile.seek(0) print filesize print conf["upmax"] if filesize <= conf["upmax"]: print "File Size Okay." noupload = False else: print "File is too Large." noupload = True Basically conf["upmax"] is a number that I extract from a configuration file that is the maximum size of an upload. I had tried setting conf["upmax"] to 1 and it should have technically disallowed a 28 byte file to pass through. But it did, so I added two lines to print the file size and the conf["upmax"] variable. The file size turned out to be "0"! thefile still is just params["upfile"].file, by the way. Any suggestions? From lasse at vkarlsen.no Sun Oct 9 09:50:12 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Sun, 09 Oct 2005 15:50:12 +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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <41hhk195gcipfarnqu85ggs606aqi89ea1@4ax.com> Message-ID: <2dadnfArEfWwvdTeRVnzvA@telenor.com> Tim Tyler wrote: >>Only if your photos are so obscure and confusing that they need captions. >> >>"Here's Johnny with the dog. Here is Johnny with the dog again. This one >>is Johnny on his own. Here is the dog. Oh look, it is Johnny with the dog >>again -- that's the dog on the left, in case it isn't clear. Just for a >>change, this is Johnny wearing a hat. It is blue with a feather in it, >>in case you couldn't tell from, oh I don't know, looking at the actual >>picture." > > > What have you got against captions? > > Giving photos captions is a *very* common practice. Perhaps he has a search engine that can find blue hats in an image and recognize people? -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From peter at engcorp.com Mon Oct 24 16:16:36 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 24 Oct 2005 16:16:36 -0400 Subject: python cgi script not understood as html In-Reply-To: <80b7f.6738$tV6.6215@newssvr27.news.prodigy.net> References: <80b7f.6738$tV6.6215@newssvr27.news.prodigy.net> Message-ID: Philippe C. Martin wrote: > The following code outputs the actual HTML text to the browser, not the > interpreted text. > > html_ok = """ > Content-Type: text/html\n > "http://www.w3.org/TR/html4/loose.dtd">\n HTTP header lines must end with \r\n, not just with \n. Not sure this is the solution to your specific problem though... -Peter From steve at REMOVETHIScyber.com.au Tue Oct 25 11:38:01 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Wed, 26 Oct 2005 01:38:01 +1000 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: On Tue, 25 Oct 2005 14:22:53 +0000, Not Bill Gates wrote: > The flaw with this is that business owners don't get to decide what > the market wants. And the market wanted the Microsoft OS. Every > other OS in the market had bit player status, via the economic > principle called increasing returns. > > You either sell what the market wants, or you go out of business. That is not true. The market was quite happy to buy competing products such as DR DOS. What the market was not happy to do was buy DR DOS, but pay for *both* DR DOS and MS DOS even though they only received DR DOS. And that, in a nutshell, is why Microsoft's actions were illegal. They were stealing from computer buyers: if you wished to buy an IBM-compatible PC, you had to pay for MS DOS even if you didn't want it, and having paid for it, there was no guarantee that you would receive it. Most users didn't know that they were paying for MS DOS -- all they knew was that MS DOS either came bundled with the PC automatically, or that if they requested some other operating system, they ended up paying more rather than less -- even when that other OS was cheaper than MS DOS. Imagine that your corner store charged $1 for a Coke, $0.90 for a Pepsi, and $5 for burger and Coke. If you asked for a burger on its own, the price would still be $5. If you asked them for a burger and Pepsi, the price would go up to $5.90 -- and the Coca-Cola company would still get their dollar for the Coke you didn't get, plus another dollar for the same Coke when the next customer bought it. If only one or two stores did this, then the market would correct itself: people who wanted Pepsi, or a burger without Coke, would go elsewhere, and save a dollar. But in the case of Microsoft, there was no practical "elsewhere" to go to. All the resellers did the same thing. Virtually the only alternative, buying an Apple Macintosh, was more or less the equivalent of driving to the next state to buy a $10 steak when what you wanted was a $5 burger. The situation was, pay Microsoft for MS DOS or go without a PC. Since users were either unaware of the situation, or unable to change it, they did the rational thing: why pay for a Coke and then pay again for a Pepsi if you just want any old drink? A few die-hard DR DOS supporters paid double for the product they wanted, and helped enrich Microsoft. The rest simply took the path of least resistance: if you're going to pay for a Coke no matter what, you might as well drink it. The thing with markets is that they only lead to efficient outcomes when there is sufficient competition. That's why anti-competitive behaviour is a bad thing, and is illegal in just about every country in the world. (Whether the laws are enforced is another story.) A few people, blinded by ideology, deny the evidence of their own experiences by insisting that monopolies do no harm. See, for instance, the contrasting situation in hardware and software. As compilers and other tools have evolved, it has become easier to develop software. Distributing it has also become easier: in 1985, Word came on five or six floppies worth perhaps a dollar each, with two or three kilograms of paper manuals. Today, you get a single CD worth maybe twenty five cents. In the case of Windows, often all you will get is a licence number, not even the media. The cost of distributing Windows is essentially zero. And yet over that same twenty year period, the cost of the operating system has more or less doubled in price. Hardware, on the other hand, has fallen in price by perhaps 90%, while simultaneously becoming far more capable. The PC I bought in 1986 for $4000 probably had less computing power than the DVD drive I paid $40 for this year. There is one desktop operating system vendor with monopoly power. There are hundreds of hardware vendors competing on price and features. Only those blinded by ideology fail to see the connection. -- Steven. From sybrenUSE at YOURthirdtower.com.imagination Mon Oct 31 05:23:37 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Mon, 31 Oct 2005 11:23:37 +0100 Subject: Why the nonsense number appears? References: <1130749726.707175.293040@g43g2000cwa.googlegroups.com> Message-ID: Ben O'Steen enlightened us with: > I think that the previous poster was asking something different. It all boils down to floating point inprecision. > If > >>>> t1 = 0.500 >>>> t2 = 0.461 >>>> print t1-t2 > 0.039 > > Then why: > >>>> t1 += 12345678910 >>>> t2 += 12345678910 >>>> # Note, both t1 and t2 have been incremented by the same amount. >>>> print t1-t2 > 0.0389995574951 It's easier to explain in decimals. Just assume you only have memory to keep three decimals. 12345678910.500 is internally stored as something like 1.23456789105e10. Strip that to three decimals, and you have 1.234e10. In that case, t1 - t2 = 1.234e10 - 1.234e10 = 0. > Using decimal as opposed to float sorts out this error as floats are > not built to handle the size of number used here. They can handle the size just fine. What they can't handle is 1/1000th precision when using numbers in the order of 1e10. 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 http Mon Oct 10 08:01:17 2005 From: http (Paul Rubin) Date: 10 Oct 2005 05:01:17 -0700 Subject: Python reliability References: <7xr7au1hr5.fsf@ruckus.brouhaha.com> <7xwtkl21hn.fsf@ruckus.brouhaha.com> Message-ID: <7xll11twc2.fsf@ruckus.brouhaha.com> Ville Voipio writes: > Just one thing: how reliable is the garbage collecting system? > Should I try to either not produce any garbage or try to clean > up manually? The GC is a simple, manually-updated reference counting system augmented with some extra contraption to resolve cyclic dependencies. It's extremely easy to make errors with the reference counts in C extensions, and either leak references (causing memory leaks) or forget to add them (causing double-free crashes). The standard libraries are pretty careful about managing references but if you're using 3rd party C modules, or writing your own, then watch out. There is no way you can avoid making garbage. Python conses everything, even integers (small positive ones are cached). But I'd say, avoid making cyclic dependencies, be very careful if you use the less popular C modules or any 3rd party ones, and stress test the hell out of your app while monitoring memory usage very carefully. If you can pound it with as much traffic in a few hours as it's likely to see in a year of deployment, without memory leaks or thread races or other errors, that's a positive sign. > Well... Here the uptime benefit from using several servers is not > eceonomically justifiable. I am right now at the phase of trying to > minimize the downtime with given hardware resources. This is not > flying; downtime does not kill anyone. I just want to avoid choosing > tools which belong more to the problem than to the solution set. You're probably ok with Python in this case. From fairwinds at eastlink.ca Fri Oct 14 14:55:09 2005 From: fairwinds at eastlink.ca (David Pratt) Date: Fri, 14 Oct 2005 15:55:09 -0300 Subject: Stripping ASCII codes when parsing Message-ID: <0ABD1968-3CE4-11DA-AE8C-000A27B3B070@eastlink.ca> I am working with a text format that advises to strip any ascii control characters (0 - 30) as part of parsing data and also the ascii pipe character (124) from the data. I think many of these characters are from a different time. Since I have never seen most of these characters in text I am not sure how these first 30 control characters are all represented (other than say tab (\t), newline(\n), line return(\r) ) so what should I do to remove these characters if they are ever encountered. Many thanks. From peter at engcorp.com Tue Oct 11 07:07:01 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 11 Oct 2005 07:07:01 -0400 Subject: Python's Performance In-Reply-To: References: <20051008040614.47429.qmail@web30607.mail.mud.yahoo.com> <178B879D-FDB6-458C-BE00-A03820D98703@advfn.com> <1128969275.804305.193460@f14g2000cwb.googlegroups.com> Message-ID: <434B9CD5.6050904@engcorp.com> Steve Holden wrote: > And we definitely need "agile" in there. Bugger, I'll go out and come in > again ... Used in the same breath as the word "bugger", I'm not sure the phrase "go out and come in again" is entirely appropriate for a family forum. ;-) But I'm also not sure I ought to post that to the group, so I'll spare them and just inflict the thought on you! Cheers, -Peter From email at christoph-haas.de Mon Oct 24 04:37:33 2005 From: email at christoph-haas.de (Christoph Haas) Date: Mon, 24 Oct 2005 10:37:33 +0200 Subject: testing '192.168.1.4' is in '192.168.1.0/24' ? In-Reply-To: <1130142091.327886.163710@g44g2000cwa.googlegroups.com> References: <1130131120.695320.180030@z14g2000cwz.googlegroups.com> <1130142091.327886.163710@g44g2000cwa.googlegroups.com> Message-ID: <200510241037.34048.email@christoph-haas.de> On Monday 24 October 2005 10:21, bonono at gmail.com wrote: > thanks, that is basically what I am doing and since it is a recipe, I > would assume there is no standard library module for it. Well, http://py.vaults.ca/~x/parnassus/apyllo.py/126307487 lists a few. I had used IPy in the past. But somehow nothing so far was a decent substitute for Perl's Net::IP. Christoph -- ~ ~ ".signature" [Modified] 1 line --100%-- 1,48 All From fredrik at pythonware.com Tue Oct 4 14:42:18 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 4 Oct 2005 20:42:18 +0200 Subject: how to get any available port References: Message-ID: Mohammed Smadi wrote: > if am using s.bind for a tcp socket. On the client side i dont really > care which socket i use as long as i get an available socket. Is there a > funciton or a way to get an available socket? why are you using bind if you're on the client side? From peter at engcorp.com Mon Oct 10 22:32:36 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 10 Oct 2005 22:32:36 -0400 Subject: [Info] PEP 308 accepted - new conditional expressions In-Reply-To: References: <3q4ro9Fd770nU3@individual.net> Message-ID: Sebastian Bassi wrote: > I don't understand why there is a new expression, if this could be > accomplished with: > > if C: > X > else: > Y > > What is the advantage with the new expression? It actually is an expression, whereas your example shows a statement (so "this" could _not_ be accomplished with what you showed). -Peter From fredrik at pythonware.com Sun Oct 9 07:43:38 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 9 Oct 2005 13:43:38 +0200 Subject: Function decorator that caches function results References: <7x4q7rt3yl.fsf@ruckus.brouhaha.com> Message-ID: Steven D'Aprano wrote: > I notice that type(some_closure) and type(ordinary_function) both return > the same result, . I also notice that both the closure > and ordinary functions have an attribute "func_closure". Is there a way to > tell which is a closure and which is not? In my tests, the ordinary > function has func_closure == None, but I don't know if that will always be > the case of just for my tests. closure != function. (did you read the wikipedia page? the closure is a combination of the function code itself, the information needed to call it, and the context it was defined in. in Python, the full closure includes stuff you can reach via assorted attributes on the function object; most notably func_closure and func_globals) > If I wanted to inspect the value of cache, where would I find it? nowhere. at least no officially; see "Rebinding names in enclosing scopes" in the design document for a discussion: http://www.python.org/peps/pep-0227.html > That assumes that cache can be seen in this way. If it can't, is this a > way to create "really private" variables in Python? no, because Python doesn't prevent you from digging into the internals: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440515 From steve at REMOVETHIScyber.com.au Sat Oct 15 03:47:24 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sat, 15 Oct 2005 17:47:24 +1000 Subject: Problem splitting a string References: Message-ID: On Fri, 14 Oct 2005 21:52:07 -0700, Anthony Liu wrote: > I have this simple string: > > mystr = 'this_NP is_VL funny_JJ' > > I want to split it and give me a list as > > ['this', 'NP', 'is', 'VL', 'funny', 'JJ'] > I think the documentation does say that the > separator/delimiter can be a string representing all > delimiters we want to use. No, the delimiter is the delimiter, not a list of delimiters. The only exception is delimiter=None, which splits on any whitespace. [Aside: I think a split-on-any-delimiter function would be useful.] > I do I split the string by using both ' ' and '_' as > the delimiters at once? Something like this: mystr = 'this_NP is_VL funny_JJ' L1 = mystr.split() # splits on whitespace L2 = [] for item in L1: L2.extend(item.split('_') You can *almost* do that as a one-liner: L2 = [item.split('_') for item in mystr.split()] except that gives a list like this: [['this', 'NP'], ['is', 'VL'], ['funny', 'JJ']] which needs flattening. -- Steven. From fredrik at pythonware.com Wed Oct 5 03:14:51 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 5 Oct 2005 09:14:51 +0200 Subject: While and If messing up my program? References: Message-ID: "CJ" wrote: > What does worry me, is that I can't seem to get the program by a > certain spot. It keeps giving me the same error, and I don't know why. quite often, exception messages means exactly what they say; if you get an index error, it's because you're trying to fetch an item that doesn't exist. for simple debugging, the "print" statement is your friend: > ttllst=[4,3,45,3] > cnto=0 > cntt=1 > rept=-1 > > print cnto > print cntt > print ttllst[cnto] > print ttllst[cntt] > choice=raw_input("Begin? ") > if choice == "yes" or choice == "y": > while cnto<>len(ttllst)+1: print cnto, cntt, len(ttllst) > if ttllst[cnto]==ttllst[cntt]: > rept=rept+1 > if cntt==len(ttllst): > print ttllst[cnto],"appears in the list",rept,"times." > cntt=-1 > cnto=cnto+1 > rept=-1 > cntt=cntt+1 > print "done." with that in place, I get Begin? y 0 1 4 0 2 4 0 3 4 0 4 4 Traceback (most recent call last): File "test.py", line 14, in ? if ttllst[cnto]==ttllst[cntt]: IndexError: list index out of range which means that your second list index (cntt) is too large. figuring out how to fix that is left as an etc etc. PS. when you've sorted this out, you might wish to check out the "count" method on list objects: >>> help(list.count) Help on method_descriptor: count(...) L.count(value) -> integer -- return number of occurrences of value From bokr at oz.net Tue Oct 25 22:25:02 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 26 Oct 2005 02:25:02 GMT Subject: Making "import" *SLIGHTLY* more verbose? References: Message-ID: <435ee6eb.970339684@news.oz.net> On Tue, 25 Oct 2005 15:34:37 -0700, Steve Juranich wrote: >First of all, just let me say that I'm aware of the "-v" switch for >Python, and I don't want anything nearly that verbose. > >I often long for the following behavior from Python when I'm running >interactively: When a new module is imported, I'd like the path to the >file providing the module to be printed out to the screen. If the >module is already in sys.modules, then don't worry about printing >anything. > >The best thing that I can think of to do is something like: > > >__builtins__.__real_import__ =3D __builtins__.__import__ > >def noisy_import(name, globals =3D globals(), locals =3D locals(), fromlist= > =3D []): > printit =3D name not in sys.modules > mod =3D __real_import__(name, globals, locals, fromlist) > if printit: > try: > print '## Loading %s (%s)' % (mod.__name__, mod.__file__) > except AttributeError: > print '## Loading %s (built-in)' % mod.__name__ > return mod > >__builtins__.__import__ =3D noisy_import > > >Which seems to work okay for basic kinds of modules, but doesn't quite >work right for modules that belong to a particular class. Any You want to go beyond just teasing, and tell us what "particular class"? ;-) >suggestions on what I might be missing here? I would imagine that >this is a cookbook type thing, and if there are any references on how >to do this, I'd greatly appreciate it (I couldn't come up with the >right Google magic words). > >Thanks in advance for any help. The imp module has a lot of info, and some example code that might be useful. I'm suspicious of the default values you provide in your noisy_import though. They are all mutable, though I guess nothing should mutate them. But will they be valid for all the contexts your hook will be invoked from? (Or are they actually useless and always overridden?) Regards, Bengt Richter From vyzasatya at gmail.com Fri Oct 7 16:59:15 2005 From: vyzasatya at gmail.com (Vyz) Date: 7 Oct 2005 13:59:15 -0700 Subject: How to run python scripts with IDLE In-Reply-To: <1128701350.660096.244310@g47g2000cwa.googlegroups.com> References: <1128690531.661166.102690@g14g2000cwa.googlegroups.com> <1128701350.660096.244310@g47g2000cwa.googlegroups.com> Message-ID: <1128718755.150612.303060@g44g2000cwa.googlegroups.com> I am trying to modify some of the tools to automate telugu wikipedia maintainence tasks and I have realised that i cannot used cmd.exe as it wont display unicode(atleast telugu). I will try the above and see if it works. can I use the above command in IDLE?? Thanks for the prompt reply Ravi From howardrh at westerncom.net Wed Oct 12 13:28:40 2005 From: howardrh at westerncom.net (hrh1818) Date: 12 Oct 2005 10:28:40 -0700 Subject: calling matlab References: Message-ID: <1129138120.654955.167760@o13g2000cwo.googlegroups.com> There is a module named pymat avvailable from http://sourceforge.net/projects/pymat that provides a limited set of functions for intertfacing Python to Matlab. The functions are: open for opening a Matlab session close for closing a Matlab session eval for evaluating a Matlab command put for sending a matrix to Matlab get for getting a matrix from Matlab Mohammed, you might want to look at this module to see if it has the functionality you need. Howard Mohammed Smadi wrote: > Hi; > > Does anyone know if we can call matlab for a python or bash script while > feeding the matlab script some command line arguments? I have an > interactive matlab script which i want to automate by feeding the args > from a script. > > I know this is probably more suitable to a matlab group but any ideas will > be appreciated. > > thanks > moe smadi From superprad at gmail.com Fri Oct 14 14:33:43 2005 From: superprad at gmail.com (PyPK) Date: 14 Oct 2005 11:33:43 -0700 Subject: File compare In-Reply-To: <434D9B93.7090300@websafe.com> References: <1129150273.991158.203660@g49g2000cwa.googlegroups.com> <434D9B93.7090300@websafe.com> Message-ID: <1129314823.547736.132020@g47g2000cwa.googlegroups.com> but what if case 1: no.of keys in f1 > f2 and case2: no.of keys in f1 < f2. Should'nt we get 1.1 if case 1 and 0.9 if case 2?? it errors of with a keyerror.? From fredrik at pythonware.com Thu Oct 27 11:03:34 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 27 Oct 2005 17:03:34 +0200 Subject: time conversion References: Message-ID: "flupke" wrote: > Is there an easy to convert following hour notation hh:mm > to decimals? > For instance 2 hours and 30 minutes as 2:30 to 2,50 > I don't really know where to search for this kind of conversion. you mean like >>> timestamp = "2:30" >>> hour, minute = timestamp.split(":") >>> print int(hour) + int(minute) / 60.0 2.5 ? From gh at ghaering.de Mon Oct 31 09:30:21 2005 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 31 Oct 2005 15:30:21 +0100 Subject: Need Python Pro for Help!! Plzz In-Reply-To: References: <5uSdnSSK7vYrTfneRVn-pQ@giganews.com> Message-ID: <43662A7D.1050302@ghaering.de> Alex Hunsley wrote: > blah at blah.blah wrote: > >>Need python Pro at newtopython at googlegroups.com , if u wanna help, > [...] > 2) Why should someone willing to help you enter into a private email > discussion? [...] Actually, it's a Google Group mailing list (formerly eGroups): http://groups.google.de/group/newtopython?lnk=sg&hl=de Maybe the people who set it up didn't know that there is perfectly good mailing list for the same topic already: http://www.python.org/mailman/listinfo/tutor -- Gerhard From chrisgarland67 at hotmail.com Tue Oct 4 14:06:34 2005 From: chrisgarland67 at hotmail.com (Cigar) Date: 4 Oct 2005 11:06:34 -0700 Subject: Controlling who can run an executable In-Reply-To: <1128404864.966640.323710@g14g2000cwa.googlegroups.com> References: <1128395422.904212.318930@g44g2000cwa.googlegroups.com> <86y85ahs1j.fsf@bhuda.mired.org> <1128404864.966640.323710@g14g2000cwa.googlegroups.com> Message-ID: <1128449194.870589.232680@g44g2000cwa.googlegroups.com> Myles Strous wrote: > What's more, Tim Golden's wmi module (see > http://tgolden.sc.sabren.com/python/wmi.html) makes getting at these > numbers very easy: > > import wmi > c = wmi.WMI () > for thingy in c.Win32_NetworkAdapter(): > print "Network Adaptor", thingy.MACAddress > for thingy in c.Win32_Processor(): > print "Processor", thingy.ProcessorId > for thingy in c.Win32_BIOS(): > print "BIOS", thingy.SerialNumber > for thingy in c.Win32_BaseBoard(): > print "BaseBoard", thingy.SerialNumber > for thingy in c.Win32_SystemEnclosure(): > print "System Enclosure", thingy.SerialNumber > for thingy in c.Win32_DiskDrive(): > print "Disk Drive", thingy.PNPDeviceID > for thingy in c.Win32_PhysicalMedia(): > print "Physical Media", thingy.SerialNumber > > Regards, Myles. Ah... thing of beauty. One of these will probably make it into my final solution. Thanks millions! From david at jotax.com Tue Oct 25 17:56:47 2005 From: david at jotax.com (David Poundall) Date: 25 Oct 2005 14:56:47 -0700 Subject: How best to reference parameters. In-Reply-To: <1130274796.584531.229340@g43g2000cwa.googlegroups.com> References: <1130274796.584531.229340@g43g2000cwa.googlegroups.com> Message-ID: <1130277407.831090.114870@o13g2000cwo.googlegroups.com> It looks like I am going to have to bite the bullet and use properties. The following should do what I want. class test: def __init__(self): self.__HB = 0 self.__VPG = 0 def _get_HB(self): return (self.__HB, 'MF1', 0) def _set_HB(self, x): self.__HB = x HB = property(_get_HB, _set_HB) def _get_VPG(self): return (self.__VPG, 'MF1', 1) def _set_VPG(self, x): self.__HB = x VPG = property(_get_VPG, _set_VPG) Usisg this I can set / and clear HB and VPG usig the syntax t = test() t.HB = 1 t.VPG = 0 and when I read them I get a tuple which holds the currcnt value in position 0 and the other parameters I need in positions 1 and 2. From fperez.net at gmail.com Fri Oct 14 17:40:09 2005 From: fperez.net at gmail.com (Fernando Perez) Date: Fri, 14 Oct 2005 15:40:09 -0600 Subject: array subset could be improved? -repost ;) References: Message-ID: Jim O'D wrote: > Hi all > > I have an array a=array([2,3,-1]). > > I want to extract an array with all the elements of a that are less than 0. Numeric is currently changing into the new scipy core. If you are willing to play with beta code, get it here: http://numeric.scipy.org if not, wait a little for an official release. With the new numeric, you'll be able to do: negatives = a[a<0] Cheers, f From john at castleamber.com Sun Oct 16 01:22:47 2005 From: john at castleamber.com (John Bokma) Date: 16 Oct 2005 05:22:47 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: "Mike Schilling" wrote: > > "John Bokma" wrote in message > news:Xns96F0C5CC4C14Dcastleamber at 130.133.1.4... > >> Which standards? W3C doesn't make standards (they talk about working >> drafts and recommendations), so nothing to warp there for MS. > > Umm, a recommendation *is* a standard. No, it's a recommendation, an advise, nothing else. Otherwise they would call it a standard. Why do you think W3C calls it recommendations? Because it are no standards. There is an ISO HTML standard though, but when people babble about HTML standards they talk about W3C *recommendations*. "Recommendation Specifications published by the W3C. They cannot be officially called "standards," since the W3C is a consortium that does not have the status of the standard body reserved for the ISO and national standard bodies. The specifications, which are finalized and approved by the Director, are then called "W3C Recommendations."" (Quote from an O'Reilly book) > And Microsoft must disagree with you. So that must mean you're right? Then wonder why there is an ISO standard (yes) for HTML. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From jason at jasonmhirst.co.uk Sun Oct 2 11:18:36 2005 From: jason at jasonmhirst.co.uk (Jason) Date: Sun, 02 Oct 2005 16:18:36 +0100 Subject: Distributing programs Message-ID: A non-python programming friend of mine has said that any programs made with Python must be distributed with, or an alternative link, to the source of the program. Is this true? From gh at ghaering.de Wed Oct 5 08:26:46 2005 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Wed, 05 Oct 2005 14:26:46 +0200 Subject: Python, Mysql, insert NULL In-Reply-To: <1128511466.880413.158140@g49g2000cwa.googlegroups.com> References: <1128509544.189126.51090@g44g2000cwa.googlegroups.com> <4343B4E0.1040902@designaproduct.biz> <1128511466.880413.158140@g49g2000cwa.googlegroups.com> Message-ID: <4343C686.5060206@ghaering.de> Python_it wrote: > I know how to insert values in a database. > That's not my problem! > My problem is how i insert NULL values in de mysql-database. > None is een object in Python and NULL not. > None is not converted to NULL? > Table shows None and not NULL! As Laszlo wrote, "None will be converted to NULL" for the Python => SQL direction. And also, NULL will be converted to None for SQL => Python direction. And to avoid unneccessary if-then-else you should follow his advice and use parametrized queries. I. e. cursor's execute method has two parameteres: 1) SQL query with placeholders 2) parameters For example: var1 = "Joe's dog" cur.execute("insert into mytable(col1) values (%s)", (var1,)) var1 = None cur.execute("insert into mytable(col1) values (%s)", (var1,)) if you use MySQLdb (the most sensible choice for a MySQL Python database adapter). Because MySQLdb uses the pyformat param style, you use the %s placeholder always, no matter which type your parameter will be. Also, the tip to read the DB-API specification http://www.python.org/peps/pep-0249.html is a good one in my opinion. It really pays off to learn how to do things the DB-API way. HTH, -- Gerhard From jabel at plus.net Tue Oct 25 10:08:05 2005 From: jabel at plus.net (John Abel) Date: Tue, 25 Oct 2005 15:08:05 +0100 Subject: Security on XML-RPC In-Reply-To: <1130243378.736452.270130@g43g2000cwa.googlegroups.com> References: <1130243378.736452.270130@g43g2000cwa.googlegroups.com> Message-ID: <435E3C45.6090505@plus.net> dcrespo wrote: >Hi all, > >Anyone knows a simpler but stronger control access to XML-RPC functions >than the one I comment here? > >My actual system works like this: > >I have a TCP Server and an XML-RPC Server. Both of them verify if the >IP address is allowed. > >The TCP Server works for validate and register an IP address if it >wasn't validated previously, while the XML-RPC Server works only if the >requester IP address was allowed through the mentioned TCP Server. This >means, anyone who wants to connect to the XML-RPC Server has to pass >the TCP Server. > >How a client connects to the TCP Server and authenticate his IP? > >Well, there is an interchange of encrypted data between the Client and >the TCP Server, where, in few words, the client sends a UserName and a >Password, all this through the send() function of the Socket >connection. If the TCP Server authenticate an IP address, then that >Client will be able to connect to the XML-RPC Server and use its >defined functions. > >The problem I see here is that if I want someone to taking advantage of >my XML-RPC functions, I have to tell him all these. I would like to get >a strong but simpler way of doing all these. > >Thank you for reading and thinking. > >Daniel > > > Not the most secure, but I have a modified XMLRPC Server/client using Digest auth, if that's any use? J From fairwinds at eastlink.ca Sun Oct 2 18:34:13 2005 From: fairwinds at eastlink.ca (David Pratt) Date: Sun, 02 Oct 2005 19:34:13 -0300 Subject: Python based unacceptable language filter In-Reply-To: Message-ID: Hi. Is anyone aware of any python based unacceptable language filter code to scan and detect bad language in text from uploads etc. Many thanks. David From amk at amk.ca Tue Oct 11 14:52:58 2005 From: amk at amk.ca (A.M. Kuchling) Date: Tue, 11 Oct 2005 14:52:58 -0400 Subject: Reminder: PyCon proposal deadline is Oct. 31st Message-ID: <20051011185258.GC15094@rogue.amk.ca> The deadline for PyCon proposals is now three weeks away; proposals must be received by Oct. 31st. Read the call for proposals for what we're looking for and how to submit: The proposal submission site is . A.M. Kuchling Chair, PyCon 2006 amk at amk.ca From tinman31337 at gmail.com Wed Oct 12 12:31:40 2005 From: tinman31337 at gmail.com (tin gherdanarra) Date: Wed, 12 Oct 2005 18:31:40 +0200 Subject: slots? SLOTS? Message-ID: <3r4s3cFhndjpU1@individual.net> Dear pythonista, what is a "slot" in python? I stumbled over it in several meta-reflection discussions and hard-core developer talk, but found no mention of it in the language reference. Google coughs up more interesting banter about it, but no specifics. Is it a feature that was once planned (for 2.2 or so) and later abandoned? I find no *new* talk about it. Thanks for your attention Tin From csubich.spam.block at spam.subich.block.com Tue Oct 25 10:09:29 2005 From: csubich.spam.block at spam.subich.block.com (Christopher Subich) Date: Tue, 25 Oct 2005 10:09:29 -0400 Subject: Would there be support for a more general cmp/__cmp__ In-Reply-To: References: Message-ID: Antoon Pardon wrote: > I also think there is the problem that people aren't used to partial > ordering. There is an ordering over sets, it is just not a total > ordering. But that some pairs are uncomparable (meaning that neither > one is smaller or greater) doesn't imply that comparing them is > ill defined. It depends on your definition of "comparison." Admittedly, <, =, !=, and > can be defined for a partial ordering, but classical mathematics, as understood by most people (even programmers), assumes that unless a == b, a > b or a < b. The comparisons, as defined this way, are done on a totally ordered set, yes. But since most comparisons ever done -are- done on a totally ordered set (namely the integers or reals), it's entirely fair to say that "a programmer's expectation" is that comparisons should work more or less like a totally ordered list. With that caevat in mind, comparison on a partially ordered domain /is/ ill-defined; it can give inconsistent results from the "a < b or a > b or a == b" rule. > > Well it is a wrong assumption is general. There is nothing impure about > partial ordering. Impure? Probably not. Useless from many perspective when "comparisons" are needed, to the point where it's probably safer to throw an exception than define results. > That is IMO irrelevant. The subset relationship is an ordering and as > such has all characteristics of other orderings like "less than", > except that the subset relationship is partial and the less than > relationship is total. How it is called "subset" vs "less than" is > IMO irrelevant. It is about mathematical characteristics. Still accident. < wouldn't be used for sets if we had a subset symbol on the standard keyboard, APL fans notwithstanding. Simce programmers familiar with Python understand that < on sets isn't a "real" comparison (i.e. provide a total order), they don't expect unique, consistent results from something like sort (or a tree, for that matter). > > >>By analogy, one can ask, "is the cat inside the box?" and get the answer >>"No", but this does not imply that therefore the box must be inside the >>cat. > > > Bad analogy, this doesn't define a mathematical ordering, the subset > relationship does. Yes, it does. Consider "in" as a mathematical operator: For the set (box, cat-in-box) box in box: False box in cat-in-box: False cat-in-box in box: True cat-in-box in cat-in-box: False For the set (box, smart-cat) # cat's too smart to get in the box box in box: False box in smart-cat: False smart-cat in box: False smart-cat in smart-cat: False In both these cases, the "in" operator is irreflexive, asymmetric, and transitive (extend to mouse-in-cat if you really care about transitive), so "in" is a partial order sans equality. A useless one, but a partial order nonetheless. >>Notice that L1 and L2 contain the same elements, just in different orders. >>Sorting those two lists should give the same order, correct? > > > No. Since we don't have a total ordering, sorting doesn't has to give > the same result. For as far as sorting is defined on this kind of > object, the only thing I would expect is that after a sort the > following condition holds. > > for all i,j if i < j then not L[i] > L[j] Highly formal, aren't you? Again, common programming allows for "not a > b" == "a <= b", so your condition becomes the more familiar: for all i,j in len(list), if i < j then L[i] <= L[j] This condition is also assumed implicitly by many other assumed "rules" of sorted lists, namely their uniqueness: "If L is a list of unique keys, then sort(L) is a unique list of keys in sorted order." Yes, this assumes that L has a total order. Big whoop -- this is a matter of programming practiciality rather than mathematical purity. >>Personally, I argue that sorting is something that you do to lists, and >>that all lists should be sortable regardless of whether the objects within >>them have a total order or not. If not, the list should impose a sensible >>ordering on them, such as (perhaps) lexicographical order ("dictionary >>order"). To reply to the grandparent poster here: that's not always easy to do. A "sensible order" isn't always easy to define on a set where a partial order exists, if it includes that order already. Adding comparison-pairs to a partially ordered set (where incomparable elements throw an exception, rather than just return False which is confusing from sort's perspective) can easily result in a graph that isn't actually transitive and antisymmetric, i.e.: A > B > C, but C > D > A for some operator ">" With this in mind, the only sensible thing for .sort to do when it encounters an exception is to fall back to its "backup" comparator (id, for example), and resort /the entire list/ using that comparator. The results returned will then be valid by sort's comparison, but a subset of that list containing only "good" objects (like integers) may not (and probably won't be) sorted itself using the object's comparison. The difficulty arises because while we may consider a single type to be fully ordered, it may also have some comparisons with other types; sorting the list by type, then value seems like it would work (and that's what the library does), but since we can sometimes compare across types, this may not give a valid comparison. Consider: [apple, wheat, cow] apple < cow (defined, totally ordered) Mammal > Grain > Fruit (accident of type id numbers) apple < wheat throws TypeError, also wheat < cow Since we encounter a TypeError when sorting this list, we first sort by type: [cow, wheat, apple] and would then sort-by-comparison within types, if we had more than one. But since apple < cow, the sublist of this list [cow, apple] is not itself sorted. This is paradoxical under a single comparison, because a sublist of any sorted list is itself supposed to be sorted. The ordering that .sort used on the full list is well-defined and total, but it's also useless. > But will all libraries sort the shelves in the same way. As far as I > understand a book gets somekind of code in a library and books are > sorted according to these codes. Now everybody sorts these codes the > same way, but the attibution of the code may differ from library to > library. Irrelevant; if you swap the order of any two (nonidentical) books in a single library, then the library is unsorted. The library has imposed a total order on books in its collection. The library example is irrelevant, anyway; two books can always be compared by the keys (author last, author first/middle, [other authors], title, editor, year published, publisher, number of pages, colour of the brightest line in the cover's emmission spectrum at 2000k in spectral order [within visible spectrum]), and for the most part this is a useful keyspace. Libraries just choose to impose a category/numbering at the head of the key. From eurleif at ecritters.biz Fri Oct 7 02:26:53 2005 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Fri, 07 Oct 2005 06:26:53 GMT Subject: os.access with wildcards In-Reply-To: <1128665933.923295.95580@f14g2000cwb.googlegroups.com> References: <1128665933.923295.95580@f14g2000cwb.googlegroups.com> Message-ID: mike wrote: > i'd like to use > > os.access(path,mode) > > where path may contain linux style wildcards. os.access(glob.glob(path), mode) From xah at xahlee.org Wed Oct 19 01:33:18 2005 From: xah at xahlee.org (Xah Lee) Date: 18 Oct 2005 22:33:18 -0700 Subject: write a loopin one line; process file paths In-Reply-To: <1129696357.539158.233870@g47g2000cwa.googlegroups.com> References: <1129672592.328278.41490@g14g2000cwa.googlegroups.com> <1129696357.539158.233870@g47g2000cwa.googlegroups.com> Message-ID: <1129699998.324180.56530@f14g2000cwb.googlegroups.com> Thanks. Here's how the inner loop should be: imgPaths2=map(lambda x: (x, re.sub( r"^(.+?)-s(\.[^.]+)$",r"\1\2", x)), imgPaths) though, now i just need something like map( lambda x: os.path.exists(s)? x[1]:x[0],impPaths2) but Pyhton doesn't support the test ? trueResult : falseResult construct. (the semantic of this construct, of a conditional that RETURNS A EXPRESSION, all in one line, is important in functional programing. Perl supports it. In Mathematica, it's simply the form If[testExpr, trueExpr, falseExpr]. In lisp, similar: (if testExpr trueExpr falseExpr) ) is there a way to similate it? Xah xah at xahlee.org ? http://xahlee.org/ bonono at gmail.com wrote: > what do you mean by one line ? Using map/filter, I believe it is > possible. > > Somthing like: > > map(lambda (s,f): os.path.exists(f) and f or s, > map(lambda x: (x, re.replace(x, "-s","")), imgPaths) > > My regex is a bit rusty but I hope you got the idea of what I am trying > to do. If there is a way to make the re return without destroying x, > the outer map is not needed I believe(that is run it twice, once for > getting the filename to do the testing, then again based on the testing > result). > From kent37 at tds.net Thu Oct 20 14:01:59 2005 From: kent37 at tds.net (Kent Johnson) Date: Thu, 20 Oct 2005 14:01:59 -0400 Subject: need some advice on x y plot In-Reply-To: <1129825379.218308.242010@g47g2000cwa.googlegroups.com> References: <1129823043.104864.73750@f14g2000cwb.googlegroups.com> <11lfgebn85liq1b@corp.supernews.com> <1129825379.218308.242010@g47g2000cwa.googlegroups.com> Message-ID: <4357d998$1_2@newspeer2.tds.net> nephish at xit.net wrote: > how ? > i have tried to use unix timestamps, and i have also tried with > DateTime objects > do i need to use a scale that isn't linear (default in most) ? > how do i putt this off ? Here is some code that works for me. It plots multiple datasets against time. The input data looks like this: 2005-04-04 16:00:00 141.154.195.129 - W3SVC1 SP6018ASP2 208.254.37.191 443 GET /rkadqsr/newskills/newskills.cfm selectedTab=1 200 0 53440 599 1594 HTTP/1.1 adqsr.skillport.com Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1) CookiesEnabled=1;+ASPSESSIONIDACTSSRAT=MCNLNLGADPOFGFKAHJHLDDKG;+CFID=785030;+CFTOKEN=27203160 https://adqsr.skillport.com/rkadqsr/login/login.cfm 2005-04-04 16:00:00 208.254.38.216 - W3SVC1 SP6018ASP2 208.254.37.191 443 POST /_rkadqsrBackend_od_cgi/aiccisapi.dll - 200 0 372 274 4547 HTTP/1.0 adqsr.skillport.com aiccisapi - - 2005-04-04 16:00:00 208.254.38.240 - W3SVC1 SP6018ASP2 208.254.37.191 443 POST /_rkadqsrBackend_od_cgi/aiccisapi.dll - 200 0 372 3019 250 HTTP/1.0 adqsr.skillport.com aiccisapi - - import datetime, time import Gnuplot dataPath = 'ex05040416.log' datasets = {} startTime = None f = open(dataPath) for line in f: try: dat, tim, c_ip, cs_username, s_sitename, s_computername, s_ip, s_port, \ cs_method, cs_uri_stem, cs_uri_query, sc_status, sc_win32_status, sc_bytes, \ cs_bytes, time_taken, cs_version, cs_host, cs_User_Agent, cs_Cookie, cs_Referer = line.split() except ValueError: print "Can't parse", line continue tim = time.mktime(time.strptime(dat+' '+tim, "%Y-%m-%d %H:%M:%S")) delay = int(time_taken) if startTime is None: startTime = tim tim -= startTime # print tim, delay datasets.setdefault(sc_status, []).append([tim, delay]) g = Gnuplot.Gnuplot(debug=1) plotter = g.plot for key, values in datasets.items(): plotter(values) plotter = g.replot raw_input('Please press return to continue...\n') From steve at holdenweb.com Mon Oct 24 09:18:31 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 24 Oct 2005 14:18:31 +0100 Subject: Redirect os.system output In-Reply-To: <1130159194.833666.250820@g47g2000cwa.googlegroups.com> References: <1129927486.854143.169670@g49g2000cwa.googlegroups.com> <43596c70$1_3@newspeer2.tds.net> <1130154552.795209.25830@g43g2000cwa.googlegroups.com> <435cd10c$1_2@newspeer2.tds.net> <1130157195.954433.131650@g49g2000cwa.googlegroups.com> <1130159194.833666.250820@g47g2000cwa.googlegroups.com> Message-ID: jas wrote: > Ok, I tried this... > > C:\>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 subprocess as sp >>>>p = sp.Popen("cmd", stdout=sp.PIPE) >>>> >>>>result = p.communicate("ipconfig") > > 'result' is not recognized as an internal or external command, > operable program or batch file. > > > > basically I was opening to send the "ipconfig" command to cmd.exe and > store the result in the "result" variable. But you can see there was > an error with result. > It looks to me like the line you thought you were typing at the Python command interpreter actually got snagged by the command processor you just ran, which presumably is taking its input from the console just like Python is. > Ideas? > Haven't used subprocess much yet, but I will just mention that this kind of thing always looks easy in principle and turns out to be surprisingly gnarly and difficult in practice. I'm not suggesting you shouldn't continue, but you are going to learn a *lot* as you proceed. Good luck. regards Steve [...] -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From steve at REMOVETHIScyber.com.au Sun Oct 16 03:40:24 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 16 Oct 2005 17:40:24 +1000 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: On Sat, 15 Oct 2005 22:28:02 -0700, David Schwartz wrote: >>> Go down to your local car dealer and see if you can buy a new car >>> without an engine. > >> That's a false analogy. A better analogy is, "go to your local car dealer >> and see if you can buy a new car with the tyres of your choice." > > How is that better? Nothing in your car depends upon what tires you have > on. But all of the rest of the software on your computer is dependent upon > your choice of OS. Within rather broad limits, you can put any tyre you like on your car, but it is not practical to change your engine. Within rather broad limits, you can run any OS you like on your computer. Car manufacturers *like* the fact that there is enormous competition in the tyre market. If (say) Bridgestone had an effective monopoly, they could charge whatever they liked and car manufacturers would have to pay it, or else not sell cars at all. So car manufacturers do not discourage consumers from choosing their own brand of tyre. If you, the consumer, cares enough to ask for Brand X tyres on your car, the dealer will fall over himself to please. PC manufacturers, on the other hand, do discourage consumers from choosing their own brand of OS. As a result, the royalties they pay to Microsoft per PC is frequently more than the profit they make. Most white-goods PC resellers are lucky to make $50 profit on a PC, *before* wages. (Presumably Tier One vendors make more than that, but not that much more.) And that is the mystery that needs to be explained. H-P/Compaq, Dell, Toshiba, and all the other Tier One and Tier Two vendors have no problem selling servers without operating systems. Some will even pre-install Linux on them for you. So why are consumers forced to make the choice of either paying for Windows with their laptop, or no laptop at all? You will notice that only 30% of servers run Windows (lots of competition in the server market) and over 90% of desktops (no competition in the desktop market). Coincidence? I think not. -- Steven. From eric.pederson at gmail.com Mon Oct 24 15:44:20 2005 From: eric.pederson at gmail.com (eric.pederson at gmail.com) Date: 24 Oct 2005 12:44:20 -0700 Subject: XML Tree Discovery (script, tool, __?) Message-ID: <1130183060.195730.178330@g47g2000cwa.googlegroups.com> Hi all, Finally diving into XML programmatically. Does anyone have a best practice recommendation for programmatically discovering the structure of an arbitrary XML document via Python? It seems like it is a common wheel I'd be re-inventing. Thanks and cheers EP From allisfree at gmail.com Mon Oct 3 07:00:10 2005 From: allisfree at gmail.com (JackPhil) Date: 3 Oct 2005 04:00:10 -0700 Subject: windows service problem In-Reply-To: <4340fd3b$0$8938$626a14ce@news.free.fr> References: <1128330845.762679.66680@f14g2000cwb.googlegroups.com> <4340fd3b$0$8938$626a14ce@news.free.fr> Message-ID: <1128337210.341363.114270@g14g2000cwa.googlegroups.com> fraca7 wrote: > > Make sure it doesn't output anything to stdout or stderr, I've run into > problems with that. I always include this kind of code in NT services: > > class Devnull: > def write(self, bf): > pass > def close(self): > pass > def flush(self): > pass > > sys.stdout = sys.stderr = Devnull() Thanks for your instructions. It's resolved my problem. From martin at v.loewis.de Wed Oct 12 04:56:44 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 12 Oct 2005 10:56:44 +0200 Subject: Why asci-only symbols? In-Reply-To: <86vf04zx0k.fsf@bhuda.mired.org> References: <86vf04zx0k.fsf@bhuda.mired.org> Message-ID: <434ccfcd$0$28021$9b622d9e@news.freenet.de> Mike Meyer wrote: > Out of random curiosity, is there a PEP/thread/? that explains why > Python symbols are restricted to 7-bit ascii? No PEP yet; I meant to write one for several years now. The principles would be - sources must use encoding declarations - valid identifiers would follow the Unicode consortium guidelines, in particular: identifiers would be normalized in NFKC (I think), adjusted in the ASCII range for backward compatibility (i.e. not introducing any additional ASCII characters as legal identifier characters) - __dict__ will contain Unicode keys - all objects should support Unicode getattr/setattr (potentially raising AttributeError, of course) - open issue: what to do on the C API (perhaps nothing, perhaps allowing UTF-8) Regards, Martin From mwm at mired.org Wed Oct 26 09:15:17 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 26 Oct 2005 09:15:17 -0400 Subject: a Haskell a Day References: <1130312303.713737.160830@g44g2000cwa.googlegroups.com> Message-ID: <86zmow1kt6.fsf@bhuda.mired.org> Erik Max Francis writes: > Xah Lee wrote: >> This is my learning notes on Haskell. I call it a-Haskell-a-day. Interesting. Xah Lee's orginals don't show up in the Python newsgroup. No big loss. In any case, please help google find Xah Lee under the proper search terms. Add a link to his website with the anchor "stupider than spam". A typical usage might be: And pointing out that some people are stupider than spam. Thanks, http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From steve at holdenweb.com Wed Oct 19 13:45:51 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 19 Oct 2005 18:45:51 +0100 Subject: Threads and socket.setdefaulttimeout In-Reply-To: <1129742832.414652.104230@o13g2000cwo.googlegroups.com> References: <1128030031.130958.185620@z14g2000cwz.googlegroups.com> <1129142005.610543.212180@o13g2000cwo.googlegroups.com> <1129742832.414652.104230@o13g2000cwo.googlegroups.com> Message-ID: Russell Warren wrote: > Thanks for the detailed repsone... sorry for the lag in responding to > it. [discussion of problems with timeouts on threaded code's sockets] > > Not quite what I was after I don't think since potentially interfering > code needs to check the lock (via acquire) to avoid conflict. What I > guess I mean is something general for the process saying "never ever > interrupt this block og code by running code on another thread, > regardless of whether the other thread(s) check a lock". Thinking more > about it it seems unreasonable so I'll drop the question. > Well, I'm about out of ideas, but c.l.py is a very inventive group, so maybe someone else will be able to contribute a bright thought. Anyone? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From steve at holdenweb.com Mon Oct 3 12:43:35 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 03 Oct 2005 17:43:35 +0100 Subject: "no variable or argument declarations are necessary." In-Reply-To: <20051003203035.486348a9.jk@ospaz.ru> References: <434084 3b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99 f9f10238681bf68f@teranews> <20051003203035.486348a9.jk@ospaz.ru> Message-ID: en.karpachov at ospaz.ru wrote: > On 3 Oct 2005 13:58:33 GMT > Antoon Pardon wrote: > > >>People often promote unittesting here. Writing all those unittest is >>an added burden too. But people think this burden is worth it. >> >>I think writing declaration is also worth it. The gain is not as >>much as with unittesting but neither is the burden, so that >>balances out IMO > > > +1 > > Some people just don't get the simple fact that declarations are > essentially kind of unit test you get for free (almost), and the compiler > is a testing framework for them. > Hmm. Presumably introspection via getattr() is way too dangerous, then? Might as well throw the function away ... regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From steve at REMOVETHIScyber.com.au Wed Oct 5 08:28:34 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Wed, 05 Oct 2005 22:28:34 +1000 Subject: While and If messing up my program? References: <1128496212.482205.8380@g14g2000cwa.googlegroups.com> Message-ID: On Wed, 05 Oct 2005 00:10:12 -0700, ajikoe at gmail.com wrote: > hi, > > to get howmany element list appear you can code: > ttllst=[4,3,45,3] > for x in ttllst: > print x, ttllst.count(x) > pass > > to get non duplicate element list you can code: > ttllst=[4,3,45,3] > print list(set(ttllst)) These are excellent things to use in Python, but for learning programming skills, they are terrible because they rely on black boxes to do everything. I remember once having to code a matrix division algorithm in "the language of your choice" for a comp sci course. So of course, being a smart arse, I programmed it in the HP-28S calculator programming language, which just happened to have matrices as a native object type, complete with division. I answered the question exactly, and learnt absolutely nothing from the exercise. (For the record, I failed that course.) It is good to tell the original poster how he should be implementing the code he is trying to write, but that is not as important as helping him work out where the code is going wrong. In this case, the problem is that C.J. carefully checks that his indexes are within the valid range for the list, but (s)he makes that check *after* attempting to use the indexes. So the code fails before it reaches the test. -- Steven. From do-not-use at invalid.net Thu Oct 27 02:13:15 2005 From: do-not-use at invalid.net (Niklas Norrthon) Date: 27 Oct 2005 08:13:15 +0200 Subject: a Haskell a Day References: <1130312303.713737.160830@g44g2000cwa.googlegroups.com> <1130312943.717481.217200@g44g2000cwa.googlegroups.com> Message-ID: <0pwtjz4hdw.fsf@niklas.ua.dynas.se> usenet at DavidFilmer.com writes: > Xah Lee wrote: > > I hope you will join me in learning Haskell. > > I think the folks here are more interested in Perl. There's a reason > why this newsgroup is called lc("comp.lang.PERL.misc"). Or python, or c, or java, or unix programming. There is a reason why this is called cross posting. /Niklas Norrthon From mwm at mired.org Fri Oct 14 13:51:38 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 14 Oct 2005 13:51:38 -0400 Subject: UI toolkits for Python References: Message-ID: <863bn4t2ad.fsf@bhuda.mired.org> "Adriaan Renting" writes: >>>>Mike Meyer 10/14/05 5:39 pm >>> > $"Adriaan Renting" writes: > $[On Qt] > $>I don't know how it performs on OSX, I think it works fine, as Qt is > $>available on OSX. > $ > $Qt on OS X is halfway there. It looks - and acts - like an aqua > $application. However, to support the Command key, they hacked things > $so that it is reported to the upper layers as the Control key. This > $means that there's no way to get to use the control key in the UI for > $qt apps on OS X. > $ > $This really rapes apps with configurable shortcuts. For instance, LyX > $comes with a couple of emacsish bindings. You can turn them on, but > $you have to use Command-key instead of Control-key, which pretty > $thoroughly defeats the purpose. > $ > $ > You have the problem that some keyboard layouts have OS specific > keys (Windows key, menu key on some PCs, Command key on apples) > which you can't support in a cross-platform way. If using > Command-Letter is the standard way of having keyboard shortcuts in > OS X, then I think I can understand why they choose this > implementation,. I suppose the Command key is more integrated into > the OS as is the Windows key in Windows. I think it would be nice if > you could choose the mapping. It's quick and dirty and does the right thing for applications that follow the UI guidelines on Windows and OS X. Generally, Command-lumberjack on OS X does the same thing as Control-lumberjack does on Windows or other CUA platform. If you want to let users bind keystrokes, then they're out of luck. > The basic problem is that a widget toolkit that supports > control/shift/alt/command as meta-keys can not be cross-platform, as > the command key has no equivalent in windows or linux. How do the > other widget toolkits handle this, do they ignore the Command key? > What does Linux PPC/YellowDog do with the Command key? I really can't say, but it seems like the obvious way to do it is to have the lower levels define the appropriate bucky bits for all platforms. No platform will generate all those bits, but so what? That just means youv'e got some symbols defined that won't be used on some platforms. Actually, since there undoubtedly exists systems that can't generate all the bucky bits for any given platform, that's "some more symbols ...". But I'm not a GUI designer, so there may be reasons for not doing it that way that I can't see. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From fiedzia at fiedzia.prv.pl Fri Oct 21 14:47:36 2005 From: fiedzia at fiedzia.prv.pl (Maciej Dziardziel) Date: Fri, 21 Oct 2005 20:47:36 +0200 Subject: Help with language, dev tool selection References: <1129915422.693950.97000@g43g2000cwa.googlegroups.com> Message-ID: <20051021184736.31FE.0.NOFFLE@fiedzia.homeip.net> vasilijepetkovic at yahoo.com wrote: > 1) What programming language to use This is trivial task, whatever language you choose, will do it. Python too, and its also simple and popular, so i can recommend it. > 2) What development tools to use You don't need nothing beyond python interpreter. > 3) Tips on how to code the solution Read the python tutorial (www.python.org) and thats probably all you need to know. > For each record I have to create an html file that will be named as the > name of the town (i.e. Sarajevo.html). The content of the file will be > rather simple; in the first row it will contain the header (i.e. > "This page displays longitude-latitude information") - The second > row will have the following word: "Grad" - and the third row will > contain the name of the city and the fourth row will have the > longitude-latitude info. Its maybe 10-20 lines of trivial code, so i suggest you to read python tutorial, unless its only do-it-once operation. Do you really need to create 30k files? this will take a lot of time (creating a file is time-consuming operation on creation, sending them to server too) and disk space greedy - even if file has 300 bytes, it may take 4kb or more on disk, depending on filesystem and its settings. Perhaps collecting names starting with the same letter in single file will be enough. -- Maciej "Fiedzia" Dziardziel (fiedzia (at) fiedzia (dot) prv (dot) pl) www.fiedzia.prv.pl Ankh if you love Isis. From johnww at worldpath.net Tue Oct 18 11:37:41 2005 From: johnww at worldpath.net (John Wingate) Date: Tue, 18 Oct 2005 15:37:41 -0000 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <11l29j29rq4jh18@corp.supernews.com> <8qs723-dr7.ln1@news.it.uc3m.es> <11l3kmgggj66800@corp.supernews.com> Message-ID: <11la5m52qm2i352@corp.supernews.com> Richard Steiner wrote: > Here in comp.os.linux.misc, > John Wingate spake unto us, saying: > >>Peter T. Breuer wrote: > >>> It seems to me that I was using 3.x. Maybe it was 3.1? I seem to >>> remember an earlier major ... was there a 2.8 or 2.9? >> >>Dunno. The first version I used was 3.4, in 1987. > > MS-DOS 3.3 was the most popular DOS release back in 1987/1988. I don't > recall there ever being a 3.4 release, though. You snipped the bits that provide the context showing that here Peter and I were talking about versions of SunOS, not MS-DOS. I too don't recall an MS-DOS 3.4. The Victor/Sirius version I mentioned was definitely 3.10 (three point ten)--the version byte was hex 030A. Perhaps the gap in sequencing was introduced to separate the versions for IBM-compatible machines from the versions for non-IBM-compatible machines. -- John Wingate Mathematics is the art which teaches johnww at worldpath.net one how not to make calculations. --Oscar Chisini From jeremy at emperorlinux.com Thu Oct 6 10:19:51 2005 From: jeremy at emperorlinux.com (Jeremy Moles) Date: Thu, 06 Oct 2005 10:19:51 -0400 Subject: PyObject_New Message-ID: <1128608391.7548.9.camel@localhost.localdomain> Hey guys, sorry to ask another question of this nature, but I can't find the answer or a single example of it anywhere. I'm sure it's been asked before, but my google-fu isn't strong enough to find anything. I have the following: struct MyType { PyObject_HEAD ... }; PyTypeObject PyType_MyType = { ... } Now, elsewhere in the code I want to create an instance of this custom type in C/C++ (rather than in the Python interpreter, where this all seems to happen magically) and return it from a method. What I'm trying now is the following: PyObject* obj = _PyObject_New(&PyType_MyType); obj = PyObject_Init(obj, &PyType_MyType); ... return obj; When "obj" gets back to the interpreter, Python sees it (or rather, it's __repr__) in accordance with what it "should" be. However, any attempt to USE the object results in a segfault. I feel my problem is simply that I'm not allocating "obj" correctly in the C++ function. If anyone has any advice, I would really appreciate it. From hagai26 at gmail.com Sat Oct 22 17:44:31 2005 From: hagai26 at gmail.com (hagai26 at gmail.com) Date: 22 Oct 2005 14:44:31 -0700 Subject: best way to replace first word in string? In-Reply-To: References: Message-ID: <1130017471.076146.203600@g44g2000cwa.googlegroups.com> The RE way, was much slower I used the spilt, it was better I tought because there was no need to take it to the memory again, but it just my thougth From pd at traxon.com Fri Oct 28 04:22:24 2005 From: pd at traxon.com (Paul Dale) Date: Fri, 28 Oct 2005 10:22:24 +0200 Subject: xml.dom.minidom - parseString - How to avoid ExpatError? In-Reply-To: <312cfe2b0510270749x2685c686w3f033a5f151a903a@mail.gmail.com> References: <312cfe2b0510251159p5e2501cbxf21e4f62f3d70b1c@mail.gmail.com> <312cfe2b0510260738j460b075ch998371a460c39df8@mail.gmail.com> <435F9C6C.50707@plus.net> <312cfe2b0510261020w1d485c98m526e325d6ada1082@mail.gmail.com> <43608B8F.1000506@plus.net> <312cfe2b0510270749x2685c686w3f033a5f151a903a@mail.gmail.com> Message-ID: <4361DFC0.9050906@traxon.com> Hi Greg, Not really an answer to your question but I've found 4Suite ( http://4suite.org/index.xhtml ) quite useful for my XML work and the articles linked to from there authored by Uche Ogbuji to be quite informative. Best, Paul Gregory Pi?ero wrote: > Thanks, John. That was all very helpful. It looks like one option > for me would be to put cdata[ around my text with all the weird > characters. Otherwise running it through on of the SAX utilities > before parsing might work. > > I wonder if the sax utilities would give me a performance hit. I have > 6000 xml files to parse at 100KB each. > > -Greg > From peter at engcorp.com Tue Oct 18 22:23:40 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 18 Oct 2005 22:23:40 -0400 Subject: Dealing with Excel In-Reply-To: <1129679183.469734.151920@f14g2000cwb.googlegroups.com> References: <1129670191.061006.146320@g47g2000cwa.googlegroups.com> <1129679183.469734.151920@f14g2000cwb.googlegroups.com> Message-ID: Robert Hicks wrote: > No, I have to format fields and everything sad to say. Another poster > up the chain of this posting gave me the nudge in the direction I > needed. Doesn't Excel also support (in addition to binary .xls and simple text .csv files) an XML format, which allows full access to formatting and all other such features? I would assume it's reasonably well documented and you could just generate that output directly. -Peter From sunspire at gmail.com Sun Oct 30 08:07:13 2005 From: sunspire at gmail.com (Max Rybinsky) Date: 30 Oct 2005 05:07:13 -0800 Subject: lambda functions within list comprehensions In-Reply-To: <1h57c0h.kcl38fefrcdrN%aleaxit@yahoo.com> References: <1130621124.101346.67750@g44g2000cwa.googlegroups.com> <1h57711.1t6uely1atckigN%aleaxit@yahoo.com> <1130624219.667062.290740@g47g2000cwa.googlegroups.com> <1h57c0h.kcl38fefrcdrN%aleaxit@yahoo.com> Message-ID: <1130677633.449893.131080@g44g2000cwa.googlegroups.com> OK. The thing i've got is an obscure semantic bug, occured because of my unawareness of the following Python "features": 1. (In major) http://mail.python.org/pipermail/python-dev/2005-September/056508.html 2. "late" bindings of the function's body Got to know! :) Thanks for your attention. From steve at holdenweb.com Fri Oct 14 11:29:17 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 14 Oct 2005 16:29:17 +0100 Subject: UI toolkits for Python In-Reply-To: References: Message-ID: Adriaan Renting wrote: [which GUI toolkit?] >>>>Kenneth McDonald 10/13/05 10:17 pm >>> > > Is there any emerging consensus on the "best" UI for toolkit. Tk > never quite made it but from what I can see, both qt and wxWin are > both doing fairly well in general. I'm already aware of the licensing > issues surrounding qt (fwiw, I think their license fee for commercial > use is eminently reasonable), so aside from that, I was wondering if > there was any feedback readers could provide on the following: > > 1) Which plays best with Python? Ideally, it would already have some > higher-level python libraries to hide the grotty stuff that is almost > never needed when actually implementing apps. > > 2) Reliability of each? > > 3) Useful external libraries for each? > > 4) Ease of installation/use on OS X? > > Something with a genuinely useful text widget would be nice, but I > know that's too much to expect...ah, TkText widget, where are you > when I need you. > Hmm. The only real answer is to make a choice and stick with it until you have enough experience to determine whether it was a good decision or not - all platforms have advantages and disadvantages. For the record, having tried several toolkits and GUI builders I have recently decided to settle (for the moment) on wxPython and wxDesigner (the latter is a modestly-priced commercial product that represents very good value for money). While wxDesigner doesn't do everything you might want it seems to be better than anything else I've come across for building resizable dialogues and panels, which are readily used as components in other more complex windowed application structures. Just my 2c, though. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From jaydonnell at gmail.com Thu Oct 27 11:54:37 2005 From: jaydonnell at gmail.com (jdonnell) Date: 27 Oct 2005 08:54:37 -0700 Subject: strange problems with urllib2 In-Reply-To: References: <1130364688.010192.39650@f14g2000cwb.googlegroups.com> Message-ID: <1130428477.452260.101680@g43g2000cwa.googlegroups.com> I haven't checked them, but will do it now. However, I don't have problems with anything but python. I can download that image in less than a second with wget or in my browser. I know that I had ipv6 problems before. I had to turn it off because of my nat router so I'll look into that sort of thing. From wholcomb at gmail.com Sat Oct 22 13:17:03 2005 From: wholcomb at gmail.com (Will) Date: 22 Oct 2005 10:17:03 -0700 Subject: subprocess exiting in an incomprehensible fashion In-Reply-To: <20051021194237.3AA2.0.NOFFLE@fiedzia.homeip.net> References: <1129916005.543449.305390@g44g2000cwa.googlegroups.com> <20051021194237.3AA2.0.NOFFLE@fiedzia.homeip.net> Message-ID: <1130001423.239130.285920@g49g2000cwa.googlegroups.com> Well, I'll be damned... Thank you very much. I'm still getting a little tripped up with blocking IO and whatnot, but I think I can work that out. This was a real help, thanks again. #!/usr/bin/python # -*- coding: UTF-8 -*- import subprocess import random import re import os import time import select calc = subprocess.Popen("dc", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) max = random.Random().randint(10, 100) for value in range(1, max): calc.stdin.write("%d\n" % value) if value > 1: calc.stdin.write("*\n") calc.stdin.write("p\n") select.select([calc.stdout.fileno()], [], []) time.sleep(.1) # Still not always getting the result string = os.read(calc.stdout.fileno(), 500) print "String: ", string dcproduct, repcount = re.subn("\\\|\\s", "", string) dcproduct = int(dcproduct) pyproduct = reduce(lambda x,y: x * y, range(1, max)) if dcproduct == pyproduct: print "?(1,%d):" % (max - 1) else: print "Products don't match: n = %d" % (max - 1) print " %d" % dcproduct print " %d" % pyproduct calc.stdin.write("q\n") status = calc.wait() print "Exited with: %d" % status From xah at xahlee.org Wed Oct 12 22:24:01 2005 From: xah at xahlee.org (Xah Lee) Date: 12 Oct 2005 19:24:01 -0700 Subject: Perl-Python-a-Day: Sorting In-Reply-To: <1128937897.500935.254770@o13g2000cwo.googlegroups.com> References: <1128937897.500935.254770@o13g2000cwo.googlegroups.com> Message-ID: <1129170241.274868.45680@g43g2000cwa.googlegroups.com> Sorting in Perl In Perl, to sort a list, do like this: @li=(1,9,2,3); @li2 = sort {$a <=> $b} @li; print join(' ', @li2); In Perl, sort is a function, not some Object Oriented thing. It returns the sorted result as another list. This is very simple and nice. It works like this: sort takes the form ?sort {...} @myList?. Inside the enclosing braces is the body of the ordering function, where variables $a and $b inside are predefined by the language to represent two elements in the list. The operator ?<=>? returns -1 if left element is less than right element. If equal, it returns 0, else 1. It is equivalent to Python's ?cmp? function. Perl provides another comparison operator ?cmp?, which treats its operands as strings. So, for example: print "3" <=> "20"; # prints -1 print "3" cmp "20"; # prints 1 In Perl, numbers and strings are mutually automatically converted if needed. Another form of sort is ?sort orderFunctionName @list?, which uses a function name in place of the comparison block Just for completeness, let's define a Perl equivalent of a Python example above. @li=( 'my283.jpg', 'my23i.jpg', 'web7-s.jpg', 'fris88large.jpg', ); # sorts a list of strings by their embedded number @li2 = sort { ($a=~m/(\d+)/)[0] <=> ($b=~m/(\d+)/)[0];} @li; print join(' ', @li2); # prints web7-s.jpg my23i.jpg fris88large.jpg my283.jpg Note, that Perl also has pure functions (lambda) construct. In Perl, a pure function is simply done as ?def {...}?, and applied to argument by the form ?pureFunction->(args)?. Unlike Python, Perl has no limitation in its pure function construct. Because of this, Perl supports a limited form of functional programing. Here's a simple example: $result = sub($) {$_[0]+1}->(3); print $result; # prints 4 # a value obtained by a pure function that adds 1 to its argument, # applied to a argument of 3. Perl, like Python, whose compiler is not very smart. In sorting, the ordering function is called unnecessarily repetitiously. Like Python, Perlers have sought means to avoid this penalty. If the programer knew in advance that his matrix is huge or knew in advance his ordering function, then he can code his sort by writing it using a very complex workaround.: Here's how this work around works: Suppose you want to sort a huge list with a expensive ordering function. If you simply do ?sort orderingFunction @myList?, then Perl is going to call your orderingFunction wantonly, and you lose. To beat Perl, you first generate a copy newList, whose elements are pairs (x,y), where x is from the original list, and y is the sorting key extracted from x. Then, you call Perl's sort function on this newList and using a ordering function based on the second list element (the y). Once this newList is sorted, you construct your original list by extracting the first element from this sorted newList. Here's the code example: # the following two lines are equivalent @li2 = sort { ($a=~m/(\d+)/)[0] <=> ($b=~m/(\d+)/)[0];} @li; @li2 = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, ($_=~m/(\d+)/)[0] ] } @li; In the above Perl code, the part ?map { [ $_, ($_=~m/(\d+)/)[0] ] } @li;? generates the intermediate newList. Then, sort is applied to it, then, another map ?map { $_->[0] }? gets the original list sorted. In this way, the cost of the internals of the ordering function is avoided. (it runs on each list element once) However, your huge list is copied 1 extra time. So, there are pros and cons. Because this work around is very complex in both its semantics and syntax, it has acquired a coolness factor among Perl coders, and is given the name Schwartzian Transform. It is interesting to note what compiler flaws can do to imperative languages and its people. In Python, the language syntax is tainted. In Perl, a complex construct is invented. In both camps, the basic mathematics of sorting and its implementation aspects are completely belied. For the official doc of Perl's sort, type on the command line: ?perldoc -f sort?. --------- this post is archived at: http://xahlee.org/perl-python/sort_list.html Xah xah at xahlee.org ? http://xahlee.org/ From fredrik at pythonware.com Fri Oct 21 11:25:52 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 21 Oct 2005 17:25:52 +0200 Subject: Compile C program -> .pyc file References: <1129905417.451369.114840@o13g2000cwo.googlegroups.com> Message-ID: "Ernesto" wrote: > Is there a way to compile a C program into a .pyc file that has the > same behavior as the compiled C program? unless you find a C->Python compiler, no. PYC files contain Python bytecode, C compilers usually generate native code for a given machine platform. From martin at v.loewis.de Sat Oct 29 13:08:07 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 29 Oct 2005 19:08:07 +0200 Subject: Building 2.4.2 on OpenBSD 3.8 In-Reply-To: References: Message-ID: <4363ac77$0$15413$9b622d9e@news.freenet.de> Dan M wrote: > /usr/include/sys/event.h:53: error: syntax error before "u_int" > /usr/include/sys/event.h:55: error: syntax error before "u_short" > *** Error code 1 > > Stop in /usr/local/src/Python-2.4.2. > > immediately upon running "make". I took at look at event.h to see if I > could find and fix the problem, but the error isn't immediately apparent > to me. In that case, it would help if you would report what line 53 of event.h precisely is. Typically, if it says "syntax error before", it means "immediately, right away before", or "the error actually is *in* u_int" (the latter indicating that u_int is not defined at that point). Generating a preprocessor output then helps, seeing whether something got #define'd in some strange sense, or whether u_int was defined before use. Most likely, it is the old BSD bug of not supporting POSIX correctly. Somebody should really work with the system developers to get this resolved; it's been several years now that the bug is present. Regards, Martin From timr at probo.com Tue Oct 11 02:19:14 2005 From: timr at probo.com (Tim Roberts) Date: Tue, 11 Oct 2005 06:19:14 GMT Subject: how to capture key pressing References: Message-ID: "billie" wrote: > >> Look at curses. > >I was searching for something portable on multiple platforms. Keyboard access is not portable. It is quite system-specific, even in C. >Curses doesn't work on Windows. Sure it does. You can find curses implementations for Windows. However, it depends on what you are planning to do. If all you want to do is wait for one character and print it, it's not too hard to have separate schemes for separate systems: C:\Data\PyTools>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 msvcrt >>> msvcrt.getch() '\x1b' >>> (I pressed "escape" after the second "enter".) -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From steve at REMOVETHIScyber.com.au Tue Oct 11 18:24:51 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Wed, 12 Oct 2005 08:24:51 +1000 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <86y853mzmr.fsf@bhuda.mired.org> <86mzlil269.fsf@bhuda.mired.org> Message-ID: On Tue, 11 Oct 2005 14:27:30 +0000, axel wrote: > I don't know how much spam other people receive but on one account I > hardly receive any as I reserve it for friends and business. On another > I had about 40 spam messages which took all of ten seconds to delete. > Hardly a serious matter. Can I remind you that spam is approximately 70% of all email traffic these days? Most of that is blocked by the ISPs, but even so you are obviously one of the lucky few. My home address, which I cunningly will not give you, used to get about fifty spams a day until I changed ISPs and email addresses. That would quadruple for a week or so whenever one of my Windows-using friends would get infected by a virus. My current home address only gets about one a month, which is what I consider acceptable. My work email address, on the other hand, is another story. We run a two layer defence: blocking blacklisted addresses at our mail server, and spam assassin at the individual user level. Even with that, I get about 100 spams a day delivered into my inbox, although many of those are addressed to generic email addresses which are automatically forwarded to me. Four years ago, one of our sys admins accidentally turned off the blacklisting at the mail server. In the ten minutes it took to get it turned back on, the CEO of our company received eight hundred spams. -- Steven. From roccomoretti at hotpop.com Fri Oct 7 10:14:30 2005 From: roccomoretti at hotpop.com (Rocco Moretti) Date: Fri, 07 Oct 2005 09:14:30 -0500 Subject: When someone from Britain speaks, Americans hear a "British accent"... In-Reply-To: References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kbgj7421kd560@corp.supernews.com> <4h5ck1hkqq0ls83pq0lodkb51tsda4053k@4ax.com> Message-ID: Steve Holden wrote: >> On Fri, 07 Oct 2005 00:33:43 -0000, Grant Edwards >> wrote: >>> For example: In British English one uses a plural verb when the >>> subject consists of more than one person. Sports teams, >>> government departments, states, corporations etc. are grammatically >>> plural. In American, the verb agrees with the >>> word that is the subject, not how many people are denoted by >>> that word. > > There aren't any universal rules, except possibly "British people speak > English while Americans don't". I believe you overgeneralize. :) A Welshman would likely be offended if you implied he spoke English, and the Scots are notorious for only speaking English when they have too. (I remember a news story some years back about a Scottish "lad" who was fined/imprisoned for replying to an official court representative with "Aye" rather than "Yes".) For that matter there are plenty of people in Cornwall and even in London (Cockney) who speak something that is only called "English" for lack of a better term. From steven.bethard at gmail.com Mon Oct 3 12:22:23 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Mon, 03 Oct 2005 10:22:23 -0600 Subject: pywordnet install problems In-Reply-To: <1128163605.623632.96660@o13g2000cwo.googlegroups.com> References: <1128057470.285356.211160@g49g2000cwa.googlegroups.com> <1128163605.623632.96660@o13g2000cwo.googlegroups.com> Message-ID: vdrab wrote: > I had WordNet 2.0 installed but just now I tried it with 1.7.1 as well > and the result was the same. It's a shame, glossing over the pywordnet > page really made me want to give it a try. > Are there any workarounds you can recommend ? What's your wordnet setup like? I have mine installed in: C:\Program Files\WordNet\2.0 and I have an environment variable WNHOME set: WNHOME=C:\Program Files\WordNet\2.0 That seems to work for me. > I had a quick look at the wordnet.py file, and it looks readable enough > to try and fiddle around with it, but if possible I'd like to avoid > having to mess with the source file. > Is there any other person / list I can ask for help on this? Unfortunately, I wasn't able to find anyone else... STeVe From volker_grabsch at v.notjusthosting.com Mon Oct 3 04:48:27 2005 From: volker_grabsch at v.notjusthosting.com (Volker Grabsch) Date: Mon, 3 Oct 2005 10:48:27 +0200 Subject: [Info] PEP 308 accepted - new conditional expressions References: <3q4ro9Fd770nU3@individual.net> Message-ID: Fredrik Lundh wrote: > /... snip comment that the natural order is C, X, Y and that programmers that > care about readable code will probably want to be extremely careful with this > new feature .../ That's also my opinion, but OTOH, Guido's syntax is more close to the syntax of list comprehensions. Greets, Volker -- Volker Grabsch ---<<(())>>--- \frac{\left|\vartheta_0\times\{\ell,\kappa\in\Re\}\right|}{\sqrt [G]{-\Gamma(\alpha)\cdot\mathcal{B}^{\left[\oint\!c_\hbar\right]}}} From __peter__ at web.de Mon Oct 10 14:51:44 2005 From: __peter__ at web.de (Peter Otten) Date: Mon, 10 Oct 2005 20:51:44 +0200 Subject: convert char to byte representation References: <434ab2f6$1@nntp0.pdx.net> Message-ID: Scott David Daniels wrote: > Philipp H. Mohr wrote: >> I am trying to xor the byte representation of every char in a string with >> its predecessor. But I don't know how to convert a char into its byte >> representation. > ord('a') == 97; chr(97) == 'a'; "ord" gives you the value of the byte. > >> e.g. everything between $ and * needs to be xor: >> $GPGSV,3,1,10,06,79,187,39,30,59,098,40,25,51,287,00,05,25,103,44* >> to get the checksum. > > Probably you want a byte-array here, rather than going char-by-char. > Try: > import array > base = ('$GPGSV,3,1,10,06,79,187,39,30,59,098,' > '40,25,51,287,00,05,25,103,44*') > bytes = array.array('b', base[1 : -1]) > for i in reversed(range(len(bytes))): > bytes[i] ^= bytes[i-1] > result = bytes.tostring() Seems like the OP doesn't need what he asked for. The simpler def checksum(s): assert s[0] == "$" assert s[-1] == "*" result = 0 for c in s[1:-1]: result ^= ord(c) return result should do. Peter From nephish at xit.net Fri Oct 21 16:48:42 2005 From: nephish at xit.net (nephish at xit.net) Date: 21 Oct 2005 13:48:42 -0700 Subject: need some advice on x y plot In-Reply-To: <11lietgq0m60f66@corp.supernews.com> References: <1129823043.104864.73750@f14g2000cwb.googlegroups.com> <11lfgebn85liq1b@corp.supernews.com> <1129825379.218308.242010@g47g2000cwa.googlegroups.com> <4357d998$1_2@newspeer2.tds.net> <1129831950.926154.196420@g47g2000cwa.googlegroups.com> <1129912485.866312.298390@g47g2000cwa.googlegroups.com> <4359244e$1_2@newspeer2.tds.net> <1129916685.172187.224140@o13g2000cwo.googlegroups.com> <11lietgq0m60f66@corp.supernews.com> Message-ID: <1129927722.835095.191620@g49g2000cwa.googlegroups.com> ok, i have a display, and its a work in progress. lemme get this straight. you used gp('set term png') is this an example of sending normal gnuplot commands? if so, are all of the gnuplot commands available ? thanks so much this is helping me out a lot here From grig.gheorghiu at gmail.com Mon Oct 31 19:55:48 2005 From: grig.gheorghiu at gmail.com (Grig Gheorghiu) Date: 31 Oct 2005 16:55:48 -0800 Subject: looking for a good python module for MS SQL server References: Message-ID: <1130806548.423359.182910@f14g2000cwb.googlegroups.com> I successfully used mxODBC () Grig From sybrenUSE at YOURthirdtower.com.imagination Wed Oct 26 06:23:23 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Wed, 26 Oct 2005 12:23:23 +0200 Subject: p2exe using wine/cxoffice References: Message-ID: Tim Golden enlightened us with: > Well, I'm with you. I'm sure a lot of people will chime in to point > out just how flexible and useful and productive Linux is as a > workstation, but every time I try to use it -- and I make an honest > effort -- I end up back in Windows I'm curious, what do you mean with "it" in the part "every time I try to use it"? There are different distributions of Linux, and putting them all on one big pile is like saying "I've tried Windows, and I really don't like it's user interface" and referring to the interface of Windows 3.1. Many people use Fedora (from RedHat) and don't like it. I agree with them - I don't like it either. For those people: give Ubuntu Linux a go. It's my favourite - and my girlfriend's too btw. 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 maksim.kasimov at gmail.com Wed Oct 5 09:31:26 2005 From: maksim.kasimov at gmail.com (Maksim Kasimov) Date: Wed, 05 Oct 2005 16:31:26 +0300 Subject: how to debug when "Segmentation fault" In-Reply-To: References: <200510041122.25067.mekstran@scl.ameslab.gov> <20051004190827.3914.1498135555.divmod.quotient.23977@ohm> Message-ID: <4343D5AE.2000601@gmail.com> jepler at unpythonic.net wrote: > I've rewritten your middle example to be clearer. > $ python2.4 > Python 2.4.1 (#1, May 16 2005, 15:15:14) > [GCC 4.0.0 20050512 (Red Hat 4.0.0-5)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>>>type("Y", (type,), {"mro": lambda x: [float]})("X", (), {}) on my machines: >>> type("Y", (type,), {"mro": lambda x: [float]})("X", (), {}) > > > and here's another one for you to enjoy: > >>>>import marshal >>>>f = lambda: None >>>>code = marshal.loads(marshal.dumps(f.func_code).replace('d\0\0S','d\xff\xffS')) >>>>f.func_code = code >>>>f() just no any output >>> dir(code) ['__class__', '__cmp__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__repr__', '__setattr__', '__str__', 'co_argcount', 'co_cellvars', 'co_code', 'co_consts', 'co_filename', 'co_firstlineno', 'co_flags', 'co_freevars', 'co_lnotab', 'co_name', 'co_names', 'co_nlocals', 'co_stacksize', 'co_varnames'] Python 2.2.3 (#1, Oct 22 2004, 03:10:44) [GCC 2.95.4 20020320 [FreeBSD]] on freebsd4 -- Best regards, Maksim Kasimov mailto: maksim.kasimov at gmail.com From john at castleamber.com Mon Oct 17 22:04:49 2005 From: john at castleamber.com (John Bokma) Date: 18 Oct 2005 02:04:49 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <1129491006.021102.43920@g14g2000cwa.googlegroups.com> <86zmp8zsjk.fsf@bhuda.mired.org> Message-ID: Steven D'Aprano wrote: > On Mon, 17 Oct 2005 21:42:09 +0000, John Bokma wrote: > >>> When did Netscape executives perjure themselves in court? >>> >>> When did Netscape commit fraud? Astro-turfing? Patent infringement? >>> Theft of code? >> >> They got killed too soon. > > Neither the Netscape executives nor Netscape the company have been > killed. They were in one race, and they lost it. >>> that was then, this is now, and unlike IBM, Microsoft hasn't yet >>> learnt about karma. >> >> Which is a good thing, since MS is not a human being. It's a company, >> a thing to make money, so it can make more money. > > Microsoft is a collection of human beings. They don't get to excuse > anti-social behaviour on the basis that they're only trying to make > money. I see little difference with other big companies. You're right that there is no excuse for such behaviour, but if MS isn't doing it, another company will take their place. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From duncan.booth at invalid.invalid Wed Oct 5 05:27:04 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Oct 2005 09:27:04 GMT Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> <434245F5.6060500@REMOVEMEcyber.com.au> <7xr7b14lk0.fsf@ruckus.brouhaha.com> <7xu0fx9l7y.fsf@ruckus.brouhaha.com> Message-ID: Antoon Pardon wrote: > It also is one possibility to implement writable closures. > > One could for instace have a 'declare' have the effect that > if on a more inner scope such a declared variable is (re)bound it > will rebind the declared variable instead of binding a local name. That is one possibility, but I think that it would be better to use a keyword at the point of the assigment to indicate assignment to an outer scope. This fits with the way 'global' works: you declare at (or near) the assignment that it is going to a global variable, not in some far away part of the code, so the global nature of the assignment is clearly visible. The 'global' keyword itself would be much improved if it appeared on the same line as the assignment rather than as a separate declaration. e.g. something like: var1 = 0 def f(): var2 = 0 def g(): outer var2 = 1 # Assign to outer variable global var1 = 1 # Assign to global From max at alcyone.com Tue Oct 4 22:14:25 2005 From: max at alcyone.com (Erik Max Francis) Date: Tue, 04 Oct 2005 19:14:25 -0700 Subject: check html file size In-Reply-To: References: <1128473042.653989.175990@o13g2000cwo.googlegroups.com> Message-ID: <7fWdnbgeuY2cqt7eRVn-gA@speakeasy.net> Matt Garrish wrote: > Even if you weren't an incredibly offensive and petulant poster, what makes > you think anyone would write a script from you? Because in addition to being offensive and petulant, he's also an idiot. -- 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 fate that cannot be surmounted by scorn. -- Albert Camus From steve at REMOVETHIScyber.com.au Sun Oct 23 18:32:15 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 24 Oct 2005 08:32:15 +1000 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> Message-ID: On Sun, 23 Oct 2005 11:43:44 -0700, David Schwartz wrote: > You are dishonest, lying sack of shit. And David posts his true colours to the mast at last. When rational argument and logical thoughts fails, fall back on personal insults. -- Steven. From arve.knudsen at gmail.com Tue Oct 25 18:07:24 2005 From: arve.knudsen at gmail.com (arve.knudsen at gmail.com) Date: 25 Oct 2005 15:07:24 -0700 Subject: How to statically link Python with ncurses and readline? In-Reply-To: <435ea4ca$0$16638$9b622d9e@news.freenet.de> References: <1130263338.291061.50210@g49g2000cwa.googlegroups.com> <435e78d1$0$2680$9b622d9e@news.freenet.de> <1130265985.862970.185070@g47g2000cwa.googlegroups.com> <435ea4ca$0$16638$9b622d9e@news.freenet.de> Message-ID: <1130278044.241389.177210@o13g2000cwo.googlegroups.com> What do you mean? A static-only build does somehow exclude that I had static libraries before? From davids at webmaster.com Wed Oct 26 14:40:38 2005 From: davids at webmaster.com (David Schwartz) Date: Wed, 26 Oct 2005 11:40:38 -0700 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> <11lsopl4qpg9gc2@corp.supernews.com> Message-ID: "Tor Iver Wilhelmsen" wrote in message news:ubr1cjmau.fsf at hotmail.com... > entropy writes: >> IBM seems to have had a history of squeezing out competition in the >> same way Microsoft has, if I recall correctly. > ... and were told not to by a court. Which is the whole reason for the > existence of IBM clones, whether PCs or mainframes. And, perhaps, is the whole reason for the existence of Microsoft. (In its present form, as the OS vendor for the majority of desktops.) DS From steve at holdenweb.com Wed Oct 5 07:07:20 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 05 Oct 2005 12:07:20 +0100 Subject: bug or feature? In-Reply-To: <1128508770.727391.313300@f14g2000cwb.googlegroups.com> References: <1128508770.727391.313300@f14g2000cwb.googlegroups.com> Message-ID: beza1e1 wrote: > Coming back from a bug hunt, i am not sure what to think of this python > behaviour. Here is a demo program: > > class A: > def __init__(self, lst=[]): > self.lst = lst > > a = A() > b = A() > b.lst.append("hallo") > print a.lst # output: ["hallo"] > > The point seems to be, that lst=[] creates a class attribute (correct > name?), which is shared by all instances of A. So a.lst ist the same > object as b.lst, despite the fact, that object a is different to object > b. > Interestingly I couldn't find this in the FAQ, though it *is* a frequently-asked question [note: my not finding it doesn't guarantee it's not there]. The nearest I could get was in http://www.python.org/doc/faq/programming.html#my-program-is-too-slow-how-do-i-speed-it-up which says: """Default arguments can be used to determine values once, at compile time instead of at run time.""" The point is that the value of the keyword argument is determined when the def statement is executed (which is to say when the function body is being bound to its name). If the default argument is (a reference to) a mutable object (such as a list instance) then if one call to the function modifies that mutable object, subsequent calls see the mutated instance as the default value. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From prasad.c.iyer at capgemini.com Tue Oct 18 02:28:41 2005 From: prasad.c.iyer at capgemini.com (Iyer, Prasad C) Date: Tue, 18 Oct 2005 11:58:41 +0530 Subject: Don't want to serialize a variable of object Message-ID: Hi, I got a class which I need to serialize, except for couple of variable. i.e. import cPickle as p class Color: def __init__(self): print "hello world" self.x=10 self.somechar="this are the characters" color=Color() f=file('poem.txt', 'w') p.dump(color, f) f.close() How do I serialize the object color without serializing the x and somechar variables? Is there any modifier which prevents the variable from being serialized. Another question: Is there a concept of private variables? regards prasad chandrasekaran --- Cancer cures smoking #-----Original Message----- #From: python-list-bounces+prasad.c.iyer=capgemini.com at python.org #[mailto:python-list-bounces+prasad.c.iyer=capgemini.com at python.org] On #Behalf Of python-list-request at python.org #Sent: Tuesday, October 18, 2005 11:00 AM #To: python-list at python.org #Subject: Python-list Digest, Vol 25, Issue 322 # #Send Python-list mailing list submissions to # python-list at python.org # #To subscribe or unsubscribe via the World Wide Web, visit # http://mail.python.org/mailman/listinfo/python-list #or, via email, send a message with subject or body 'help' to # python-list-request at python.org # #You can reach the person managing the list at # python-list-owner at python.org # #When replying, please edit your Subject line so it is more specific #than "Re: Contents of Python-list digest..." This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. From fredrik at pythonware.com Sun Oct 2 16:32:39 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 2 Oct 2005 22:32:39 +0200 Subject: struct.unpack References: Message-ID: "g.franzkowiak" wrote: > I've read a pipe and store it in a object. > My next step was the separation from 4 bytes with > obj = string.join(list(dataObject)[:4] ==> '\x16 \x00 \x00 \x00' > and the converting by > value = struct.unpack('I', obj) generated the error > "unpack str size does not match format" > > Unfortunately is len(obj) 7, but integer lengt 4. > Why 7 ? because string.join inserts a space between the bytes, by default (as your example shows) if you really need that join(list) thing (it's not clear how you read it, but I find it a bit hard to believe that you've managed to read it into some- thing that's supported by list but not unpack), you can do obj = string.join(list(dataObject)[:4], "") or obj = "".join(list(dataObject[:4])) or some variation thereof. From steve at REMOVETHIScyber.com.au Sun Oct 30 17:20:02 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 31 Oct 2005 09:20:02 +1100 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <87ek65kbw5.fsf@lucien.dreaming> <1h57cu1.1jywbjibu87obN%aleaxit@yahoo.com> <1h58jkz.1byi9q5qwo1owN%aleaxit@yahoo.com> Message-ID: On Sun, 30 Oct 2005 08:35:12 -0700, Alex Martelli wrote: > Steven D'Aprano wrote: > ... >> > Don't ever catch and ``handle'' exceptions in such ways. In particular, >> > each time you're thinking of writing a bare 'except:' clause, think >> > again, and you'll most likely find a much better approach. >> >> What would you -- or anyone else -- recommend as a better approach? > > That depends on your application, and what you're trying to accomplish > at this point. > > >> Is there a canonical list somewhere that states every possible exception >> from a file open or close? > > No. But if you get a totally unexpected exception, I'm more concerned about getting an expected exception -- or more accurately, *missing* an expected exception. Matching on Exception is too high. EOFError will probably need to be handled separately, since it often isn't an error at all, just a change of state. IOError is the bad one. What else can go wrong? > something that shows > the world has gone crazy and most likely any further action you perform > would run the risk of damaging the user's persistent data since the > macchine appears to be careening wildly out of control... WHY would you > want to perform any further action? In circumstances where, as you put it, the hard disk has crashed, the CPU is on strike, or the memory has melted down, not only can you not recover gracefully, but you probably can't even fail gracefully -- at least not without a special purpose fail-safe operating system. I'm not concerned with mylist.append(None) unexpectedly -- and impossibly? -- raising an ImportError. I can't predict every way things can explode, and even if they do, I can't safely recover from them. But I can fail gracefully from *expected* errors: rather than the application just crashing, I can at least try to put up a somewhat informative dialog box, or at least print something to the console. If opening a preferences file fails, I can fall back on default settings. If writing the preferences file fails, I can tell the user that their settings won't be saved, and continue. Just because the disk is full or their disk quota is exceeded, doesn't necessarily mean the app can't continue with the job on hand. -- Steven. From jepler at unpythonic.net Thu Oct 27 12:20:41 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Thu, 27 Oct 2005 11:20:41 -0500 Subject: sys.exit call from pythonw.exe gives error In-Reply-To: References: Message-ID: <20051027162041.GA2696@unpythonic.net> I wrote the following small program: #----------------------------------------------------------------------- import sys, Tkinter t = Tkinter.Tk() b = Tkinter.Button(command=lambda: sys.exit(0), text="Click to exit") b.pack() t.mainloop() #----------------------------------------------------------------------- and ran it with pythonw.exe from python 2.3.4 on a machine running Windows NT 4.0. (I actually used Start > Run and entered "d:\python23\pythonw.exe x:\app.pyw" rather than clicking on the app.pyw icon, but this shouldn't make a difference) When the button is clicked, the application exits without giving any error like the one you described. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From duncan.booth at invalid.invalid Mon Oct 3 07:49:35 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 3 Oct 2005 11:49:35 GMT Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> Message-ID: Antoon Pardon wrote: > A language where variable have to be declared before use, would allow > to give all misspelled (undeclared) variables in on go, instead of > just crashing each time one is encounterd. Wrong. It would catch at compile-time those misspellings which do not happen to coincide with another declared variable. It would give the programmer a false sense of security since they 'know' all their misspellings are caught by the compiler. It would not be a substitute for run-time testing. Moreover, it adds a burden on the programmer who has to write all those declarations, and worse it adds a burden on everyone reading the code who has more lines to read before understanding the code. Also there is increased overhead when maintaining the code as all those declarations have to be kept in line as the code changes over time. It's a trade-off: there is a potential advantage, but lots of disadvantages. I believe that the disadvantages outweight the possible benefit. Fortunately there are plenty of languages to choose from out there, so those who disagree with me are free to use a language which does insist on declarations. From peter at engcorp.com Tue Oct 25 19:42:39 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 25 Oct 2005 19:42:39 -0400 Subject: Execute C code through Python In-Reply-To: <1130272231.210978.316140@g14g2000cwa.googlegroups.com> References: <1129844737.586396.61080@g47g2000cwa.googlegroups.com> <1129861083.010702.6770@g49g2000cwa.googlegroups.com> <1129906892.696582.288010@g43g2000cwa.googlegroups.com> <11li3b2hsa3lhb5@corp.supernews.com> <1130272231.210978.316140@g14g2000cwa.googlegroups.com> Message-ID: Ernesto wrote: > So i generated the .exe file "myFile.exe" > > This is a Windows - text based application. Right now, when I run: > > import subprocess > subprocess.call("myFile") > > the application starts in its own console window. Is there a way for > it to run inside the python interface? Google found the following (after I read the docs for subprocess and learned about the "startupinfo" flag, and searched for "subprocess startupinfo"). Does this help? http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/409002 -Peter From noway at sorry.com Sun Oct 16 07:01:54 2005 From: noway at sorry.com (Giovanni Bajo) Date: Sun, 16 Oct 2005 11:01:54 GMT Subject: Some set operators References: <1129408019.100885.323870@g47g2000cwa.googlegroups.com> <1h4hwtl.np9wjhchw3duN%aleax@mail.comcast.net> <1h4ipj6.z65uja1mk94z9N%aleax@mail.comcast.net> Message-ID: Alex Martelli wrote: >>> I still vaguely hope that in 3.0, where backwards incompatibilities >>> can be introduced, Python may shed some rarely used operators such >>> as >>> these (for all types, of course). >> >> I hope there is no serious plan to drop them. There is nothing wrong >> in having such operators, and I wouldn't flag bit operations as >> "rarely used". They are very common when calling C-based API and >> other stuff. I know I use them very often. They have a clear and >> well-understood meaning, as they appear identical in other >> languages, including the widely-spread C and C++. > > Well, C and C++ don't have unbounded-length integers, nor built-in > sets, so the equivalence is slightly iffy; and the precedence table of > operators in Python is not identical to that in C/C++. The equivalence was trying to make a point about the fact that bitwise operators are not an uncommon and obscure operator like GCC's " As for > frequency > of use, that's easily measured: take a few big chunks of open-source > Python code, starting with the standard library (which does a lot of > "calling C-based API and other stuff") and widespread applications > such as mailman and spambayes, and see what gives. I grepped in a Python application of mine (around 20k lines), and I found about 350 occurrences of ^, | and &, for either integers or builtin sets. > But the crux of our disagreement lies with your assertion that there's > nothing wrong in having mind-boggling varieties and numbers of > operators, presumably based on the fact that C/C++ has almost as many. When exactly did I assert this? I am just saying that an infix operator form for bitwise or, and, xor is very useful. And once we have them for integers, using them for sets is elegant and clear. Notice also that a keyword-based alternative like "bitand", "bitor", "bitxor" would serve well as a replacement for the operators for integers, but it would make them almost useless for sets. > I contend that having huge number of operators (and other built-ins) > goes against the grain of Python's simplicity, We agree on this. > makes Python > substantially harder to teach, and presents no substantial advantages > when compared to the alternative of placing that functionality in a > built-in module (possibly together with other useful bit-oriented > functionality, such as counts of ones/zeros, location of first/last > one/zero bit, formatting into binary, octal and hexadecimal, etc). Such a module would be very useful, but I believe it's orthogonal to having an infix notation for common operations. We have a string module (and string methods), but we still have a couple of operators for strings like "+". -- Giovanni Bajo From grante at visi.com Wed Oct 19 16:12:52 2005 From: grante at visi.com (Grant Edwards) Date: Wed, 19 Oct 2005 20:12:52 -0000 Subject: Python variables are bound to types when used? References: <1129751462.061785.124830@g49g2000cwa.googlegroups.com> <11ld9qtgvead8d0@corp.supernews.com> Message-ID: <11lda64jq5s1u12@corp.supernews.com> On 2005-10-19, Grant Edwards wrote: >> So, if I use "l2" thus: >> >> if (l2): # only then does it make it a boolean? > > That doesn't affect the type of the object with the name "l2" > at all. It checks to see if l2 has a false value or not. > Examples of basic objects with false values are an iteger 0, a > floating point 0.0, an empty string "", an empty list [], an > empty tuple (), or an empty dictionary {}. Oh, and a bool False, obviously. -- Grant Edwards grante Yow! It's so OBVIOUS!! at visi.com From apardon at forel.vub.ac.be Thu Oct 20 03:14:51 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 20 Oct 2005 07:14:51 GMT Subject: Would there be support for a more general cmp/__cmp__ Message-ID: I was wondering how people would feel if the cmp function and the __cmp__ method would be a bit more generalised. The problem now is that the cmp protocol has no way to indicate two objects are incomparable, they are not equal but neither is one less or greater than the other. So I thought that either cmp could return None in this case or throw a specific exception. People writing a __cmp__ method could do the same. -- Antoon Pardon From __peter__ at web.de Tue Oct 4 10:18:41 2005 From: __peter__ at web.de (Peter Otten) Date: Tue, 04 Oct 2005 16:18:41 +0200 Subject: email module, redirecting to stdout References: Message-ID: Laszlo Zsolt Nagy wrote: > I have this code: > > s = smtplib.SMTP() > s.set_debuglevel(1) > s.connect(host=smtp_host) > s.set_debuglevel(0) > log("Connected, sending e-mail") > sys.stdout.flush() > s.sendmail( > consts.EMAIL_FROMADDRESS, > [to], > msg.as_string() > ) > log("E-mail sent OK") > s.quit() > > The problem is that whenever I set the debuglevel to 1, messages will go > to stderr. I would like them to go to stdout. Using > > sys.stderr = sys.stdout > > has no effect. Redirecting stderr to stdout from the shell is not an > option for me, because I need to use stderr for other messages. smtplib obtains a copy of stderr by from sys import stderr Therefore you have to do smtplib.stderr = sys.stdout to get the desired effect. Peter From jmw136 at gmail.com Mon Oct 31 15:09:35 2005 From: jmw136 at gmail.com (John W) Date: Mon, 31 Oct 2005 14:09:35 -0600 Subject: Asyncore Loop Question In-Reply-To: References: Message-ID: Steve, Ar you saying that I should close the connection until I have data to write? Or should I be using the readable and writable methods to turn it off? Thanks for your help, unfortunatly, I have struggled with the documentation and getting a clear understanding of everything. This is my first socket program as well. Thanks, John On 10/31/05, Steve Holden wrote: > > John W wrote: > > Hello, > > > > I have a gui application where I am trying to use the asyncore module to > > gather data from other computers. I am able to connect, but I am getting > > constant handle_write_event method calls into my application. It is > > obviously slowing down the gui processing significantly. > > > > My understanding is that the handle_write_event and handle_read_event > are > > both edge notifications and I should just get the method call > essentially > > just once. > > > > I think the problem is how I have my loop() call configured. All I am > trying > > to do with the code below is to open the socket (that works) and then > > receive a single handle_write_event method call. Instead, I am getting > > constantly barraged with them. > > > > I have tried several different types of the loop() call (using poll, > > timeout...) but with no luck. If anyone can explain what I should be > doing > > to get a single handle_write_event call until I actually write something > to > > the socket (which my code is not presently doing yet), I would > appreciate > > > > Below is some code showing what I am doing: > > > > -------------------------------------------------------------- > > class Connection(asyncore.dispatcher): > > def __init__ (self, server_name, port_num ): > > self.message_queue = [] > > > > asyncore.dispatcher.__init__(self) > > self.create_socket( socket.AF_INET, socket.SOCK_STREAM ) > > self.connect(( server_name, port_num )) > > > > > > def handle_read_event( self ): > > print "handle_read_event received" > > > > > > def handle_write_event( self ): > > print "Asking for a write" > > > > if len( self.message_queue ) > 0: > > # Pop the first message off the queue > > self.send_next_message() > > > > > > class TestApp: > > def __init__( self, server_name, port_number ): > > > > self.nomad = Connection( server_name, port_number ) > > asyncore.loop() > > > > > > Output ends up being a constant stream of: > > Asking for a write > > Asking for a write > > Asking for a write > > Asking for a write > > Asking for a write > > .... > > ... > > ... > > > > > Normally if a socket channel asks for a write and you have no data you > should respond by removing it from the list of write-enabled channels > for the asyncore loop until you *do* have some data for it. Otherwise > every time the loop scans the channels expecting notification it will > tell you again that you can write to that channel. > > regards > Steve > -- > Steve Holden +44 150 684 7255 +1 800 494 3119 > Holden Web LLC www.holdenweb.com > PyCon TX 2006 www.python.org/pycon/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From davids at webmaster.com Thu Oct 27 07:15:10 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 04:15:10 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: Roedy Green wrote: > On Sun, 16 Oct 2005 16:31:41 GMT, Roedy Green > wrote, quoted or > indirectly quoted someone who said : >> I used to be a retailer of custom computers. MS used a dirty trick >> to compete with IBM's OS/2. They said to me as a retailer. You must >> buy a copy of our OS for EVERY machine you sell. The alternative is >> to pay full retail for the OSes. > Through intimidation, MS managed to control the entire retail computer > market in Vancouver BC to the extent you could not buy even the most > stripped down computer without having to buy a copy of Windows with > it, whether you wanted it or not. > > You might not want it because you bought OS/2. > > You might not want it because you already owned Windows from your > older machine you were upgrading. > > You might not want it because somebody stole your machine and they did > not steal all your software masters. Tell me, can you buy a new car without seats? Guess what, you have to buy those seats whether you want them or not. Try to start a business selling competing seats for a new car. Your seats may be cheaper, better, but how can you possibly compete when people have to pay for factory car seats whether they want them or not? The real reason PCs were not available without Windows was because not enough people wanted them that way to justify setting up a business to provide them that way, and Microsoft was not going to let a business parasitically use Windows to build a business that touted the advantages of competing products. (Just as Burger King corporate will not you sell Big Macs in the same store in which you sell Whoppers.) DS From *firstname*nlsnews at georgea*lastname*.com Sun Oct 2 23:43:29 2005 From: *firstname*nlsnews at georgea*lastname*.com (Tony Nelson) Date: Mon, 03 Oct 2005 03:43:29 GMT Subject: gtk.TextView.move_mark_onscreen() broken? Message-ID: <*firstname*nlsnews-85FB93.23433702102005@news.verizon.net> Is gtk.TextView.move_mark_onscreen() broken? Perhaps only in Python's gtk module, in Python 2.3, gtk 2.4.14? I'm asking here because I'm using gtk from Python and don't want to write a C program to verify my issue. I've also tried gtk.TextView.scroll_to_mark() and gtk.TextView.place_cursor_onscreen(), and none of them want to do anything. The rest of my program works, so I'm not a complete gtk bazo. ________________________________________________________________________ TonyN.:' *firstname*nlsnews at georgea*lastname*.com ' From fredrik at pythonware.com Fri Oct 7 12:56:10 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 7 Oct 2005 18:56:10 +0200 Subject: CSV like file format featured recently in Daily Python URL? References: <1128688213.7906.7.camel@localhost.localdomain> Message-ID: Alex Willmer wrote: > I'm trying to track down the name of a file format and python module, > that was featured in the Daily Python URL some time in the last month or > two. http://www.netpromi.com/kirbybase.html ? From fredrik at pythonware.com Tue Oct 25 10:04:34 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 25 Oct 2005 16:04:34 +0200 Subject: Tricky import question. References: <1130247555.359770.169070@o13g2000cwo.googlegroups.com> Message-ID: David Poundall wrote: > importedfiles = {} > for f in FileList > f2 = f.split('.')[0] # strip the .py, .pyc > __import__(f2) > s2 = f2+'.main()' # main is the top file in each import > c = compile(s2, '', 'eval') > importedfiles[f2] = eval(c) > > 'importedfiles' should hold an object reference to the main() function > within each imported file. > > The problem is, the import function works but I can't get the object > reference into the imortedfiles dictionary object. the code keeps > telling me > > NameError: name 'C1_Dosing' is not defined. > > in this instance C1_Dosing is the first file name in the filelist. The > import worked, why not the compile ?? because your __import__ statement didn't assign the returned module to anything, so there's no C1_Dosing in the current namespace. assuming that the main function in each module returns something that you want to store in the importedfiles dictionary, here's a better way to do it: m = __import__(f2) importedfiles[f2] = getattr(m, "main")() tweak as necessary. From peiyin.li at gmail.com Fri Oct 7 15:27:10 2005 From: peiyin.li at gmail.com (peiyin.li at gmail.com) Date: 7 Oct 2005 12:27:10 -0700 Subject: multiple logger Message-ID: <1128713230.539865.202980@g49g2000cwa.googlegroups.com> Hi, I want to have two loggers that logs to two different files. Here is what I have: import logging import logging.handlers project1Handler = logging.handlers.RotatingFileHandler( 'project1.log', maxBytes=1024) project1Handler.setLevel(logging.INFO) formatter1 = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') project1Handler.setFormatter(formatter1) logging.getLogger('project1').addHandler(project1Handler) logger1 = logging.getLogger('project1') logger1.debug('Quick zephyrs blow, vexing daft Jim.') logger1.info('How quickly daft jumping zebras vex.') logger1.warning('Jail zesty vixen who grabbed pay from quack.') logger1.error('The five boxing wizards jump quickly.') project2Handler = logging.handlers.RotatingFileHandler( 'project2.log', maxBytes=1024) project2Handler.setLevel(logging.DEBUG) formatter2 = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') project2Handler.setFormatter(formatter2) logging.getLogger('project2').addHandler(project2Handler) logger2 = logging.getLogger('project2') logger2.debug('Quick zephyrs blow, vexing daft Jim.') logger2.info('How quickly daft jumping zebras vex.') logger2.warning('Jail zesty vixen who grabbed pay from quack.') logger2.error('The five boxing wizards jump quickly.') However, I got this for project1.log: project1 : WARNING Jail zesty vixen who grabbed pay from quack. project1 : ERROR The five boxing wizards jump quickly. and this for project2.log: project2 : WARNING Jail zesty vixen who grabbed pay from quack. project2 : ERROR The five boxing wizards jump quickly. Where are the DEBUG and INFO messages go? I then add this at the begining of my code: logging.basicConfig(level=logging.DEBUG) Now it seems that both project1.log and project2.log has the correct output. But I also see all the log message going to the console, which I really don't want. What did I miss here? Do I have to set a handler for the root logger before I can set something for the child loggers? If yes, how do I make the root logger logs to nowhere? Thanks in advance! Albert From john at castleamber.com Tue Oct 18 02:57:47 2005 From: john at castleamber.com (John Bokma) Date: 18 Oct 2005 06:57:47 GMT Subject: Microsoft Hatred FAQ References: <%jV4f.3121$tV6.2659@newssvr27.news.prodigy.net> <2u59l1555jubv8qv09q57qh8m4skei9dqi@4ax.com> Message-ID: Roedy Green wrote: > On 18 Oct 2005 06:20:56 GMT, John Bokma wrote > or quoted : > >> >>That an HTML standard (ISO/IEC 15445:2000) and an HTML recommendation by >>w3c (4.01 for example) are two different things, and mixing them up by >>calling both standards is a bad thing. > > Because ... what are the consequences? If you mean if you are put in jail for 20 years, and tortured, none. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From PrikrylP at skil.cz Mon Oct 17 06:14:47 2005 From: PrikrylP at skil.cz (Petr Prikryl) Date: Mon, 17 Oct 2005 12:14:47 +0200 Subject: Any 3state Check Tree Ctrl for wxPython available? Message-ID: Hi, I am experimenting with wxPython on Windows box. What I need to implement is a check tree control with 3 states for each checkbox: unchecked, checked, gray checked. The status of the checkbox should reflect the status of the children. When ALL children are checked, then the status should be checked. When NO children are checked, the status should be unchecked. When SOME children are selected, the status should be checked with gray background. I have found something else that could be valuable after I start understand that: http://mitglied.lycos.de/drpython/CheckTreeCtrl.tar Anyway, is there something similar with 3 states available around? Thanks for your time and experience, pepr -- Petr Prikryl (prikrylp at skil dot cz) From http Fri Oct 14 23:37:24 2005 From: http (Paul Rubin) Date: 14 Oct 2005 20:37:24 -0700 Subject: deleting a parameter's name as it is passed to a function References: <1129336848.353805.176360@o13g2000cwo.googlegroups.com> <7xfyr3mwr6.fsf@ruckus.brouhaha.com> <1129337961.450468.220780@g14g2000cwa.googlegroups.com> Message-ID: <7xwtkfo3gr.fsf@ruckus.brouhaha.com> "Amir Michail" writes: > But dosomestuff can get rid of its reference before it returns (perhaps > it has a lot more to do before it returns and so you would want to > garbage collect the parameter object as soon as possible). That would be so rare and weird that your best bet is to just pass a boxed object in the odd circumstances where it will make any difference. Instead of dosomestuff(x), say dosomestuff([x]). Then dosomestuff can mutate the list: def dosomestuff(xl): x = xl.pop() ... do stuff with x ... x = None # free the reference ... more stuff... From steve at holdenweb.com Mon Oct 10 11:58:27 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 10 Oct 2005 16:58:27 +0100 Subject: Send password over TCP connection In-Reply-To: References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> Message-ID: Peter Tillotson wrote: > simplest approach is to 1 way hash the password ... perhaps using md5 > No, it isn't - see below. > normally with passwords the server only has to check if it is the same > word, assuming the same hash algorithms the same hash value can be > created at client. > Unfortunately this means that the client sends the same string every time the user authenticates. > Its not hugely secure ... anyone sniffing can grab your hash value and > then try to crack it at their leisure. It would be better to communicate > over ssl. > It's not even that secure: all they have to do is replay the data sniffed from the server and they too can authenticate themselves. They don't have to know what the plain-text password is. > Anyone know of a simple ssl api in python :-) > A safer way would be to use some sort of challenge-response mechanism, where the server presents a challenge C to the client, which then computes some function of both C and the plain-text password provided by the user. The server then authenticates by performing the same computation on C and the known password. As long as the server uses a different challenge each time then this is at least secure from replay attacks. But this scheme does have the weakness that the server must know the password of each user. For something even more secure, look at OPIE and similar schemes. But let's not forget that all these schemes only secure the authentication exchange: they do nothing to protect application data. regards Steve > dcrespo wrote: > >>Hi all, >> >>I have a program that serves client programs. The server has a login >>password, which has to be used by each client for logging in. So, when >>the client connects, it sends a string with a password, which is then >>validated on the server side. The problem is obvious: anyone can get >>the password just sniffing the network. >> >>How can I solve this? >> >>Daniel >> -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From antonyliu2002 at yahoo.com Fri Oct 14 01:32:38 2005 From: antonyliu2002 at yahoo.com (Anthony Liu) Date: Thu, 13 Oct 2005 22:32:38 -0700 (PDT) Subject: Problem processing Chinese Message-ID: <20051014053238.4950.qmail@web35802.mail.mud.yahoo.com> I believe that topic related to Chinese processing was discussed before. I could not dig out the info I want from the mail list archive. My Python script reads some Chinese text and then split a line delimited by white spaces. I got lists like ['\xbc\xc7\xd5\xdf', '\xd0\xbb\xbd\xf0\xbb\xa2', '\xa1\xa2'] I had #-*- coding: gbk -*- on top of the script. My Windows 2000 system's default language is Chinese (GB2312) and displays Chinese perfectly. I don't know how to configure python or what else I need to properly process such two-byte-character text. Thanks. __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com From jepler at unpythonic.net Tue Oct 11 21:59:49 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Tue, 11 Oct 2005 20:59:49 -0500 Subject: Profiling Python using gprof In-Reply-To: <20051011221135.3188.qmail@web30608.mail.mud.yahoo.com> References: <20051011221135.3188.qmail@web30608.mail.mud.yahoo.com> Message-ID: <20051012015949.GH21569@unpythonic.net> It should be the same as for any program.... $ program-compiled-with-pg $ gprof /path/to/program-compiled-with-pg you'll need to make sure that python is not only *compiled* with -pg but that the *link line* contains -pg as well. That's a common "gotcha" when it comes to profiling. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From vinay_sajip at yahoo.co.uk Thu Oct 6 13:31:05 2005 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: 6 Oct 2005 10:31:05 -0700 Subject: How to prevent logging warning? References: <1128551304.960549.235420@f14g2000cwb.googlegroups.com> Message-ID: <1128619865.329954.44600@g43g2000cwa.googlegroups.com> Thomas Heller wrote: > I do *not* think 'no handler' is a misconfiguration. Is it possible to > differentiate between a misconfiguration and 'no configuration'? It's a fair point. The line was more blurred when the logging package was newly released into the wild ;-) But "no configuration" could be caused e.g. by an unreadable config file, which might also be categorised as a "misconfiguration". > That would be fine. But there are also other ways - you could, for > example, print the warning only when __debug__ is False. And you could > use the warnings module instead of blindly printing to stderr, this way > it could also be filtered out. Compatibility with 1.5.2 precludes use of the warnings module. If using raiseExceptions meets your requirement, I'll use that. I'm not sure it's a good idea for the behaviour to change between running with and without -O. > BTW: Since I have your attention now, is the graphical utility to > configure the logging.conf file still available somewhere, and > compatible with the current logging package (with 'current' I mean > the one included with Python 2.3.5)? You can always get my attention via email :-) The graphical utility (logconf.py) is available from the download at http://www.red-dove.com/python_logging.html#download AFAIK it should work OK with 2.3.5, though I haven't tested it recently as there wasn't much interest in it. In fact you're the first person to ask! It generates a few extra entries in the config file which are used by the utility only, which are seemingly regarded as "cruft" by most people. Regards, Vinay Sajip From bokr at oz.net Sun Oct 16 12:45:43 2005 From: bokr at oz.net (Bengt Richter) Date: Sun, 16 Oct 2005 16:45:43 GMT Subject: Function to execute only once References: <1129317118.937439.159550@g43g2000cwa.googlegroups.com> Message-ID: <43527aa9.156193794@news.oz.net> On 14 Oct 2005 12:11:58 -0700, "PyPK" wrote: >Hi if I have a function called >tmp=0 >def execute(): > tmp = tmp+1 > return tmp > >also I have >def func1(): > execute() > .... >and >def func2(): > execute() > .... > >now I want execute() function to get executed only once. That is the >first time it is accessed. >so taht when funcc2 access the execute fn it should have same values as >when it is called from func1. > You could have the execute function replace itself with a function that returns the first result from there on, e.g., (assuming you want the global tmp incremented once (which has bad code smell, but can be expedient ;-)): >>> tmp = 0 >>> def execute(): ... global tmp, execute ... tmp = cellvar = tmp + 1 ... def execute(): ... return cellvar ... return tmp ... >>> def func1(): ... return execute() # so we can see it ... >>> def func2(): ... return execute() # so we can see it ... >>> func1() 1 >>> tmp 1 >>> func2() 1 >>> tmp 1 >>> execute() 1 >>> execute >>> import dis >>> dis.dis(execute) 5 0 LOAD_DEREF 0 (cellvar) 3 RETURN_VALUE But if you want to call the _same_ "execute" callable that remembers that it's been called and does what you want, you need a callable that can remember state one way or another. A callable could be a function with a mutable closure variable or possibly a function attribute as shown in other posts in the thread, or maybe a class bound method or class method, or even an abused metaclass or decorator, but I don't really understand what you're trying to do, so no approach is likely to hit the mark very well unless you show more of your cards ;-) Regards, Bengt Richter From steve at REMOVETHIScyber.com.au Sun Oct 9 06:11:18 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 09 Oct 2005 20:11:18 +1000 Subject: Weighted "random" selection from list of lists References: Message-ID: On Sat, 08 Oct 2005 12:48:26 -0400, Jesse Noller wrote: > Once main_list is populated, I want to build a sequence from items > within the lists, "randomly" with a defined percentage of the sequence > coming for the various lists. For example, if I want a 6 item > sequence, I might want: > > 60% from list 1 (main_list[0]) > 30% from list 2 (main_list[1]) > 10% from list 3 (main_list[2]) If you are happy enough to match the percentages statistically rather than exactly, simply do something like this: pr = random.random() if pr < 0.6: list_num = 0 elif pr < 0.9: list_num = 1 else: list_num = 2 return random.choice(main_list[list_num]) or however you want to extract an item. On average, this will mean 60% of the items will come from list1 etc, but for small numbers of trials, you may have significant differences. -- Steven. From fredrik at pythonware.com Sun Oct 9 03:30:50 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 9 Oct 2005 09:30:50 +0200 Subject: Here I am again, same old arguments References: Message-ID: "CJ" wrote: > Well, for some reason, the FOR loop is altering two of my lists. Using > PRINT magic, I was able to narrow down the lines that were causing it. > But the question remains: Why is it doing this? I'm sure there's a simple > answer that I just overlooked in the manual or something. here you create a list, and name it "grub": > grub=[3,25,3,5,3,"a","a","BOB",3,3,45,36,26,25,"a",3,3,3,"bob","BOB",67] here you add a new name for that list: > grubrpt=grub after this operation, "grubrpt" and "grub" are two names for the same object, not two distinct objects. in Python, variables are names, not small "boxes" in memory than contain stuff. you can add print id(grub), id(grubrpt) to see the object identities. required reading: http://effbot.org/zone/python-objects.htm (short version, available in english, french, and czech) http://starship.python.net/crew/mwh/hacks/objectthink.html (long version, with ascii art!) some common patterns: to copy a list, use grubrpt = grub[:] or the copy module. to build a new list from an old one, use new_list = [] for item in old_list: ... do something ... new_list.append(item) for some cases, a list comprehension can be a nicer way to write that: new_list = [... item ... for item in old_list ...] etc. From gimp-developer-bounces at lists.xcf.berkeley.edu Thu Oct 27 13:17:38 2005 From: gimp-developer-bounces at lists.xcf.berkeley.edu (gimp-developer-bounces at lists.xcf.berkeley.edu) Date: Thu, 27 Oct 2005 10:17:38 -0700 Subject: Your message to Gimp-developer awaits moderator approval Message-ID: Your mail to 'Gimp-developer' with the subject report Is being held until the list moderator can review it for approval. The reason it is being held: Post by non-member to a members-only list Either the message will get posted to the list, or you will receive notification of the moderator's decision. If you would like to cancel this posting, please visit the following URL: http://lists.xcf.berkeley.edu/mailman/confirm/gimp-developer/c7abb25fec4af698360aa7a095d40914ad1cac68 From my_email_is_posted_on_my_website at munged.invalid Wed Oct 12 18:20:55 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 12 Oct 2005 22:20:55 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <86ek6ul1c5.fsf@bhuda.mired.org> Message-ID: On Sun, 09 Oct 2005 19:25:46 -0400, Mike Meyer wrote or quoted : >Right. Nobody sends email to addresses that come off business cards, >or off a web site, or .... Nowadays website email addresses are becoming rarer. Instead you fill in a form to initiate your conversation. In a business card exchange both parties might set up a permission for the other, so they are not exactly strangers. There are some people who naturally get mail from the general public, e.g. newspaper editors, salesmen, me. However, if you block a sufficiently high percentage of spam, the spam industry will go away and these people will be the natural beneficiaries. You don't need 100% spam blocking to effectively solve the spam problem. You just have to make spam uneconomic. There was an analogous problem with telephone spam. It was even easier for the telepest to get addresses, just add one. That was solved by legal means. It could come back as long distance rates drop and some country harbours them. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From raphael.marc at free.fr Tue Oct 4 05:56:51 2005 From: raphael.marc at free.fr (=?ISO-8859-1?Q?Rapha=EBl_MARC?=) Date: Tue, 04 Oct 2005 11:56:51 +0200 Subject: Processing an image with numarray.nd image Message-ID: <434251e3$0$11154$636a15ce@news.free.fr> Hello, Can anyone tell me how to open an image and transform it into a list so that the functions of the multi dimensionnal module of numarray (numarray.nd image) can process it ? Do I have to use PIL ? So I would code something like : import Image im = Image.open("Python.jpg") data = list(im.getdata()) import numarray.nd image as ti ti.median filter(data,...) Is that the correct way to do ? Thanks for any help. Rapha?l From deets at web.de Wed Oct 12 11:20:51 2005 From: deets at web.de (Diez B. Roggisch) Date: 12 Oct 2005 08:20:51 -0700 Subject: Adding a __filename__ predefined attribute to 2.5? In-Reply-To: <1129130299.270571.113250@z14g2000cwz.googlegroups.com> References: <1129098667.336115.303060@g47g2000cwa.googlegroups.com> <1129103007.870187.101790@g44g2000cwa.googlegroups.com> <3r3u8kFhhsqmU1@uni-berlin.de> <1129108543.596435.200600@g47g2000cwa.googlegroups.com> <1129130299.270571.113250@z14g2000cwz.googlegroups.com> Message-ID: <1129130450.987294.259990@g44g2000cwa.googlegroups.com> Diez B. Roggisch wrote: > And requesting random features built into the interpreter without even > specifying a usecase - as remote as it may be - isn't very likely > happen, don't you think? Which I wanted to express with my apparently > misunderstood solve_my_problem()-example. Reread your post - you did specify it. So forget about that. Maybe I _have_ a bad hair day - even though I'm pretty bald. Might be because of too much JAVA these days... *sigh* Sorry. Diez From steve at rueb.com Sun Oct 2 13:47:31 2005 From: steve at rueb.com (Steve Bergman) Date: Sun, 02 Oct 2005 12:47:31 -0500 Subject: Distributing programs In-Reply-To: References: Message-ID: <43401D33.5070805@rueb.com> Leif K-Brooks wrote: >But remember that Python bytecode can be easily decompiled with a >publicly-available program. > > I hope it is not considered too antisocial to bring it up here, but there is always PyObfuscate: http://www.lysator.liu.se/~astrand/projects/pyobfuscate/ -Steve Bergman From no.mail.here.at.here at gmail.com Fri Oct 7 02:18:53 2005 From: no.mail.here.at.here at gmail.com (mike) Date: 6 Oct 2005 23:18:53 -0700 Subject: os.access with wildcards Message-ID: <1128665933.923295.95580@f14g2000cwb.googlegroups.com> i'd like to use os.access(path,mode) where path may contain linux style wildcards. i've failed so far. my workaround is the bash command. os.system('[ -e %s ]' % fn ) any suggestions? From cppnewb at noway.com Thu Oct 6 10:36:27 2005 From: cppnewb at noway.com (CppNewB) Date: Thu, 06 Oct 2005 14:36:27 GMT Subject: So far Message-ID: I am absolutely loving my experience with Python. Even vs. Ruby, the syntax feels very clean with an emphasis on simplification. My only complaint is that there doesn't appear to be a great commercial IDE for the language. I've tried Komodo, etc and they are nice applications, but they don't feel like they give me the "power" like a Visual Studio or Delphi (I wish I could articulate better the differences). Finding a descent GUI builder has been a challenge as well. Most of them have support for Dialogs, but what about more complex UI's? I may need a resizable frame within a resizable frame? I haven''t found a GUI builder with a great feel yet. Other than that, my experience has been wonderful. Even after my complaints, I plan on sticking with Python for a while. From steve at holdenweb.com Thu Oct 20 03:24:45 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 20 Oct 2005 08:24:45 +0100 Subject: Some more odd behaviour from the Regexp library In-Reply-To: <86wtk8vofq.fsf@bhuda.mired.org> References: <1129777843.892280.302490@g44g2000cwa.googlegroups.com> <86wtk8vofq.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > "David Veerasingam" writes: [...] > Of course, being the founder of SPARE, I have to point out that > a.split(': ') will get you the same two strings as the re I used > above. > Let me guess: the Society for the Prevention of Abuse of Regular Expressions? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From steve at uptime.org.uk Wed Oct 26 09:03:24 2005 From: steve at uptime.org.uk (Stephen Hildrey) Date: Wed, 26 Oct 2005 14:03:24 +0100 Subject: tool for syntax coloring in html In-Reply-To: <1130330426.059794.282450@g49g2000cwa.googlegroups.com> References: <1130330426.059794.282450@g49g2000cwa.googlegroups.com> Message-ID: <435F7E9C.7040608@uptime.org.uk> Xah Lee wrote: > Is there a tool that produce codes in html with syntax coloring? I'm sure there's a million-and-one tools that will do what you want, and suggest you search Google. Personally, I've used vim to do this in the past. The following generates marked-up code: :runtime syntax/2html.vim Regards, Steve -- Stephen Hildrey E-mail: steve at uptime.org.uk / Tel: +442071931337 Jabber: steve at jabber.earth.li / MSN: foo at hotmail.co.uk From steve at REMOVETHIScyber.com.au Sat Oct 1 02:33:17 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sat, 01 Oct 2005 16:33:17 +1000 Subject: OT: Phases of the moon References: <1128003857.930444.47650@g14g2000cwa.googlegroups.com> <1128013745.763757.144280@g44g2000cwa.googlegroups.com> <1128015868.201617.153240@g14g2000cwa.googlegroups.com> <0001HW.BF63479501083049F0407550@news.individual.de> Message-ID: On Sat, 01 Oct 2005 00:18:44 -0400, Sherm Pendley wrote: > *whoosh* > > That, my friend, was the sound of a joke flying past and completely > missing you. ;-) Wouldn't be the first time, and surely not the last. *wink* -- Steven. From timr at probo.com Tue Oct 4 02:44:17 2005 From: timr at probo.com (Tim Roberts) Date: Tue, 04 Oct 2005 06:44:17 GMT Subject: question about smtplib References: <1128366567.887891.267520@g43g2000cwa.googlegroups.com> <1128380307.865252.289510@f14g2000cwb.googlegroups.com> Message-ID: <1494k1pvqvo9lg21q8bhi9qrgmc2ftl5kn@4ax.com> nephish at xit.net wrote: >cool. so this line >server = smtplib.SMTP(localhost) >is when i connect ? Use the source, Luke. Source code for every standard module is included on your hard disk. If you look in the __init__ for "class SMTP", your question will be answered. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From tim at tt1lock.org Tue Oct 18 03:59:47 2005 From: tim at tt1lock.org (Tim Tyler) Date: Tue, 18 Oct 2005 07:59:47 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <11kj8ghonmialfc@corp.supernews.com> Message-ID: In comp.lang.java.programmer Ross Bamford wrote or quoted: > Roedy, I would just _love_ to see the response from the industry when you > tell them they should dump their whole mail infrastructure, and switch > over to a whole new system (new protocols, new security holes, new > problems start to finish). [...] That's essentially what the IM folk did. It seems quite possible that future email systems will evolve out of existing IM ones. Essentially, IM can do pretty-much everything email can these days, but the reverse is not true at all. IM also seems more evolvable than email is managing to be. About all email has going for it these days is an open format and a large existing user base. -- __________ |im |yler http://timtyler.org/ tim at tt1lock.org Remove lock to reply. From tziade at nuxeo.com Wed Oct 19 12:11:05 2005 From: tziade at nuxeo.com (=?ISO-8859-15?Q?Tarek_Ziad=E9?=) Date: Wed, 19 Oct 2005 18:11:05 +0200 Subject: ssl and timeout issue Message-ID: <43567019.2000109@nuxeo.com> Hello, I cannot manage to use socket timeouts with an imap ssl connector,and i badly *need* it :'( I have already mentionned it here: http://archives.free.net.ph/message/20050620.151244.e5390efe.en.html Does anyone have a solution ? (I thought of coding my own threaded timer over the ssl socket, but...) Tarek Traceback: >>> from imaplib import IMAP4_SSL, IMAP4_SSL_PORT >>> import socket >>> test = IMAP4_SSL('mail.xxxx.com', 993) >>> test.sock.settimeout(10) >>> test.login('xxx at xxx', 'password') Traceback (most recent call last): File "", line 1, *in* ? File "/usr/lib/python2.4/imaplib.py", line 480, *in* login typ, dat = self._simple_command('LOGIN', user, self._quote(password)) File "/usr/lib/python2.4/imaplib.py", line 1028, *in* _simple_command *return* self._command_complete(name, self._command(name, *args)) File "/usr/lib/python2.4/imaplib.py", line 858, *in* _command_complete typ, data = self._get_tagged_response(tag) File "/usr/lib/python2.4/imaplib.py", line 959, *in* _get_tagged_response self._get_response() File "/usr/lib/python2.4/imaplib.py", line 876, *in* _get_response resp = self._get_line() File "/usr/lib/python2.4/imaplib.py", line 969, *in* _get_line line = self.readline() File "/usr/lib/python2.4/imaplib.py", line 1135, *in* readline char = self.sslobj.read(1) socket.sslerror: The read operation timed out >>> test = IMAP4_SSL('mail.xxxx.com', 993) >>> test.login('xxx at xxx', 'password') ('OK', ['LOGIN Ok.']) -- Tarek Ziad? | Nuxeo R&D (Paris, France) CPS Plateform : http://www.cps-project.org mail: tziade at nuxeo.com | tel: +33 (0) 6 30 37 02 63 You need Zope 3 - http://www.z3lab.org/ From mwm at mired.org Tue Oct 18 16:45:03 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 18 Oct 2005 16:45:03 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86fyqzzskt.fsf@bhuda.mired.org> <86y84rxryr.fsf@bhuda.mired.org> <2R75f.2005$dO2.1121@newssvr29.news.prodigy.net> <86mzl6yfko.fsf@bhuda.mired.org> <861x2iy4vs.fsf@bhuda.mired.org> <6Jc5f.4734$Zv5.2558@newssvr25.news.prodigy.net> Message-ID: <86u0fewo4w.fsf@bhuda.mired.org> "Mike Schilling" writes: > "Mike Meyer" wrote in message > news:861x2iy4vs.fsf at bhuda.mired.org... >> One alternative, as I've said, is to write to the standards, and then >> work around bugs in the popular browsers. If the public whim changes >> which browser is most popular - > I am not holding my breath. Neither did the people who coded for Mosaic, then Netscape. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From jstroud at mbi.ucla.edu Fri Oct 28 13:53:06 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Fri, 28 Oct 2005 10:53:06 -0700 Subject: Scanning a file In-Reply-To: <87ek65kbw5.fsf@lucien.dreaming> References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <87ek65kbw5.fsf@lucien.dreaming> Message-ID: <200510281053.07008.jstroud@mbi.ucla.edu> On Friday 28 October 2005 06:29, Bj?rn Lindstr?m wrote: > "pinkfloydhomer at gmail.com" writes: > > f = open("filename", "rb") > > s = f.read() > > sub = "\x00\x00\x01\x00" > > count = s.count(sub) > > print count > > That's a lot of lines. This is a bit off topic, but I just can't stand > unnecessary local variables. > > print file("filename", "rb").read().count("\x00\x00\x01\x00") The "f" is not terribly unnecessary, because the part of the code you didn't see was f.close() Which would be considered good practice. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From PrikrylP at skil.cz Thu Oct 6 02:39:21 2005 From: PrikrylP at skil.cz (Petr Prikryl) Date: Thu, 6 Oct 2005 08:39:21 +0200 Subject: What encoding is used when initializing sys.argv? Message-ID: Thanks, Martin v. L?wis, Neil Hodgson, and Tim Roberts. I really appreciate your valuable comments. It simply works. Thanks again, Petr "Neil Hodgson" wrote... > Petr Prikryl: > > > I do not understand what encoding should be used > > to convert the sys.argv into unicode. > > Martin mentioned CP_ACP. In Python on Windows, this > can be accessed as the "mbcs" codec. > > import sys > print repr(sys.argv[1]) > print repr(unicode(sys.argv[1], "mbcs")) > > C:\bin>python glurp.py abc?* > 'abc\xdf\x95' > u'abc\xdf\u2022' > > Neil From kenneth.m.mcdonald at sbcglobal.net Mon Oct 17 13:19:22 2005 From: kenneth.m.mcdonald at sbcglobal.net (Kenneth McDonald) Date: Mon, 17 Oct 2005 12:19:22 -0500 Subject: UI toolkits for Python In-Reply-To: <863bn12k6i.fsf@bhuda.mired.org> References: <7xslv56ud1.fsf@ruckus.brouhaha.com> <3ras6oFit2djU1@individual.net> <4350dd34$0$6774$9b4e6d93@newsread4.arcor-online.net> <863bn12k6i.fsf@bhuda.mired.org> Message-ID: Web interfaces are missing a lot more than this. Here are just a few things that cannot be done with web-based interfaces (correct me where I'm wrong): 1) A real word processor. 2) Keybindings in a web application 3) Drag and drop 4) Resizable windows (i.e. not the browser window) within the application. 5) Anything other than absolutely trivial graphical programs. State is a very small part of the whole thing. Progress is being made, but web interfaces are still basically forms that can contain buttons, checkboxes, text fields, and a few other basic controls. I wish it were otherwise. Ken On 16-Oct-05, at 5:04 PM, Mike Meyer wrote: > Malte Clasen writes: > > >> Claudio Grondi wrote: >> >>> What is that complex, that it can't be solved using an Internet >>> Browser as a >>> GUI? >>> >> >> Nothing, but session management isn't trivial with http >> interfaces. You have to deal with the back button of the browsers, >> bookmarks to pages that result from posted forms, users leaving the >> application without notice, etc.. >> > > This fact seems to have escaped the notice of most developers of web > applications. They just fail and/or misbehave under all those > conditions. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bronger at physik.rwth-aachen.de Tue Oct 4 00:56:52 2005 From: bronger at physik.rwth-aachen.de (Torsten Bronger) Date: Tue, 04 Oct 2005 06:56:52 +0200 Subject: help w/ simple GPIB prog. References: <1128394242.934045.165100@z14g2000cwz.googlegroups.com> Message-ID: <87r7b1j2wb.fsf@wilson.rwth-aachen.de> Hall?chen! "whoopsi" writes: > Could someone give me some simple commands for communicating with > GPIB devices. If you find a file called visa32.dll on your system, you can just use . NI ships this file bundled with their GPIB hardware, and you can download the latest version from . Tsch?, Torsten. -- Torsten Bronger, aquisgrana, europa vetus ICQ 264-296-646 From __peter__ at web.de Thu Oct 6 05:29:24 2005 From: __peter__ at web.de (Peter Otten) Date: Thu, 06 Oct 2005 11:29:24 +0200 Subject: Class property (was: Class methods) References: <42C7E766869C42408F0360B7BF0CBD9B01CD75BE@pnlmse27.pnl.gov> Message-ID: Laszlo Zsolt Nagy wrote: > I was trying for a while, but I could not implement a 'classproperty' > function. Is it possible at all? You could define a "normal" property in the metaclass: >>>>> class A: ... class __metaclass__(type): ... @property ... def clsprp(cls): return 42 ... >>> A.clsprp 42 Peter From bokr at oz.net Mon Oct 3 21:32:28 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 04 Oct 2005 01:32:28 GMT Subject: Will python never intend to support private, protected and public? References: <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <1128001308.905398.321670@g44g2000cwa.googlegroups.com> <311b5ce105092908332c12164c@mail.gmail.com> <7xbr2btv84.fsf@ruckus.brouhaha.com> <7xy85fvxny.fsf@ruckus.brouhaha.com> <86vf0inlt3.fsf@bhuda.mired.org> <7xd5mq9ir9.fsf@ruckus.brouhaha.com> <86wtkym33t.fsf@bhuda.mired.org> <7xll1d7l2c.fsf@ruckus.brouhaha.com> <86slvlmdnv.fsf@bhuda.mired.org> <7xr7b3spri.fsf@ruckus.brouhaha.com> <86br27mztp.fsf@bhuda.mired.org> <7x8xxbidtp.fsf@ruckus.brouhaha.com> <86ll1bkz99.fsf@bhuda.mired.org> <7xpsqn6wpx.fsf@ruckus.brouhaha.com> <8664sfkwol.fsf@bhuda.mired.org> <7x4q7zp36t.fsf@ruckus.brouhaha.com> <861x33km69.fsf@bhuda.mired.org> <7xzmprueyg.fsf@ruckus.brouhaha.com> <86wtkujx04.fsf@bhuda.mired.org> <7xwtku1dh4.fsf@ruckus.brouhaha.com> Message-ID: <4341b386.3123890456@news.oz.net> On 03 Oct 2005 14:45:43 -0700, Paul Rubin wrote: >Mike Meyer writes: >> > If you have a java class instance with a private member that's (say) a >> > network socket to a special port, access to the port is controlled >> > entirely by that class. >> >> Are you sure? My understanding was that Java's introspection mechanism >> could be used to access private variables. > >Right, I should have been more specific, if I understand correctly, >there are some JVM settings that turn that on and off (I'm not any >kind of expert on this). For sandbox applets, it's turned off, for >example. This came up in a huge discussion thread on sci.crypt a few >months ago. Apparently the default is for it to be turned on, to the >surprise and disappointment of some: > > http://groups.google.com/group/sci.crypt/msg/23edaf95e9978a8d > >> A couple of other things to think about: >> Are you sure you want to use the C++ model for privilege separation? > >I'm not sure what you mean by the C++ model. If you mean the Java >model, as I keep saying, applet sandbox security relies on it, so it >may not be perfect but it's not THAT bad. Using it routinely in >normal applications would be a big improvement over what we do now. >High-security applications (financial, military, etc.) would still >need special measures. > >> C++'s design doesn't exactly inspire confidence in me. > >Me neither, "C++ is to C as lung cancer is to lung". > >> Finally, another hole to fix/convention to follow to make this work >> properly in Python. This one is particularly pernicious, as it allows >> code that doesn't reference your class at all to violate the private >> variables. Anyone can dynamically add methods to an instance, the >> class it belongs to, or to a superclass of that class. > >Yes, Python isn't even type-safe any more: > > class A(object): pass > class B(object): pass > a = A() > print type(a) > a.__class__ = B > print type(a) # oops > >IMHO that "feature" you describe is quite inessential in Python. The >correct way to override or extend the operations on a class is to >subclass it. I can't think of a single place where I've seen Python >code legitimately go changing operations by jamming stuff into the >class object. I'd consider the stdlib's socket.py to be illegitimate >and it cost me a couple of hours of debugging one night: > > http://groups.google.com/group/comp.lang.python/msg/c9849013e37c995b > >and even that is only messing with specific instances, not classes. >Make sure to have a barf bag handy if you look at the socket.py code. >I really should open a sf bug about it. But a class definition is just a syntactic sugar way to associate functions with certain automatic method-binding operations for its instances, invoked by other syntactic sugar. But you can do it without modifying the class itself. E.g., >>> add5 = (lambda self, x: self+x).__get__(5, type(5)) >>> add5 of 5> >>> add5(10) 15 I can't stuff the method on type(5) since it's built in, >>> type(5).add5 = (lambda self, x: self+x).__get__(5, type(5)) Traceback (most recent call last): File "", line 1, in ? TypeError: can't set attributes of built-in/extension type 'int' but that doesn't stop forming a bound method ;-) for a better name than you can always fix it up ;-) >>> add5.im_func.func_name = 'add5' >>> add5 Regards, Bengt Richter From my_email_is_posted_on_my_website at munged.invalid Sun Oct 9 15:28:31 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sun, 09 Oct 2005 19:28: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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <41hhk195gcipfarnqu85ggs606aqi89ea1@4ax.com> Message-ID: On Sun, 09 Oct 2005 20:54:32 +1000, Steven D'Aprano wrote or quoted : >Only if your photos are so obscure and confusing that they need captions. That is a hair shirt approach. What if someone is sending photos of their new house? What if I am sending diagrams to help someone repair their computer? It is ridiculous to tie people's arms behind their backs. What you do instead is work to prevent abuse. Captions in and of themselves are not dangerous things. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From spammers-go-here at spam.invalid Wed Oct 12 15:55:10 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Wed, 12 Oct 2005 15:55:10 -0400 Subject: Force flushing buffers References: <4345b6e8$0$49009$14726298@news.sunsite.dk> Message-ID: <434d69fc$0$49009$14726298@news.sunsite.dk> Robert Wierschke wrote: > Madhusudan Singh schrieb: >> Hi >> >> I have a python application that writes a lot of data to a bunch >> of files >> from inside a loop. Sometimes, the application has to be interrupted and >> I find that a lot of data has not yet been writen (and hence is lost). >> How do I flush the buffer and force python to write the buffers to the >> files ? I intend to put this inside the loop. >> >> Thanks. > disable the buffer! > > open( filename[, mode[, bufsize]]) > > open takes an optional 3ed argument set bufsize = 0 means unbuffered. > see the documentation of the in build file() mehtod as open is just > another name Though I will not be using this solution (plan to use flush() explicitly) for speed reasons, thanks ! I will file this away for future reference :) From smadim2 at grads.ece.mcmaster.ca Wed Oct 5 12:38:13 2005 From: smadim2 at grads.ece.mcmaster.ca (M.N.A.Smadi) Date: Wed, 05 Oct 2005 12:38:13 -0400 Subject: Posix return or exit Message-ID: <43440175.9050406@grads.ece.mcmaster.ca> hi; my script must return codes which are based on the POSIX spec of returning a positive value. A work perl version of my code uses exit(code_num). I am not sure if the equivilant in python is also: exit(code_num) or return code_num any ideas? thanks moe smadi From juho.schultz at helsinki.fi Fri Oct 14 09:09:57 2005 From: juho.schultz at helsinki.fi (Juho Schultz) Date: Fri, 14 Oct 2005 16:09:57 +0300 Subject: my array subset method could be improved? In-Reply-To: References: Message-ID: Jim O'D wrote: > Hi all > > I have an array a=array([2,3,1]). > > I want to extract an array with all the elements of a that are less than 0. > > Method 1. > new = array([i for i in a if i < 0]) > > Method 2. > new = a[nonzero(a<0)] > > I'm using Numeric arrays but can't seem to find a function that does this. > > Am I missing a more obvious way to do it quickly? > > Thanks > > Jim new = Numeric.compress(Numeric.less(a,0),a) From steve at holdenweb.com Mon Oct 31 10:07:12 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 31 Oct 2005 15:07:12 +0000 Subject: Scanning a file In-Reply-To: <3smn47FoolfbU1@individual.net> References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <87ek65kbw5.fsf@lucien.dreaming> <1h5760l.1e2eatkurdeo7N%aleaxit@yahoo.com> <3siakvFohl3aU1@individual.net> <1h57cij.16dkc141lds4s4N%aleaxit@yahoo.com> <1h597yx.wjk2a71spyjhyN%aleaxit@yahoo.com> <3smn47FoolfbU1@individual.net> Message-ID: Paul Watson wrote: > Alex Martelli wrote: > ... > >>>>>gc.garbage >> >>[<__main__.a object at 0x64cf0>, <__main__.b object at 0x58510>] >> >>So, no big deal -- run a gc.collect() and parse through gc.garbage for >>any instances of your "wrapper of file" class, and you'll find ones that >>were forgotten as part of a cyclic garbage loop and you can check >>whether they were explicitly closed or not. >> >> >>Alex > > > Since everyone needs this, how about building it in such that files > which are closed by the runtime, and not user code, are reported or > queryable? Perhaps a command line switch to either invoke or suppress > reporting them on exit. > This is a rather poor substitute from correct program design and implementation. It also begs the question of exactly what constitutes a "file". What about a network socket that the user has run makefile() on? What about a pipe to another process? This suggestion is rather ill-defined. > Is there any facility for another program to peer into the state of a > Python program? Would this be a security problem? It would indeed be a security problem, and there are enough of those already without adding more. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From paul at boddie.org.uk Wed Oct 19 11:16:06 2005 From: paul at boddie.org.uk (Paul Boddie) Date: 19 Oct 2005 08:16:06 -0700 Subject: UI toolkits for Python References: <7xslv56ud1.fsf@ruckus.brouhaha.com> <3ras6oFit2djU1@individual.net> <4350dd34$0$6774$9b4e6d93@newsread4.arcor-online.net> <863bn12k6i.fsf@bhuda.mired.org> <7xslv02aoj.fsf@ruckus.brouhaha.com> <87psq39aur.fsf@wilson.rwth-aachen.de> <7xwtkbud5q.fsf@ruckus.brouhaha.com> <1h4mhm2.1rmv4fh1czi843N%aleaxit@yahoo.com> <86r7aiyg4g.fsf@bhuda.mired.org> <86ek6iy790.fsf@bhuda.mired.org> Message-ID: <1129734966.013458.154650@g47g2000cwa.googlegroups.com> Mark Roseman wrote: > What I'm suggesting is taking the effort you'd put to the 5%, and > applying that effort instead to making the 95% even better. If that > extra effort would affect conversion rates, it's a justifiable option. Yes, but isn't this where the 90/10 rule kicks in? In other words, you transfer the effort from the 5% of users you don't care about, but then just end up adding polish to the "majority" solution which doesn't significantly improve conversion rates, all because you've done the most effective work to "convert" those users already. In this case it's even more perilous: adding "polish" could quite easily eliminate parts of your audience, resulting in an only slightly more plush red carpet being offered to significantly fewer people. Paul From codecraig at gmail.com Mon Oct 24 13:17:39 2005 From: codecraig at gmail.com (jas) Date: 24 Oct 2005 10:17:39 -0700 Subject: Read/Write from/to a process In-Reply-To: References: <1130163642.868252.148070@g44g2000cwa.googlegroups.com> Message-ID: <1130174259.472124.114790@f14g2000cwb.googlegroups.com> Thanks, that is certainly a start. As you mentioned, the "cd" could is an issue. Perhaps checking to see if the line ends with ">" is sufficient? Dennis Lee Bieber wrote: > On 24 Oct 2005 07:20:42 -0700, "jas" declaimed the > following in comp.lang.python: > > > Hi, > > I would like to start a new process and be able to read/write from/to > > it. I have tried things like... > > > > import subprocess as sp > > p = sp.Popen("cmd.exe", stdout=sp.PIPE) > > p.stdin.write("hostname\n") > > > > however, it doesn't seem to work. I think the cmd.exe is catching it. > > One: you didn't read any of the "returned" output... > > Two: the output only seems to be available upon EOF, which means the > spawned command processor has to exit first... Though you CAN read one > character at a time, and then have to build lines and expected prompt > strings... > > > This seems to work: > -=-=-=-=-=-=-=-=- > import subprocess > import os > > PROMPT = os.getcwd() + ">" > > def getLine(proc): > ld = [] > while True: > c = proc.stdout.read(1) > if c == "\r": continue #skip Windows > if c != "\n": ld.append(c) #save all but > if c is None or c == "\n" or c == ">": break > ln = "".join(ld) > return ln > > p = subprocess.Popen("cmd.exe", stdout=subprocess.PIPE, stdin = > subprocess.PIPE) > > print "**** START of captured output" > while True: > ln = getLine(p) > print ln > if ln == PROMPT: break > print "**** END of captured output" > > p.stdin.write("ipconfig\n") > print "**** START of captured output" > while True: > ln = getLine(p) > print ln > if ln == PROMPT: break > print "**** END of captured output" > > p.stdin.write("dir\n") > print "**** START of captured output" > while True: > ln = getLine(p) > print ln > if ln == PROMPT: break > print "**** END of captured output" > > p.stdin.write("exit\n") > -=-=-=-=-=-=-=-=-=- > E:\UserData\Dennis Lee Bieber\My Documents>python script1.py > **** START of captured output > Microsoft Windows XP [Version 5.1.2600] > (C) Copyright 1985-2001 Microsoft Corp. > > E:\UserData\Dennis Lee Bieber\My Documents> > **** END of captured output > **** START of captured output > ipconfig > > Windows IP Configuration > > > Ethernet adapter Local Area Connection: > > Connection-specific DNS Suffix . : > IP Address. . . . . . . . . . . . : 192.168.1.100 > Subnet Mask . . . . . . . . . . . : 255.255.255.0 > IP Address. . . . . . . . . . . . : fe80::211:11ff:fee1:f303%4 > Default Gateway . . . . . . . . . : 192.168.1.1 > > Tunnel adapter Teredo Tunneling Pseudo-Interface: > > Connection-specific DNS Suffix . : > IP Address. . . . . . . . . . . . : > 3ffe:831f:4004:1956:0:fbde:bd0a:e50b > IP Address. . . . . . . . . . . . : fe80::5445:5245:444f%5 > Default Gateway . . . . . . . . . : :: > > Tunnel adapter Automatic Tunneling Pseudo-Interface: > > Connection-specific DNS Suffix . : > IP Address. . . . . . . . . . . . : fe80::5efe:192.168.1.100%2 > Default Gateway . . . . . . . . . : > > E:\UserData\Dennis Lee Bieber\My Documents> > **** END of captured output > **** START of captured output > dir > Volume in drive E is Data > Volume Serial Number is 2626-D991 > > Directory of E:\UserData\Dennis Lee Bieber\My Documents > > 10/24/2005 09:23 AM > . > 10/24/2005 09:23 AM > .. > 07/25/2005 10:39 PM > .metadata > 10/06/2005 09:54 AM > Ada Progs > 08/13/2005 02:01 PM > Agent Data > 10/21/2005 09:29 AM 421,820 apress_offer.pdf > 07/03/2005 11:36 AM 132 cp.py > 07/17/2005 12:25 PM > Cyberlink > 07/06/2005 09:32 AM 102,400 db1.mdb > 07/26/2005 12:20 AM 26,614 eclipse_code.xml > 10/24/2005 01:08 AM > Eudora > 06/24/2005 08:50 PM 667 fake_oosums.ads > 06/24/2005 08:50 PM 695 fake_oosums.ali > 09/06/2005 09:01 PM > Genealogy > 07/13/2005 10:56 PM > HomeSite > 05/08/2005 01:05 PM > Investing > 10/21/2005 10:04 PM > Java Progs > 08/04/2005 10:13 PM 162 main.py > 10/11/2005 10:43 PM > My Downloads > 05/01/2005 10:31 AM > My eBooks > 04/22/2005 12:09 AM > My Music > 07/10/2005 11:43 AM > My Pictures > 06/29/2005 11:55 PM > My PSP Files > 05/23/2005 09:30 AM > My Videos > 05/01/2005 12:49 PM > Office Documents > 06/27/2005 03:19 PM 7,961,778 > org.eclipse.jdt.doc.user.I20050627-1435.pdf > 06/27/2005 03:19 PM 6,791,109 > org.eclipse.platform.doc.user.I20050627-1435.pdf > 10/11/2005 10:52 PM 56 oth_tsr_rm_750.ram > 07/20/2005 09:32 AM 108,457 parkerred15yc.jpg > 09/03/2005 10:36 PM > Python Progs > 10/20/2005 10:38 PM > Quicken > 07/10/2005 12:09 PM 3,356,248 results.xml > 06/11/2005 12:03 PM 935 Scout_Ship Database.lnk > 07/03/2005 12:38 PM > Scout_Ship My Documents > 10/24/2005 09:23 AM 971 Script1.py > 09/25/2005 12:40 PM 1,107 Script1_old.py > 08/28/2005 11:47 AM > SimpleMu Logs > 06/24/2005 08:56 PM 1,201 student_pack.ads > 06/24/2005 08:49 PM 1,144 student_pack.ads.0 > 06/24/2005 08:56 PM 1,342 student_pack.ali > 08/02/2005 11:39 PM 4,096 t.DOC > 06/20/2005 10:11 AM 104 t.rx > 08/05/2005 08:41 PM 66,452 Untitled-1.tif > 08/05/2005 08:41 PM > VCheck > 10/03/2005 02:58 AM > Visual Studio > 10/03/2005 02:51 AM > Visual Studio 2005 > 21 File(s) 18,847,490 bytes > 25 Dir(s) 267,162,845,184 bytes free > > E:\UserData\Dennis Lee Bieber\My Documents> > **** END of captured output > > E:\UserData\Dennis Lee Bieber\My Documents> > > -=-=-=-=-=-=-=-=- > > Note that my "getLine()" has to return on either a real EOL, OR on > the end of a command prompt ("stuff>"). I also had to initialize the > prompt at the start. If someone issued a "cd" command to the subprocess, > the prompt would be all out of sequence, and the code would hang. > > You'll also note that the prompt /ends/ a capture sequence, and the > next command is the start of the /next/ capture sequence. > > -- > > ============================================================== < > > wlfraed at ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG < > > wulfraed at dm.net | Bestiaria Support Staff < > > ============================================================== < > > Home Page: < > > Overflow Page: < From steve at REMOVETHIScyber.com.au Sun Oct 23 05:56:54 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 23 Oct 2005 19:56:54 +1000 Subject: best way to replace first word in string? References: <1129822003.246170.303920@f14g2000cwb.googlegroups.com> <861x2dbcwv.fsf@bhuda.mired.org> <86u0f894w3.fsf@bhuda.mired.org> Message-ID: On Sun, 23 Oct 2005 01:30:36 -0400, Mike Meyer wrote: >> At least, that's what it looks like to me -- I'm perplexed by the *vast* >> increase in speed in your version, far more than I would have predicted >> from pulling out the char conversion. I can think of three >> possibilities: > > Everything got faster, so it wasn't just pulling the chr conversion. Sure -- I'm not concerned about proportional speed increases. >> (1) Your PC is *hugely* faster than mine; > > It's a 3Ghz P4. Perhaps a tad faster, but not too much. >> (2) Your value of x is a lot smaller than I was using (you don't actually >> say what x you use); or > > It's still in the buffer, and I copied it from your timings: > >>>> x = 100000 > >> (3) You are using a version and/or implementation of Python that has a >> different underlying implementation of string concatenation. > > I'm runing Python 2.4.1 built with GCC 3.4.2. There is a difference there: http://www.python.org/doc/2.4/whatsnew/node12.html Second-last paragraph: [quote] String concatenations in statements of the form s = s + "abc" and s += "abc" are now performed more efficiently in certain circumstances. This optimization won't be present in other Python implementations such as Jython, so you shouldn't rely on it; using the join() method of strings is still recommended when you want to efficiently glue a large number of strings together. (Contributed by Armin Rigo.) [end quote] -- Steven. From maksim.kasimov at gmail.com Tue Oct 4 12:49:24 2005 From: maksim.kasimov at gmail.com (Maksim Kasimov) Date: Tue, 04 Oct 2005 19:49:24 +0300 Subject: how to debug when "Segmentation fault" In-Reply-To: References: Message-ID: there are a lot of packeges under suspicion: cPickle, select, threading, logging, socket, struct Michael Ekstrand wrote: > On Tuesday 04 October 2005 11:13, Maksim Kasimov wrote: > >>my programm sometime gives "Segmentation fault" message (no matter >>how long the programm had run (1 day or 2 weeks). And there is >>nothing in log-files that can points the problem. My question is how >>it possible to find out where is the problem in the code? Thanks for >>any help. > > > What extension modules are you using? > > I've never seen "stock" Python (stable release w/ only included modules) > segfault, but did see a segfault with an extension module I was using > the other week (lxml IIRC, but I'm not sure). > > - Michael -- Best regards, Maksim Kasimov mailto: maksim.kasimov at gmail.com From finite.automaton at gmail.com Thu Oct 20 19:00:35 2005 From: finite.automaton at gmail.com (Lonnie Princehouse) Date: 20 Oct 2005 16:00:35 -0700 Subject: reload fails if module not in sys.path Message-ID: <1129849234.985211.141940@g47g2000cwa.googlegroups.com> So, it turns out that reload() fails if the module being reloaded isn't in sys.path. Maybe it could fall back to module.__file__ if the module isn't found in sys.path?? ... or reload could just take an optional path parameter... Or perhaps I'm the only one who thinks this is silly: >>> my_module = imp.load_module(module_name, *imp.find_module(module_name,path)) >>> reload(my_module) Traceback (most recent call last): File "", line 1, in ? ImportError: No module named whatever I guess I could just deal with this by fiddling with sys.path or using imp.load_module again, but.. um.. I like to complain. ;-) The context here is that I'm loading user-defined modules as plugins, and I don't want to keep the plugin directory in sys.path because of potential module name conflicts. From robert.kern at gmail.com Thu Oct 13 19:50:31 2005 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 13 Oct 2005 16:50:31 -0700 Subject: matching elements of numeric arrays In-Reply-To: <1129239096.340248.222440@g49g2000cwa.googlegroups.com> References: <1129239096.340248.222440@g49g2000cwa.googlegroups.com> Message-ID: daniel.neilson at gmail.com wrote: > I have two one-dimensional Numeric arrays, and I need to know the > indices in the second array of elements from the first. > > so if i had: > > a=array([2,4,6]) > b=array([2,3,4,5,6]) > > i want a function match that does this: > > >>>>match(a,b) > > array([0,2,4]) > > i have something that works, but it involves converting things to lists > and using 'in', and it is rather slow. if someone could point me to a > better solution, i would appreciate it. If b is sorted, then you can use Numeric.searchsorted(b, a). Otherwise: In [28]: import Numeric as N In [29]: a = N.array([2,4,6]) In [30]: b = N.array([2,3,4,5,6]) In [31]: match = N.equal.outer(a, b) In [32]: idx = N.compress(N.sum(match), N.arange(len(b))) In [33]: idx Out[33]: array([0, 2, 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 bdesth.quelquechose at free.quelquepart.fr Sat Oct 29 19:57:54 2005 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sun, 30 Oct 2005 01:57:54 +0200 Subject: How to replace all None values with the string "Null" in a dictionary In-Reply-To: <1130502180.688390.207960@g44g2000cwa.googlegroups.com> References: <1130444785.353905.85380@g47g2000cwa.googlegroups.com> <4361e8f5$0$32420$636a15ce@news.free.fr> <1130502180.688390.207960@g44g2000cwa.googlegroups.com> Message-ID: <436402aa$0$19243$626a54ce@news.free.fr> dcrespo a ?crit : >>I think it would be time for you to read the Fine Manual... > > > hi, thanks for your answer... I really did it the same way you > suggested, but I forgot to tell you that I wanted to get a better way > for doing it. Let us know if you find one... > > By the way, knowing your wisdom, > what do I have to install to get the > following code work (Win XP, Python 2.4.2) Being wise, I don't use Windows !-) From istvan.albert at gmail.com Tue Oct 4 09:07:30 2005 From: istvan.albert at gmail.com (Istvan Albert) Date: 4 Oct 2005 06:07:30 -0700 Subject: "no variable or argument declarations are necessary." In-Reply-To: References: Message-ID: <1128431250.573501.46540@g14g2000cwa.googlegroups.com> > What can one do to swiftly detect this type of bug? While I can only speak from my own experience I can't remember a single instance where this type of bug caused any kind of serious problem. IMHO these are very trivial errors, that get caught immediately and I would not even qualify them as bugs, more like typos, spelling mistakes, etc. Real bugs are a lot more insidious than that, and they might even occur more frequently if there was type checking ... since it might even lead to longer code just my $0.01 Istvan. From lasse at vkarlsen.no Tue Oct 11 08:51:29 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Tue, 11 Oct 2005 14:51:29 +0200 Subject: Merging sorted lists/iterators/generators into one stream of values... References: <1128667968.421469.180910@g47g2000cwa.googlegroups.com> <1128691708.c6930b5cb9f3673ed3abe8755178d163@teranews> <1128692196.410209.252100@g14g2000cwa.googlegroups.com> <1128695317.c6a5acb3e62787f011310c96f0c7cc35@teranews> <1h439qe.pz7c451jcec6hN%aleax@mail.comcast.net> <1128795319.09c32ac9943b0580a86b7bcada7facc1@teranews> <1128797447.501582.24560@o13g2000cwo.googlegroups.com> <1h47iae.6d2ps91u8eafuN%aleax@mail.comcast.net> <1h485kt.1bru0if72epwrN%aleax@mail.comcast.net> Message-ID: Lasse V?gs?ther Karlsen wrote: > > > Another idea for this method would be that in some cases I noticed that > it was useful to know which source each element would come from as well, > as well as removing duplicates from the results. > The "removing duplicates" problem would probably be best as a separate function and it occurs to me that perhaps Python has such a function already. Again, this function would need the following criteria: 1. Be able to iterate through something other than a list 2. Yield the values, not return a list 3. Take an arbitrary cmp function to determine what is a duplicate As sugar, perhaps also the following criteria: - Ability to "combine" the duplicates through a special function A simple first-version function I hacked together does this: def unique(source, cmp=cmp, key=None, combine=None): it = iter(source) first = True value = it.next() values = [value] while True: try: value = it.next() if key is not None: cmp_result = cmp(values[0][key], value[key]) else: cmp_result = cmp(values[0], value) if cmp_result == 0: values.append(value) else: if combine is not None: yield combine(values) else: yield values[0] values = [value] except StopIteration: if combine is not None: yield combine(values) else: yield values[0] break raise StopIteration Note that this function does not do any sorting so if the source that it gets the values from is not sorted, the result will be very wrong. This is again due to my criteria of being able to handle cursors retrieving data from a database and thus avoid loading everything into memory. The combine function is passed a list of "duplicate" values and must return a value that will be yielded out of unique. Example of usage: def sum_counts(values): value = values[0][0] sum = 0 for row in values: sum += row[1] return value, sum fruits = [["Apple", 10], ["Apple", 15], ["Banana", 23], ["Orange", 17], ["Orange", 17]] for fruit, total_sum in unique(fruits, key=0, combine=sum_counts): print fruit, "has a sum of", total_sum This will produce: Apple has a sum of 25 Banana has a sum of 23 Orange has a sum of 34 Function name is perhaps not the best one. It occurs to me that this is the GROUP BY function in SQL so perhaps a different name is better, but then again this might be moot if such a function already exists somewhere :) -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From dcrespo at gmail.com Mon Oct 31 20:24:54 2005 From: dcrespo at gmail.com (dcrespo) Date: 31 Oct 2005 17:24:54 -0800 Subject: OpenSSL in Python In-Reply-To: References: <1130425810.431748.39660@g14g2000cwa.googlegroups.com> Message-ID: <1130808294.188603.169680@g47g2000cwa.googlegroups.com> First, is the PYTHON OpenSSL C wrapper what I need to get running. Second, if you don't know how to answer, then limit your opinion to yourself. Thanks. From martin at v.loewis.de Tue Oct 11 20:30:47 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 12 Oct 2005 02:30:47 +0200 Subject: Python name lookups / Interning strings In-Reply-To: References: Message-ID: <434C5937.6060007@v.loewis.de> Dave wrote: > What exactly does it mean to "intern" a string? "exactly" it means to place lookup the string in the global interning dictionary. If an entry is found, then interning yields the string in the interning dictionary. If the string is not found, it is added to the interning dictionary, and returned; its "interning state" is set to "interned" (either mortally or immortally, depending on the exact interning request). More colloquially, it means to find a unique representative of the set of all equal-valued strings (e.g. one unique representative for all strings equalling "close"). If a and b are variables referring to interned strings, 'a==b' implies 'a is b' (whereas usually only the reverse is true). HTH, Martin From http Fri Oct 7 18:07:17 2005 From: http (Paul Rubin) Date: 07 Oct 2005 15:07:17 -0700 Subject: socketServer questions References: <1128699247.9040.15.camel@athop1.ath.vt.edu> <7xll15paha.fsf@ruckus.brouhaha.com> <1128718708.7800.2.camel@athop1.ath.vt.edu> Message-ID: <7xoe61yoa2.fsf@ruckus.brouhaha.com> rbt writes: > The server just logs data, nothing else. It's not private or important > data... just sys admin type stuff (ip, mac addy, etc.). I just don't > want some script kiddie discovering it and trying to 'hack' it. By doing > so, they'd fill the log up with crap. So, If the data doesn't contain x, > y, and z and if the data is too big or too small, I record it to a > 'tamper' log and tell the leet hacker to 'go away'. Well, rather than this x,y,z stuff, it's best to do it properly and authenticate the records with the hmac module. From scott.daniels at acm.org Mon Oct 24 06:50:58 2005 From: scott.daniels at acm.org (Scott David Daniels) Date: Mon, 24 Oct 2005 03:50:58 -0700 Subject: [OT] Python vs Ruby In-Reply-To: <435c9906$0$14034$636a15ce@news.free.fr> References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> <4358d9f6$0$19694$626a14ce@news.free.fr> <43593468$1@nntp0.pdx.net> <435c9906$0$14034$636a15ce@news.free.fr> Message-ID: <435cbbd6$1@nntp0.pdx.net> bruno modulix wrote: > Scott David Daniels wrote: >>bruno modulix wrote: >>>... Another language that failed to make it to the mainstream but is >>>worth giving a try is Smalltalk - the father of OOPLs (Simula being the >>>GrandFather). >>I would say Simula is the forefather of modern OOPLs, and Smalltalk is >>the toofather. > Err... I'm afraid I don't understand this last word (and google have not > been of much help here) Sorry, I was being too cute by half. If Simula is the fore father (4 away) then Smalltalk is half as far (2) away. Hence the "toofather." "Toofather" by analogy with the homophones "fore" and "four" we use the homophones "two" and "too". --Scott David Daniels scott.daniels at acm.org From mtebeka at qualcomm.com Tue Oct 11 04:52:51 2005 From: mtebeka at qualcomm.com (Miki Tebeka) Date: Tue, 11 Oct 2005 10:52:51 +0200 Subject: SOAPpy, WSDL, non-standard types and my graying hair Message-ID: <20051011085251.GJ9272@qualcomm.com> Hello, I'm trying to use SOAPpy with WSDL (talking to http://www.seapine.com/ttpro.html). proxy.show_methods for getRecordListForTable is: Method Name: getRecordListForTable In #0: cookie ((u'http://www.w3.org/2001/XMLSchema', u'long')) In #1: tablename ((u'http://www.w3.org/2001/XMLSchema', u'string')) In #2: filtername ((u'http://www.w3.org/2001/XMLSchema', u'string')) In #3: columnlist ((u'urn:testtrack-interface', u'ArrayOfCTableColumn')) Out #0: recordlist ((u'urn:testtrack-interface', u'CRecordListSoap')) I know how to prepare the first three arguments (using SOAPpy.stringType and SOAPpy.longType). I can't find the documentation on how to prepare the last argument. Any ideas? pointers? ... 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 http Sat Oct 29 18:18:09 2005 From: http (Paul Rubin) Date: 29 Oct 2005 15:18:09 -0700 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <87ek65kbw5.fsf@lucien.dreaming> <1h5760l.1e2eatkurdeo7N%aleaxit@yahoo.com> <3siakvFohl3aU1@individual.net> Message-ID: <7x1x24x90e.fsf@ruckus.brouhaha.com> "Paul Watson" writes: > How could I identify when Python code does not close files and depends on > the runtime to take care of this? I want to know that the code will work > well under other Python implementations and future implementations which may > not have this provided. There is nothing in the Python language reference that guarantees the files will be closed when the references go out of scope. That CPython does it is simply an implementation artifact. If you want to make sure they get closed, you have to close them explicitly. There are some Python language extensions in the works to make this more convenient (PEP 343) but for now you have to do it by hand. From horton_brian at hotmail.com Mon Oct 3 05:22:00 2005 From: horton_brian at hotmail.com (horton_brian at hotmail.com) Date: 3 Oct 2005 02:22:00 -0700 Subject: cspython on Windows? Message-ID: <1128331320.592073.108160@f14g2000cwb.googlegroups.com> Looking around the web I get the impression development of cspython hasn't kept up with the development of Crystalspace itself, but is it possible without rebuilding the whole of Crystalspace from source, to install cspython on Windows so as to access the Crystalspace runtime environment I've installed using crystalspace_0.99_050823.exe? Brian From aleaxit at yahoo.com Wed Oct 19 02:23:20 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Wed, 19 Oct 2005 08:23:20 +0200 Subject: UI toolkits for Python References: <7xslv56ud1.fsf@ruckus.brouhaha.com> <3ras6oFit2djU1@individual.net> <4350dd34$0$6774$9b4e6d93@newsread4.arcor-online.net> <863bn12k6i.fsf@bhuda.mired.org> <7xslv02aoj.fsf@ruckus.brouhaha.com> <87psq39aur.fsf@wilson.rwth-aachen.de> <7xwtkbud5q.fsf@ruckus.brouhaha.com> <1h4mhm2.1rmv4fh1czi843N%aleaxit@yahoo.com> <86r7aiyg4g.fsf@bhuda.mired.org> <1h4n6ag.5uhq7a7xe1v4N%aleaxit@yahoo.com> <86ach6y6ta.fsf@bhuda.mired.org> Message-ID: <1h4o6eo.4gi3s6xgesmzN%aleaxit@yahoo.com> Mike Meyer wrote: > aleaxit at yahoo.com (Alex Martelli) writes: > > Mike Meyer wrote: > >> What surprises me is that marketing types will accept turning away - > >> what's the current internet user base? 200 million? - 10 million > >> potential customers without a complaint. Or maybe they just don't get > >> told that that's what's going on. > > In firms where marketing has lots of power, they may indeed well decide > > to pursue those "10 millions" by demanding an expenditure of effort > > that's totally out of proportion > > What makes you think that the expenditure of effort is "totally out of > proportion"? In my experience, that isn't the case - at least if you > go into it planning on doing things that way. Retrofitting a site that > was built without any thought but "make it work in my favoriter > browser in my favorite configuration" can be a radically different > thing. Why, of course -- coding a site to just one browser would be foolish (though there exist sites that follow that strategy, it's still despicable). What I'm talking about is sites that are _supposed_ to be able to support a dozen browsers, in three or four versions each, not to mention a dozen features each of which the user "might" have chosen to disable (for a total of 2**12 == 4096 possibilities). Of course, the site's poor authors cannot possibly have tested the 4096 * 12 * 3.5 possibilities, whence the "_supposed_ to be". We ARE talking about moving from supporting 95% to supporting (*supposedly*!) 100%, after all -- very much into the long, *LONG* tail of obscure buggy versions of this browser or that, which SOME users within those last centiles may have forgotten to patch/upgrade, etc. And THAT is what makes the effort totally out of proportion (differently from the effort to go from 60% to 95%, which, while far from negligible, is well within sensible engineering parameters). > > Maybe that's part of the explanation for the > > outstanding success of some enterprises founded by engineers, led by > > engineers, and staffed overwhelmingly with engineers, competing with > > other firms where marketing wield power...? > > You mean like google? Until recently, they're an outstanding example > of doing things right, and providing functionality that degrades > gracefully as the clients capabilities go down. I'm not sure what you mean by "until recently" in this context. AFAIK, we've NEVER wasted our efforts by pouring them into the quixotic task of supporting *100%* of possible browsers that may hit us, with the near infinite number of combinations of browsers, versions and disabled feature that this would require. One may quibble whether the target percentage should be, say, 93%, 95%, or 97%, and what level of degradation can still be considered "graceful" around various axes, but the 100% goal which you so clearly imply above would, in my personal opinion, be simply foolish now, just as it would have been 3 years ago. Alex From peter at engcorp.com Tue Oct 18 22:38:32 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 18 Oct 2005 22:38:32 -0400 Subject: How to get a raised exception from other thread In-Reply-To: <1129646761.521348.52230@o13g2000cwo.googlegroups.com> References: <1129326320.914350.171460@o13g2000cwo.googlegroups.com> <1129571521.699077.224300@f14g2000cwb.googlegroups.com> <1129646761.521348.52230@o13g2000cwo.googlegroups.com> Message-ID: <8MudnZpGf80SLMjeRVn-vQ@powergate.ca> dcrespo wrote: >>Before, after, or during the .start() call, or somewhere else? > I'd like to catch *just after* the .start() call. Excellent. That makes it pretty easy then, since even though you are spawning a thread to do the work, your main thread isn't expected to continue processing in parallel. See my draft solution below. If it doesn't seem to suit, explain where it fails you and we can try to evolve it (assuming we're on the same page at all here). > When you specify the case number 2, the IP must be valid for the > computer where the program runs, otherwise, it raises an exception > saying that "Can't assign requested address". > > MainProgram.py > ... > SrvrTCP = module.ThreadedTCPServer(ip,port) > SrvrTCP.start() > #Here, I want to know if the TCPServer started well. Leave that part as it is. We'll override the start() method in your subclass to solve your problem. > module.py > ... > class ThreadedTCPServer(threading.Thread): > > def __init__(self, ip,port): > threading.Thread.__init__(self) > self.ip= ip > self.port= port self.startError = None self.startedEvent = threading.Event() def start(self): '''start thread and wait for successful start''' threading.Thread.start(self) self.startedEvent.wait() if self.startError: raise self.startError > def run(self): > TCPServer((self.ip,self.port)) #Here, if the self.ip is > invalid, it raises an exception. > ... We have to change the run() method slightly now: def run(self): try: try: TCPServer((self.ip, self.port)) except Exception, ex: self.startError = ex return finally: self.startedEvent.set() # do the rest of the existing run() code here Now that may not be perfect, since I'm not familiar with the TCPServer() call. I've sort of assumed it does something quickly and returns, or raises an exception if the input is bad. If it doesn't actually return if it starts successfully, you would need a little different approach. Probably adding a simple timeout to the self.startEvent.wait() call would work. Note also that you don't get the full original traceback with this technique. I'm not sure you can, actually (though I can imagine that with Python one could "stitch together" a traceback from a previous exception as one raises a new exception). From what you describe, however, it sounds like you just need to know that the exception occurred, not the precise line of code down in TCPServer() where it was originally raised. I hope that helps and/or gives you some leads on a better solution. -Peter From nicopernetty at nowhere.fr Fri Oct 14 20:46:18 2005 From: nicopernetty at nowhere.fr (Nicolas Pernetty) Date: Sat, 15 Oct 2005 02:46:18 +0200 Subject: Numeric array equivalent of index ? Message-ID: <20051015024618.655167de@linuxcestcomplique.fr> Hello, I'm trying to find a clear and fast equivalent to the index method of plain python list : >> a = [5,1,4,3,4] >> a.index(4) 2 I have to use it on a Numeric array, so the best I've come up with is (rather ugly I think) : >> from Numeric import array, equal, nonzero >> a = array([5,1,4,3,4]) >> nonzero(equal(a,4))[0] 2 Does someone know of a more Pythonic way ? Thanks, From ashokagk at gmail.com Thu Oct 27 14:53:04 2005 From: ashokagk at gmail.com (Ashok) Date: 27 Oct 2005 11:53:04 -0700 Subject: how to associate files with application Message-ID: <1130439184.801178.280190@g14g2000cwa.googlegroups.com> hi, i want to know how to make a specific type of file open in an application i developed in python when the user clicks on the file.(in windows) for eg. a .txt file when clicked opens in notepad, a .doc file when clicked opens in MS-word. In the same way i want to make a .xyz file open in the application i developed when clicked. thanks in advance for any advice. From mru at inprovide.com Sat Oct 15 20:17:53 2005 From: mru at inprovide.com (=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=) Date: Sun, 16 Oct 2005 01:17:53 +0100 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: "David Schwartz" writes: > "Mike Meyer" wrote in message > news:86ll0vs1sw.fsf at bhuda.mired.org... > >> What you call "clever marketing" the DOJ calls "monopolistic >> practices". The courts agreed with the DOJ. Having had several large >> PC manufacturers refuse to sell me a system without some form of >> Windows because MS made it impossible for them to compete if they >> didn't agree to do so, I agree with the courts and the DOJ. > > Go down to your local car dealer and see if you can buy a new car > without an engine. That's more like buying a computer without a CPU, which I can in fact do. Buying a computer without ms windows is more like buying a hifi set without a Britney Spears CD. I can do that too. -- M?ns Rullg?rd mru at inprovide.com From robert.kern at gmail.com Mon Oct 10 03:21:29 2005 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 10 Oct 2005 00:21:29 -0700 Subject: Pythot doc problem: lambda keyword... In-Reply-To: <1128925487.783702.198410@f14g2000cwb.googlegroups.com> References: <1128925487.783702.198410@f14g2000cwb.googlegroups.com> Message-ID: Xah Lee wrote: > i'm trying to lookup on the detail of language Python's ?lambda? > function feature. google("site:docs.python.org lambda") -- 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 christoph.soellner at web.de Tue Oct 18 07:23:46 2005 From: christoph.soellner at web.de (Christoph Söllner) Date: Tue, 18 Oct 2005 13:23:46 +0200 Subject: HTTPResponse.read() returns an empty string? Message-ID: Hi again, my Source: """ import httplib conn = httplib.HTTPConnection('www.python.org'); conn.request("GET", "/index.html"); answ = conn.getresponse(); print answ.status, answ.reason >>> 200 OK conn.close(); print "Start"; >>> Start print answ.read(); >>> print len(answ.read()); >>> 0 print "End"; >>> End And the header states a content length of 11kBytes. What am I doin wrong? Thanks again, Chris From steve at REMOVETHIScyber.com.au Sun Oct 2 04:06:03 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 02 Oct 2005 18:06:03 +1000 Subject: Python 3! Finally! References: Message-ID: On Sun, 02 Oct 2005 02:06:26 -0500, Steve Bergman wrote: > Someone proposes that in the case that there is a > filename collision, the user might simply be prompted to decide on a > filename. You mean like every single other GUI application that saves files does? > Firefox devs totally reject that idea (and rather > vehemently). You see, that would totally freak out the end user, You mean like they freak out when it happens with IE, Word, Excel, Pagemaker, Quark Xpress, Photoshop, Gimp, OpenOffice, Access, Corel Draw, Outlook, Opera, and Kwrite (to mention just a few)? > and that is *certainly* not a good solution. Heaven's no, we can't be having with that sort of thing. > So the interim solution, for over a year, has been to leave it broken > for everyone... Because of course end users certainly won't be confused to save a file called "Fred1" and find "Fred2" instead, oh no. I'm surprised that they don't just add Yet Another Secret Option to Firefox's preferences: FileCollision, with two possible values: "Do the wrong thing" and "Ask the user". After all, more preferences are always good, right? -- Steven. From http Sat Oct 15 03:40:51 2005 From: http (Paul Rubin) Date: 15 Oct 2005 00:40:51 -0700 Subject: Problem splitting a string References: Message-ID: <7xhdbjp6rg.fsf@ruckus.brouhaha.com> Anthony Liu writes: > I do I split the string by using both ' ' and '_' as > the delimiters at once? Use re.split. From Anthony.Hornby at cdu.edu.au Wed Oct 26 19:29:47 2005 From: Anthony.Hornby at cdu.edu.au (Anthony.Hornby at cdu.edu.au) Date: Thu, 27 Oct 2005 08:59:47 +0930 Subject: Web presentation layer/framework for python - recommendations? Message-ID: Hi, I am a python newbie and need some advice. I have been charged with redeveloping a web application with a front end written in python that has a backend of XML files. Currently it doesn't adequately separate out the presentation code from the content code. Frankly it?s a mess (think bowl of spagetti). Does anyone have any recommendations for python toolkits or templating systems that would simplify the cleanup and make the code more maintainable in the future? I am a newbie, but not afraid to have a go. I also haven't done any real application programming for a while - bit of perl and java stuff a few years back. Just do perl/python/shell scripting these days. All comments welcome :-) Regards Anthony. Mr Anthony Hornby Library Systems and Technology Coordinator Charles Darwin University (CRICOS 300K) Phone: +61 8 8946 6011 Email: anthony.hornby at cdu.edu.au.no-spam (remove the .no-spam) From joerg.schuster at gmail.com Tue Oct 25 03:32:45 2005 From: joerg.schuster at gmail.com (Joerg Schuster) Date: 25 Oct 2005 00:32:45 -0700 Subject: more than 100 capturing groups in a regex In-Reply-To: References: <1130160675.270886.208420@z14g2000cwz.googlegroups.com> Message-ID: <1130225565.592108.197670@z14g2000cwz.googlegroups.com> > Some people, when confronted with a problem, think "I know, > I'll use regular expressions." Now they have two problems. > --Jamie Zawinski Thanks for the citation. If my goal had been to redesign my program, I would not ask questions about regular expressions. I do not have the time to redesign my program. And knowing that my situation would be better, if I had written other code in the past, does not help me at all. I just want to use more than 100 capturing groups. If someone told me that it is very unlikely for Python to get rid of the said limitation, I would recode part of my program in C++ using pcre. But I would prefer to be able to do everything in Python. That is why I asked. J?rg From quietwarlock at gmail.com Thu Oct 20 16:27:44 2005 From: quietwarlock at gmail.com (quietwarlock at gmail.com) Date: 20 Oct 2005 13:27:44 -0700 Subject: First Person View with Python Message-ID: <1129840064.911904.152580@g14g2000cwa.googlegroups.com> Hey, For a bit, I've been trying to create a first person view in Python, currently using the Soya engine. And while I can make the camera, and where I want it, how do I link it to controls? So that I can use WASD, etc. to move the camera? From kent37 at tds.net Wed Oct 19 16:13:25 2005 From: kent37 at tds.net (Kent Johnson) Date: Wed, 19 Oct 2005 16:13:25 -0400 Subject: Python variables are bound to types when used? In-Reply-To: <1129751462.061785.124830@g49g2000cwa.googlegroups.com> References: <1129751462.061785.124830@g49g2000cwa.googlegroups.com> Message-ID: <4356a6e7$1_1@newspeer2.tds.net> pranab_bajpai at yahoo.com wrote: > So I want to define a method that takes a "boolean" in a module, eg. > > def getDBName(l2): > ... > > Now, in Python variables are bound to types when used, right? > > Eg. > x = 10 # makes it an INT > whereas > x = "hello" # makes it a string You don't have it quite right. In each case, the name 'x' is bound to a value. The type is a property of the value, not of the name. > > I take it, the parameters to a function (in the above example "l2") are > bound in the definition, rather than as invoked. No, the parameter values are bound to the parameter names at the time of call. Again, it is the value that is typed, not the name. > > So, if I use "l2" thus: > > if (l2): # only then does it make it a boolean? No, this doesn't change the type of the value bound to l2, it just evaluates the value as True or False according to the rules here: http://docs.python.org/ref/Booleans.html#Booleans > > and if I did, > > if (l2 = "hello"): # would it become string? No; assuming you mean to compare l2 == "hello", this will call a special method of the object bound to l2, passing "hello" as a parameter. The result will be evaluated as True or False. The actual method called on l2 may be __cmp__ or __eq__. http://docs.python.org/ref/customization.html Kent > > and what if I never used it in the definition body? > > Elucidate please. > From my_email_is_posted_on_my_website at munged.invalid Wed Oct 12 20:05:31 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Thu, 13 Oct 2005 00:05:31 GMT Subject: Jargons of Info Tech industry References: <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <5hrik11q3p5ugcjm4hmmgqgq20o8fdrhr9@4ax.com> <7x4q7q2yer.fsf@ruckus.brouhaha.com> <8q0rk1tiktr86ksdu55mgsqffpkf2uus1c@4ax.com> <1129154547.6d0f3b178a128cc5f647dc0e128bc180@teranews> Message-ID: uOn Wed, 12 Oct 2005 22:02:23 GMT, iddw at hotmail.com (Dave Hansen) wrote or quoted : >Summary: a buffer overflow problem in Microsoft's JPEG redering >library, used my almost all Windoze email and web clients, would allow >an attacker to execute any arbitrary code he wished on your computer >simply by tricking you into viewing a doctored JPEG image. Since >solved (this problem is _so_ last year, dahling), but it belies your >assertion that "pictures are not code." By your definition all socket communications contains code because of the existence of buffer overrun "bugs" -- probably deliberately put there by unscrupulous employees. The pictureness is not at fault. MS was at fault. No wonder the community has failed to solve spam with attitudes like that -- extreme naysaying, misplacing the source of the problem, and calling each other "dahling" is bound to get everyone out of a problem-solving mode. You probably were all told the story of the three sillies as a child about people who wept themselves to inaction worrying imagined futures rather than dealing with the realities of the present. I think fretting about minutiae, and the desire for a perfect ant-spam solution has blocked getting on with a reasonable solution. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From my_email_is_posted_on_my_website at munged.invalid Sun Oct 9 16:26:50 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sun, 09 Oct 2005 20:26:50 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> Message-ID: On Sun, 9 Oct 2005 13:44:42 GMT, Tim Tyler wrote or quoted : >``Like ICQ, someone cannot send you mail without your prior permission. > They can't send you mail because they don't have your public key to > encrypt the mail.'' > >...is pretty confusing - because "public key" is a term with a technical >meaning in cryptography - and a public key really *is* public. What I envisioned was you would give a "public" key to someone you wanted to converse with you. He would encrypt all mail with that. He could give that key to someone else, who could then impersonate him. Most likely that second person would be his laptop. Let's say he posted the key in the New York Times, then anyone could impersonate him. You would the deactivate him, just as if he were a spammer. You might or might not give him a new key when he begged for permission to communicate. In my opinion, the weakest link in my scheme is the initial beg for permission to send. Here a stranger has to, in one line, tell you who he is and why he wants to talk to you. This is much like a spam title that tries to trick you into reading the body of the message. You still need spam list to help filter these types out. My scheme should work fine if you are not someone like me who gets a lot of legit mail from strangers. Perhaps you could slow them down with some randomly chosen questions to prove they know something about you. Companies could do the same thing. You can inconvenience the sender to a fair degree since most people don't often write strangers with the expectation of a personal correspondence. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From chrisgarland67 at hotmail.com Tue Oct 4 06:49:50 2005 From: chrisgarland67 at hotmail.com (Cigar) Date: 4 Oct 2005 03:49:50 -0700 Subject: Controlling who can run an executable References: <1128395422.904212.318930@g44g2000cwa.googlegroups.com> <7x3bnhlx1m.fsf@ruckus.brouhaha.com> Message-ID: <1128422990.741343.292310@o13g2000cwo.googlegroups.com> Paul Rubin wrote: > "Cigar" writes: > > Now that I'm three months into the development of this program, my > > client tells me she would like to protect her investment by preventing > > her employees from doing the same to her. (Going to the competition > > and using her program.) > > Exactly what is the threat here? I think the BIGGEST threat here is a feeling of vulnerablity. She now realizes that she is in a position that her competition was many years ago when she came into possesion of program the 'other side' was using and that she is now vulnerable. She wants to feel safe in the knowledge that she didn't reach into her pocket and pay thousands of dollars for a program that now could now be used by her competition. Nobody wants to pay money to level the playing field for all in a business environment. > Misuse of confidential data, or It's just a collection of names, addresses, phone numbers, birthdays and drivers licences/health cards. I can think of a few dishonest things that could be done with this but her competition has the basically the same clients. > just the code itself? > Does the code do anything that fantastic? Not by my standards but it is slowly replacing a paper system. (Police officer shows up and says 'We've just arrested John Smith. Has he sold you anything in the last 90 days. The client says 'Just a minute' and reaches for a set of 4" d-ring binders and turns hundreds of pages looking for a Smith name...) My client is relived that this senario will soon disappear. > Did the employees sign NDA's? Usually this kind of thing is taken care of by > legal agreements. Good question! I'm pretty sure not but that's something I could suggest to her. > What is the competitor going to do with this code even if they get it? Simplify their lives. See above. > It's just keeping track of transactions and stuff, right? You are correct sir. > It's being > tailored to one person's specific preferences and requirements, and > the competitor's needs will be different and they may as well just use > something generic. Not really. The client just wants to track people and what they buy, sell or put on buyback. Their competitions needs are the same. > Also, is there an office network? Maybe you could run the program on > a server that most employees wouldn't have access to. They'd use it > through some limited client program or through a web browser. A network exists but the client insists on a standalone PC. From dan at wolf.com Sun Oct 30 07:25:51 2005 From: dan at wolf.com (Dan M) Date: Sun, 30 Oct 2005 04:25:51 -0800 Subject: query a port References: <1130642480.233982.197760@g49g2000cwa.googlegroups.com> <1130653276.745449.31030@z14g2000cwz.googlegroups.com> Message-ID: On Sat, 29 Oct 2005 23:21:16 -0700, eight02645999 wrote: > thanks alot! > that's all there is to it..so it's just a simple connect. If all you want to do is check that the given port is open on the given host, that's it. I tried it on my local box. When connecting to port 25, it made the connection fine. Trying to connect to port 26 raised a socket.error. From stefan.sonnenberg at freenet.de Fri Oct 28 17:29:09 2005 From: stefan.sonnenberg at freenet.de (Stefan Sonnenberg-Carstens) Date: Fri, 28 Oct 2005 23:29:09 +0200 Subject: newstyle classes and __getattribute__ In-Reply-To: <4362977f$0$7227$9b622d9e@news.freenet.de> References: <4362977f$0$7227$9b622d9e@news.freenet.de> Message-ID: <43629825.1020102@freenet.de> Stefan Sonnenberg-Carstens schrieb: > Hi there, > I'm facing some strange things - but maybe only me is strange - anyway... > > i wrote the following code: > > > +++ > class T(object): > def __init__(self,name='',port=80): > self.name=name > self.port=port > +++ > > looks fine - to me. > > Now I can do: > > > >>> t = T(name="test",port=8080) > >>> print t > <__main__.T object at 0x00BE36D0> > > >>> print t.name > test > >>> dir(t) > ['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', > '__hash__', '__init__', '__module__', '__new__', '__reduce__', > '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', > 'name', 'port'] > > Everything ok. > > Now, I do this: > > class T(object): > def __init__(self,name='',port=80): > self.name=name > self.port=port > def __getattribute__(self,key): > if key=='somekey': > return None > > where > > >>> dir(T) > ['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', > '__hash__', '__init__', '__module__', '__new__', '__reduce__', > '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__'] > > is ok, also. > > But, then surprise: > >>> t = T(name="test123",port=443) > >>> dir(t) > [] > > What the hell is going wrong here ? > I'm running Python 2.4.2 from python.org on Windows XP SP2, all patches > applied. > > Thx in advance. > Ok, to make it worse: I tried the same under Cygwin with Python 2.4.1 - it worked as expected. From ejensen at visi.com Thu Oct 20 10:45:50 2005 From: ejensen at visi.com (Ed Jensen) Date: Thu, 20 Oct 2005 14:45:50 -0000 Subject: UI toolkits for Python References: <3ras6oFit2djU1@individual.net> <3rg3aiFjgc47U1@individual.net> <3rlj78Fjsu7mU1@individual.net> <3rmh1uFk236lU1@individual.net> <11lcnqt2c7jhmcc@corp.supernews.com> Message-ID: <11lfbcufad70618@corp.supernews.com> Kenneth McDonald wrote: > I'd have to agree with this. Unfortunately, the only way to use Swing > (in a > reasonable manner) from Python is to use Jython, and Jython has other > shortcomings that make me not want to use it. What shortcomings? From donbro at mac.com Mon Oct 31 00:28:22 2005 From: donbro at mac.com (donbro) Date: 30 Oct 2005 21:28:22 -0800 Subject: MacOS Extension Carbon.File.FSCatalogInfo file sizes should be UInt64? Message-ID: <1130736502.902026.91020@g43g2000cwa.googlegroups.com> If my read of the extension source (Mac/Modules/file/_Filemodule.c) is correct, the parameter sizes specified for data and resource file sizes are UInt32 where they should be UInt64. In both OS9 and OSX Carbon, the MacOS File Manager (Files.h) uses UInt64 values for data and resource filesizes. Testing Python 2.3 and 2.4.2 on MacOS 10.3 returns 0L for the file size values and correct values for other elements such as parentDirID: >>> fsRef = FSRef('LICENSE') >>> catinfo, d1, d2, d3 = fsRef.FSGetCatalogInfo(-1L) >>> catinfo.dataPhysicalSize 0 >>> catinfo.parentDirID 2026177 in Files.h, both OS9 and OSX Carbon, the elements are UInt64: struct FSCatalogInfo { [...] UInt64 dataLogicalSize; UInt64 dataPhysicalSize; UInt64 rsrcLogicalSize; UInt64 rsrcPhysicalSize; [...] } in _Filemodule.c the spec looks to be 32 bit: static PyObject *FSCatalogInfo_get_dataLogicalSize(FSCatalogInfoObject *self, void *closure) { return Py_BuildValue("l", self->ob_itself.dataLogicalSize); } I have, perhaps naively, just changed my local copy to use a BuildValue parameter of "L" instead of "l" for each of these get and set methods and this has survived my initial testing: static PyObject *FSCatalogInfo_get_dataLogicalSize(FSCatalogInfoObject *self, void *closure) { return Py_BuildValue("L", self->ob_itself.dataLogicalSize); } But my questions are: Has anyone else seen this? Does this seem like the right fix? There is another routine in _Filemodule.c: FSCatalogInfo_tp_init() that also seems to hold information relevant to parameter size. Should this be changed as well? If this is a bug, what's the best procedure to report this? Sourceforge? This mailing list? I'm porting a MacOS9 application from C++ to python and I expect to be seeing a lot of these python macintosh filesystem extensions in the near future! Thanks for any help Don From mwm at mired.org Sat Oct 8 18:07:24 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 08 Oct 2005 18:07:24 -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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> Message-ID: <86y853mzmr.fsf@bhuda.mired.org> Roedy Green writes: > On Tue, 04 Oct 2005 17:57:13 -0000, gordonb.u09l7 at burditt.org (Gordon > Burditt) wrote or quoted : > >>HTML enables a heck of a lot of problems: "web bugs" in email, >>links to fake sites that appear as real ones in what shows up >>on the screen, Javascript viruses, denial-of-service attacks >>(pages that open two windows when you close one), etc. >> >>>That is like hating all choirs because televangelists use them. >> >>I liken it more to hating all viruses because some of them >>install keyloggers. > > I take it then you avoid browsers or use Lynx? It's not quite that bad. You run multiple browsers: your default browser turns off all the crap that can run code on your machine. You use a second browser that has most of that turned on, and bookmark the sites that need those features that you now trust. Maybe your browser lets you have multiple profiles, in which case you can use those instead of multiple browsers. Unless your goat browser is IE (or Mozilla on Unix), you should keep a copy of IE (Mozilla on Unix) around, with an untouched configuration, for the sites that either enforce their belief that they only work on IE, or are one of those rare sats where correctly believe that. Finally, you configure your mail and news readers to *not* decode MIME messages unless given an explicit command to do so. I understand some browsers now let you enable dangers features on a site-by-site basis. I'll check those out one of these days. FWIW, I like w3m as a default browser, because it has the ability to launch external browsers on a page or link. > No you FIX the problems rather than wear a hair shirt. Same for > email. Why should rich expressions only be permitted to those with > websites. The technial problems have been solved for over a decade. NeXT shipped systems that used text/richtext, which has none of the problems that HTML has. The problems are *social* - you've got to arrange for people to use mail/news readers that understand a rich text format that isn't a vector for viruses. > Some people use email PRIMARILY for sharing photos. That doesn't take HTML. I get - and send - pictures via email all the time, with nary a tag of HTML in sight. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From enleverlesO.OmcO at OmclaveauO.com Fri Oct 7 23:48:07 2005 From: enleverlesO.OmcO at OmclaveauO.com (Do Re Mi chel La Si Do) Date: Sat, 8 Oct 2005 05:48:07 +0200 Subject: PIL Image can't open png file with "I"? References: Message-ID: <434741b0$0$19239$626a54ce@news.free.fr> Hi ! Perhaps... ";" better than "," : im=Image.open(r"C:\vodka3.png"); im.show() Perhaps... more simplist : im=Image.open(r"C:\vodka3.png").show() Perhaps... other thing ? @-salutations Michel Claveau From bobrien18 at yahoo.com Wed Oct 19 23:14:40 2005 From: bobrien18 at yahoo.com (KraftDiner) Date: 19 Oct 2005 20:14:40 -0700 Subject: destroy your self???? In-Reply-To: References: <1129776816.148308.210460@g44g2000cwa.googlegroups.com> Message-ID: <1129778080.444432.115690@g14g2000cwa.googlegroups.com> Well I guess what I'm trying to achive is the invalidate the instance of the object. I have been using None to denote an invalide or uninitialized instance of an object. There is a degenerate case in my code where a polygon has less than 3 points and I want to class to flag this instance of the object as invalid. so.. like super.self = None :) From benji at benjiyork.com Fri Oct 14 11:59:25 2005 From: benji at benjiyork.com (Benji York) Date: Fri, 14 Oct 2005 11:59:25 -0400 Subject: Problems with properties In-Reply-To: References: Message-ID: <434FD5DD.6000302@benjiyork.com> Michael Schneider wrote: > The get property access is working, but the the set > property is not working. The classes need to be "new style" for properties to work right. Just change "class Task:" to "class Task(object):". Your "setNothing" method is unnecessary, if you don't proved a "setter" an exception will be raised automatically. Also (if you're using Python 2.4) you probably want to look at decorator syntax. So you're class could look like this: class Task(object): def __init__(self,command): self._command = command @property def command(self): return self._command -- Benji York From viridia at gmail.com Sat Oct 29 16:06:13 2005 From: viridia at gmail.com (Talin) Date: 29 Oct 2005 13:06:13 -0700 Subject: Recursive generators and backtracking search Message-ID: <1130616373.235379.140630@g49g2000cwa.googlegroups.com> I've been using generators to implement backtracking search for a while now. Unfortunately, my code is large and complex enough (doing unification on math expressions) that its hard to post a simple example. So I decided to look for a simpler problem that could be used to demonstrate the technique that I am talking about. I noticed that PEP 255 (Simple Generators) refers to an implementation of the "8 Queens" problem in the lib/test directory. Looking at the code, I see that while it does use generators, it doesn't use them recursively. As an alternative, I'd like to present the following implementation. If you compare this one with the one in lib/test/test_generator.py you will agree (I hope) that by using recursive generators to implement backtracking, the resulting code is a little more straightforward and intuitive: # Example of using generators to implement backtracking search. # The example below is an implementation of the classic "N queens" # problem (place N queens on an N x N chessboard so that none are # threatened by the others.) # # Board representation: Since no two queens can be one the same # row, the board is represented as a tuple of N length, where # each element is the column occupied by the queen on that row. def queens( bsize ): # Function to test if a queen is threatened by any previously # placed queen. def threaten( qarray, newpos ): # Now check the diagonals dist = len( qarray ) # Distance between rows for q in qarray: if q == newpos: return True # Same column if q + dist == newpos: return True # diagonal if q - dist == newpos: return True # diagonal dist -= 1 return False def qsearch( qarray = () ): for q in range( 0, bsize ): # Try each position if not threaten( qarray, q ): # If not threatened pos = qarray + ( q, ); # Append to the pos array if len( pos ) >= bsize: # Are we done? yield pos # Yield the answer else: # recursively call new generator for pos in qsearch( pos ): yield pos print "Queens problem for", bsize, "x", bsize, "board." for ans in qsearch(): ` # Print out the board print "+" + "---+" * bsize; for q in ans: print "|" + " |" * q + " Q |" + " |" * (bsize - q - 1) print "+" + "---+" * bsize; print queens( 8 ) Now, you may be wondering what is my point? Well, first, I want to encourage people to think about using Python as a language for complex heuristic search problems. Traditionally, LISP and Prolog have been the language of choices for "AI" type programming, however there is a clear advantage to the readability and maintainability of Python, as well as being much more integrated into modern computing environments (in terms of available interpreters, IDEs, libraries, etc.) Secondly, I want to lobby for additional support in the language and standard libraries for handling such problems. There are a number of fairly obvious language enhancements which would make the above example even simpler - for examle, the idea of being able to return the output of one generator directly from another instead of having to iterate through all of the results and then re-yield them has already been discussed in this forum. From bokr at oz.net Mon Oct 31 11:18:19 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 31 Oct 2005 16:18:19 GMT Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <4363fdd4$0$2107$edfadb0f@dtext02.news.tele.dk> Message-ID: <43663b19.1454241668@news.oz.net> On Mon, 31 Oct 2005 09:41:02 +0100, =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= wrote: >David Rasmussen wrote: > >> If you must know, the above one-liner actually counts the number of >> frames in an MPEG2 file. I want to know this number for a number of >> files for various reasons. I don't want it to take forever. > > >Don't you risk getting more "frames" than the file actually have? What >if the encoded data happens to have the magic byte values for something >else? > Good point, but perhaps the bit pattern the OP is looking for is guaranteed (e.g. by some kind of HDLC-like bit or byte stuffing or escaping) not to occur except as frame marker (which might make sense re the problem of re-synching to frames in a glitched video stream). The OP probably knows. I imagine this thread would have gone differently if the title had been "How to count frames in an MPEG2 file?" and the OP had supplied the info about what marks a frame and whether it is guaranteed not to occur in the data ;-) Regards, Bengt Richter From grante at visi.com Fri Oct 28 11:02:50 2005 From: grante at visi.com (Grant Edwards) Date: Fri, 28 Oct 2005 15:02:50 -0000 Subject: Suggestion for (re)try statement References: Message-ID: <11m4fcq8pifa641@corp.supernews.com> On 2005-10-27, Sori Schwimmer wrote: > Hi, > > I think that would be useful to have an improved > version of the "try" statement, as follows: > > try(retrys=0,timeout=0): > # things to try > except: > # what to do if failed > > and having the following semantic: > > for i in range(retrys): > try: > # things to try > except: > if i < retrys: > i += 1 > sleep(timeout) > else: > # what to do if failed > else: > break The "i += 1" line is almost certainly wrong. > Of course, "break" may be the last statement in the > "try" branch, and "try"'s "else" may be ommited > completely. And that's pretty much exactly how I usually write it: for i in range(retries): try: whatever break except retryableExceptionList: sleep(delay) > Can't think of a syntax to keep it look like a statement > rather than a function. > > Opinions? I don't see what's wrong with the for loop construct. You can add an else: clause to the for loop to detect the case where you ran out of retries: for i in range(retries): try: whatever break except retryableExceptionList: sleep(delay) else: whatelse > Is it worth for a PEP? I don't think you can come up with a syntax that is really that much better than the for loop, but give it a go if you like. -- Grant Edwards grante Yow! My BIOLOGICAL ALARM at CLOCK just went off... It visi.com has noiseless DOZE FUNCTION and full kitchen!! From steve at REMOVETHIScyber.com.au Fri Oct 7 22:35:27 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sat, 08 Oct 2005 12:35:27 +1000 Subject: noob question Letters in words? References: Message-ID: On Fri, 07 Oct 2005 20:46:39 -0400, Ivan Shevanski wrote: > Alright heres another noob question for everyone. Alright, say I have a > menu like this. > > print "1. . .Start" > print "2. . .End" > choice1 = raw_input("> ") > > and then I had this to determine what option. Firstly, you need to decide on what you want to accept. If you really do want to (I quote from later in your post) > For instance I could type in Stop and would get the first option since > it had an "s" in it? then you can, but that would be a BAD idea!!! py> run_dangerous_code() WARNING! This will erase all your data if you continue! Are you sure you want to start? Yes/Start/Begin > Stop Starting now... data erased. Oh yeah, your users will love you for that. I could handle it like this: def yesno(s): """Returns a three-valued flag based on string s. The flag is 1 for "go ahead", 0 for "don't go" and -1 for any other unrecognised response. Recognises lots of different synonyms for yes and no. """ s = s.strip().lower() # case and whitespace doesn't matter if s in ('1', 'start', 's', 'begin', 'ok', 'okay', 'yes'): return 1 elif s in ('2', 'end', 'e', 'cancel', 'c', 'stop', 'no'): return 0 else: return -1 def query(): print "Start process: 1 start" print "End process: 2 end" raw_choice = raw_input("> ") choice = yesno(raw_choice) if choice == -1: print "I'm sorry, I don't understand your response." return query() else: return choice But that's probably confusing. Why do you need to offer so many ways of answering the question? Generally, the best way of doing this sort of thing is: - give only one way of saying "go ahead", which is usually "yes". - give only one way of saying "don't go ahead", which is usually "no". - if the thing you are doing is not dangerous, allow a simple return to do the same as the default. - if, and only if, the two choices are unambiguous, allow the first letter on its own (e.g. "y" or "n") to mean the same as the entire word. Using this simpler method: def yesno(s): s = s.strip().lower() if s in ('yes', 'y'): return 1 elif s in ('no', 'n'): return 0 else: return -1 def query: print "Start process? (y/n)" choice = yesno(raw_choice("> ")) if choice == -1: print "Please type Yes or No." return query() else: return choice Hope this is helpful. -- Steven. From anjuman2 at gmail.com Sun Oct 30 01:12:50 2005 From: anjuman2 at gmail.com (Sam Merca) Date: 29 Oct 2005 23:12:50 -0700 Subject: SNMP In-Reply-To: <1130515702.436348.190240@g43g2000cwa.googlegroups.com> References: <1130515702.436348.190240@g43g2000cwa.googlegroups.com> Message-ID: <1130652770.571194.245940@g44g2000cwa.googlegroups.com> py wrote: > >From what I have seen Python does not come with an snmp module built > in, can anyone suggest some other SNMP module (preferably one you have > used/experienced)..I have googled and seen yapsnmp and pysnmp (which > seem to be the two most active SNMP modules). > > Thanks I've used pysnmp on Windows to successfully monitor and set parameters in half a dozen different 802.11a/b/g access points from different vendors, so I guess, it gets my nod. The documentation is adequate but no spoon-feeding here! You'll have to try and see if it serves your needs. -A From prince_amir86 at yahoo.com Sat Oct 8 18:53:09 2005 From: prince_amir86 at yahoo.com (Brandon K) Date: Sat, 08 Oct 2005 17:53:09 -0500 Subject: new forum -- homework help/chit chat/easy communication In-Reply-To: References: <1128798687.305818.66010@g49g2000cwa.googlegroups.com> <1128810677_124183@spool6-east.superfeed.net> Message-ID: <1128812148_124207@spool6-east.superfeed.net> > In other words, what is the difference between a "scripting language" > and a "programming language". > Good point. ----== Posted via Newsgroups.com - Usenet Access to over 100,000 Newsgroups ==---- Get Anonymous, Uncensored, Access to West and East Coast Server Farms! ----== Highest Retention and Completion Rates! HTTP://WWW.NEWSGROUPS.COM ==---- From bokr at oz.net Thu Oct 27 13:45:31 2005 From: bokr at oz.net (Bengt Richter) Date: Thu, 27 Oct 2005 17:45:31 GMT Subject: Would there be support for a more general cmp/__cmp__ References: Message-ID: <43610f31.1111721130@news.oz.net> On 27 Oct 2005 08:12:15 GMT, Antoon Pardon wrote: [...] > >The evidence suggests that cmp is not used in sorting. If you have a >list of sets, sort will happily try to sort it, while calling cmp >with a set as an argument throws an exception. > A data point re evidence: >>> class C: ... def __getattr__(self, attr): print attr; raise AttributeError ... >>> sorted((C(),C())) __lt__ __gt__ __gt__ __lt__ __coerce__ __coerce__ __cmp__ __cmp__ [__repr__ <__main__.C instance at 0x02EF388C>, __repr__ <__main__.C instance at 0x02EF38CC>] I think it will be slightly different if you define those methods in a new-style class -- oh, heck, why not do it: >>> class D(object): ... def __lt__(*ignore): print '__lt__'; return NotImplemented ... def __gt__(*ignore): print '__gt__'; return NotImplemented ... def __coerce__(*ignore): print '__coerce__'; return NotImplemented ... def __cmp__(*ignore): print '__cmp__'; return NotImplemented ... >>> sorted((D(),D())) __lt__ __gt__ __cmp__ __cmp__ (I haven't followed the thread much, so please excuse if irrelevant ;-) Regards, Bengt Richter From deets at nospam.web.de Sun Oct 9 18:11:02 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 10 Oct 2005 00:11:02 +0200 Subject: Function decorator that caches function results In-Reply-To: References: <7x4q7rt3yl.fsf@ruckus.brouhaha.com> <3qssr4Fgjc2qU1@uni-berlin.de> Message-ID: <3qtirmFgnatvU1@uni-berlin.de> > > [penny drops] Now we're getting somewhere... a closure is something > _added_ to a function. So we should talk about functions-without-closures > and functions-with-closures. Yes. > > >>Speaking in >>terms of "is a" could be seen as some inheritance relation. > > > [penny rises again] Dammit, just when I thought I got it. So a closure is > like a subclass of function? Functions are a higher level classification, > like mammals. There are mammals that are primates (functions that _are_ > closures) and mammals that aren't (functions that _aren't_ closures). > Hrmpf. No, I wanted to say the exact opposite. My bad - just ignore that paragraph of mine in the earlier post, ok? > Right! So closures are something which functions _have_ -- which is why > Python functions have an attribute called func_closure, which is empty in > functions without closures, and contain a tuple of cells in those with > them. Yes. > > Now somebody is going to tell me this is an implementation detail and it > isn't true in the general language independent case... Paul Rubin did so, and I guess it is, although I don't know for sure. > Now you're trying to trick me... they are both *instances* of Foo, not > Foo. Foo is a class, and f and g are not classes, let alone the same class. As two functions are instances of the "class of functions". I just wanted to point out that two instances of one class can have differnet state. The analogy isn't perfect, as this special state "closure" isn't available easily for you to alter, and gets created behind the scenes. But as each function with a closure is created on the fly - same code, different closure data - it sort of fitted, I hoped. > > >>- but one has a different attribute set. And if Foo >>had some semantics that did something different based on bar, would you >>also say they're supposed have two different classes? You could in fact >>do that - create one class for each incarnation of possible state. But >>then the concept of classes and objects gets somewhat blurred, as each >>instance would have its own class. The same is true for functions. > > > Ah, but in languages like Pascal that can take functions as arguments, but > can't return functions as output, *all* functions have to be created > separately. To take your analogy and run with it, Pascal would be like a > language that didn't allow f and g to have different attributes unless > they belonged to different classes. > > Python is not like that, which is why you can write a function to return > functions (a factory function?). If the output function needs access to > the namespace of the factory function, Python adds a closure to that > output function, giving it access to the objects in that namespace. Hm, no. You can return functions in other languages, e.g. C. Don't know pascal good enough. But they will always be the same without any state associated to them, whereas in python you have some state. The same way as bound methods know about their first arguments, functions with closures know about - well, their closure :) A closure is really only an environment, adding values to locals() - implemented as cells in python - that adds to the local variables when the function is executed, and is dynamically created when a function with a closure is defined. This works because of the interpreted nature of python. Regards, Diez From davids at webmaster.com Mon Oct 17 01:42:51 2005 From: davids at webmaster.com (David Schwartz) Date: Sun, 16 Oct 2005 22:42:51 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: "Roedy Green" wrote in message news:ftv4l11dg1adoe4ar4lhjno7bsqdeloe1u at 4ax.com... > On Sat, 15 Oct 2005 15:48:18 -0700, "David Schwartz" > wrote or quoted : >> Go down to your local car dealer and see if you can buy a new car >>without an engine. > Given that that the OS and the hardware come from completely different > companies, I think that a specious analogy. With many cars, the engine is made by a different manufacturer from the body. The point is, they're sold as a unit because a car won't run without an engine and most people in the market want a car with an engine. DS From my_email_is_posted_on_my_website at munged.invalid Sun Oct 16 12:29:16 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sun, 16 Oct 2005 16:29:16 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: On Sat, 15 Oct 2005 15:48:18 -0700, "David Schwartz" wrote or quoted : > Go down to your local car dealer and see if you can buy a new car >without an engine. Given that that the OS and the hardware come from completely different companies, I think that a specious analogy. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From wookie at aces.localdomain Tue Oct 25 16:33:33 2005 From: wookie at aces.localdomain (Harold Stevens) Date: Tue, 25 Oct 2005 20:33:33 -0000 Subject: Microsoft Hatred FAQ References: <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> <435E8C5A.5030105@sun.removeme.com> Message-ID: In <435E8C5A.5030105 at sun.removeme.com> Brian Utterback: [Snip...] > that the laws have been in place since the late 1800's, the consent > decree explicitly and in no uncertain terms informed them of their > violations, and they continued to violate the law even afterward. It's M$ corporate DNA; they literally couldn't change and survive: Howard University law professor Andrew Gavil said he wonders whether Microsoft's early demands -- which would have compelled manufacturers to distribute to consumers only Microsoft's Windows Media Player software -- were a genuine mistake or a signal the company intends to revert to its hardball tactics. "It's somewhat amazing it even happened," said Gavil, who has closely followed the Microsoft case. "It's troubling that anyone inside Microsoft was still thinking this was a legitimate business strategy." Well, duh. All they got was a useless wrist-slap from the dickless US DOJ in 2002, so this is not at all surprising--just bidness as usual for M$. More: http://biz.yahoo.com/ap/051020/microsoft_antitrust.html?.v=6 And any M$ apologists are just as much liars and thieves as M$ itself. -- Regards, Weird (Harold Stevens) * IMPORTANT EMAIL INFO FOLLOWS * Pardon any bogus email addresses (wookie) in place for spambots. Really, it's (wyrd) at airmail, dotted with net. DO NOT SPAM IT. Kids jumping ship? Looking to hire an old-school type? Email me. From erniedude at gmail.com Tue Oct 25 16:30:31 2005 From: erniedude at gmail.com (Ernesto) Date: 25 Oct 2005 13:30:31 -0700 Subject: Execute C code through Python In-Reply-To: <11li3b2hsa3lhb5@corp.supernews.com> References: <1129844737.586396.61080@g47g2000cwa.googlegroups.com> <1129861083.010702.6770@g49g2000cwa.googlegroups.com> <1129906892.696582.288010@g43g2000cwa.googlegroups.com> <11li3b2hsa3lhb5@corp.supernews.com> Message-ID: <1130272231.210978.316140@g14g2000cwa.googlegroups.com> So i generated the .exe file "myFile.exe" This is a Windows - text based application. Right now, when I run: import subprocess subprocess.call("myFile") the application starts in its own console window. Is there a way for it to run inside the python interface? Thanks, From gregpinero at gmail.com Wed Oct 26 18:07:49 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Wed, 26 Oct 2005 18:07:49 -0400 Subject: syntax question - if 1:print 'a';else:print 'b' Message-ID: <312cfe2b0510261507m2732e947p2be6fdae99a7c3d7@mail.gmail.com> Any idea why I can't say: if 1:print 'a';else:print 'b' all in one line like that? It's just a random question I ran across a few days ago. -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com ) -------------- next part -------------- An HTML attachment was scrubbed... URL: From manatlan at gmail.com Thu Oct 6 07:25:29 2005 From: manatlan at gmail.com (manatlan at gmail.com) Date: 6 Oct 2005 04:25:29 -0700 Subject: /usr/bin/env python, force a version Message-ID: <1128597929.636452.223890@o13g2000cwo.googlegroups.com> I've got a trouble, and i think that anybody there can help me I've got a python script which i distribute in somes packages for *nix. This script is full of python and need python 2.4 ! And i'd like to display a message when the user doesn't have a python2.4 version. if i put, at the top of the script (which can be done with /usr/bin env too): #/usr/bin/python2.4 it will be good, but py2.3 users can't run the script, and the message comes from the system ;-( ... it can't be a message from my script ;-( #/usr/bin/python2.3 it will not be good, because my scrill will not work at all ;-) #/usr/bin/python it will select the defined python version of the platform ... And here is the problem. On debian/sid, users have python2.3 (default), et py2.4 : So the script will start with 2.3, and my message will be displayed. But it could work because there is a py2.4 on the machine ;-(. I'd like to make my script (or a starter script) which will be able to detect all python versions of the machine. And run my script with the good one ; py2.4, or display a message to the user to say her it must install py2.4 ... I hope you understand my needs. Is there a python/bash mechanism to override the default python version of the system ... and run the script with any version of python (but the most recent) ? or can you explain me how to do that ? the simplest way ? From scott.daniels at acm.org Sat Oct 8 16:22:56 2005 From: scott.daniels at acm.org (Scott David Daniels) Date: Sat, 08 Oct 2005 13:22:56 -0700 Subject: Weighted "random" selection from list of lists In-Reply-To: References: Message-ID: <43482a54@nntp0.pdx.net> Jesse Noller wrote: > Once main_list is populated, I want to build a sequence from items > within the lists, "randomly" with a defined percentage of the sequence > coming for the various lists. For example: > 60% from list 1 (main_list[0]), 30% from list 2 (main_list[1]), 10% from list 3 (main_list[2]) import bisect, random main_list = [['a', 'b', 'c'], ['dog', 'cat', 'panda'], ['blue', 'red', 'green']] weights = [60, 30, 10] cumulative = [] total = 0 for index, value in enumerate(weights): total += value cumulative.append(total) for i in range(20): score = random.random() * total index = bisect.bisect(cumulative, score) print random.choice(main_list[index]), -- -Scott David Daniels scott.daniels at acm.org From grante at visi.com Tue Oct 4 17:40:03 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 04 Oct 2005 21:40:03 -0000 Subject: how to get any available port References: <7xmzlpj7nr.fsf@ruckus.brouhaha.com> Message-ID: <11k5tljq83pd8e0@corp.supernews.com> On 2005-10-04, Paul Rubin <> wrote: > Mohammed Smadi writes: >> #transmission socket >> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >> s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) >> s.bind(("",hp_port)) # do some error checking >> ... >> any suggestions for alternative implementation? > > In this particular instance, don't bind the transmission socket. I'm > also not sure why you set SO_REUSEADDR. I've done some socket > programming but am no expert. You set SO_REUSEADDR when you need to bind to a specific port, and you want to be able to re-use that port address for a new connection without waiting for the time specified in the TCP RFC after the old connection was closed. In the OP's case, there is no need to bind to a specific port, so just getting rid of the bind() and setsockopt() calls is the obvious answer. -- Grant Edwards grante Yow! If I had a Q-TIP, I at could prevent th' collapse visi.com of NEGOTIATIONS!! From haraldarminmassa at gmail.com Mon Oct 10 14:34:35 2005 From: haraldarminmassa at gmail.com (Harald Armin Massa) Date: 10 Oct 2005 11:34:35 -0700 Subject: Python's Performance In-Reply-To: References: <20051008040614.47429.qmail@web30607.mail.mud.yahoo.com> <178B879D-FDB6-458C-BE00-A03820D98703@advfn.com> Message-ID: <1128969275.804305.193460@f14g2000cwb.googlegroups.com> Fredrik, but still some very valuable people write: """ What is Python? Python is an interpreted, interactive, object-oriented programming language. It is often compared to Tcl, Perl, Scheme or Java. """ taken from http://www.python.org/doc/Summary.html maybe someone could update that??? Harald From jamesd at echeque.com Sun Oct 2 16:52:21 2005 From: jamesd at echeque.com (James A. Donald) Date: Sun, 02 Oct 2005 13:52:21 -0700 Subject: "no variable or argument declarations are necessary." Message-ID: I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that means that if I misspell a variable name, my program will mysteriously fail to work with no error message. If you don't declare variables, you can inadvertently re-use an variable used in an enclosing context when you don't intend to, or inadvertently reference a new variable (a typo) when you intended to reference an existing variable. What can one do to swiftly detect this type of bug? -- http://www.jim.com From bellman at lysator.liu.se Tue Oct 11 11:22:04 2005 From: bellman at lysator.liu.se (Thomas Bellman) Date: Tue, 11 Oct 2005 15:22:04 +0000 (UTC) Subject: subprocess and non-blocking IO (again) References: <434a80e4_2@news3.prserv.net> Message-ID: Marc Carter writes: > The problem with the above is that the subprocess buffers all its output > when used like this and, hence, this automation is not informing me of > much :) You may want to take a look at my asyncproc module. With it, you can start subprocesses and let them run in the background without blocking either the subprocess or your own process, while still collecting their output. You can download it from http://www.lysator.liu.se/~bellman/download/asyncproc.py I suspect that it doesn't work under MS Windows, but I don't use that OS, and thus can't test it. -- Thomas Bellman, Lysator Computer Club, Link?ping University, Sweden "Beware of bugs in the above code; I have ! bellman @ lysator.liu.se only proved it correct, not tried it." ! Make Love -- Nicht Wahr! From nochiel at gmail.com Sat Oct 29 13:23:28 2005 From: nochiel at gmail.com (yoda) Date: 29 Oct 2005 10:23:28 -0700 Subject: py.log using decorators for DRY Message-ID: <1130606608.107621.138650@z14g2000cwz.googlegroups.com> I'm using py.log for logging and I find that I end up having the following pattern emerge within my code (influenced by http://agiletesting.blogspot.com/2005/06/keyword-based-logging-with-py-library.html): def foo(**kwargs): log.foo(kwargs) #body form This led me to believe that I could simplify that pattern with the following idiom : def logit (fn): ''' decorator to enable logging of all tagged methods ''' def decorator (**kwargs): # call a method named fn.func_name on log with kwargs #should be something like: log.func_name (kwargs) return decorator I can then do add @logit to all my existing methods via a script (there's a truck load of methods to tag): @logit def oldfoo () : pass My question is in regards to the body form in the decorator. How do I call that method on the log object at runtime? (ps. I hope my question is clear $) From da_hmea98 at hotmail.com Fri Oct 14 01:07:38 2005 From: da_hmea98 at hotmail.com (da_hmea98 at hotmail.com) Date: 13 Oct 2005 22:07:38 -0700 Subject: String code required please References: <1129263625.991136.236320@g49g2000cwa.googlegroups.com> Message-ID: <1129266458.136019.142460@g44g2000cwa.googlegroups.com> dapgy at yahoo.com wrote: > Does someone have the Python code to pull just the filename and > extension from the end of an absolute path please. > > Thanks in advance ... # Here you go... import os.path # Example path p1 = "C:\\WINDOWS\\system32\\DirectX\\Dinput\\mse.ini" # This will return: 'mse.ini' os.path.basename(p1) """ You can read more about manipulating file paths by reading the Python documentation under "6.2 os.path -- Common pathname manipulations". DA """ From noway at sorry.com Mon Oct 31 19:24:37 2005 From: noway at sorry.com (Giovanni Bajo) Date: Tue, 01 Nov 2005 00:24:37 GMT Subject: Reuse base-class implementation of classmethod? Message-ID: <9By9f.17396$65.522385@twister1.libero.it> Hello, what's the magic needed to reuse the base-class implementation of a classmethod? class A(object): @classmethod def foo(cls, a,b): # do something pass class B(A): @classmethod def foo(cls, a, b): A.foo(cls, a, b) # WRONG! I need to call the base-class classmethod to reuse its implementation, but I'd like to pass the derived class as first argument. -- Giovanni Bajo From rupole at hotmail.com Tue Oct 4 19:21:34 2005 From: rupole at hotmail.com (Roger Upole) Date: Tue, 4 Oct 2005 19:21:34 -0400 Subject: Python script to install network printers References: Message-ID: <1128468336_42527@spool6-east.superfeed.net> You can use win32print.AddPrinterConnection(r'\\server\sharedprinter'). However, if the printer driver has to be copied to the client machine and installed, that's probably where most of the time is spent. hth Roger "Matt Chan" wrote in message news:mailman.1446.1128439429.509.python-list at python.org... Hi, I am trying to create a python script to install a set of network printers. I have had success using an os.popen statement, using rundll32 and printui.dll. This takes way too long. Can someone point me in a quicker direction? thanks, Matt ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= East/West-Coast Server Farms - Total Privacy via Encryption =--- From michele.petrazzo at TOGLIunipex.it Fri Oct 21 03:15:19 2005 From: michele.petrazzo at TOGLIunipex.it (Michele Petrazzo) Date: Fri, 21 Oct 2005 09:15:19 +0200 Subject: sort problem In-Reply-To: <4357de42$1_3@newspeer2.tds.net> References: <4357c22d$0$8481$5fc30a8@news.tiscali.it> <1129825485.883210.297890@f14g2000cwb.googlegroups.com> <4357c9a4$0$8498$5fc30a8@news.tiscali.it> <4357de42$1_3@newspeer2.tds.net> Message-ID: <43589576$0$8488$5fc30a8@news.tiscali.it> Kent Johnson wrote: > or learn about decorate-sort-undecorate: > > lst = [ ...whatever ] lst = [ x[3], i, x for i, x in enumerate(lst) ] > I think that here the code must be changed (for the future): lst = [ (x[3], i, x) for i, x in enumerate(lst) ] > lst.sort() lst = [ x for _, _, x in lst ] Wow, this work with my py 2.3! > > Kent > Thanks, Michele From jeffrey.schwab at rcn.com Sun Oct 2 11:39:22 2005 From: jeffrey.schwab at rcn.com (Jeff Schwab) Date: Sun, 02 Oct 2005 11:39:22 -0400 Subject: Distributing programs In-Reply-To: References: Message-ID: Jason wrote: > A non-python programming friend of mine has said that any programs made > with Python must be distributed with, or an alternative link, to the > source of the program. > > Is this true? Sorta, but not really. Typically, you might distribute the source (.py) files, but if you don't want to do that, you can distribute the compiled .pyc files instead. Python creates these files automatically when your modules are imported. From http Mon Oct 10 18:13:14 2005 From: http (Paul Rubin) Date: 10 Oct 2005 15:13:14 -0700 Subject: Send password over TCP connection References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> <1128979760.251637.316480@o13g2000cwo.googlegroups.com> Message-ID: <7xk6glhvgl.fsf@ruckus.brouhaha.com> "dcrespo" writes: > 3. Both Client and Server creates a hash string from > > 4. Client sends the hash string to the server > 5. Server compares his hash result with the hash string received from > de client. > > I think it is a very good solution, Isn't it? No. It's vulnerable to dictionary search. Use SRP if you can. From john at castleamber.com Wed Oct 12 22:21:52 2005 From: john at castleamber.com (John Bokma) Date: 13 Oct 2005 02:21:52 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <868xx3m2ve.fsf@bhuda.mired.org> <86irw6l1mc.fsf@bhuda.mired.org> Message-ID: Keith Thompson wrote: > There are several newsgroups that deal with e-mail abuse. This > discussion isn't being posted to any of them. Please stop. This just adds to the noise, and isn't going to work. Just kill the entire thread. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From fredrik at pythonware.com Wed Oct 19 16:09:16 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 19 Oct 2005 22:09:16 +0200 Subject: Extention Module/ list of chars-> string References: <1129749035.667046.98630@g14g2000cwa.googlegroups.com> Message-ID: "Tuvas" wrote: > I am currently writing an extention module that needs to recieve a list > of characters that might vary in size from 0 to 8. This is written as a > list of characters rather than a string because it's easier to > manipulate. However, when I pass this list of characters into the > extention module, it keeps giving errors. Is there a way to do one of > the following? > > A. Change a list of chars to a single string or that's easier to do at the python side of things (see martin's reply), but if you'd rather do > B. Read a list of chars in an extention module you might find the code on this page somewhat useful: http://effbot.org/zone/python-capi-sequences.htm (use PyString_Check, PyString_Size and PyString_AsString to process the sequence items. see the C API reference for details) From fredrik at pythonware.com Mon Oct 10 02:30:21 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 10 Oct 2005 08:30:21 +0200 Subject: non descriptive error References: <4346002C.3080504@open-networks.net> <200510070240.56350.hancock@anansispaceworks.com> <4349A55C.90203@open-networks.net> <4349AE08.1000306@open-networks.net> Message-ID: Timothy Smith wrote: > it is definately a bug in 2.3 when using the decimal module. i can > reproduce it. > > from decimal import Decimal > a = Decimal('0' > > and when you attempt to run it you will get "error" $ python script.py File "script.py", line 3 ^ SyntaxError: invalid syntax > of course i do understand that decimal wasn't part of 2.3, but atleast > now when if anyone gets that terse message they know where to start > looking :) on your machine ? From projecktzero at yahoo.com Fri Oct 7 09:07:23 2005 From: projecktzero at yahoo.com (projecktzero) Date: 7 Oct 2005 06:07:23 -0700 Subject: Book "Python and Tkinter Programming" In-Reply-To: <1128620086.240847.235490@g44g2000cwa.googlegroups.com> References: <1128620086.240847.235490@g44g2000cwa.googlegroups.com> Message-ID: <1128690443.478697.33250@g44g2000cwa.googlegroups.com> striker wrote: > Does anyone who has this book willing to sell it. Please e-mail me the > condition and any other details if you are interested. > Thanks, > Kevin half.com has a couple of people selling it. One for $35.24 and another for $129.97. From my_email_is_posted_on_my_website at munged.invalid Thu Oct 27 03:58:42 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Thu, 27 Oct 2005 07:58:42 GMT Subject: Microsoft Hatred FAQ References: <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> Message-ID: On Thu, 27 Oct 2005 00:49:27 -0700, "David Schwartz" wrote, quoted or indirectly quoted someone who said : > I guess I don't understand what you're saying. Are you saying that >Microsoft demanded you pay them per machine you sold under the table in the >absence of a written contract that said that? Or are you simply saying that >they changed the terms of your agreement when it came up for renewal? This was all under the table. -- Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching. From apardon at forel.vub.ac.be Mon Oct 10 04:09:13 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 10 Oct 2005 08:09:13 GMT Subject: "no variable or argument declarations are necessary." References: <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <3qi8erFf252rU1@uni-berlin.de> <3qkdbrFfgga9U1@uni-berlin.de> <3qkn7qFffkl6U1@uni-berlin.de> <3qkr1hFfgj5uU1@uni-berlin.de> <3qmrd2Ffocu8U1@uni-berlin.de> <1128686332.212150.275360@g43g2000cwa.googlegroups.com> <1128694004.950502.123170@z14g2000cwz.googlegroups.com> Message-ID: Op 2005-10-07, Diez B. Roggisch schreef : > > Well, that exactly is the point where we make the transition from "this > is how things work" to pure speculation. Everything starts with pure speculation. I had no intention of introducing the big type system here. I just think people who oppose type systems, limit themselves too much to how things currently work and from there oppose anything that resembles a type system instead of thinking of what they would like a type system to do even if it is not implemtable now. > Can't say that there won't be > a solution someday - but certainly it requires much more, and from > above nobody can say that this would solve _any_ problem. > > What you propose above is what JAVA does - plus more dynamicity. So it isn't exactly JAVA afterall. > Well, > given that even the "non-dynamic, everything has to be annotated" JAVA > fails to deal with ANY (called Object there), So please explain how my system fails with the ANY. > I can't see how a more > dynamic environment will do _better_ in that respect. You first argued that a type system had to limit the coder and you gave the example of the homegeneous list. I suggested an ANY type and asked how a homegeneous list of ANY's would limit the coder. Your respons was that this was like a JAVA Object or C void* hack, that can be used to circumvent the type system and cause all kinds of problems, presumebly python was not vulnerable to. So I would either like you to explain how my idea can be used to circumvent the type system and cause problems, which don't concern python or explain how this system will limit the coder with respect what can be done in python. > So unless you lay > out some more detailed ideas how that works, this surely won't do much > if any better than JAVA does today - and JAVA sucks _precisely_ because > of the half-static-half-dynamic nature. It gives you both troubles - > runtime errors like in python, together with compile-time limitations. I have no need to convince you. It was you who made this claim how a type system had to limit the coder. That you can't see how it could be done is not an argument. Surely if a typesystem *must* limit the user or else cause all kinds of problems as more general argument can be given that doesn't depend on the specific implementation. > Let's face it: you don't know much about type-systems. I do know a bit > more - but don't claim to possess the holy grail. And I don't say that > more powerful analyzing isn't possible. However, all you do so far is > fantasizing and "fail to see why not". Well, that failure might be > because of limited sight on your side - not necessarily on our, which > you constantly claim. Well, I could accept that if you would have explained what the problem would be with my system instead of just saying you couldn't see how it would be more usefull than JAVA Objects. > Visions are a nice thing - but actually, in the scientific domain not > so much a vision, but proofs are what is needed. Well you made the claim that a type system had to limit the coder. Now prove your claim. Untill this is done I see no problem thinking about type systems that don't limit the coder. > And if you consider it > hostile that nobody buys your ideas because so far they aren't more > than marketing/whishful thinking, I'm sorry that I can't help you. I don't consider it hostile that nobody buys my ideas. I considered the environment here hostile to type systems long before I brought my two cents to the discussions about this subject here. -- Antoon Pardon From mwm at mired.org Tue Oct 18 12:07:03 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 18 Oct 2005 12:07:03 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86fyqzzskt.fsf@bhuda.mired.org> <86y84rxryr.fsf@bhuda.mired.org> <2R75f.2005$dO2.1121@newssvr29.news.prodigy.net> Message-ID: <86mzl6yfko.fsf@bhuda.mired.org> "Mike Schilling" writes: > "Mike Meyer" wrote in message > news:86y84rxryr.fsf at bhuda.mired.org... >> "Mike Schilling" writes: >>> "Mike Meyer" wrote in message >>> news:86fyqzzskt.fsf at bhuda.mired.org... >>>> "Mike Schilling" writes: >>>>> What matters in generating HTML is which browsers you want to support >>>>> and >>>>> what they understand. Standards and recommendations are both >>>>> irrelevant. >>>> Unless, of course, you want to support any compliant browser. >>> Since no browser I know of is perfectly compliant (e.g. bug-free), that's >>> not a feasible goal. >> I guess you'd say developing any software isn't a feasible goal, >> because it'll never be bug-free, will never have bug-free compilers to >> compile it, bug-free linkers to link it, bug-free GUI/db/etc libraries >> to link with it, bug-free servers to communicate with, and bug-free >> operating systems to run it on. Fortunately, most developers aren't >> quite that anal, and realize that you can get useful work done in a >> less-than-perfect environment. > I'm not speaking theroetically. My company (though not me personally) > creates browser-based UIs, and one of the biggest expenses has been dealing > with IE rendering bugs Given the market share of IE, the fact that > something should work, and even does work in Firefox, Opera, etc, is > irrelevant. If it breaks IE, we can't use it. Been there, done that, threw out the T-shirt as to ugly to wear. Yes, you have to work around bugs in the popular browsers. That hasn't changed since the first published specs showed up. That doesn't mean you throw out the standards and only support a trivial set of browsers. That means you restrict yourself to a subset of the standard, or - better - detect the deficiency and fail soft, the same as you would do when you get a visit from someone who's disabled some feature you want to use. In extreme cases, you wind up implementing something twice: once for busted-but-popular browsers, and once for people using browsers written by developers who read specifications. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From python at rcn.com Tue Oct 11 07:03:36 2005 From: python at rcn.com (Raymond Hettinger) Date: 11 Oct 2005 04:03:36 -0700 Subject: Idle bytecode query on apparently unreachable returns References: Message-ID: <1129028616.859306.283720@o13g2000cwo.googlegroups.com> [Tom Anderson]: > What puzzles me, though, are bytecodes 17, 39 and 42 - surely these aren't > reachable? Does the compiler just throw in a default 'return None' > epilogue, with routes there from every code path, even when it's not > needed? If so, why? Since unreachable code is never executed, there is no performance payoff for optimizing it away. It is not hard to write a dead-code elimination routine, but why bother? It would save a few bytes, slow down compilation time, save nothing at runtime, and make the compiler more complex/fragile. FWIW, the peephole optimizer in Python/compile.c is mature -- the low hanging fruit has already been harvested, leaving the field of remaining optimizations somewhat barren. Raymond From http Fri Oct 7 04:12:12 2005 From: http (Paul Rubin) Date: 07 Oct 2005 01:12:12 -0700 Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <3qi8erFf252rU1@uni-berlin.de> <3qkdbrFfgga9U1@uni-berlin.de> <3qkn7qFffkl6U1@uni-berlin.de> <3qkr1hFfgj5uU1@uni-berlin.de> Message-ID: <7xr7ax690j.fsf@ruckus.brouhaha.com> Steve Holden writes: > In other words, you want Python to be strongly-typed, but sometimes > you want to allow a reference to be to any object whatsoever. In which > case you can't possibly do any sensible type-checking on it, so this > new Python+ or whatever you want to call it will suffer from the same > shortcomings that C++ and java do, which is to say type checking can't > possibly do anything useful when the acceptable type of a reference is > specified as ANY. Let's see if I understand what you're saying: C and Java: you get useful type checking except when you declare a reference as type ANY. This is a shortcoming compared to: Python: where you get no useful type checking at all. That is not very convincing logic. From rune.strand at gmail.com Wed Oct 12 02:31:07 2005 From: rune.strand at gmail.com (Rune Strand) Date: 11 Oct 2005 23:31:07 -0700 Subject: Adding a __filename__ predefined attribute to 2.5? Message-ID: <1129098667.336115.303060@g47g2000cwa.googlegroups.com> Is it an idea to include a new __filename__ predefined attribute to 2.5, so that __file__ contains the entire path to the module, and __filename__ only the name of the module? For instance it's useful to include a not-static reference to the filename in a scripts usage() section and it's cumbersome to extract the filename or to do module imports just to parse it. From vvoipio at kosh.hut.fi Tue Oct 11 01:43:14 2005 From: vvoipio at kosh.hut.fi (Ville Voipio) Date: Tue, 11 Oct 2005 08:43:14 +0300 (EEST) Subject: Python reliability References: <7xr7au1hr5.fsf@ruckus.brouhaha.com> Message-ID: In article , Thomas Bartkus wrote: > > All in all, it would seem that the reliability of the Python run time is the > least of your worries. The best multi-tasking operating systems do a good > job of segragating different processes BUT what multitasking operating > system meets the standard you request in that last paragraph? Well, let's put it this way. I have seen many computers running Linux with a high load of this and that (web services, etc.) with uptimes of years. I have not seen any recent Linux crash without faulty hardware or drivers. If using Python does not add significantly to the level of irreliability, then I can use it. If it adds, then I cannot use it. > type of rugged use you are demanding. I would google "embedded systems". > If you want to use Python/Linux, I might suggest you search "Embedded > Linux". I am an embedded system designer by my profession :) Both hardware and software for industrial instruments. Computers are just a side effect of nicer things. But here I am looking into the possibility of making something with embedded PC hardware (industrial PC/104 cards). The name of the game is "as good as possible with the given amount of money". In that respect this is not flying or shooting. If something goes wrong, someone loses a bunch of dollars, not their life. I think that in this game Python might be handy when it comes to maintainability and legibility (vs. C). But choosing a tool which is known to be bad for the task is not a good idea. - Ville -- Ville Voipio, Dr.Tech., M.Sc. (EE) From aleax at mail.comcast.net Thu Oct 13 10:21:24 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Thu, 13 Oct 2005 16:21:24 +0200 Subject: Python's garbage collection was Re: Python reliability References: <7xr7au1hr5.fsf@ruckus.brouhaha.com> <7xwtkl21hn.fsf@ruckus.brouhaha.com> <7xll11twc2.fsf@ruckus.brouhaha.com> <1h4a5l4.13vx8k7etyxy1N%aleax@mail.comcast.net> Message-ID: <1h4dmad.u2vd2b1jfy8N%aleax@mail.comcast.net> Tom Anderson wrote: > On Tue, 11 Oct 2005, Alex Martelli wrote: > > > Tom Anderson wrote: > > ... > >> Has anyone looked into using a real GC for python? I realise it would be a > > > > If you mean mark-and-sweep, with generational twists, > > Yes, more or less. > > > that's what gc uses for cyclic garbage. > > Do you mean what python uses for cyclic garbage? If so, i hadn't realised Yes, gc (a standard library module) gives you access to the mechanism (to some reasonable extent). > that. There are algorithms for extending refcounting to cyclic structures > (i forget the details, but you sort of go round and experimentally > decrement an object's count and see it ends up with a negative count or > something), so i assumed python used one of those. Mind you, those are > probably more complex than mark-and-sweep! Not sure about that, when you consider the "generational twists", but maybe. > >> lot more complexity in the interpreter itself, but it would be faster, > >> more reliable, and would reduce the complexity of extensions. > > > > ??? It adds no complexity (it's already there), it's slower, > > Ah. That would be why all those java, .net, LISP, smalltalk and assorted > other VMs out there, with decades of development, hojillions of dollars > and the serried ranks of some of the greatest figures in computer science > behind them all use reference counting rather than garbage collection, > then. > > No, wait ... Not everybody agrees that "practicality beats purity", which is one of Python's principles. A strategy based on PURE reference counting just cannot deal with cyclic garbage -- you'd also need the kind of kludges you refer to above, or a twin-barreled system like Python's. A strategy based on PURE mark-and-sweep *CAN* be complete and correct... at the cost of horrid delays, of course, but what's such a practical consideration to a real purist?-) In practice, more has probably been written about garbage collection implementations than about almost every issue in CS (apart from sorting and searching;-). Good techniques need to be "incremental" -- the need to "stop the world" for unbounded amounts of time (particularly in a paged virtual memory world...), typical of pure m&s (even with generational twists), is simply unacceptable in all but the most "batch" type of computations, which occupy a steadily narrowing niche. Reference counting is intrinsically "reasonably incremental"; the worst-case of very long singly-linked lists (such that a dec-to-0 at the head causes a cascade of N dec-to-0's all along) is as rare in Python as it is frequent in LISP (and other languages that go crazy with such lists -- Haskell, which defines *strings* as single linked lists of characters, being a particularly egregious example) [[admittedly, the techniques for amortizing the cost of such worst-cases are well known in any case, though CPython has not implemented them]]. In any case, if you like Python (which is a LANGUAGE, after all) and don't like one implementation of it, why not use a different implementation, which uses a different virtual machine? Jython, for the JVM, and IronPython, for MSCLR (presumably what you call ".net"), are quite usable; project pypy is producing others (an implementation based on Common LISP was one of the first practical results, over a year ago); not to count Parrot, and other projects yet... > > it is, if anything, LESS reliable than reference counting (which is way > > simpler!), > > Reliability is a red herring - in the absence of ill-behaved native > extensions, and with correct implementations, both refcounting and GC are > perfectly reliable. And you can rely on the implementation being correct, > since any incorrectness will be detected very quickly! Not necessarily: tiny memory leaks in supposedly "stable" versions of the JVM, for example, which get magnified in servers operating for extremely long times and on very large scales, keep turning up. So, you can't count on subtle and complicated implementations of garbage collection algorithms being correct, any more than you can count on that for (for example) subtle and complicated optimizations -- corner cases can be hidden everywhere. There are two ways to try to make a software system reliable: make it so simple that it obviously has no bugs, or make it so complicated that it has no obvious bugs. RC is definitely tilted towards the first of the two options (and so would be mark-and-sweep in the pure form, the one where you may need to stop everything for a LONG time once in a while), while more sophisticated GC schemes get more and more complicated. BTW, RC _IS_ a form of GC, just like, say, MS is. > > and (if generalized to deal with ALL garbage) it might make it almost > > impossible to write some kinds of extensions (ones which need to > > interface existing C libraries that don't cooperate with whatever GC > > collection you choose). > > Lucky those existing C libraries were written to use python's refcounting! > > Oh, you have to write a wrapper round the library to interface with the > automatic memory management? Well, as it happens, the stuff you need to do > is more or less identical for refcounting and GC - the extension has to > tell the VM which of the VM's objects it holds references to, so that the > VM knows that they aren't garbage. Ah, but there is an obvious difference, when we're comparing reference counting with mark and sweep in similarly simple incarnations: reference counting has no "sweep" phase! M&S relies on any memory area not otherwise accounted for being collectable during the "sweep" part, while RC will intrinsically and happily leave alone any memory area it does not know about. Adding sophistication to M&S often makes things even more ticklish, if there are "random" pieces of memory which must be hands-off -- the existing C library you're interfacing may give you no idea, on an API-accessible level, where such internal "random" pieces might be at any time. E.g., said existing libraries might be returning to you "opaque handles" -- say you know they're pointers (already you're having to breach the encapsulation and abstraction of the library you're interfacing...), but pointers to WHAT? To structures which may internally hold other pointers yet -- and what do THOSE point to...? By ``handwaving'' about "the VM's objects" you imply a distinction between such "objects" and other generic "areas of memory" that may not be easy to maintain. In RC, no problem: the reference-counting operations intrinsically discriminate (you don't addref or decref to anything but such an "object"). In MS, the problem is definitely there; your VM's allocator needs to be able to control the "sweep", which may require quite a lot of extra overhead if it can't just assume it "owns" all of the memory. > > Are we talking about the same thing?! > > Doesn't look like it, does it? Apparently not. Most of my "production-level" implementations of garbage collection schemes hark back to the late '70s (as part of my thesis) and early '80s (working at Texas Instruments to architect a general purpose CPU with some kind of GC support in hardware); after leaving the field, when I got back to it, years later, I essentially found out that the universality of paged virtual memory had changed every single parameter in the game. I did some work on pointer-swizzling "incremental sort-of-compacting" collectors, and conservative M&S a la Boehm, but by that time I was more interested in real-world applications and none of those efforts ever yielded anything practical and production-quality -- so, I either used existing libraries and VMs (and more often than not cursed at them -- and, generally, the FFIs whose gyrations I had to go through to work with them), or, when I was implementing GC in my applications, relied on simple and solid techniques such as variants on reference-counting, arenas, etc etc. The crusher was a prototype application based on Microsoft's CLR (or ".net", as you call it) which needed to use MSCLR's ``advanced, modern, sophisticated'' GC for many new parts, and "unmanaged" mode for a lot of existing "legacy" libraries and subsystems. I won't say that it wasted a year of my life, because I was leading that effort at about half-time... so, it only wasted HALF a year of my life!-) Of course, that was in the bad dark ages of about 5 years ago -- I'm sure that by now everything is perfect and flawless and the experience of the previous 25 years is thereby nullified, right?-) >From your tone I assume that your experience in implementing and cooperating with modern, "advanced" GC techniques is much fresher and more successful than mine. Personally, I'm just happy that other Python developers must clearly have scars similar to mine in these respects, so that Python's implementation is solid and conservative, one whose correctness you CAN essentially count on. > >> So python doesn't use the old SmallTalk 80 SmallInteger hack, or similar? > >> Fair enough - the performance gain is nice, but the extra complexity would > >> be a huge pain, i imagine. > > > > CPython currently is implemented on a strict "minimize all tricks" > > strategy. > > A very, very sound principle. If you have the aforementioned decades, > hojillions and serried ranks, an all-tricks-turned-up-to-eleven strategy > can be made to work. 78% of software projects fail -- and I believe the rate of failures in large IT departments and software houses is higher than average. > If you're a relatively small non-profit outfit like > the python dev team, minimising tricks buys you reliability and agility, > which is, really, what we all want. And if you're a relatively large (and tumultuously growing), pretty-good-profit outfit, minimizing tricks builds you scalability and solidity. Funny enough, I've found that my attitude that "clarity, solidity and prudence are THE prime criteria of good implementations", born of thirty years' worth of scars and "arrows in my back", made me an "instant cultural fit" for Google (which I joined as Uber Technical Lead just over six months ago, and where I'm currently happily prospering)... Alex From http Fri Oct 7 08:26:28 2005 From: http (Paul Rubin) Date: 07 Oct 2005 05:26:28 -0700 Subject: Python recipes: list mixin, improved timeit, etc References: <1128687060.102240.56040@g44g2000cwa.googlegroups.com> Message-ID: <7xbr21zf63.fsf@ruckus.brouhaha.com> "Michele Simionato" writes: > Once in a time, I thought mixins where a good idea; now I don't think > so since they are too easily abused (see Zope 2) and as a consequence > you get spaghetti-inheritance, where you have objects with methods > inherited from everywhere. So be very careful if you want to use > mixins; often you can go without them. Yeah, I wonder though how much of that is a result of Python's cavalier approach to multiple inheritance. Does that happen much in CLOS? In Java because of multiple interfaces? I've studied Flavors a little and mix-ins were used in some extensive ways, but maybe programs using them required extra care. The Python tutorial does caution against indiscriminate use of multiple inheritance. I tried coding something without it, wished that I'd used it and did so in the next version, but still am not sure if I gained anything or not. From tim at tt1lock.org Mon Oct 17 08:33:22 2005 From: tim at tt1lock.org (Tim Tyler) Date: Mon, 17 Oct 2005 12:33:22 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <11l48tuqj7m11b5@corp.supernews.com> Message-ID: In comp.lang.java.programmer Jeroen Wenting wrote or quoted: > "Mike Meyer" wrote in message > > "Jeroen Wenting" writes: [Microsoft] > >> no, they got their by clever marketing [snip] > > > > What you call "clever marketing" the DOJ calls "monopolistic > > practices". The courts agreed with the DOJ. Having had several large > > PC manufacturers refuse to sell me a system without some form of > > Windows because MS made it impossible for them to compete if they > > didn't agree to do so, I agree with the courts and the DOJ. > > And were later forced to rescind. [...] That is inaccurate. -- __________ |im |yler http://timtyler.org/ tim at tt1lock.org Remove lock to reply. From chris at kateandchris.net Mon Oct 24 17:13:56 2005 From: chris at kateandchris.net (Chris Lambacher) Date: Mon, 24 Oct 2005 17:13:56 -0400 Subject: win32 process information, using win32 extension In-Reply-To: <1129903954.839508.298270@o13g2000cwo.googlegroups.com> References: <1129903954.839508.298270@o13g2000cwo.googlegroups.com> Message-ID: <20051024211356.GC17848@kateandchris.net> I started down the win32process path trying to solve the same problem. That only ended in misery for me. Try this recipie instead: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/442477 -Chris On Fri, Oct 21, 2005 at 07:12:34AM -0700, Java and Swing wrote: > i need to get information about the processes running on a windows pc > (98, 2k, xp) > > i can get the pid's using, win32process.EnumProcesses()...and I can get > a handle on a process using an id..such as > > handle = win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION, 0, > pids[0]) > > ..but how can i get the name of the process, path to process, etc. I > have the win32 extensions (pywin32) on python 2.4. > > thanks. > > -- > http://mail.python.org/mailman/listinfo/python-list From mwm at mired.org Sat Oct 1 12:02:46 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 01 Oct 2005 12:02:46 -0400 Subject: OT: Phases of the moon References: <1128003857.930444.47650@g14g2000cwa.googlegroups.com> <1128013745.763757.144280@g44g2000cwa.googlegroups.com> <1128015868.201617.153240@g14g2000cwa.googlegroups.com> <0001HW.BF63479501083049F0407550@news.individual.de> Message-ID: <86oe69mdi1.fsf@bhuda.mired.org> Bart Lateur writes: > Steven D'Aprano wrote: > >>A skeptical policeman who says he doesn't actually believe the moon >>affects behaviour nevertheless reports that "last weekend" things were >>really crazy, and it was a full moon. Somebody writes in to correct him: >>no, the full moon is actually "tomorrow". > > As a similar example: I've been told by various women independently, > that "there are more babies born near a full moon." > > So... is there a correlation between insanity and babies being born? :) If what they say is true, then yes, there is. That doesn't mean there's a logical - or even rational - explanation for that correlation. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From my_email_is_posted_on_my_website at munged.invalid Wed Oct 12 18:33:50 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 12 Oct 2005 22:33:50 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> Message-ID: <3g3rk1lv2dhcerqcn3hambu6p4l6mn70gq@4ax.com> On Sun, 09 Oct 2005 20:19:46 +1000, Steven D'Aprano wrote or quoted : >Likewise I avoid emails that are broken. If it looks like it will contain >web-bugs, javascript exploits, or badly formatted unreadable text, then I >avoid any mail client that can't display it in plain text. > >And by "looks like", I mean "contains any HTML". That is overreacting. All you need is a something that refuses to run code. There is no need to ignore the formatting. I have well meaning friends who send me rather syrupy emails, formatted. I don't run any enclosures, but I look at the pictures and the message. They are not spam. If people like sending such messages to each other it is not our business to interfere. On the contrary. Our job it help people send arbitrary messages to each other as easily as possible. Censoring content and style is none of our business. Our job is to help get messages through reliably, safely and efficiently. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From piet at cs.uu.nl Sat Oct 29 08:52:37 2005 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sat, 29 Oct 2005 14:52:37 +0200 Subject: popen2 References: <1130524659.070912.256550@o13g2000cwo.googlegroups.com> Message-ID: >>>>> "g.franzkowiak" (gf) wrote: >gf> If starts a process with popen2.popen3('myprogram') and myprogram.exe is >gf> running before, I've a connection to the second process, not to the first. >gf> I can find the process by name before I start a process with popen2..., >gf> but how bcan I connect t this process with a pipe ? You have to use a named pipe. -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From jzgoda at o2.usun.pl Wed Oct 19 16:03:16 2005 From: jzgoda at o2.usun.pl (Jarek Zgoda) Date: Wed, 19 Oct 2005 22:03:16 +0200 Subject: How to organize Python files in a (relatively) big project In-Reply-To: References: Message-ID: Micah Elliott napisa?(a): >>How to install this structure eg. on Linux? What layout do you >>recommend? It's tempting to use /opt hierarchy for installation >>target (as it gives relatively much freedom within application >>directory), but many administrators are reluctant to use this >>hierarchy and prefer more standarized targets, such as /usr or >>/usr/local. > > Read about (and use) the Python-provided distutils, and let it do the > work for you. In particular, > > discusses installation location. The file name is a misnomer; it's > equally applicable to linux. I think that installing *application* (not misc. library) modules in site-packages is at least stupid idea, as it makes a special filesystem inside other, much more standarized filesystem (Windows, FHS, etc.). Why not to do this usual way: libraries to $prefix/lib/$appname-$version, binary to $prefix/bin, shared files to $prefix/share/$appname, etc -- and appropriately on Windows. -- Jarek Zgoda http://jpa.berlios.de/ From hipertracker at gmail.com Sun Oct 23 06:56:10 2005 From: hipertracker at gmail.com (Jaroslaw Zabiello) Date: Sun, 23 Oct 2005 12:56:10 +0200 Subject: IDE recommendation please References: <1h4usyj.1ndvf691bu0zvuN%aleaxit@yahoo.com> <1130052821.015256.9630@g49g2000cwa.googlegroups.com> Message-ID: <1f6ph623nsgjb$.1la6l5vyzxepl.dlg@40tude.net> Dnia 23 Oct 2005 00:33:41 -0700, kery napisa?(a): > Any suggestions for Linux, specifically SuSE or perhaps Red Hat? Eric3 http://www.die-offenbachs.de/detlev/eric3.html Eclipse http://www.eclipse.org/ + pydev plugin http://pydev.sourceforge.net/ SPE http://pythonide.stani.be/ -- JZ From tim.peters at gmail.com Thu Oct 13 22:05:45 2005 From: tim.peters at gmail.com (Tim Peters) Date: Thu, 13 Oct 2005 22:05:45 -0400 Subject: Hidden string formatting bug In-Reply-To: <910885da0510131748y16dd9603n4e013553e28797df@mail.gmail.com> References: <910885da0510131748y16dd9603n4e013553e28797df@mail.gmail.com> Message-ID: <1f7befae0510131905i6f99be4bncef50660107823ee@mail.gmail.com> [Echo] > I have been trying to figure out the problem with this string formatting: [monstrous statement snipped] > when it executes, I get this error: "inv argument required". That shoud be "int", not "inv". > I have checked and rechecked both the string and the tuple. I cant figure > out what the problem is. After playing around with it, i found out if change > the last line to: "%s,%i) %(... I get a different error. The error is "not all > arguments converted during string formatting". > > So I am baffled and confused as of why this wont work. Is anyone able to > shed some light on my hidden bug? Yup, it's precedence. Here's the same thing: sql = "%s" + \ "%i" % ("abc", 2) Run that and you get "int argument required". Change the last %i to %s and you get "not all arguments converted during string formatting". Both error messages are accurate. That's because % binds tighter than "+". As a 1-liner, and inserting redundant parentheses to make the precedence obvious, my simplified example is sql = "%s" + ("%i" % ("abc", 2)) What you intended _requires_ inserting more parentheses to force the intended order (if you're going to stick to this confusing coding style): sql = ("%s" + "%i") % ("abc", 2) Better is to not use "+" on string literals, and not use backslash continuation either; try this instead: sql_format = ('string1' 'string2' 'string3' ... 'last string') Build the format in a separate statement to reduce the chance of errors (for example, your original mistake would have been impossible to make this way). Use parens instead of backslashes. Don't use "+" to catenate string literals: the Python compiler automatically catenates adjacent string literals for you, and at compile-time (so it's even more efficient than using '"+"). From timothy at open-networks.net Sun Oct 9 19:42:07 2005 From: timothy at open-networks.net (Timothy Smith) Date: Mon, 10 Oct 2005 09:42:07 +1000 Subject: non descriptive error In-Reply-To: <20051009233046.GB6224@unpythonic.net> References: <4346002C.3080504@open-networks.net> <200510070240.56350.hancock@anansispaceworks.com> <4349A3CD.8030603@open-networks.net> <20051009233046.GB6224@unpythonic.net> Message-ID: <4349AACF.7000708@open-networks.net> jepler at unpythonic.net wrote: >On Mon, Oct 10, 2005 at 09:12:13AM +1000, Timothy Smith wrote: > > >>FAYI i have already found it and it was a wrongly indented code block :/ >> >> > >When indentation leaves an illegal program structure, Python gives a very >informative error message, such as > > File "/tmp/x.py", line 3 > return 3 > ^ >IndentationError: unindent does not match any outer indentation level > >Jeff > > not in my first case it didn't. i simply tabbed an incorrect block in and it worked. i should have saved it to show you From deets at nospam.web.de Mon Oct 31 18:52:32 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 01 Nov 2005 00:52:32 +0100 Subject: cx_Oracle, is anything selected? In-Reply-To: References: Message-ID: <3snp20Foku05U1@uni-berlin.de> Damjan wrote: > Is there a way to see if the SELECT in cx_Oracle didn't return anything? > I want to optimize the situation when the number of selected rows is zero. > Is select count(*) the only option, seems inefficient? I don't understand your problem - if your select doesn't return anything, the fetch* methods on the cursor will tell you if there is any data to expect at all. Additionally there is teh rowcount-property that holds the number of rows the last execute* yielded. Diez From kenneth.m.mcdonald at sbcglobal.net Thu Oct 13 16:49:59 2005 From: kenneth.m.mcdonald at sbcglobal.net (Kenneth McDonald) Date: Thu, 13 Oct 2005 15:49:59 -0500 Subject: UI toolkits for Python In-Reply-To: <7xslv56ud1.fsf@ruckus.brouhaha.com> References: <7xslv56ud1.fsf@ruckus.brouhaha.com> Message-ID: <285FA816-BA45-4A74-8623-1DF39310DC4C@sbcglobal.net> Thanks for reminding me of Gtk. OK, add that to the list. The Web Browser interface is good for simple things, and will get better with CSS2's adoption, but they still don't have a good way for important things like interactive styled text, key bindings, etc. Good for simple things (for which I use them), not for more complex stuff. As for Tkinter, well, sigh, I have to go into a semi-rant, semi- eulogy right now. Tk was, IMHO, the hands-down award winner for UI toolkit farthest ahead of its time. I used it for years and years and years. Tcl, on the other had, wasn't the _worst_ scripting language of all time, but it was sure down in the bottom ten percent. How John Ousterhout could come up with Tk on one hand and the other at the same Tcl boggles my mind. Unfortunately, while Tkinter did provide in theory full access to Tk, it was in practice never finished. I wrote quite a bit of code to try to add a true pythonic interface to Tk via Tkinter (I'm happy to give it away if anyone wants--some of it is actually in pretty good shape). But it's a big job, and it became clear to me that Tk is going the way of the dinosaurs, so I abandoned it. Ddevelopment on the advanced features of Tk--what really made it worth using--has languished. Both marks and tags in the Text widget have been fundamentally broken forever (not buggy, I mean broken in the sense that their semantics destroys a great deal of their real potential), and I don't see they'll ever be fixed. Same thing with tags in the Canvas widget. Plus the lack of well-thought-out new widgets, and various other sins of omission and comission, and I decided that Tkinter was clearly in the last of its days. That said, if I was one of the founders of Google, Tk would be one of the projects I'd hire a lot of people to get on to and actually realize its potential. But I don't even buy lottery tickets :-) Now I'm just waiting until one of the other kits becomes mature enough (if ever) to start using it. So this is a query about that :-) On 13-Oct-05, at 3:21 PM, Paul Rubin wrote: > Kenneth McDonald writes: > >> 1) Which plays best with Python? Ideally, it would already have some >> higher-level python libraries to hide the grotty stuff that is almost >> never needed when actually implementing apps. >> >> 2) Reliability of each? >> >> 3) Useful external libraries for each? >> >> 4) Ease of installation/use on OS X? >> > > The answer to each of those questions points to Tkinter. It comes > with Python by default (the least installation hassles of any > toolkit), is pretty reliable, has a reasonably Pythonic interface, and > I don't understand the question about external libraries. > > However, Tkinter not most people's favorite, because the widgets look > crude, they don't resemble the native widgets of any popular platform, > and the widget set is somewhat limited. > > That suggests you're not asking the right questions. > > I use Tkinter because the Python gui's I've built so far have been for > straightforward functionality purposes without being fancy. However, > if I were doing something for wide distribution and wanted it to look > sharp, at this point I think I'd go for PyGtk despite the preference > of many for wxpython. > > Finally, don't overlook the possibility of embedding a basic web > server in your app, and having the user communicate with it through a > web browser. That turns HTML into your gui, which is very easy to > program. It also lets you easily handle remote clients, multiple > concurrent clients, etc, and gives users a familiar and intuitive > interface. > -- > http://mail.python.org/mailman/listinfo/python-list > From gandalf at designaproduct.biz Wed Oct 12 06:37:06 2005 From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy) Date: Wed, 12 Oct 2005 12:37:06 +0200 Subject: Need a spider library Message-ID: <434CE752.8030509@designaproduct.biz> Hi All, I'm writting a spider program. I need to go to serveral URLs and extract information from the HTML source. Including links. I was using FancyURLOpener and my own function that extracts the links from a HTML page. The problem is that I always need to change it. This is because some sites use lower case tag names, others upper case tag names. Some of them use href="page.html" others do it without the quotation href=page.html but I could even find unclosed quotations References: <312cfe2b0510261507m2732e947p2be6fdae99a7c3d7@mail.gmail.com> <312cfe2b0510270757o51d3cfa7h2fccc775068b5549@mail.gmail.com> <8c7f10c60510270806y65510087t@mail.gmail.com> <312cfe2b0510270931r52a18d0em29168b9702d2c748@mail.gmail.com> <20051027174139.GC2575@kitchen.client.attbi.com> <312cfe2b0510271100y32f6163es8a27524ccc37747c@mail.gmail.com> <1130436984.22172.28.camel@dot.uniqsys.com> Message-ID: Carsten Haese wrote: > On Thu, 2005-10-27 at 14:00, Gregory Pi?ero wrote: > >>Not quite because if something(3) fails, I still want something(4) to >>run. > > > def something_ignore_exceptions(x): > try: something(x) > except: pass > > something_ignore_exceptions(1) > something_ignore_exceptions(2) > # etc... Then the obvious extension: for i in range(20): ... but I get the idea that Gregory was thinking of different statements rather than calls to the same function with different arguments. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From quiteblack at gmail.com Wed Oct 12 10:05:20 2005 From: quiteblack at gmail.com (black) Date: 12 Oct 2005 07:05:20 -0700 Subject: can we save print msg into a file when script running ? In-Reply-To: References: <1129079641.137785.320000@g44g2000cwa.googlegroups.com> Message-ID: <1129125919.957270.308200@g49g2000cwa.googlegroups.com> unluckly i am with windows, anyway tks ! From steve at REMOVETHIScyber.com.au Fri Oct 28 19:50:29 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sat, 29 Oct 2005 09:50:29 +1000 Subject: Newbie question: string replace References: <1130258229.662596.228630@g49g2000cwa.googlegroups.com> <3s7620FlqdmnU1@uni-berlin.de> <1130521026.584455.288370@g44g2000cwa.googlegroups.com> <86slule9vy.fsf@bhuda.mired.org> <1130527656.685340.235470@g44g2000cwa.googlegroups.com> Message-ID: On Fri, 28 Oct 2005 12:27:36 -0700, usgog at yahoo.com wrote: > hm...Is there a way to get rid of the newline in "print"? Yes, by using another language *wink* Or, instead of using print, use sys.stdout.write(). -- Steven. From my_email_is_posted_on_my_website at munged.invalid Sun Oct 9 16:58:38 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sun, 09 Oct 2005 20:58:38 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <868xx3m2ve.fsf@bhuda.mired.org> Message-ID: On Sun, 09 Oct 2005 05:55:01 -0400, Mike Meyer wrote or quoted : >Actually, you present a design that forces a solution that makes them >do what you want down their throats, never mind what they want, or >what they've been doing. It shows an amazing ignorance about the >internet and how people behave on it. Like most antispam proposals, it >won't actually stop spam, just force spammers to concentrate on >different channels. You seem to have randomly broken quoting for >people who download mail and read it offline, and for any medium >that's unreliable or doesn't reliably deliver messages "in order" - >which includes mail and news. Virus writers will love the ability to >change peoples address books remotely. The problem of differing >character sets is technically solved. Practically, the solution >doesn't work because people implementing the software ignore the >standards. What's your server going to do when it gets messages with >characters in them that aren't valid in the charset that it's declared >as being? Better yet, what's it going to do when the characters are >valid, but the declared charset isn't the one the author actually >used? You implementation sketch only covers the client talking to the >first server (in that it requires the client to encrypt a challange >phrase with the private key belonging the email id, which is >presumably what 2822 uses for the envelope sender). Most mail on the >internet goes through at least two servers, and news is much >worse. For instance, your messages apparently passed through 10 >servers getting to me. You really have to deal with store and forward, >or convince a large number of corporations that potentially hostile >users should be allowed to talk directly to their mail servers, which >isn't very likely. Kudos for recognizing that spam needs to be dealt >with by people with guns, but you lose half of them for making ISPS >liable for it. > >I also read the comment about wanting an automated "Ask them to run my >browser in my favorite configuration", which is equally naive. A lot >of sites have such cruft on them already. I find them funny - I surf >the web on three different platforms, none of them Windows. Any >pointer to download a new browser or plugin for Windows just impresses >me with the authors lack of skills. The only browser I know of that >runs on all three platforms is Opera, and it's something radically >different on one of the three. Even should you get the platform right, >almost nobody is going to bother upgrading following the download >links. The very small percentage of users who are real geeks will >silently thank you for the notice, and update their software. Most >users will ignore it so long as the page isn't obviously broken. For >those for whom it's broken, all but small percentage will simply find >some other site to visit. I'd suggest that anyone thinking about writing Your post brings up a meta-issue. How long should posts be? I note several schools of thought. There is the initial post, sort of a mini lecture on something covering perhaps 7 major points. Then you can have the theatre-critic style response where each person in turn goes through the 7 points saying when they think. Then they repeat the 7 points each commenting on what each of the others had to say on the seven points. etc. Then there is the conversational style where you discuss one major point at a time, perhaps with several threads, one for each point. These threads meander or split off themselves. My preference is to think of a post, other than perhaps the initial essay post, as like a paragraph. It should stick to one main idea. Seems to me google will have an easier time classifying posts if they don't cover too much ground. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From iddw at hotmail.com Fri Oct 7 17:35:41 2005 From: iddw at hotmail.com (Dave Hansen) Date: Fri, 07 Oct 2005 21:35:41 GMT Subject: dictionaries/pointers References: <1128720229.615202.4670@g47g2000cwa.googlegroups.com> Message-ID: <1128720944.14f3466d6f1e5fc332c4958f1db59251@teranews> On 7 Oct 2005 14:23:49 -0700, "Rob Conner" wrote: >I dont know how to do this and can't think of a simple way to. > >All I want is a dictionary where two keys point to the same object. >(to steal the ascii art from >http://starship.python.net/crew/mwh/hacks/objectthink.html) >I want sometihng like this: > >,------. +-------+ >| dict |------>|+-----+| +---+ >`------' || "a" |+---->| 1 | > |+-----+| +---+ > | | ^ > |+-----+| | > || "b" |+-------' > |+-----+| > +-------+ > | | > |+-----+| +---+ > || "c" |+---->| 2 | > |+-----+| +---+ > +-------+ > >Where if I change "a" or "b" to 3 the other one will change? >Is this even possible? How would I do it? A simple, ugly answer: Use a mutable object rather than a plain integer. Example: >>> elt = [1] >>> dict = {"a":elt, "b":elt, "c":[2]} >>> print dict {'a': [1], 'c': [2], 'b': [1]} >>> dict["a"][0] = 3 >>> print dict {'a': [3], 'c': [2], 'b': [3]} >>> Regards, -=Dave -- Change is inevitable, progress is not. From jason.lai at gmail.com Thu Oct 20 05:00:55 2005 From: jason.lai at gmail.com (Jason Lai) Date: 20 Oct 2005 02:00:55 -0700 Subject: How can I call a subclass method from parent class ? In-Reply-To: <1129780540.378921.269250@g43g2000cwa.googlegroups.com> References: <1129780540.378921.269250@g43g2000cwa.googlegroups.com> Message-ID: <1129798854.968065.99860@g47g2000cwa.googlegroups.com> If you use a newstyle class, e.g. class A(object), then you can get the superclass with cls.__base__. You could also use super(cls,cls), although note that it returns a object that isn't exactly the same thing as a class -- but good enough for just accessing attributes. Make sure to check that your superclass isn't , otherwise it'll complain about not having a foo attribute. __base__ is probably easier for this purpose. Also be careful with multiple inheritance. No such thing as __super though. From http Mon Oct 3 03:38:22 2005 From: http (Paul Rubin) Date: 03 Oct 2005 00:38:22 -0700 Subject: Will python never intend to support private, protected and public? References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xd5mstqab.fsf@ruckus.brouhaha.com> <7xzmpwuxd0.fsf@ruckus.brouhaha.com> <20050930075313.67b9b676.jk@ospaz.ru> <7xbr2a6dlz.fsf@ruckus.brouhaha.com> <7xk6gyoibc.fsf@ruckus.brouhaha.com> <433f56a3.2969039483@news.oz.net> <1128274267.064255.306980@f14g2000cwb.googlegroups.com> <7x8xxbgj4h.fsf@ruckus.brouhaha.com> Message-ID: <7xslvj3v9t.fsf@ruckus.brouhaha.com> Paul Rubin writes: > def countdown(): > n = 3 > while n > 0: > yield n Bah, ommitted a line: def countdown(): n = 3 while n > 0: yield n n -= 1 From fredrik at pythonware.com Tue Oct 4 09:24:20 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 4 Oct 2005 15:24:20 +0200 Subject: Dynamical loading of modules References: <43418BF5.90504@gmail.com> <1128372108.4070.31.camel@dot.uniqsys.com> <1128372287.4070.33.camel@dot.uniqsys.com> <1128428782.4070.42.camel@dot.uniqsys.com><43427640.3010707@holdenweb.com><1128430810.4070.55.camel@dot.uniqsys.com> <43427D77.7020503@holdenweb.com> Message-ID: > (is 295 angle brackets in a single message perhaps some kind of c.l.py record?) oh, nevermind. From rrr at ronadam.com Wed Oct 19 16:28:19 2005 From: rrr at ronadam.com (Ron Adam) Date: Wed, 19 Oct 2005 20:28:19 GMT Subject: multi-property groups? Message-ID: I was trying to see if I can implement property groups so I can set and pass arguemts as dictionaries. I think this will simplify interfacing to multiple objects and funtions that use a lot of keywords as arguments. But so far, the the following seems like it's not the most efficient way to do it. So is there a better way? Is there a way to use properties to do this same thing? I'd also like a way to override the dictionary methods __getitem__, __setitem__, and __delitem__. (Or an equivalent) Cheers, Ron class Pobject(object): """ an objects class that can have property groups """ __props__ = {} def Properties(self, *args): dct = {} for i in args[1:]: dct.setdefault(i,None) self.__props__[args[0]]=dct return dct def __getattr__(self, name): for dct in self.__props__: if name in self.__props__[dct]: return self.__props__[dct].__getitem__(name) return self.__dict__[name] def __setattr__(self, name, value): for dct in self.__props__: if name in self.__props__[dct]: self.__props__[dct].__setitem__(name,value) return self.__dict__[name] = value class shapes(Pobject): def __init__(self): self.A = self.Properties('A', 'square', 'triangle', 'cube') self.B = self.Properties('B', 'red', 'blue', 'green') def show(self, it): if it == 'shapes': self.pp(it, self.A) # pass properties as groups! elif it == 'colors': self.pp(it, self.B) # have several property groups! else: print "I have no %s.\n" % it def pp(self, it, obj): print '%s I have:' % it for item in obj.keys(): print ' %s = %r' % (item,obj[item]) print box = shapes() box.square = 10 box.blue = 5 print box.square print box.blue print box.green box.purple = 'violet' print box.purple print box.show('shapes') box.show('colors') box.show('flowers') 10 5 None violet shapes I have: cube = None square = 10 triangle = None colors I have: blue = 5 green = None red = None I have no flowers. From alainpoint at yahoo.fr Fri Oct 7 11:35:38 2005 From: alainpoint at yahoo.fr (alainpoint at yahoo.fr) Date: 7 Oct 2005 08:35:38 -0700 Subject: Python interpreter bug References: <1128686833.994339.295780@f14g2000cwb.googlegroups.com> <1128695602.718637.144720@g43g2000cwa.googlegroups.com> Message-ID: <1128699338.667416.56250@o13g2000cwo.googlegroups.com> No doubt you're right but common sense dictates that membership testing would test identity not equality. This is one of the rare occasions where Python defeats my common sense ;-( Alain From nothingcanfulfill at gmail.com Tue Oct 4 16:06:45 2005 From: nothingcanfulfill at gmail.com (ncf) Date: 4 Oct 2005 13:06:45 -0700 Subject: how to get any available port In-Reply-To: References: Message-ID: <1128456405.664869.170530@g47g2000cwa.googlegroups.com> Hmm...perhaps he is trying to do a transfer thing like many chat programs do. Instead of sending large files across a server, you "Direct Connect" and send the file directly. :shrugs: From whzhao at gmail.com Wed Oct 5 05:17:47 2005 From: whzhao at gmail.com (Wenhua Zhao) Date: Wed, 05 Oct 2005 17:17:47 +0800 Subject: Does python support the expression "a = b | 1"??? Message-ID: a = b | 1 a = b if b != nil else a =1 Is there such expression in python? Thanks a lot! From m.barenco at gmail.com Tue Oct 11 14:06:32 2005 From: m.barenco at gmail.com (m.barenco at gmail.com) Date: 11 Oct 2005 11:06:32 -0700 Subject: dictionnaries and lookup tables Message-ID: <1129053992.141269.149840@z14g2000cwz.googlegroups.com> Hello, I am considering using dictionnaries as lookup tables e.g. >>>D={0.5:3.9,1.5:4.2,6.5:3} and I would like to have a dictionnary method returning the key and item of the dictionnary whose key is smaller than the input of the method (or <=,>,>=) but maximal (resp. maximal,minimal,minimal) eg.: >>>D.smaller(3.0) (1.5,4.2) >>>D.smaller(11.0) (6.5,3) >>>D.smaller(-1.0) None (or some error message) Now, I know that dictionnaries are stored in a non-ordered fashion in python but they are so efficient in recovering values (at least wrt lists) that it suggests me that internally there is some ordering. I might be totally wrong because I don't know how the hashing is really done. Of course I would use such methods in much larger tables. So is this possible or should I stick to my own class with O(log2(N)) recovery time? Note that when I type: >>>dir(D) ['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__str__', 'clear', 'copy', 'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values'] the functions __ge__, __gt__, __lt__, __le__ seem to be non-implemented but there is some __doc__ in them. Is there the intention to do something similar as is described above or are they here for some (future) dictionnary comparison purposes? Thanks a lot! Martino From sszmidt at netwvcom.com Mon Oct 3 19:59:22 2005 From: sszmidt at netwvcom.com (sszmidt at netwvcom.com) Date: Mon, 3 Oct 2005 19:59:22 -0400 Subject: Python Debug Build In-Reply-To: References: <20051003210217.88812.qmail@web30614.mail.mud.yahoo.com> Message-ID: <200510031959.22492.sszmidt@netwvcom.com> On Monday 03 October 2005 17:41, Steve Holden wrote: > Celine & Dave wrote: > > Hi, > > > > What happens if I build Python with debug option > > (--with-pydebug)? Do I see any changes in my program > > output? What is --with-pydebug good for? > > It's used for debugging the Python interpreter itself. And if I recall correctly from the documentation, it will also run a bit slower. But verify that ... -- Steve From sigzero at gmail.com Tue Oct 18 19:46:23 2005 From: sigzero at gmail.com (Robert Hicks) Date: 18 Oct 2005 16:46:23 -0700 Subject: Dealing with Excel In-Reply-To: References: <1129670191.061006.146320@g47g2000cwa.googlegroups.com> Message-ID: <1129679183.469734.151920@f14g2000cwb.googlegroups.com> No, I have to format fields and everything sad to say. Another poster up the chain of this posting gave me the nudge in the direction I needed. Thanks all, Robert From aleaxit at yahoo.com Mon Oct 17 04:35:33 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 17 Oct 2005 10:35:33 +0200 Subject: Queue question References: <1129413036.271162.279880@g43g2000cwa.googlegroups.com> <1129419092.954592.59630@z14g2000cwz.googlegroups.com> Message-ID: <1h4knxw.1s6kxw4l9w7yN%aleaxit@yahoo.com> Steve M wrote: > According to my "Python in a Nutshell": > > q.get(block=True) > > is the signature, so, as you use it above, the call will hang until > something is on the queue. If block is false and the queue is empty, > q.get() will raise the exception Empty. > > q.get_nowait is apparently synonymous with q.get(block=False) Yep. Nowadays you can also have an optional timeout= argument to the .get method, to obtain the Empty exception only after the get attempt has waited for some time for some item to arrive. > q.not_empty, if it existed, I expect would be true just in case there > was at least one item in the queue. But according to my book there is > q.empty and q.full, which is true when the queue has the maximum > allowed number of items (a value specified when the queue is created). not_empty and not_full are not methods but rather instances of the threading.Condition class, which gets waited on and notified appropriately. I'm not entirely sure exactly WHAT one is supposed to do with the Condition instances in question (I'm sure there is some design intent there, because their names indicate they're public); presumably, like for the Lock instance named 'mutex', they can be used in subclasses that do particularly fiendish things... but I keep planning not to cover them in the 2nd edition of the Nutshell (though there I _will_ cover the idea of subclassing Queue to implement queueing disciplines other than FIFO without needing to worry about synchronization, which I had skipped in the 1st edition). > Also, I don't think you can rely on q.empty in the way you may expect. > For example, another thread can empty the queue between the time you > test whether q.empty is false and the time you call q.get. Absolutely true. "Anything can happen" right after you call q.empty(), so the existence of that method isn't a good idea (it's somewhat of an "attractive nuisance" -- its existence prompts some programmers who don't read docs to try and use it, possibly producing unreliable code which works when tested but silently breaks in real-life use). Alex From ron at vnetworx.net Mon Oct 17 11:32:51 2005 From: ron at vnetworx.net (Ron Guerin) Date: Mon, 17 Oct 2005 11:32:51 -0400 Subject: NYLUG meeting: 10/26 The Python Object Model with Alex Martelli & Google (open bar and food!) Message-ID: <4353C423.6080605@vnetworx.net> (date and time inadvertently omitted last time. sorry!) The New York Linux User's Group invites you to a special presentation by Alex Martelli of Google, on the Python Object Model. This presentation will be held at P.J. Clarke's Sidecar, rather than our usual location, and Google is picking up the tab for an hour and a half of open bar and food. Additionally, if you're looking for a job as a Python developer, bring your resume. Please RSVP at http://rsvp.nylug.org to attend, as seating is limited. PS: You may wish to bring ID and a GPG fingerprint for keysigning. - Ron (announcement follows) The New York Linux User's Group Presents Alex Martelli - on - The Python Object Model Held at P.J. Clarke's Sidecar October 26, 2005 6:00pm-10:00pm 915 Third Avenue @ 55th Street - NY Python is a multi-paradigm programming language, but, out of the paradigms it supports, there is no doubt that OOP (Object Oriented Programming) is the paradigm that forms Python's core. If you have done any substantial programming with Python, you have, most likely, used some of its OOP features. But -- have you ever stopped to really think about those OOP features, the mechanisms that Python uses (and exposes!) to implement them, and how best to make use of the possibilities this state of things offers? This subject is generally known as the "Object Model" of a language. This talk stops a bit short of examining every level of Python's Object Model -- in particular, it does not get into metatypes (metaclasses) and similar levels of "Black Magic". Rather, the talk sticks to the most practically interesting aspects of Python's Object Model as seen from the point of view of a programmer using Python -- understanding exactly what's going on in all kind of everyday OOP-usage situation, what alternatives and trade-offs these mechanisms imply (for example, when should you use closures, and when should you use functors instead? when to inherit, and when to delegate instead?), and how Design Patterns play into the mix (Python subsumes and build-ins some classic DPs, and makes a few others irrelevant due to its highly dynamic typing, but other classic DPs yet remain extremely relevant and important for optimal day to day use of OOP in Python). About Alex Martelli ------------------- Alex Martelli is Uber Technical Lead at Google, in Production Software. He wrote Python in a Nutshell and co-edited the Python Cookbook, and is a member of the Python Software Foundation. Before joining Google, Martelli spent 8 years with IBM, 12 with think3 inc, and 3 as a Python freelance consultant, mostly for AB Strakt (Sweden). P. J. Clarke's Sidecar ---------------------- 915 Third Avenue @ 55th Street - NY Sidecar is PJ Clarkes handsome semiprivate upstairs dining room. You enter Sidecar through a distinct yet discreet door on East 55th Street. Subway: Take the E, V or 6 Subways to 51st Street, cut over to Third Avenue and walk north 4 blocks. Take the 4, 5 or 6 Trains to 59th Street, cut over to Third and walk 4 blocks south. Bus: Take the 101, 102 or 103 Buses to 55th. If you're coming downtown on Lexington, cut across to Third. If you're coming up on Third, it's right across the street. http://pjclarkes.com/htm/sidecar.htm About NYLUG ----------- NYLUG is the New York Linux Users Group, which has met every month without fail for the last six years. Meetings are free and open to the public, but require advance RSVP due to fire code and security requirements at our usual meeting space at the IBM Building. Our announcements mailing list at http://nylug.org/mailman/listinfo/nylug-announce provides a low-volume but steady stream of Linux, Free and Open Source, and related community and other user group announcements for the tri-state area. Our technical discussion list is a moderate-volume list featuring a diverse group that from home users to enterprise security experts. http://nylug.org/mailman/listinfo/nylug-talk http://www.nylug.org/ From codecraig at gmail.com Wed Oct 26 07:49:20 2005 From: codecraig at gmail.com (jas) Date: 26 Oct 2005 04:49:20 -0700 Subject: Client/Server socket send user input In-Reply-To: References: <1130256091.162014.12570@z14g2000cwz.googlegroups.com> <1130269146.851225.201320@g44g2000cwa.googlegroups.com> Message-ID: <1130327360.059626.198170@g44g2000cwa.googlegroups.com> Dennis, Thanks. That certainly looks like it could work. I understand about the interactive shell and my app going back and forth with the reads/writes. When my program runs it won't be used in an interactive python shell, but that is the only way I know of to really test it. From steve at REMOVETHIScyber.com.au Sat Oct 22 21:56:00 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 23 Oct 2005 11:56:00 +1000 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <86k6g59ke6.fsf@bhuda.mired.org> Message-ID: On Sat, 22 Oct 2005 18:02:44 -0700, David Schwartz wrote: > I see you are a totalitarianist or perhaps a communist. If you want to > live in America and discuss things that are relevent to America, let me > know. In other words, "why don't you go back to Russia, you commie pinko fascist Jew Nazi". Mike Meyer has got just as much right to live in America as David Schwartz. Nice to see how quickly Americans' supposed love of freedom disappears once they are exposed to views that contradict their own. -- Steven. From grante at visi.com Tue Oct 25 11:52:00 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 25 Oct 2005 15:52:00 -0000 Subject: need some advice on x y plot References: <1129823043.104864.73750@f14g2000cwb.googlegroups.com> <1130253519.330211.92880@o13g2000cwo.googlegroups.com> Message-ID: <11lsl50soghlt8f@corp.supernews.com> On 2005-10-25, nephish at xit.net wrote: > Ok, first off, thanks for all the help guys, > > this part "set xtics ("label" pos, "label" pos, "label" pos)" > is mainly what i was confused about. the 'pos' part. i think > that the way i am writing this leaves this out. in fact, i am > pretty sure. Yup, it looks like it. > here is the code i am trying out. [Another hint: when posting code, don't wrap it. It won't run as it was posted, and people aren't generally going to be willing to go through and un-wrap the lines in order to try it.] > gnuplot> set title "testing" > gnuplot> set term png > gnuplot> set out "/home/piv/PivData/tmp/images/graph.png" > gnuplot> set xtics (['10/18 09:54', '10/17 22:42', '10/17 11:30', > '10/17 00:18', '10/16 13:06', '10/16 01:54', '10/15 14:42', '10/15 > 03:30', '10/14 16:18', '10/14 05:06', '10/13 17:54', '10/13 06:42', > '10/12 19:30', '10/12 08:18', '10/25 09:54']) OK, You need to get rid of the sqare brackets, and you need an x-position value after each of the strings. > i noticed in the docs for gnuplot, that it can do date/time > and by default uses seconds since 2000. and then you can pass > the format that you want to show it in. would this give the > same kind of result that i am looking for ? It looks like it. Though I've used custom tics in the past, it was never for time values. Based on the help from gnuplot, I suspect you can get what you want without doing custom tics, but rather using the commands set xdata time set timefmt set format x Interestingly, using Unix timestamps creates some sort of resolution problems. The following ought to work but doesn't. It appears that there is some sort of resolution problem: ------------------------------8<------------------------------ import Gnuplot,time,sys,math def pause(): sys.stdout.write("Press enter to continue: ") sys.stdin.readline() def fgrid(start,stop,count): for i in xrange(count): yield start + ((stop-start)*i)/count start = time.time() xdata = [x for x in fgrid(0,600.0,10)] # two minutes worth ydata = [math.sin(x/100.0) for x in xdata] data = Gnuplot.Data(xdata,ydata,with='linespoints',using=(1,2)) gp = Gnuplot.Gnuplot(debug=1) gp.title('Data starting at %s' % time.asctime(time.gmtime(start+xdata[0]))) # x axis will use default tics (seconds since start of run) gp.plot(data) pause() # same data with x value as Unix timestamps xdata = [x+start for x in xdata] print xdata data = Gnuplot.Data(xdata,ydata,with='linespoints',using=(1,2)) gp('set xdata time') gp('set timefmt "%s') gp('set format x "%r"') gp('set xtics 120') gp.plot(data) pause() ------------------------------8<------------------------------ -- Grant Edwards grante Yow! LOOK!!! I'm WALKING at in my SLEEP again!! visi.com From ajsiegel at optonline.net Fri Oct 21 11:46:49 2005 From: ajsiegel at optonline.net (Arthur) Date: Fri, 21 Oct 2005 11:46:49 -0400 Subject: coloring a complex number Message-ID: <43590D69.8010008@optonline.com> Spending the morning avoiding responsibilities, and seeing what it would take to color some complex numbers. class color_complex(complex): def __init__(self,*args,**kws): complex.__init__(*args) self.color=kws.get('color', 'BLUE') >>> a=color_complex(1,7) >>> print a (1+7j) #good so far >>> a=color_complex(1,7,color='BLUE') Traceback (most recent call last): File "", line 1, in -toplevel- a=color_complex(1,7,color='BLUE') TypeError: 'color' is an invalid keyword argument for this function No good... it seems that I am actually subclassing the built_in function 'complex' when I am hoping to have been subclassing the built_in numeric type - complex. but some googling sends me to lib/test/test_descr.py where there a working subclass of complex more in accordance with my intentions. class color_complex(complex): def __new__(cls,*args,**kws): result = complex.__new__(cls, *args) result.color = kws.get('color', 'BLUE') return result >>> a=color_complex(1,7,color='BLUE') >>> print a (1+7j) >>> print a.color BLUE which is very good. But on the chance that I end up pursuing this road, it would be good if I understood what I just did. It would certainly help with my documentation ;) Assistance appreciated. NOTE: The importance of the asset of the depth and breadth of Python archives - for learning (and teaching) and real world production - should not be underestimated, IMO. I could be confident if there was an answer to getting the functionality I was looking for as above, it would be found easily enough by a google search. It is only with the major technologies that one can hope to pose a question of almost any kind to google and get the kind of relevant hits one gets when doing a Python related search. Python is certainly a major technology, in that respect. As these archives serve as an extension to the documentation, the body of Python documentation is beyond any normal expectation. True, this asset is generally better for answers than explanations. I got the answer I needed. Pursuing here some explanation of that answer. Art From codecraig at gmail.com Tue Oct 4 16:28:09 2005 From: codecraig at gmail.com (Java and Swing) Date: 4 Oct 2005 13:28:09 -0700 Subject: Call C functions from Python In-Reply-To: <11k5mpg999eos1f@corp.supernews.com> References: <1128454231.381256.297280@g47g2000cwa.googlegroups.com> <11k5mpg999eos1f@corp.supernews.com> Message-ID: <1128457689.105158.24700@g44g2000cwa.googlegroups.com> ok i got ctypes...now i try >> from ctypes import * >> myApp = CDLL("C:\\myapp.dll") ..now how can I call functions on in myapp.dll? From the tutorial I am not sure..i try, dir(cdll.myApp) and dir(myApp)..but don't see my functions listed. thanks Grant Edwards wrote: > On 2005-10-04, Java and Swing wrote: > > > Is there some other way, besides SWIG, which will allow me to call > > functions inside an Ansi C DLL? > > ctypes > > -- > Grant Edwards grante Yow! Now KEN and BARBIE > at are PERMANENTLY ADDICTED to > visi.com MIND-ALTERING DRUGS... From sybrenUSE at YOURthirdtower.com.imagination Fri Oct 21 03:36:47 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Fri, 21 Oct 2005 09:36:47 +0200 Subject: Set an environment variable References: <43573022$0$155$edfadb0f@dread16.news.tele.dk> <1129798724.366618.194650@g44g2000cwa.googlegroups.com> <86k6g8uosa.fsf@bhuda.mired.org> Message-ID: Mike Meyer enlightened us with: > It's simpler to use eval and command substitution: > > eval $(python myScript.py) This looks like the best solution to me. 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 tengo at DELETEMEecc.lu Thu Oct 13 18:52:17 2005 From: tengo at DELETEMEecc.lu (Stefaan A Eeckels) Date: Fri, 14 Oct 2005 00:52:17 +0200 Subject: Jargons of Info Tech industry References: <1124804082_1011@spool6-east.superfeed.net> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <41hhk195gcipfarnqu85ggs606aqi89ea1@4ax.com> <20051010004218.03171fb6.tengo@DELETEMEecc.lu> Message-ID: <20051014005217.32b82c84.tengo@DELETEMEecc.lu> On Wed, 12 Oct 2005 22:04:14 GMT Roedy Green wrote: > On Mon, 10 Oct 2005 00:42:18 +0200, Stefaan A Eeckels > wrote or quoted : > > >"I don't understand that attitude. Don't we want email that has > > dancing bears, cute little videos, musical tunes, animated waving > > hands, sixty fonts, and looks like it's been done with crayolas? > > Good grief, man, think like a three year old!" > > that excuse could also be used to explain why you have not cracked a > book since high school. The same tools that create dancing bears can > do a UML diagram. Mine doesn't. Stick figures is as far as it'll go. Specific document formats can be attached to an email without any problems. When exact rendering is important, the appropriate format (e.g. PDF) can be used. Only a fool would want his email program to render a UML diagram (which is far more than a cute drawing done in Visio, in case you hadn't noticed). -- Stefaan -- As complexity rises, precise statements lose meaning, and meaningful statements lose precision. -- Lotfi Zadeh From durumdara at mailpont.hu Thu Oct 6 03:33:39 2005 From: durumdara at mailpont.hu (durumdara at mailpont.hu) Date: Thu, 6 Oct 2005 09:33:39 +0200 (CEST) Subject: Copy files to Linux server through ssh tunnel Message-ID: <43278.195.228.229.142.1128584019.squirrel@195.228.229.142> Hi ! I have some backup files on a server farm. I want to store these local backup files on a backup file server for "safety's snake". These files are compressed zip files with 12 character length password. But my system admin asked me, how can I improve the safety of the copy operation, and the storing (now I use Samba share to store these files. I map the SMB share on the client, copy these files, and unmap SMB). Then I thinking to ssh protocol to improve protection. The backup script is a py script. I see that Winscp can copy files through ssh tunnel. Can I do it too ? How ? How to I do it in pythonic way ? Please help me with some examples or urls or other infos ! Thanks * 1000: dd ---------------------------------------------- 1 Gbyte Ingyenes E-Mail T?rhely a MailPont-t?l http://www.mailpont.hu/ From davids at webmaster.com Wed Oct 26 22:51:53 2005 From: davids at webmaster.com (David Schwartz) Date: Wed, 26 Oct 2005 19:51:53 -0700 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <3s6l8mFmj3fjU1@individual.net> <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> <58j533-40o.ln1@news.it.uc3m.es> Message-ID: Peter T. Breuer wrote: > In comp.os.linux.misc David Schwartz wrote: >> . Microsoft said you can sell Windows >> and other operating systems, but there will be a charge for every >> machine you sell without Windows -- if you want to be able to buy >> Windows wholesale. Someone could comply with this by not selling any >> other operating systems at all and never pay the fee. Therefore, >> this is a lesser restriction than saying you can only sell Windows >> wholesale if you don't sell or offer any competing systems. > No - you claim that allowing somebody (by contract?) to do Z at a > penalty is "lesser" than disallowing them from doing Z. Sorry - both > are equal in market economics (where the financial imperatve rules). Umm, no it's lesser in a strictly logical sense. > Indeed, no contract can "disallow" somebody from doing Z - you are > always at liberty to break a contract! (See the RH Enterprise licence > as an example of a contract that you are at liberty to break by > copying RHE to more machines at the penalty of losing RH maintenance > support- I recently had this argument with Rick Moen). The penalty > for doing so is what is at issue. > > So your definitions are anyway without semantic content, and hence the > argument cannot proceed. My argument proceeds exactly the same if they're equal as if they're lesser. It is totally not dependent upon how much lesser it is. > And even if the argument were too proceed, your use of "lesser" would > fail, because it appears to mean "is a (proper) subset of the ways > that" without having established what different (i.e. same) means, and > I'd submit that there is no diffence between the elements you exhibit > in the setting of market regulation law. My argument proceeds the same if they're equivalent. (Did you read it?!) DS From jstroud at mbi.ucla.edu Tue Oct 18 17:28:22 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Tue, 18 Oct 2005 14:28:22 -0700 Subject: Intersection of lists/sets -- with a catch Message-ID: <200510181428.22646.jstroud@mbi.ucla.edu> Hello All, I find myself in this situation from time to time: I want to compare two lists of arbitrary objects and (1) find those unique to the first list, (2) find those unique to the second list, (3) find those that overlap. But here is the catch: comparison is not straight-forward. For example, I will want to compare 2 objects based on a set of common attributes. These two objects need not be members of the same class, etc. A function might help to illustrate: def test_elements(element1, element2): """ Returns bool. """ # any evaluation can follow return (element1.att_a == element2.att_a) and \ (element1.att_b == element2.att_b) So my very naieve solution usually bears resemblance to the following code (made inelegant by the irritating necessity to keep track of a counter): for some_element in some_list: i = 0 while i < len(another_list): another_element = another_list[i] overlap = test_elements(some_element, another_element) if overlap: store_overlap(some_element, another_element) # speed-up, same as i+=1 another_list.pop(i) break else: i += 1 if not overlap: store_unique_some(some_element) After this loop, "identical" elements (according to the evaluation criteria) from the two lists are stored somewhere, elements unique to 'some_list' are stored somewhere else, and 'another_list' has only elements originally unique to itself according to the evaluation criteria remaining. Of course this code assumes that both original lists contained only unique elements within themselves and were previously sorted based on the evaluation criteria (to speed-up the loop). So, one improvement I can think of is to use an iterator for the inner loop: for some_element in some_list: for another_element in another_list: overlap = test_elements(some_element, another_element) if overlap: store_overlap(some_element,another_element) # big problem here -- iterator gets lost another_list.remove(another_element) break if not overlap: unique_some.append(some_element) But the problem is obvious, the iterator becomes out of sync with 'another_list'. An example can illustrate: py> alist = [1,2,3,4] py> for el in alist: ... print el ... if el == 3: ... alist.remove(el) ... 1 2 3 py> alist [1, 2, 4] So, a question would be how one might "correct" the iterator in this situation. Inspecting dir(iter) provides no clues as to the identity of an iterator's internal counter. Its probably obvious to everyone that this type of task seems perfect for sets. However, it does not seem that sets can be used in the following way, using a hypothetical "comparator" function. The "comparator" would be analagous to a function passed to the list.sort() method. Such a device would crush the previous code to the following very straight-forward statements: some_set = Set(some_list, comparator=test_elements) another_set = Set(another_list, comparator=test_elements) overlaps = some_set.intersection(another_set) unique_some = some_set.difference(another_set) unique_another = another_set.difference(some_set) I am under the personal opinion that such a modification to the set type would make it vastly more flexible, if it does not already have this ability. Any thoughts on how I might accomplish either technique or any thoughts on how to make my code more straightforward would be greatly appreciated. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From fredrik at pythonware.com Sat Oct 8 07:56:43 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 8 Oct 2005 13:56:43 +0200 Subject: noob question Letters in words? References: <1128735204.407666.193440@g14g2000cwa.googlegroups.com> Message-ID: (re that earlier thread, I think that everyone that thinks that it's a good thing that certain Python constructs makes grammatical sense in english should read the previous post carefully...) Rob Cowie wrote: > A string can be thought of as a tuple of characters. footnote: the correct python term is "sequence of characters". > Tuples support membership testing thus... > > choice1 = raw_input("> ") > > if '1' or 's' or 'S' in choice1: > #do something > elif '2' or 'e' or E' in choice1: > #do something > > It doesn't seem to me to be a good idea; If the input is 'Start', > option1 is executed, likewise if the input is 'Stop', or any other > string with 's' in it. in fact, the first choice is always executed, because if '1' or 's' or 'S' in choice1: ... might look as if it meant if ('1' in choice1) or ('s' in choice1) or ('S' in choice1): ... but it really means if ('1') or ('s') or ('S' in choice1): ... since non-empty strings are true, the '1' will make sure that the entire expression is always true, no matter what choice1 contains. > Perhaps a better idea is to present the user with a choice that cannot > be deviated from, along the lines of... > > def main(): > print "1.\tStart" > print "2.\tSomething Else" > print "3.\tStop" > > x = raw_input() > if x is '1': print 'Start' > elif x is '2': print 'Something else' > elif x is '3': print 'End' > else: main() The "is" operator tests for object identity, not equivalence. Nothing stops a Python implementation from creating *different* string objects with the same contents, so the above isn't guaranteed to work. (it does work on current CPython versions, but that's an implementation optimization, and not something you can rely on). You should always use "==" to test for equivalence (and you should never use "is" unless you know exactly what you're doing). From smcg4191zz at friizz.RimoovAllZZs.com Sun Oct 23 14:07:39 2005 From: smcg4191zz at friizz.RimoovAllZZs.com (Stuart McGraw) Date: Sun, 23 Oct 2005 12:07:39 -0600 Subject: wxpython - passing arg to wx.app OnInit References: <11lm687nih0l7ac@corp.supernews.com> <7pGdnfmqQoJJG8beRVn-iA@powergate.ca> Message-ID: <11lnkbipmbgl0d2@corp.supernews.com> "Peter Hansen" wrote in message news:7pGdnfmqQoJJG8beRVn-iA at powergate.ca... > Stuart McGraw wrote: > > I have a wxPython app, conventionally structured > > with a Application class derived from wx.App. > > My problem is that the app accepts a command > > line argument that must be acted upon within the > > OnInit() method of the Application class. How do > > I pass it cleanly from main() into app.OnInit()? In > > the simplified example below, dbfn is the piece of > > info that is in main() that OnInit() needs to use. > > Is a global variable is the only way? :-( > > There are various ways, but the simplest is to accept that sys.argv is > *already* a "global" and just to access it directly from the > Application's OnInit() method. > > This wiki page demonstrates: > http://wiki.wxpython.org/index.cgi/UsingCommandLineArguments > > -Peter I simplied the my code for posting. In my real program, the thing being passed is not a command line argument per se, but the result of signifigant processing dependent on the command line argument. I do not want to repeat that processing in the wx.App method. Would you elaborate on the other ways? From jeremy at emperorlinux.com Wed Oct 5 21:58:48 2005 From: jeremy at emperorlinux.com (Jeremy Moles) Date: Wed, 05 Oct 2005 21:58:48 -0400 Subject: Absolultely confused... Message-ID: <1128563928.3513.8.camel@localhost.localdomain> So, here is my relevant code: PyArg_ParseTuple(args, "O!", &PyType_vector3d, &arg1) And here ismy error message: argument 1 must be pylf.core.vector3d, not pylf.core.vector3d I know PyType_vector3d "works" (as I can use them in the interpreter all day long), and I know I'm passing a pylf.core.vector3d (well, apparently not...) I've spent hours and hours on this and I'm finally just giving up and asking. I've tried everything to get my program to verify that arg1 is really a PyType_vector3d, but to no avail. If I take out the "!" in the format string and just use "O", I can at least get past PyArg_ParseTuple. Then I try something like... PyObject_TypeCheck(arg1, &PyType_vector3d) Which also fails, but I know for a fact that arg1's PyObject_Repr is what it should be. (pylf.core.vector3d) I guess my question is: what in the world could be causing this to fail? It seems like I'm just not able to use ParseType or BuildValue to create objects of my own type. I know I haven't provided a lot of information, but does anyone have any ideas or where I should start looking? From python-url at phaseit.net Tue Oct 25 22:08:03 2005 From: python-url at phaseit.net (Cameron Laird) Date: Wed, 26 Oct 2005 02:08:03 GMT Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Oct 26) Message-ID: QOTW: "Using Unix for 20+ years probably warps one's perception of what's obvious and what isn't." -- Grant Edwards "... windoze users--despite their unfortunate ignorance, they are people too." -- James Stroud "The Widget Construction Kit (WCK) is an extension API that allows you to implement custom widgets in pure Python." A typical recent enhancemennt is slightly more efficient anti-aliased drawing under Windows: http://online.effbot.org/2005_10_01_archive.htm#20051022 Mike Meyer and others demonstrate the paranoia and propensity to abstraction of the experienced when thinking about something as simple as replacement of one string for another: http://groups.google.com/group/comp.lang.python/browse_thread/thread/98f0d93332748af9/ Similarly, Bengt Richter illustrates that "a month" is a far more complicated idea than first appears: http://groups.google.com/group/comp.lang.python/browse_thread/thread/68b08f36ca516aa2/ "The deadline for PyCon 2006 submissions is now only a week away." http://www.python.org/pycon/2006/cfp Is there a good way to manage Python installations on multiple (Windows) hosts? There are several: http://groups.google.com/group/comp.lang.python/browse_thread/thread/1343f89416f8f783/ ======================================================================== 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 There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. 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 jwkenne at attglobal.net Sat Oct 15 23:08:27 2005 From: jwkenne at attglobal.net (John W. Kennedy) Date: Sat, 15 Oct 2005 23:08:27 -0400 Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: Tim Roberts wrote: > "Jeroen Wenting" wrote: > >>Microsoft isn't evil, they're not a monopoly either. >>If they were a monopoly they'd have 100% of the market and there'd be no >>other software manufacturers at all. > > > This is wrong. The dictionary definition of a monopoly is when a > manufacturer has all or nearly all of a market. Microsoft DOES have a > monopoly on PC operating systems. > > That, in itself, is not necessarily illegal. However, Microsoft then USED > that monopoly power to stifle their competition, and that IS illegal. > > Part of their behavior really escape me. The whole thing about browser > wars confuses me. Web browsers represent a zero billion dollar a year > market. Why would you risk anything to own it? So they can disrupt standards and make it extremely difficult to create websites that work both with IE and with any non-Windows browser. The most blatant example is that, a full five years after XHTML came out, IE doesn't render it at all. A few years ago, they did the same thing with browser plugins. IE used to support the same plugins that Netscape did. Then MS arbitrarily designed a new way of doing plugins that can only work with Windows (and which, incidentally, opens security holes), and removed support for standard plugins. As a result, plugin makers have to support two different plugins, or else choose between compatibility with IE and compatibility with everybody else. The message -- "co-operate with us, or be punished". -- John W. Kennedy "...if you had to fall in love with someone who was evil, I can see why it was her." -- "Alias" From gc_nospam2004-allerlei at yahoo.de Fri Oct 28 07:49:20 2005 From: gc_nospam2004-allerlei at yahoo.de (Georg Christmann) Date: Fri, 28 Oct 2005 13:49:20 +0200 Subject: x-plat gui development question Mac OS X Message-ID: Hello everybody, I have recently started tinkering about with Python. If there are any Macintosh-based Python developers reading this newsgroup I would like to ask them one Macintosh-specific question: If you want to write GUI scripts on the Mac, say with Tkinter, you need to invoke "pythonw" instead of "python" and use "#! /usr/bin/pythonw" for a shebang line in your saved scripts. Of course, although a tiny problem, it is still less than welcome for cross-platform development. As one obvious workaround, would it cause any problems if I would link "/usr/bin/python/" to "/usr/bin/pythonw" instead of "/usr/bin/python2.3" (in other words I would always be using "pythonw", even for non-GUI scripts) ? So far I can't tell any difference in the interactive mode - invoking "pythonw" for non-GUI work seems to work just fine. I am not sure though if there are any system processes, say during boot-up, that depend on "python" pointing to the original location, or if there could be problems with more complex code than "Hello world". Any insights welcome Georg From steve at holdenweb.com Mon Oct 3 17:41:03 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 03 Oct 2005 22:41:03 +0100 Subject: Python Debug Build In-Reply-To: <20051003210217.88812.qmail@web30614.mail.mud.yahoo.com> References: <20051003210217.88812.qmail@web30614.mail.mud.yahoo.com> Message-ID: Celine & Dave wrote: > Hi, > > What happens if I build Python with debug option > (--with-pydebug)? Do I see any changes in my program > output? What is --with-pydebug good for? > It's used for debugging the Python interpreter itself. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From bobrien18 at yahoo.com Fri Oct 28 16:42:49 2005 From: bobrien18 at yahoo.com (KraftDiner) Date: 28 Oct 2005 13:42:49 -0700 Subject: How do I sort these? In-Reply-To: <3sfarbFnt8bvU1@uni-berlin.de> References: <1130524906.918612.38540@g49g2000cwa.googlegroups.com> <3sfarbFnt8bvU1@uni-berlin.de> Message-ID: <1130532169.033398.155010@g14g2000cwa.googlegroups.com> unzip doesn't seem to work for me... From webmaster at smallco.com Sat Oct 8 11:53:59 2005 From: webmaster at smallco.com (Webmaster) Date: Sat, 8 Oct 2005 11:53:59 -0400 (EDT) Subject: Automatic response to your mail (Error) Message-ID: The automatic reply to this e-mail which you should have received in response to your e-mail to webmaster at smallco.com has not been defined. Please contact postmaster at smallco.com for assistance. From larry.bates at websafe.com Thu Oct 13 16:56:36 2005 From: larry.bates at websafe.com (Larry Bates) Date: Thu, 13 Oct 2005 15:56:36 -0500 Subject: extract PDF pages In-Reply-To: References: Message-ID: <434ECA04.10604@websafe.com> I've used ReportLab's PageCatcher. It isn't free, but I've gladly paid for the functionality it gives me. Larry Bates http://www.reportlab.com/pagecatcher_index.html David Isaac wrote: > While pdftk is awesome > http://www.accesspdf.com/pdftk/ > I am looking for a Python solution. > Just for PDF page extraction. > Any hope? > > Thanks, > Alan Isaac > > From mwm at mired.org Fri Oct 21 15:34:35 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 21 Oct 2005 15:34:35 -0400 Subject: how to modify text in html form from python References: <0Ra6f.5050$q%.616@newssvr12.news.prodigy.com> Message-ID: <86d5lyu0j8.fsf@bhuda.mired.org> "Philippe C. Martin" writes: > PS: If my question is not clear, I am trying to "share" the form between the > client and server. Yes, your question is not clear. And this statement doesn't clarify it. That you quoted the "share" shows you are probably aware of this, if not consciously so. > just as many sites out there allow you to modify existing data: > 1) the server pops up a form with your data in it. > 2) the client can modify it and submit. This doesn't really help, either. The server can't "pop up" a form; only the client can do that. All the server can do is send data to the client. The client can't modify data on the server. It can send data to the server, but that arrives as *new* data. The server can use that to replace old data, thus modifying that old data. > I know this is a _basic_ question, sorry. It's not clear it's a basic question, because it's not clear what you're trying to do. Try answering these questions: Where do you expect the HTML to come from? Where do you expect the data originally in the HTML form to come from? Where do you expect the data the user inputs into the form to be stored? Philippe > > > > Philippe C. Martin wrote: > >> Hi, >> >> I am trying to change the data in a form field from python. The following >> code does not crash but has no effect as if "form" is just a copy of the >> original html form. >> >> Must I recreate the form order to do that ? >> >> My point is for the client to be able to re-read the modified data. >> >> >> Thanks, >> >> Philippe >> #!/usr/bin/python >> >> import cgi >> import os >> import sys >> import logging >> import cgi >> sys.stderr = sys.stdout >> print "Content-type: text/html\n" >> try: >> form = cgi.FieldStorage() >> #logging.warning (form) >> >> except: >> logging.exception("\nEXCEPTION 1") >> try: >> >> form['tosrv'].value = "TEST" >> except: >> logging.exception("\nEXCEPTION 2") >> pass >> >> >> >> Smart Logon >>

Smart Logon

>>
>>
>> >>
>> >> TO SERVER:
>> >>
>> FROM SERVER
>> >>

>> >> >>

>>
>> >> > -- Mike Meyer http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From john at castleamber.com Mon Oct 17 21:58:37 2005 From: john at castleamber.com (John Bokma) Date: 18 Oct 2005 01:58:37 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <%jV4f.3121$tV6.2659@newssvr27.news.prodigy.net> Message-ID: "Mike Schilling" wrote: > > "John Bokma" wrote in message > news:Xns96F2A7259B695castleamber at 130.133.1.4... >> "Mike Schilling" wrote: >> >>> "John Bokma" wrote in message >>> news:Xns96F1E4E128EA8castleamber at 130.133.1.4... >> >>>> Yup, but ISO C++ is a standard, and XML is a recommendation. >>> >>> And the practical difference between the two is.... >>> >>> That's right, nil. >> >> If you both read them as a collection of words, you're right. >> However, as a >> (freelance) programmer, things like this *do* make a difference to >> me, and my customers. > > That is, you assume that files claiming to contain XML documents may > actually contain some variant of XML, because that's only a > recommendation, while files claiming to contain C++ are all > ISO-conformant, because that's a standard? > > If so, you've got things precisely backwards. C++ compilers that > contain extensions or are not quite compliant are everywhere. XML > parsers that accept non-well-formed XML are, ASFAIK, non-existent. My goodness, re read that again please, and rethink what you really want to say. I mean "claiming to contain C++". Is that like: all files claiming to contain HTML are automatically conforming to the ISO HTML standard? -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From gordonb.u09l7 at burditt.org Tue Oct 4 13:57:13 2005 From: gordonb.u09l7 at burditt.org (Gordon Burditt) Date: Tue, 04 Oct 2005 17:57:13 -0000 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> Message-ID: <11k5gjpqkt7878b@corp.supernews.com> >>I think e-mail should be text only. > >I disagree. Your problem is spam, not HTML. Spam is associated with >HTML and people have in Pavlovian fashion come to hate HTML. > >But HTML is not the problem! HTML enables a heck of a lot of problems: "web bugs" in email, links to fake sites that appear as real ones in what shows up on the screen, Javascript viruses, denial-of-service attacks (pages that open two windows when you close one), etc. >That is like hating all choirs because televangelists use them. I liken it more to hating all viruses because some of them install keyloggers. Gordon L. Burditt From erniedude at gmail.com Wed Oct 26 10:44:54 2005 From: erniedude at gmail.com (Ernesto) Date: 26 Oct 2005 07:44:54 -0700 Subject: Execute C code through Python In-Reply-To: References: <1129844737.586396.61080@g47g2000cwa.googlegroups.com> <1129861083.010702.6770@g49g2000cwa.googlegroups.com> <1129906892.696582.288010@g43g2000cwa.googlegroups.com> <11li3b2hsa3lhb5@corp.supernews.com> <1130272231.210978.316140@g14g2000cwa.googlegroups.com> Message-ID: <1130337893.983691.185780@g44g2000cwa.googlegroups.com> Peter Hansen wrote: > > Google found the following (after I read the docs for subprocess and > learned about the "startupinfo" flag, and searched for "subprocess > startupinfo"). Does this help? > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/409002 > > -Peter Thanks Peter! That's exactly what I need. From david at jotax.com Wed Oct 26 09:17:15 2005 From: david at jotax.com (David Poundall) Date: 26 Oct 2005 06:17:15 -0700 Subject: How do I access the property info in this example ? Message-ID: <1130332635.319629.91900@o13g2000cwo.googlegroups.com> How do I access the property information in this example ? class C(object): def getx(self): return self.__x def setx(self, value): self.__x = value def delx(self): del self.__x x = property(getx, setx, delx, "I'm the 'x' property.") I would like to get at ... "I'm the 'x' property." ... if at all possible. TIA From mwm at mired.org Mon Oct 17 18:28:34 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 17 Oct 2005 18:28:34 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: <86fyqzzskt.fsf@bhuda.mired.org> "Mike Schilling" writes: > What matters in generating HTML is which browsers you want to support and > what they understand. Standards and recommendations are both irrelevant. Unless, of course, you want to support any compliant browser. In which case standards and recommendations are the only things that are relevant. Pages on the internet written for a specific browser are part of the harm that NS did the community when the ignored the standards process in favor of proprietary extensions. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From robert.kern at gmail.com Sat Oct 15 01:03:08 2005 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 14 Oct 2005 22:03:08 -0700 Subject: Problem splitting a string In-Reply-To: <20051015045208.28476.qmail@web35811.mail.mud.yahoo.com> References: <20051015045208.28476.qmail@web35811.mail.mud.yahoo.com> Message-ID: Anthony Liu wrote: > I have this simple string: > > mystr = 'this_NP is_VL funny_JJ' > > I want to split it and give me a list as > > ['this', 'NP', 'is', 'VL', 'funny', 'JJ'] > I think the documentation does say that the > separator/delimiter can be a string representing all > delimiters we want to use. No, it doesn't. In [1]: str.split? Type: method_descriptor Base Class: String Form: Namespace: Python builtin Docstring: S.split([sep [,maxsplit]]) -> list of strings Return a list of the words in the string S, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done. If sep is not specified or is None, any whitespace string is a separator. > I do I split the string by using both ' ' and '_' as > the delimiters at once? You could use regular expressions as Jason Stitt mentions, or you could replace '_' with ' ' and then split. In [2]: mystr = 'this_NP is_VL funny_JJ' In [3]: mystr.replace('_', ' ').split() Out[3]: ['this', 'NP', 'is', 'VL', 'funny', 'JJ'] -- 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 Thu Oct 20 13:57:41 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 20 Oct 2005 19:57:41 +0200 Subject: best way to replace first word in string? References: <1129822003.246170.303920@f14g2000cwb.googlegroups.com> <20051020172527.GC27602@kitchen.client.attbi.com> Message-ID: Micah Elliott wrote: > And the regex is comparatively slow, though I'm not confident this one > is optimally written: > > $ python -mtimeit -s'import re' ' > re.sub(r"^(\w*)", r"/\1/", "a b c")' > 10000 loops, best of 3: 44.1 usec per loop the above has to look the pattern up in the compilation cache for each loop, and it also has to parse the template string. precompiling the pattern and using a callback instead of a template string can speed things up somewhat: timeit -s"import re; sub = re.compile(r'^(\w*)').sub" "sub(lambda x: '/%s/' % x.groups(), 'a b c')" (but the replace solutions should be faster anyway; it's not free to prepare for a RE match, and sub uses the same split/join implementation as replace...) From rbt at athop1.ath.vt.edu Mon Oct 10 10:56:30 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Mon, 10 Oct 2005 10:56:30 -0400 Subject: socketServer questions In-Reply-To: <7xzmph77lo.fsf@ruckus.brouhaha.com> References: <1128699247.9040.15.camel@athop1.ath.vt.edu> <7xll15paha.fsf@ruckus.brouhaha.com> <1128718708.7800.2.camel@athop1.ath.vt.edu> <7xoe61yoa2.fsf@ruckus.brouhaha.com> <1128774994.14078.2.camel@athop1.ath.vt.edu> <7xu0frogwj.fsf@ruckus.brouhaha.com> <1128948284.15030.7.camel@athop1.ath.vt.edu> <7x4q7po7l2.fsf@ruckus.brouhaha.com> <1128953995.15590.19.camel@athop1.ath.vt.edu> <7xzmph77lo.fsf@ruckus.brouhaha.com> Message-ID: <1128956190.18652.1.camel@athop1.ath.vt.edu> On Mon, 2005-10-10 at 07:46 -0700, Paul Rubinhttp: wrote: > rbt writes: > > > Instead, for client #i, let that client's key be something like > > > hmac(your_big_secret, str(i)).digest() > > > and the client would send #i as part of the string. > > > > How is this different from sending a pre-defined string from the client > > that the server knows the md5 hash of? The clients know the string, the > > server knows the hash of that string. > > I'm confused, I don't understand what that md5 whatever would do for you. > I'm assuming the server is secure and the clients are less secure. > > > Also, could this not be done both ways? So that, if an attacker figures > > out the string he's supposed to send from a client to the server (which > > he could easily do). He could not easily figure out the string the > > server should send back as all he would have is the hash of that string. > > I'm still confused OK, we'll leave it at that and just accept that we're from different planets ;) Thanks for the help. From http Mon Oct 17 19:08:47 2005 From: http (Paul Rubin) Date: 17 Oct 2005 16:08:47 -0700 Subject: Comparing lists References: <1128930699.799657.146210@g47g2000cwa.googlegroups.com> <1128952417.0544cc73190bbbd4e683448c137969c8@teranews> <434ba977@nntp0.pdx.net> <1129216693.445956.155490@g47g2000cwa.googlegroups.com> <1h4knvy.41r7fw1k4bge7N%aleaxit@yahoo.com> <1h4lfof.1jirgzd1rpwucsN%aleaxit@yahoo.com> Message-ID: <7xoe5nivwg.fsf@ruckus.brouhaha.com> aleaxit at yahoo.com (Alex Martelli) writes: > implementation of the components one's considering! Rough ideas of > *EXPECTED* run-times (big-Theta) for various subcomponents one is > sketching are *MUCH* more interesting and important than "asymptotic > worst-case for amounts of input tending to infinity" (big-O) -- for I thought big-Theta meant the intersection of big-O (upper bound on the worst case) and big-Omega (lower bound on the worst case). > example, where I sketch-in (mentally, on paper, or on whiteboard) a > "hash table" subcomponent, I consider the *expected* (Theta) performance > (constant-time lookups), definitely NOT the big-O "linear time" lookups > which just MIGHT occur (if, say, all inputs just happened to hash to the > same value)... otherwise, I'd never use hash tables, right?-) You really have to be careful about choices like that. See: http://www.cs.rice.edu/~scrosby/hash/ which I also cited last night. Exercise: suspend disbelief for a moment and imagine that 1) Google search works by spidering the web and building a giant hash table of words that it finds in web pages, to use for servicing future queries; 2) The hash function is similiar to the one used in Python dicts and is either public knowledge or else leaks out of the company somehow; and 3) (biggest disbelief suspension of them all) I work for Microsoft. Question: how could I use knowledge of the hash function to give Google a hard time? At least one well known implementer apparently does intend to quit using hash tables due to considerations like this: http://cr.yp.to/critbit.html From brian at sweetapp.com Fri Oct 7 04:28:27 2005 From: brian at sweetapp.com (Brian Quinlan) Date: Fri, 07 Oct 2005 10:28:27 +0200 Subject: "no variable or argument declarations are necessary." In-Reply-To: <7xu0fucuhi.fsf@ruckus.brouhaha.com> References: <7xu0fucuhi.fsf@ruckus.brouhaha.com> Message-ID: <434631AB.5060804@sweetapp.com> Paul Rubin wrote: > Brian Quinlan writes: > >>Without a clear idea of the nature of the proposal, it is impossible >>to assess it's costs and benefits. So could a proponent of optional >>declarations please provide a more clear proposal? > > > There is no proposal on the table. There's a discussion of how this > stuff can work, and whether it's useful. As for how the compiler > deals with imported modules, see for example Common Lisp or Haskell or > ML--how do they do it? Except that you are providing neither useful input on how it could work nor on whether it would be useful. All you are doing is telling people to do research on other languages (that resumably do things in a way more to your liking). In conclusion, this thread is unlikely to make any useful progress. Cheers, Brian From mwm at mired.org Fri Oct 28 14:56:39 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 28 Oct 2005 14:56:39 -0400 Subject: Opaque documentation References: <1130513632.359922.113550@g47g2000cwa.googlegroups.com> Message-ID: <86wtjxeahk.fsf@bhuda.mired.org> "Ben Sizer" writes: > Documentation is often a problem with Python and its libraries, sadly. > The same almost certainly goes for most open source projects. You over-specified the last clause. It should say "most software projects." http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From fredrik at pythonware.com Thu Oct 6 08:27:12 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 6 Oct 2005 14:27:12 +0200 Subject: Using command line args on Windows References: <1128544715.139551.15960@g43g2000cwa.googlegroups.com> Message-ID: "k8" wrote: > I'm stuck on a Windows machine today and would love to fully play with > and test a simple python script. I want to be able to type "python > myscript myarg" somewhere. Is there anything out there to help me? footnote: if you'd prefer to type "myscript myarg" instead, you might want to check out this tool: http://effbot.org/zone/exemaker.htm From fredrik at pythonware.com Fri Oct 7 12:00:25 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 7 Oct 2005 18:00:25 +0200 Subject: users of pycurl here? References: <1128698989.351313.90070@f14g2000cwb.googlegroups.com> Message-ID: Michele Simionato wrote: > I am having a hard time in finding out how to retrieve information > about the *size* of files I want to download from an FTP site. Should I > send a QUOTE SIZE command to the ftp server or is there an easier way? SIZE isn't a standard FTP command, so that only works for some servers. if you want your code to work for a wider range of servers, you need to parse the output from the LIST command: http://cr.yp.to/ftp/list.html here's a robust parser for various LIST output formats: http://cr.yp.to/ftpparse.html (google for "ftpparse" to find python bindings for that module) From xah at xahlee.org Thu Oct 20 06:47:24 2005 From: xah at xahlee.org (Xah Lee) Date: 20 Oct 2005 03:47:24 -0700 Subject: Perl-Python-a-Day: one-liner loop Functional Style Message-ID: <1129805244.523066.84450@f14g2000cwb.googlegroups.com> One-Liner Loop in Functional Style Xah Lee, 200510 Today we show a example of a loop done as a one-liner of Functional Programing style. Suppose you have a list of file full paths of images: /Users/t/t4/oh/DSCN2059m-s.jpg /Users/t/t4/oh/DSCN2062m-s.jpg /Users/t/t4/oh/DSCN2097m-s.jpg /Users/t/t4/oh/DSCN2099m-s.jpg /Users/t/Icons_dir/icon_sum.gif For those ending with -s (indicate a smaller version), you want to change it to the full version without the -s, if it exists. Here's the code: # -*- coding: utf-8 -*- # python import re, os.path imgPaths=[u'/Users/t/web/Periodic_dosage_dir/lanci/t4/oh/DSCN2059m-s.jpg', u'/Users/t/web/Periodic_dosage_dir/lanci/t4/oh/DSCN2062m-s.jpg', u'/Users/t/web/Periodic_dosage_dir/lanci/t4/oh/DSCN2097m-s.jpg', u'/Users/t/web/Periodic_dosage_dir/lanci/t4/oh/DSCN2099m-s.jpg', u'/Users/t/web/Icons_dir/icon_sum.gif'] # change the image path to the full sized image, if it exists # that is, if image ends in -s.jpg, find one without the '-s'. imgPaths2=[] for myPath in imgPaths: p=myPath (dirName, fileName) = os.path.split(myPath) (fileBaseName, fileExtension)=os.path.splitext(fileName) if(fileBaseName[-2:] == '-s'): p2=os.path.join(dirName,fileBaseName[0:-2]) + fileExtension if os.path.exists(p2): p=p2 imgPaths2.append(p) print imgPaths2 But how do you do it in a functional programing style? Namely, something of the from imgPath2=f(imgPath), where the f is some function. Normally, the f would be a pure function construct made up on the spot, that is, lambda. But Python's lambda is limited to only a expression as its body. Nevertheless, one can achieve a functional style with some workaround, using map twice. Here's the code: imgPaths3 = map( lambda x: os.path.exists(x[1]) and x[1] or x[0], \ map(lambda x: (x, re.sub( r"^(.+?)-s(\.[^.]+)$",r"\1\2", x)), imgPaths)) The first map: newList = map(lambda x: (x, re.sub( r"^(.+?)-s(\.[^.]+)$",r"\1\2", x)), imgPaths) generate a list of pairs (x, y), where x is the same element in imgPaths, and y is one without the -s. Then, a second map: map( lambda x: os.path.exists(x[1]) and x[1] or x[0], newList, imgPaths)) checks if the path y exists, if so, use that, else, use the x part. The function body is essentially of a conditional EXPRESSION, of the from (test, if true return result1, else return result2). This form of a test that returns a expression is very important in functional programing. Because, in functional programing a common pattern is to sequence functions and passing values. One cannot stop in the middle and use a block structure. Here's how this form's syntax in several languages: test? trueExpression: falseExpression (C, Perl) If[test, trueExpression, falseExpression] (Mathematica) (test trueExpression falseExpression) (LISP) In Python, there's no such form for this, but a semantically equivalent workaround is to sequence boolean expressions as used in our example. Namely: test and trueExpression or falseExpression (Python) This works because it exploits a particular behavior of how Python treats boolean sequences. In Python, ?x and y? returns y if x is true. And, ?x or y? returns x if x is true. This behavior is compatible with the mathematical sense of booleans. For example, mathematically ?x and y? should be true if both are true, yet in Python if x is true then y is returned, and if y is true then this is compatible with the math sense, but if y is false then the whole result is also false, so it also satisfies the math sense. Similar is the case of ?x or y?. The point here is that one of the element is returned, instead of a real True or False value. Therefore, in a twisted way this can be used for the If[test, trueExpression, falseExpression] form. Example. result1= True and 4 or 5 # returns 4 result2= False and 4 or 5 # returns 5 print result1 print result2 Such language behavior is a result of the laziness of the compiler implementation, particular seen in unix shells (&& and ||). The problem with this design is that codes relying on the the returned element of a boolean sequence does not clearly indicate the programer's intention. It works by language pecularities, instead of expressed program logic. For the official doc on evaluating booleans, see: http://python.org/doc/2.4.2/lib/boolean.html Here's the Perl code of the same loop block: # perl use File::Basename; @imgPaths=( '/Users/t/web/Periodic_dosage_dir/lanci/t4/oh/DSCN2059m-s.jpg', '/Users/t/web/Periodic_dosage_dir/lanci/t4/oh/DSCN2062m-s.jpg', '/Users/t/web/Periodic_dosage_dir/lanci/t4/oh/DSCN2097m-s.jpg', '/Users/t/web/Periodic_dosage_dir/lanci/t4/oh/DSCN2099m-s.jpg', '/Users/t/web/Icons_dir/icon_sum.gif'); # change the image path to the full sized image, if it exists # that is, if image ends in -s.jpg, find one without the '-s'. $imgPaths2=(); for $myPath (@imgPaths){ $p=$myPath; ($fileBaseName, $dirName, $fileExtension) = fileparse($myPath, ('\.[^.]+$') ); if (substr($fileBaseName,-2,2) eq '-s') { $p2= $dirName . '/' . substr($fileBaseName,0,length($fileBaseName)-2) . $fileExtension; print $p2, "\n"; if (-e $p2) { $p=$p2} } push(@imgPaths2,$p); } use Data::Dumper; print Dumper(\@imgPaths2) In Perl, this can be written in a functional style one-liner: @imgPaths3= map{ $y = $_; $y =~ s/^(.+?)-s(\.[^.]+)$/$1$2/; -e $y ? $y : $_; } @imgPaths; For the official doc of Perl's map, type in command line: ?perldoc -f map? ------ this article is archived at: http://xahlee.org/perl-python/one-liner_loop.html Xah xah at xahlee.org ? http://xahlee.org/ From jstephens at friendfinderinc.com Mon Oct 17 14:10:15 2005 From: jstephens at friendfinderinc.com (Jon Stephens) Date: Mon, 17 Oct 2005 11:10:15 -0700 Subject: Huge performance gain compared to perl while loading a text file in a list ...!? Message-ID: <20051017181020.138FE1E4002@bag.python.org> I happened to stumble across this. I'll admit now that I've never touched python. But I was curious of your example. Does python maintain the file handle? I don't see any explicit handling of the file like in your perl script. Since if you are opening and then maintaining a file handle in the python script it will of course stomp your perl script. Mainly because you put the OPEN and CLOSE inside of the loop. So it's constantly opening and closing the file handle. I've never seen anyone do that before, and I hope I never see it again. It should have looked like this: #!/usr/bin/perl open(DATA, "data.test"); for ($i = 0; $i < 20; $i++) { @Data = ; } close(DATA); When I did a quick test with a 3MB file I had in my directory I got these results by changing the perl script. My test script: 1 #!/usr/bin/perl 2 3 open DATA,"; 6 } 7 close DATA; 8 9 1; With the open/close outside of the loop. [jstephens at pe66 (11:05:35) ~]$ time ./test.pl real 0m1.293s user 0m0.071s sys 0m0.036s With the open/close inside of the loop [jstephens at pe66 (11:06:56) ~]$ time ./test.pl real 0m1.854s user 0m1.612s sys 0m0.114s So using a poorly written perl script for a performance comparison isn't really fair. If you fix your perl script I'm sure you'll see drastic performance increases. Jon -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Tue Oct 18 15:59:28 2005 From: aahz at pythoncraft.com (Aahz) Date: 18 Oct 2005 12:59:28 -0700 Subject: Question on class member in python References: <1129537638.714752.120290@g49g2000cwa.googlegroups.com> <1129613041.473285.84800@g44g2000cwa.googlegroups.com> <1h4mjg9.1n5khr7pjy1zN%aleaxit@yahoo.com> Message-ID: In article <1h4mjg9.1n5khr7pjy1zN%aleaxit at yahoo.com>, Alex Martelli wrote: >Johnny Lee wrote: > ... >> Thanks for your help, maybe I should learn how to turn an attibute into >> a property first. > >Easy -- in your class's body, just code: > > def getFoo(self): ... > def setFoo(self, value): ... > def delFoo(self): ... > foo = property(getFoo, setFoo, delFoo, 'this is the foo') > > >Note that if you want subclasses to be able to customize behavior of foo >accesses by simple method overrides, you need to program some "hooks" >(an extra level of indirection, if you will). Or wait for foo = property('getFoo', 'setFoo') (Currently proposed by Guido on python-dev) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." --Red Adair From martin at v.loewis.de Sun Oct 2 15:20:55 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 02 Oct 2005 21:20:55 +0200 Subject: RELEASED Python 2.4.2 (final) In-Reply-To: References: <433CCF02.6060005@v.loewis.de> <433DB7BC.6090002@v.loewis.de> Message-ID: <43403317$0$13961$9b622d9e@news.freenet.de> Bugs wrote: > - I had an old ActiveState python24.dll in \windows\system32 which I > deleted. That must've been left over from a 2.4.1 ActiveState > installation which I had installed then uninstalled sometime ago. > > - I then uninstalled Python 2.4.2 and re-installed it for "all" users. > After that everything seemed to work properly. That is somewhat mysterious... > I'm not sure where the Python 2.4.2 installation put it's python24.dll? It depends on whether this is a "for all" installation, or a "just for me" installation. In the "for all" installation, it goes to \windows\system32. In the "just for me" installation, it goes to c:\python24 (ie. the directory where python.exe is). The rationale is that a non-admin user might not have enough permissions to write to system32. > Please let me know if you need additional details. It would be good if you could recall what mode the original 2.4.2 installation had. If it was "just for me", then you might have installed the 2.4.2 version of python24.dll into the python directory. Still, it is then puzzling why it would have used the version in system32, as the application's (i.e. python.exe) directory should be searched first. For the record, please also report what operating system you were using. The other theory is that the 2.4.2 installer failed to overwrite the ActivePython version. This should not have happened, though, since the installer should have noticed that the 2.4.2 version is newer than the 2.4.1 one (and indeed, in a test installation, it did so correctly). It is probably too late to recreate all details, so we should just watch whether it happens again. Regards, Martin From 700MHz at gmail.com Fri Oct 21 02:29:38 2005 From: 700MHz at gmail.com (700MHz) Date: 20 Oct 2005 23:29:38 -0700 Subject: a simple question about the third index in slice Message-ID: <1129876178.607754.120750@g43g2000cwa.googlegroups.com> I cannot quite understand when the third index is a negative number,like this: a = '0123456789' a[1:10:2] I know the index step is 2, so it will collect items from offset 1, 3, 5, 7, 9 but when a negative number come,like: a[1::-1] answer '10', and a[1:10:-1] only answer '', what is the different between the two expression, where does the offset begin and what is the end offset? Thanks! From juho.schultz at helsinki.fi Fri Oct 7 07:16:37 2005 From: juho.schultz at helsinki.fi (Juho Schultz) Date: Fri, 07 Oct 2005 14:16:37 +0300 Subject: recursive function In-Reply-To: References: Message-ID: mg wrote: > Hello, > > In a recursive function like the following : > > > def foo( j ) : > j += 1 > while j < n : j = foo( j ) > return j > > > in found that the recursivity is limited (1000 iterations). Then, I have > two questions : > - why this mecanism has been implemented ? > - it is possible to increase or remove (and how) the number of iterations ? > > Regards, > Mathieu Try the following for answers to both questions: import sys print sys.setrecursionlimit.__doc__ I guess 1000 is the default value. From luizgeron at gmail.com Tue Oct 25 09:15:17 2005 From: luizgeron at gmail.com (Luiz Geron) Date: 25 Oct 2005 06:15:17 -0700 Subject: PDO and database abstraction In-Reply-To: References: <1130240852.794081.158320@g47g2000cwa.googlegroups.com> <435E2313.3090504@ghaering.de> Message-ID: <1130246117.103331.61170@g44g2000cwa.googlegroups.com> This is one example where I need to use such abstraction: I have a dictionary with the fields and values to be inserted into the database, with a code like this: dic = {'field1' : 1, 'field2' : 2} #this dict comes from a Cherrypy request cur.execute('update table set field_one = :value1, field2 = :value2' , dic) and I want to use it even with kinterbasdb, wich does not support named paramstyle. The problem with your use of % is that the db module does not automatically put '' in varchar fields, and so on. This is what PDO does, or say that does. I think that I should make a wrapper that simply swap :var to ? when the db paramstyle is qmark, and so on. Is this correct? From mwm at mired.org Thu Oct 13 19:42:49 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 13 Oct 2005 19:42:49 -0400 Subject: FORM data in cgi References: Message-ID: <864q7lugp2.fsf@bhuda.mired.org> "jponiato" writes: > Greetings. > An HTML form submits it's data to a python cgi script on my server. This script accepts this POST data, and uses urllib.urlopen() to call a different cgi script (on an external server), passing this same data. I'm using cgi.FieldStorage() to create a mapping of the FORM data, then using urllib.urlencode() to turn it back into form data for urlopen(). > Question - is there a more efficient way to do this? Yes. But the question you should be asking is "Is there an easier way to do it that's worth doing?" Unless you're passing around files, or really huge forms, the amount of time you spend doing decoding and encodinng the form data will be pretty trivial. Unless you're really pressed for cycles, why bother fixing it? And if you're really pressed for cycles, you should start by instrumenting things to make sure that you're optimizing something that will do you some good. Anyway, the general idea is to skip cgi.FieldStorage, and parse the request yourself. You'll have to deal with the headers. But you can just grab the post data with a read(). I'm not sure you can use urllib to send pre-encoded POST data; you'll have to check that yourself. If not, you'll have to do the HTTP request processing by yourself. That's not hard, though. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From peter at engcorp.com Mon Oct 10 21:40:51 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 10 Oct 2005 21:40:51 -0400 Subject: Python reliability In-Reply-To: References: <434A2F31.6010507@REMOVEMEcyber.com.au> Message-ID: Ville Voipio wrote: > I am not building a redundant system with independent > instruments voting. At this point I am trying to minimize > the false alarms. This is why I want to know if Python > is reliable enough to be used in this application. > > By the postings I have seen in this thread it seems that > the answer is positive. At least if I do not try > apply any adventorous programming techniques. We built a system with similar requirements using an older version of Python (either 2.0 or 2.1 I believe). A number of systems were shipped and operate without problems. We did have a memory leak issue in an early version and spent ages debugging it (and actually implemented the suggested "reboot when necessary feature" as a stop-gap measure at one point), before finally discovering it. (Then, knowing what to search for, we quickly found that the problem had been fixed in CVS for the Python version we were using, and actually released in the subsequent major revision. (The leak involved extending empty lists, or extending lists with empty lists, as I recall.) Other than that, we had no real issues and definitely felt the choice of Python was completely justified. I have no hesitation recommending it, other than to caution (as I believe Paul R did) that use of new features is "dangerous" in that they won't have as wide usage and shouldn't always be considered "proven" in long-term field use, by definition. Another suggestion would be to carefully avoid cyclic references (if the app is simple enough for this to be feasible), allowing you to rely on reference-counting for garbage collection and the resultant "more deterministic" behaviour. Also test heavily. We were using test-driven development and had effectively thousands of hours of run-time by the time the first system shipped, so we had great confidence in it. -Peter From steve at holdenweb.com Fri Oct 7 08:52:50 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 07 Oct 2005 13:52:50 +0100 Subject: When someone from Britain speaks, Americans hear a "British accent"... In-Reply-To: References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kbgj7421kd560@corp.supernews.com> <4h5ck1hkqq0ls83pq0lodkb51tsda4053k@4ax.com> Message-ID: Richie Hindle wrote: > [Steve] > >>and yes, I split that infinitive just to >>annoy any pedants who may be reading > > > [Steven] > >>*Real* pedants will know that English is not Latin, does not follow the >>grammatical rules of Latin, and that just because split infinitives are >>impossible -- not forbidden, impossible -- in Latin is no reason to forbid >>them in English. > > > Your previous post to this thread was chock-full of split nominatives: "The > Hollywood voice", "the specific regional accent", "the English-speaking > world", "the original French". And you call yourself a grammarian. > I am presuming this post was meant to be a joke? No smileys, though, so you force us to make up our own minds. Or is "the green tomato" also unacceptable? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From bokr at oz.net Tue Oct 25 16:05:00 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 25 Oct 2005 20:05:00 GMT Subject: Tricky import question. References: <1130247555.359770.169070@o13g2000cwo.googlegroups.com> Message-ID: <435e8530.945320799@news.oz.net> On 25 Oct 2005 06:39:15 -0700, "David Poundall" wrote: >importedfiles = {} >for f in FileList > f2 = f.split('.')[0] # strip the .py, .pyc importedfiles[f2] = __import__(f2).main # it sounds like all you want is the above (untested ;-), or # use __import__(f2).main() if you actually want the _result_ returned by main Either way, you don't need the following > __import__(f2) > s2 = f2+'.main()' # main is the top file in each import > c = compile(s2, '', 'eval') > importedfiles[f2] = eval(c) > >'importedfiles' should hold an object reference to the main() function >within each imported file. Do you want a reference to the function, or the result of calling the function? If you want a reference to the function itself, you should leave off the () after main, otherwise you will execute the function. > >The problem is, the import function works but I can't get the object >reference into the imortedfiles dictionary object. the code keeps >telling me > >NameError: name 'C1_Dosing' is not defined. probably your first file is C1_Dosing.py (or some other extension after the '.') so f2 becomes 'C1_Dosing' and s2 becomes 'C1_Dosing.main()' and you compile that into code bound to c, and when you try to eval(c), it tries to find C1_Dosing in the current environment, et voila! you have the error. When confronted with mysteries such as presented by your code results, I suggest you intruduce print statements to verify what you are assuming about what it is doing. E.g., you could print repr(f2) after assignment, and after the __import__ if you thought it was going to do something to f2 in the local name space, and repr(s2) after the assignment, etc. to see if I guessed right. Or a quick line to clone for a snapshot of local varibles at different points might be (untested) print '\n'.join('%15s: %s'%(k, repr(v)[:60]) for k,v in sorted(locals().items())) > >in this instance C1_Dosing is the first file name in the filelist. The >import worked, why not the compile ?? I think the compile did work. But your code didn't produce a binding for the name 'C1_Dosing' which the code c was looking for when eval(c) was called. If you wanted to make your code work, perhaps replacing (untested) __import__(f2) with exec '%s = __import__(f2)'%f2 # bind imported module to name specified by f2 string might have got by the error in eval (c), but I suspect you would want to leave the () off the .main in any case. And why go through all that rigamarole? > >TIA. > Try it both ways and report back what you found out ;-) Regards, Bengt Richter From vel.accel at gmail.com Mon Oct 3 13:34:42 2005 From: vel.accel at gmail.com (D.Hering) Date: 3 Oct 2005 10:34:42 -0700 Subject: morphological image processing in Python In-Reply-To: <1128355854.416660.215260@g49g2000cwa.googlegroups.com> References: <1128355854.416660.215260@g49g2000cwa.googlegroups.com> Message-ID: <1128360882.552198.45570@o13g2000cwo.googlegroups.com> Take a look at ADaM and it's python wrappers: http://datamining.itsc.uah.edu/adam/documentation.html From fredrik at pythonware.com Wed Oct 26 06:27:50 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 26 Oct 2005 12:27:50 +0200 Subject: assignment to reference References: Message-ID: Loris Caren wrote: > a = 'apple' > b = 'banana' > c = 'cabbage' > > How can I get something like:- > > for i in 'abc': > r = eval(i) > if r == 'cabbage': r = 'coconut' > > actually change the object referenced by r rather > than creating a new object temporarily referenced by it? if you need a container, you should use a container object instead of the local namespace. in this case, a dictionary is what you want: stuff = { 'a': 'apple', 'b': 'banana', 'c': 'cabbage' } for i in "abc": if stuff[i] == "cabbage": stuff[i] = "coconut" (tweak as necessary) From brussel at insightbb.com Wed Oct 12 23:21:47 2005 From: brussel at insightbb.com (brussel13) Date: Thu, 13 Oct 2005 03:21:47 -0000 Subject: setup.py dll linking Message-ID: Hi, I'd like to link a dll/pyd against another which was compiled by a distutils script and mingw32, winxp obviously. there aren't any symbols in the symbol table of the first pyd. i removed the -s which distutils sends to mingw32 but that only made symbols appear with nm. pexports still reports only __init__. mingw still complains that the functions in the first dll can't be found when compiling the second. ross From steve at holdenweb.com Tue Oct 25 19:07:39 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 26 Oct 2005 00:07:39 +0100 Subject: Would there be support for a more general cmp/__cmp__ In-Reply-To: References: Message-ID: Steven D'Aprano wrote: > On Tue, 25 Oct 2005 10:09:29 -0400, Christopher Subich wrote: > > >>>>By analogy, one can ask, "is the cat inside the box?" and get the answer >>>>"No", but this does not imply that therefore the box must be inside the >>>>cat. >>> >>> >>>Bad analogy, this doesn't define a mathematical ordering, the subset >>>relationship does. >> >>Yes, it does. Consider "in" as a mathematical operator: >> >>For the set (box, cat-in-box) >> >>box in box: False >>box in cat-in-box: False >>cat-in-box in box: True >>cat-in-box in cat-in-box: False >> >>For the set (box, smart-cat) # cat's too smart to get in the box >> >>box in box: False >>box in smart-cat: False >>smart-cat in box: False >>smart-cat in smart-cat: False >> >>In both these cases, the "in" operator is irreflexive, asymmetric, and >>transitive (extend to mouse-in-cat if you really care about transitive), >>so "in" is a partial order sans equality. A useless one, but a partial >>order nonetheless. > > > What do you mean "in" is a useless ordering? It makes a huge difference > whether "nuclear bomb in New York" is true or not. > > In fact, I'm quite surprised that Antoon should object to "in" as "this > doesn't define a mathematical ordering, the subset relationship does" when > "subset" is just "in" for sets: set S is a subset of set T if for all > elements x in S, x is also in T. Informally, subset S is in set T. > > Can somebody remind me, what is the problem Antoon is trying to solve here? > > Being Belgian, I suspect. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From shkelley at gmail.com Fri Oct 21 07:44:23 2005 From: shkelley at gmail.com (shkelley at gmail.com) Date: 21 Oct 2005 04:44:23 -0700 Subject: pushing python to multiple windows machines Message-ID: <1129895063.490493.26360@g44g2000cwa.googlegroups.com> I am working on a project that requires python to be installed on a large number of windows servers and was wondering if anyone has found a method to do this. I found the article from 2003, but nobody ever stated that they have found an option for this. http://groups.google.com/group/comp.lang.python/browse_frm/thread/f42f0813bc271995?tvc=1&q=%22Pushing+Python+to+Windows+workstations%22 -shawn From larry.bates at websafe.com Mon Oct 10 18:50:10 2005 From: larry.bates at websafe.com (Larry Bates) Date: Mon, 10 Oct 2005 17:50:10 -0500 Subject: Changing console text color In-Reply-To: References: Message-ID: <434AF022.5050100@websafe.com> You can use this module to control console windows background and text colors. http://www.effbot.org/zone/console-index.htm -Larry Bates Steve M wrote: > Hello, > > I've been trying to change the text color on a windows console > program I've been working on with no luck. I should mention that I'm > a novice so please dummy up your replies. > > Thanks-in-Advance > Steve From frank at chagford.com Tue Oct 11 03:30:44 2005 From: frank at chagford.com (Frank Millman) Date: 11 Oct 2005 00:30:44 -0700 Subject: Question about StringIO In-Reply-To: References: <1128849763.117104.34370@f14g2000cwb.googlegroups.com> <3qsacmFftrn5U1@uni-berlin.de> <1128940255.694551.318760@g14g2000cwa.googlegroups.com> Message-ID: <1129015844.347274.145840@g44g2000cwa.googlegroups.com> Benjamin Niemann wrote: > Frank Millman wrote: > > > I will try to explain my experience with popen() briefly. > > > > I run through all the scripts and create a StringIO object with the > > string I want to pass. It is about 250 000 bytes long. If I run psql > > using popen(), and pass it the string via stdin, it works fine, but I > > get all the messages on the screen. If I do the same, but end the > > command with ' > fjm 2>&1' it works correctly and the messages end up > > in the file fjm, which is about 40 000 bytes long. If I run it with > > popen4(), it starts ok, but then hangs about 1/4 of the way through. > > Exactly the same happens on MSW. It seems to be hitting a limit on the > > size of the stdout file - is that possible? > > > > That's probably a deadlock as described in > > Thanks for this pointer. I have read it, but I don't think it applies to my situation, as it talks about 'reading' from the child's stdout while the child is 'writing' to stderr. I am not doing that, or at least not consciously. Here is a code snippet. 's' is a StringIO object that contains my input. It is about 6000 lines/250000 bytes long. ------------- sql_stdin,sql_stdout = os.popen4('psql -U %s -d %s' % (user,database)) sql_stdin.writelines(s.readlines()) s.close() sql_stdin.close() ------------- It starts, and then hangs, after processing about 6% of my input. If I add ' > fjm 2>&1' to the command, it works, so it is definitely connected with the child writing to stdout/stderr. I tried storing my input in a list, and passing ''.join(s), but it had the same result. I also looped over the list and wrote one line at a time to sql_stdin - same result. I can work around this, so a solution is not critical. However, it would be nice to know if this is a limitation of popen4(), or if I am doing something wrong. > > BTW, is there an equivalent of /dev/null on MSW? > > Dunno - but as a last resort, you could create a tempfile with a unique name > (to be sure, not to override any existing data), dump your output there and > later os.unlink() it... > A quick google revealed the answer - there is a device called NUL which achieves the same purpose. Thanks Frank From ddelay at club-internet.fr Sun Oct 9 06:52:17 2005 From: ddelay at club-internet.fr (daniel delay) Date: Sun, 09 Oct 2005 12:52:17 +0200 Subject: What about letting x.( ... ? ... ) be equivalent to ( ... x ... ) In-Reply-To: References: Message-ID: <4348f644$0$644$626a14ce@news.free.fr> Fredrik Lundh a ?crit : > ddelay at club-internet.fr wrote: > > >>These 3 intermediate variables used to improve readability >>can introduce bugs : you have to check that b, c and d are >>not used anywhere else in the code. > > > if you have a fear of introducing new local variables, you have problems > that cannot be solved by syntax. > > > Before to introduce a new variable named "x", you have to take care of the fact the name "x" is not defined elsewhere and visible in the present scope. It is not a fear, but something you must keep in mind, otherwise it can be a source of errors. If you have a syntax in which you use less variables names to do the same thing, with the same (or better?) readability, that seems better for me. From http Mon Oct 10 18:12:26 2005 From: http (Paul Rubin) Date: 10 Oct 2005 15:12:26 -0700 Subject: Send password over TCP connection References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> <7xd5md76kd.fsf@ruckus.brouhaha.com> <1128976311.779178.304900@g14g2000cwa.googlegroups.com> Message-ID: <7xpsqdhvhx.fsf@ruckus.brouhaha.com> "dcrespo" writes: > Hi. I found TSL, a Python Library that supports SRP. > Do you know where can I find a sample client and server code? Thanks > for your help. I don't know about TSL, but TLSLite (www.trevp.net/tlslite) supports SRP. From fredrik at pythonware.com Sat Oct 8 04:10:01 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 8 Oct 2005 10:10:01 +0200 Subject: os.access with wildcards References: <1128665933.923295.95580@f14g2000cwb.googlegroups.com><1128698336.836590.96080@g44g2000cwa.googlegroups.com><1128698792.787399.160460@g49g2000cwa.googlegroups.com><86psqhnrx4.fsf@bhuda.mired.org><1128727042.273430.64640@g44g2000cwa.googlegroups.com> <1128732066.947274.206270@o13g2000cwo.googlegroups.com> Message-ID: > > if glob.glob(...): ... > > As for your possible solutions, if you consider any > of yours to be "readable", then i have no interest in > coding with you. > > if glob.glob(...): ... > > I guess, for readability, nothing has come up that > seems _great_. > > if glob.glob(...): ... > > It works, it's elegant, and it uses python strengths. cute. I guess this thread shows that python can grow on you. From steve at holdenweb.com Mon Oct 17 15:13:56 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 17 Oct 2005 20:13:56 +0100 Subject: gprof results In-Reply-To: <20051017183520.50722.qmail@web30601.mail.mud.yahoo.com> References: <20051017183520.50722.qmail@web30601.mail.mud.yahoo.com> Message-ID: Dave wrote: > Hello All, > > I googled to find an answer for my question, but had > no luck. I'm trying to profile a Python program using > gprof, but I don't understand what _moncount and > mcount are. I couldn't find their source code under > Python source tree. moncount takes about 30% of my > program... What are _moncount and mcount for? Are they > functions or variables? Any ideas? > > Thank you for your help! Do you realise that you won't get any useful information about the Python program using gprof? That will give you information about the performance of the python interpreter itself, somewhat unrelated to the Python program it's running. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From aleaxit at yahoo.com Sun Oct 23 20:37:16 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 23 Oct 2005 17:37:16 -0700 Subject: how to count and extract images References: Message-ID: <1h4wb7v.1r2ecoz1sur1ldN%aleaxit@yahoo.com> Joe wrote: > I'm trying to get the location of the image uisng > > start = s.find(' stop = s.find('">Save File', > start) fileName = s[start:stop] > and then construct the url with the filename to download the image > which works fine as cause every image has the Save File link and I can > count number of images easy the problem is when there is more than image I > try using while loop downlaod files, wirks fine for the first one but > always matches the same, how can count and thell the look to skip the fist > one if it has been downloaded and go to next one, and if next one is > downloaded go to next one, and so on. Pass the index from where the search must start as the second argument to the s.find method -- you're already doing that for the second call, so it should be pretty obvious it will also work for the first one, no? Alex From uid09012_ti at collinsrealtime.com Thu Oct 27 05:44:34 2005 From: uid09012_ti at collinsrealtime.com (uid09012_ti at collinsrealtime.com) Date: 27 Oct 2005 02:44:34 -0700 Subject: Missing modules '_ssl', 'ext.IsDOMString', 'ext.SplitQName' In-Reply-To: References: <1130003715.743391.237890@f14g2000cwb.googlegroups.com> <1130230864.068474.118500@g43g2000cwa.googlegroups.com> <1130311678.936969.302020@g43g2000cwa.googlegroups.com> Message-ID: <1130406274.356454.141040@o13g2000cwo.googlegroups.com> Hi,,thanks for the tip. I'*m still stuck, but that link got me past the problem with the unknow encoding. I now get this traceback: Traceback (most recent call last): File "App1.py", line 23, in ? File "App1.py", line 19, in main File "wx\_core.pyc", line 5691, in __init__ File "wx\_core.pyc", line 5343, in _BootstrapApp File "App1.py", line 13, in OnInit File "Frame1.pyc", line 25, in create File "Frame1.pyc", line 170, in __init__ File "brain.pyc", line 15, in __init__ File "points.pyc", line 16, in __init__ File "xml\dom\ext\reader\Sax2.pyc", line 385, in FromXmlStream File "xml\dom\ext\reader\Sax2.pyc", line 346, in __init__ File "xml\sax\saxexts.pyc", line 77, in make_parser xml.sax._exceptions.SAXReaderNotAvailable: No parsers found I checked out what Ron suggested, but I've no files where the names could clash with python modules. Thanks, Martin. From nehagupta29_2005 at yahoo.com Wed Oct 19 07:04:11 2005 From: nehagupta29_2005 at yahoo.com (neha) Date: 19 Oct 2005 04:04:11 -0700 Subject: problem running a python script using apache,mod_python on linux Message-ID: <1129719851.948290.67990@g47g2000cwa.googlegroups.com> hi, i m trying to integrate python with apache on linux.For this i m using mod_python. I dont see any problem with the versions of python,apache and mod_python i m using. the versions i m using are apache version2. mod_python v3.1.14 python2.4 The problem is,when i m running my python script,after starting apache ,it is showing me the code it has. My error_log is showing the following message [Tue Oct 18 19:01:06 2005] [notice] Apache/2.0.55 (Unix) mod_python/3.1.4 Python/2.4.2 configured -- resuming normal operations [Tue Oct 18 19:01:06 2005] [info] Server built: Oct 17 2005 13:07:52 [Tue Oct 18 19:01:06 2005] [debug] prefork.c(956): AcceptMutex: sysvsem (default: sysvsem) the access_log is showing this message: 127.0.0.1 - - [18/Oct/2005:19:01:14 +0530] "GET /apache_pb.gif HTTP/1.1" 200 2326 127.0.0.1 - - [18/Oct/2005:19:01:19 +0530] "GET /test/mptest.py HTTP/1.1" 200 110 from the python script,i m returning an apache.OK ,so i think it goin on fine,as i m getting 200i.e the hhtp processing is goin on fine. I have made the required changes to the httpd.conf file *** LoadModule python_module /home/ngupta/Apache2/modules/mod_python.so DocumentRoot "/home/ngupta/Apache2/htdocs" AllowOverride FileInfo *** I m using a .htaccess file placed under Apache2/htdocs/test/ The .htaccess file has the following code ** AddHandler mod_python .py PythonHandler mptest PythonDebug On ** where mptest is python script and is as follows ** from mod_python import apache def handler(req): req.send_http_header() req.write("Hello") return apache.OK ** so if anyone knows where the problem lies ,please tell me. thanks. Neha gupta From tim.golden at viacom-outdoor.co.uk Wed Oct 26 15:10:34 2005 From: tim.golden at viacom-outdoor.co.uk (Tim G) Date: 26 Oct 2005 12:10:34 -0700 Subject: Windows vs Linux In-Reply-To: References: Message-ID: <1130353834.320068.213020@g47g2000cwa.googlegroups.com> Bernhard Herzog wrote: > "Tim Golden" writes: > > > But as far as I can tell > > from my experience and from the docs -- and I'm not near a > > Linux box at the mo -- having used ctrl-r to recall line x > > in the history, you can't just down-arrow to recall x+1, x+2 etc. > > Or can you? > > You can. It works fine on this box, at least. > GNU bash, version 2.05a.0(1)-release (i386-pc-linux-gnu) > libreadline 4.2a Sadly, this seems not to be the case on my Ubuntu Breezy: bash 3.00.16, libreadline 4.3/5.0 (not sure which one bash is using). ctrl-r is fine; but you can't down-arrow from there; it just beeps at you. Is there some setting I'm missing? TJG From jgrahn-nntq at algonet.se Wed Oct 26 12:04:12 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 26 Oct 2005 16:04:12 GMT Subject: distutils - distributing non-python data files References: <1130261753.871759.11690@g14g2000cwa.googlegroups.com> Message-ID: On 25 Oct 2005 10:35:53 -0700, RickMuller wrote: > I really appreciate the ease that the distutils make distributing > Python modules. However, I have a question about using them to > distribute non-Python (i.e. text) data files that support Python > modules. I think you forgot to explain why you cannot simply use distutil's data_files parameter. Do you have trouble finding the file at runtime? http://docs.python.org/dist/node12.html /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From sw at wordtech-software.com Sun Oct 23 17:35:34 2005 From: sw at wordtech-software.com (Kevin Walzer) Date: Sun, 23 Oct 2005 17:35:34 -0400 Subject: IDE recommendation please In-Reply-To: References: Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 microsnot wrote: | I'm new to Python but am wondering what IDE Python developers use? I use Mac | OS X 10.4.2. I have PythonIDE which comes with MacPython but I don't think | that has even rudimentary "intellisense". Xcode and Eclipse don't seem to | support Python out of the box. Suggestions for plugins for Eclipse would | also be nice. | The situation has been pretty bleak, and I've tried (even maintained Mac packages for awhile) nearly all the open-source IDE's out there, including SPE, Boa, Eric3, etc. They all crashed constantly in my experience. SPE has been making more of a Mac push since I stopped maintaining Mac packages so it may have improved. Komodo is a good IDE and is currently in beta testing on OS X: see www.activestate.com for the particulars. It's more polished than any of the open-source tools (though it should be for the $300 that the pro version costs), and runs natively (as an Aqua app). Komodo is not Python-only, but if you are developing commercially it is a very good tool to consider. WingIDE is also very powerful, but runs only as an X11 app on the Mac. That may or may not be a problem for you. I've ultimately settled on a primitive set of tools myself, Emacs or IDLE, plus the console. Fewer bells and whistles, but they are stable, and don't get in my way. - -- Cheers, Kevin Walzer, PhD WordTech Software - "Tame the Terminal" http://www.wordtech-software.com sw at wordtech-software.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (Darwin) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDXAIlJmdQs+6YVcoRAqsKAJ0YX14aGH5pUpujXb+wmYoWbGUkWQCfX0oK 6kiXX9w+rAIbo5qCYGUWIuc= =YSju -----END PGP SIGNATURE----- From twic at urchin.earth.li Wed Oct 5 17:40:05 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Wed, 5 Oct 2005 22:40:05 +0100 Subject: dictionary interface In-Reply-To: References: Message-ID: On Tue, 4 Oct 2005, Robert Kern wrote: > Tom Anderson wrote: >> On Tue, 4 Oct 2005, Robert Kern wrote: >> >>> Antoon Pardon wrote: >>> >>>> Anyone a reference? >>> >>> The function dict_compare in dictobject.c . >> >> Well there's a really helpful answer. > > Well, *I* thought it was. And indeed it was. I'm sorry i was so rude - i must have been in a bad mood. My apologies. > What do you want? Personalized Python tutorials delivered by candygram? YES DAMMIT! WITH BIG KISS FROM GUIDO! tom -- The revolution is here. Get against the wall, sunshine. -- Mike Froggatt From rupole at hotmail.com Wed Oct 26 15:47:36 2005 From: rupole at hotmail.com (Roger Upole) Date: Wed, 26 Oct 2005 15:47:36 -0400 Subject: Small utility program for the windows References: Message-ID: <1130356307_677@spool6-east.superfeed.net> It works fine for me (XP, Python 2.4.2). Where exactly do you get the access denied ? When writing to the registry, or trying to start python, or within the python code ? Roger "Iyer, Prasad C" wrote in message news:mailman.2474.1130155648.509.python-list at python.org... Hi, I am trying to create a small utility program which would be configured in registry. Something like this Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\*\shell\ShortCut\command] @="\"python C:\\workspace\\python\\Tut\\ShortCut.py\"" It gives me access denied exception when I try it. Can anyone help me out. Following is the code from Tkinter import * import sys class BaseClass(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.grid() self.createWidget() def createWidget(self): self.text=Text(self, width=20, height=3) self.text.grid(row=0,column=0) Button(self, text="ok", command=self.addText).grid(row=1, column=0) def addText(self): print "hello world" baseClass=BaseClass() print sys.argv[0] for i in range(0, len(sys.argv)): print sys.argv[i] baseClass.mainloop() I have to modify the code further so that it takes argument. This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= East/West-Coast Server Farms - Total Privacy via Encryption =--- From john at castleamber.com Sat Oct 15 20:47:09 2005 From: john at castleamber.com (John Bokma) Date: 16 Oct 2005 00:47:09 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: joe at invalid.address wrote: > John Bokma writes: > >> joe at invalid.address wrote: >> >> > John Bokma writes: >> > >> >> "David Schwartz" wrote: >> >> > >> >> > "Tim Roberts" wrote in message >> >> > news:a103l1tkejrc99s0385qjqqhm96d46dpc4 at 4ax.com... >> >> > >> >> >> Part of their behavior really escape me. The whole thing >> >> >> about browser wars confuses me. Web browsers represent a zero >> >> >> billion dollar a year market. Why would you risk anything to >> >> >> own it? >> >> > >> >> > It really isn't that hard to understand that web-based >> >> > applications that work in any browser on any OS threaten to >> >> > make it irrelevent what OS you're running. >> >> >> >> And it's even easier to understand that your statement is >> >> nonsense. >> >> >> >> It doesn't matter which Linux distribution you pick, all use the >> >> Linux kernel. On all I can run OpenOffice, and get the same >> >> results. Yet people seem to prefer one distribution over one >> >> other. >> > >> > He was talking about the browser war, and gave a pretty good >> > reason why it was important. So you respond by pointing out that >> > people choose a linux distribution for personal (non-technical, >> > non-marketing) reasons. I think I missed the connection. >> >> web based applications that work with any browser make OS irrelevant >> -> not true, since for OpenOffice it doesn't matter which Linux >> distribution one runs (or even if it's Linux), yet people seem to >> make a point of which distribution they use. > > A linux distribution isn't an OS, it's a distribution, so I'm not sure > what your point here is. Ok, let me spell it out for you: If all your applications are web based, and the OS shouldn't matter, why do Linux distributions matter? It doesn't matter which one you use to run, for example, OpenOffice. Yet people pick a certain distribution. Why? Well, one reason is that people like to belong to a group. So even if it really doesn't matter which OS you are going to use to access a web application, or even which browser, people will pick a certain browser, and a certain OS, just because. > In fact, there are lots How much? > of Microsoft-centric web pages that don't > work well when accessed from a linux system. ActiveX, MS Java, etc. Does it matter? There are webpages that just don't work for some people, no matter that they do work for others. You can't just make up one standard average user and design the web for it. >> >> > MS has a strong interest in making sure it's important >> >> > to be running on one of their OSes. >> >> >> >> Maybe *they* do have a point :-). >> > >> > Which is? >> >> That it *does* matter. It doesn't matter which brand makes your >> graphics card, since most stick close to the reference design of the >> GPU chip supplier, yet people take the brand in consideration when >> they buy. > > I don't think that's true, at least not yet. I recently bought a > Compaq Presario, Hey, me too :-) (SR1505LA to be exactly, and it does work with Kubuntu, or at least I get a picture). > which came with XP installed. I wiped the disk and Me too (but that was to get rid of the Spanish XP) > installed Linux, only to find that the hardware would only work under > XP. Now that's odd, since mine worked, network, video, sound, etc. > So I then had to install network, video, sound etc cards to get it > working. Odd, very odd. But I am quite sure that if you don't have a driver for a certain chip set, that it doesn't matter who puts the chip set on a piece of PCB, it isn't going to work. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From steve at REMOVEMEcyber.com.au Mon Oct 10 21:51:21 2005 From: steve at REMOVEMEcyber.com.au (Steven D'Aprano) Date: Tue, 11 Oct 2005 11:51:21 +1000 Subject: Looking for info on Python's memory allocation Message-ID: <434B1A99.8040107@REMOVEMEcyber.com.au> Can somebody help me please? I've spent a fruitless hour googling with no luck. I'm discussing memory allocation techniques with somebody, and I'm trying to find a quote from -- I think -- Tim Peters where he discusses the way Python allocates memory when you append to lists. In basic terms, he says that every time you try to append to a list that is already full, Python doubles the size of the list. This wastes no more than 50% of the memory needed for that list, but has various advantages -- and I'm damned if I can remember exactly what those advantages were. Can anyone point me in the right direction? Thanks, -- Steven. From robert.kern at gmail.com Thu Oct 6 10:49:13 2005 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 06 Oct 2005 07:49:13 -0700 Subject: Simple prototype text editor in python In-Reply-To: <1128609090.858119.28110@g43g2000cwa.googlegroups.com> References: <1128530997.895468.164240@g49g2000cwa.googlegroups.com> <1128609090.858119.28110@g43g2000cwa.googlegroups.com> Message-ID: thakadu wrote: > Hi Viktor > > At the moment I dont have any web site where I can > upload it. Do you or anyone have any suggestions or > know of any web sites where one can post python code? > If not please email me and I will send you the code by email. If you package it with distutils, then you can upload the source distribution automatically to PyPI: http://python.org/pypi > Regarding the license I have not yet decided what type > of license (if any, since its very few lines of code) but probably > will be GPL or BSD style. I have no former experience in > licensing code so any suggestions will be welcome there as well. > (For one, do you know if simply stating somewhere in the > code "This is licensed under blah blah" is sufficient > to consider the code licensed?) Perhaps, but you really should include the full license text somewhere. Since your code is so short, then I highly recommend using a short, permissive license. It does no one any good to attach a license that's longer than the program 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 kylotan at gmail.com Wed Oct 19 05:03:56 2005 From: kylotan at gmail.com (Ben Sizer) Date: 19 Oct 2005 02:03:56 -0700 Subject: Upgrading 2.4.1 to 2.4.2 In-Reply-To: <1129690538.026623.28230@o13g2000cwo.googlegroups.com> References: <20051017192011.28785.qmail@web50206.mail.yahoo.com> <1129690538.026623.28230@o13g2000cwo.googlegroups.com> Message-ID: <1129712636.124150.248200@g44g2000cwa.googlegroups.com> brusstoc at gmail.com wrote: > Not sure that is a good idea on a linux system. MS should be fine, but > I actually tried that on linux. Didn't realize how much on a linux > system depends on Python. I had that problem once, although to be fair it really does depend on which distribution you use as to how many problems you're going to have. Perhaps the way to do it is to install the new Python version in /usr/local/ (alongside the distro's version is in /usr/ ), then when you're sure your new version is installed and working, change the references over - perhaps it's possible to do this with just 1 symbolic link somewhere. -- Ben Sizer From leomendoza at gmail.com Mon Oct 3 17:34:40 2005 From: leomendoza at gmail.com (leo) Date: 3 Oct 2005 14:34:40 -0700 Subject: Exception raising, and performance implications. Message-ID: <1128375280.034852.119910@o13g2000cwo.googlegroups.com> Hello all - I was wondering about the performance implications of explicitly raising exceptions to get information about the current frame. Something like what the inspect module does, with: --- def currentframe(): """Return the frame object for the caller's stack frame.""" try: raise 'catch me' except: return sys.exc_traceback.tb_frame.f_back --- I come from a java background, where Exceptions are a big Avoid Me, but are the performance implications the same in Python? We're expecting a big load on our app (100,000 users/hour) , so we'd like to be as tuned as possible. Thanks, leo From steve at REMOVETHIScyber.com.au Tue Oct 25 10:50:12 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Wed, 26 Oct 2005 00:50:12 +1000 Subject: Would there be support for a more general cmp/__cmp__ References: Message-ID: On Tue, 25 Oct 2005 10:09:29 -0400, Christopher Subich wrote: >>>By analogy, one can ask, "is the cat inside the box?" and get the answer >>>"No", but this does not imply that therefore the box must be inside the >>>cat. >> >> >> Bad analogy, this doesn't define a mathematical ordering, the subset >> relationship does. > > Yes, it does. Consider "in" as a mathematical operator: > > For the set (box, cat-in-box) > > box in box: False > box in cat-in-box: False > cat-in-box in box: True > cat-in-box in cat-in-box: False > > For the set (box, smart-cat) # cat's too smart to get in the box > > box in box: False > box in smart-cat: False > smart-cat in box: False > smart-cat in smart-cat: False > > In both these cases, the "in" operator is irreflexive, asymmetric, and > transitive (extend to mouse-in-cat if you really care about transitive), > so "in" is a partial order sans equality. A useless one, but a partial > order nonetheless. What do you mean "in" is a useless ordering? It makes a huge difference whether "nuclear bomb in New York" is true or not. In fact, I'm quite surprised that Antoon should object to "in" as "this doesn't define a mathematical ordering, the subset relationship does" when "subset" is just "in" for sets: set S is a subset of set T if for all elements x in S, x is also in T. Informally, subset S is in set T. Can somebody remind me, what is the problem Antoon is trying to solve here? -- Steven. From mwm at mired.org Fri Oct 28 16:50:28 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 28 Oct 2005 16:50:28 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <66u633-etj.ln1@news.it.uc3m.es> <7xbr1aewtq.fsf@ruckus.brouhaha.com> <86acgulv5z.fsf@localhost.localdomain> <7xvezi8ypy.fsf@ruckus.brouhaha.com> <86y84ehd3j.fsf@bhuda.mired.org> <86hdb2h750.fsf@bhuda.mired.org> <86zmoufiww.fsf@bhuda.mired.org> Message-ID: <86oe59e57v.fsf@bhuda.mired.org> "David Schwartz" writes: > "Mike Meyer" wrote in message > news:86zmoufiww.fsf at bhuda.mired.org... >> The quote about the mafia doesn't compare MS's actions to "actual use >> of force". > I'm sorry, that's just absurd. I won't speculate on what motivates you > to engage in such crazy distortion. Of course the quote about the Mafia > compares MS's actions to actual use of force. Maybe true, maybe not - but it doesn't matter. The point is that you respond to *every* comparison of MS with other criminals as a comparison to "criminals with guns", and then refuse to discuss the issue, with utter disregard as to what the other person said. That you might be right in one case is irrelevant - we're talking about a pattern of behavior. If MS had been found guilty of abuse of monopoly power in one instance, few people would care. People do make mistakes. That they have been found guilty of such abuse repeatedly, on multiple continents, and were recently caught doing it yet again - that's what makes them criminals. It's the pattern of behavior that matters, not the single instances. I'm still waiting for you to come up with an explanation for the pattern of your behavior other than that you're taking orders from MS. But I expect yout to deny that it exists. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From davids at webmaster.com Sat Oct 22 21:02:44 2005 From: davids at webmaster.com (David Schwartz) Date: Sat, 22 Oct 2005 18:02:44 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <86k6g59ke6.fsf@bhuda.mired.org> Message-ID: "Mike Meyer" wrote in message news:86k6g59ke6.fsf at bhuda.mired.org... >>> Neither I, nor you, nor the government of any nation, should care a >>> monkey's toss specifically for Microsoft's success. Microsoft is one >>> special interest, out of a potentially unbounded number of possible >>> players in the economy of a country and the world. >> No, not at all. It is the gravest act of self-contradiction to >> maintain >> that one should be allowed to pursue one's own interest while denying >> that >> same right to others. > Not at all. No one is denying anyones right to purssue their own > interest. What's being denied is the right to use illegal means to do > so. If MS restricted themselves to legal means, no one would have a > problem with them. The conclusion that the means were illegal is predicated on the definition of the relevent market as "desktop operating systems for 32-bit x86 computers". Conduct is not illegal unless some law puts people on adequate notice that their conduct is illegal. What law put Microsoft on notice that the relevent market would be defined in the bizarre and almost nonsensical way? >>> Unless you or I are specifically shareholders in Microsoft, we should >>> not >>> care about their specific success; and the government should be entirely >>> agnostic about who are the winners and losers in an economy. >> We should certainly care that Microsoft be allowed to pursue their >> own >> success. The government should be agnostic about who the winners and >> losers >> are, but must respect each entity's right to attempt to be that winner. > Nice thought. Unfortunately, the government doesn't work that > way. They believe that a practical monopoly is a bad thing, and limit > the things such a company can do, and have been known to disassemble > companies they believe are harming the economy in general. In other words, they believe the rights of Microsoft to do what they please with what is theirs is subservient to some general obligation to help the economy as a whole. I am saying that Microsoft has no obligaiton to the economy as a whole but instead has an obligation to its stockholders. It would be the gravest dereliction of that obligation for Microsoft to sacrifice itself for some general benefit. >>> The >>> government's role should be to ensure a level playing field, and minimum >>> levels of health, safety and environmental standards. There is no place >>> for government giving special-interests like Microsoft favours. >> The problem is, people complain when the playing field is in fact >> level. >> For example, Microsoft's "exclusionary" Windows agreements didn't ask for >> more than Windows was worth (or nobody would have agreed to them). Yet >> they >> are considered examples of the playing field not being level. > No, they didn't ask for more than Windows were worth. They tilted the > playing field against MS competitors by causing consumers to pay MS > money for products they didn't receive. In most countries, taking > money from unwilling victims without giving them anything in exchange > is called "theft". It is not theft if you can simply say "no" to the deal and all that happens is that you don't get the product. Your argument is preposterous. If you accept arguments that equate guns with arguments, the next step is that using a gun is a rational response to an argument one doesn't like. Oh wait, you're already there. >>> Microsoft's behaviour over-all has been just as anti-social, >>> anti-competitive and harmful to the over-all running of the economy as a >>> hypothetical Walmart or Safeway that regularly parked their trucks in >>> the >>> middle of the main road for a few hours while they unloaded. >> The problem is, the government does not own the economy. So it does >> not >> get to manage it the way it gets to manage the roads it in fact owns. > Sorry, but you're wrong. The government *does* own the econnomy. If you believe that, then there is no reaching you with reason. > Who > do you think originally created all the money that is flowing through > it? The government created a medium of exchange, but that is not the same as saying it created the wealth that money represents. The government created the money simply as a stand in for the wealth that was created by others. > The government charges you for the privilege of participating in > their economy - it's called "income tax". 2000 years ago Christ knew > who owned the economy, and said "Render unto Ceaser that which is > Ceasers." The government charges you, notionally, for the services it provides. It is somewhat silly to phrase as this as charging you for the privilege of participating in *their* economy. I am familiar with just about every theory for justifying government power, and I know of none that justifies a claim of complete government ownership of the economy other than those that lead to Communism or Totalitariansm. >>> Maybe, just maybe, if Mom & Pop's Corner Store tried it once or twice, >>> we >>> could afford to turn a blind eye, especially if the disruption caused by >>> towing their delivery van was greater than the disruption caused by >>> their >>> double-parking. Thousands of people break the law by double-parking for >>> a >>> few minutes, and society doesn't collapse. But something that we can >>> afford to ignore when done by M&P's Corner Store becomes a serious >>> problem >>> if done by somebody with the economic power of Walmart, with their >>> thousands of deliveries by 18-wheelers every day across the country. >> Again, the analogy fails. You are comparing the government's right to >> manage its own property with the government's "right" to interfere with >> other people's right to manage their property. > Sorry, but nobody but the government actually owns property. In most > places, you can't make non-trivial changes to "your" property without > permission from the government. They even charge you rent on "your" > property, only they call it "property tax". I see you are a totalitarianist or perhaps a communist. If you want to live in America and discuss things that are relevent to America, let me know. >> When a criminal willing to use force points a gun at your head, you >> lie >> to him. > You sound like an anarchist to me. This wasn't a criminal, this was > the government. Lieing to random individuals isn't a crime. Lieing to > the government is. If the government prosecutes people for crimes wherein there was no notice whatsoever that their conduct was criminal, it is acting criminally itself. Apparently, in your world the only alternatives are that the government owns everything or that the government owns nothing. As soon as I claim anything is beyond the government's power, I'm an anarchist in your book. >>> In any case, even if you are right that Microsoft had no ideas... so >>> what? >>> Ignorance of the law never has been an excuse for criminal behaviour. It >>> has always been every individual's responsibility to make sure that they >>> do not act illegally, and that goes for companies as well. >> I am not saying Microsoft did not know the law. I am saying that no >> rational person could have expected the law to be applied to Microsoft >> that >> way it was. The law *must* put a person on notice of precisely what >> conduct >> it prohibits. However, in this case, the law's applicability was >> conditioned >> on an abritrary and irrational choice of what the relevant market was. > MS has a long history of dancing with the DOJ, and has been repeatedly > warned about the legality - or lack thereof - of their behavior. No > rational person who knew of that history could expect the law to be > applied to MS in any way other than the way it was. Since when does the DOJ get to make the law? (George Bush's claims to the contrary not withstanding.) The issue is whether the *LAW* put Microsoft on notice. A just law must itself put people on notice as to precisely what conduct constitutes a violation of that law. DS From mde at micah.elliott.name Tue Oct 4 15:15:05 2005 From: mde at micah.elliott.name (Micah Elliott) Date: Tue, 4 Oct 2005 12:15:05 -0700 Subject: Newbie regular expression ? In-Reply-To: <1128450779.107011.5370@z14g2000cwz.googlegroups.com> References: <1128450779.107011.5370@z14g2000cwz.googlegroups.com> Message-ID: <20051004191505.GA32363@kitchen.client.attbi.com> On Oct 04, len wrote: > I have the following statement and it works fine; > > list1 = glob.glob('*.dat') > > however I now have an additional requirement the the string must begin > with any form of "UNQ,Unq,unq,..." > > as an example if I had the following four files in the directory: > > unq123abc.dat > xy4223.dat > myfile.dat > UNQxyc123489-24.dat > > only unq123abc.dat and UNQxyc123489-24.dat would be selected If glob is your preferred means, one option is: $ touch unq1.dat UnQ1.dat unQ1.dat UNQ1.dat foo.dat $ python -c ' - import glob - print glob.glob("[uU][nN][qQ]*.dat") - ' ['unq1.dat', 'UnQ1.dat', 'unQ1.dat', 'UNQ1.dat'] $ man 3 fnmatch -- Micah Elliott From skip at pobox.com Thu Oct 6 19:57:20 2005 From: skip at pobox.com (skip at pobox.com) Date: Thu, 6 Oct 2005 18:57:20 -0500 Subject: Force flushing buffers In-Reply-To: <4345b6e8$0$49009$14726298@news.sunsite.dk> References: <4345b6e8$0$49009$14726298@news.sunsite.dk> Message-ID: <17221.47584.829941.335497@montanaro.dyndns.org> Madhusudan> How do I flush the buffer and force python to write the Madhusudan> buffers to the files ? I intend to put this inside the loop. f = open("somefile", "w") f.write("foo") f.flush() Skip From ptb at oboe.it.uc3m.es Thu Oct 27 07:27:12 2005 From: ptb at oboe.it.uc3m.es (Peter T. Breuer) Date: Thu, 27 Oct 2005 13:27:12 +0200 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: In comp.os.linux.misc David Schwartz wrote: > Microsoft was not going to let a business > parasitically use Windows to build a business that touted the advantages of > competing products. Well, it should have, because that's what manufacturers of operating systems, washing machines, and so on, are supposed to do. And so says the legal system. Attempting to subvert market economics like that is illegal. > (Just as Burger King corporate will not you sell Big > Macs in the same store in which you sell Whoppers.) They're not obliged to. There is no comparison. Not even the same kind of business in the abstract. Try :- Cow Meat Inc. will see that no supplier will ever sell you cow meat again if you also sell vegetables in your totally independent restaurant. Peter From fredrik at pythonware.com Sat Oct 15 02:50:54 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 15 Oct 2005 08:50:54 +0200 Subject: MD5 module Pythonicity References: <6815022a0510142223q3b6ae449ja0483f2f25ebb263@mail.gmail.com> Message-ID: Fredrik Lundh wrote: > Forcing every digest module to add code to cater for just one of many > use cases is most likely a waste of time. here's the hash API specification, btw: http://www.python.org/peps/pep-0247.html From nemesis at nowhere.invalid Sat Oct 15 09:36:56 2005 From: nemesis at nowhere.invalid (Nemesis) Date: Sat, 15 Oct 2005 13:36:56 GMT Subject: [ANN] XPN 0.5.5 released References: <20051013194207.1700.5269.XPN@orion.homeinvalid> <1129300207_2667@spool6-east.superfeed.net> <20051014170644.1803.75237.XPN@orion.homeinvalid> <1129316814_3173@spool6-east.superfeed.net> Message-ID: <20051015094021.2058.55430.XPN@orion.homeinvalid> Mentre io pensavo ad una intro simpatica "Cousin Stanley" scriveva: [Upgrading XPN to 0.5.5 ...] [...] > files .... > > o custom_headers.txt > o groups_list > o server_logs.dat I'd add also config.txt ;-) > No initial configuration, downloading newsrc file, > or re-subscribing to newsgroups was required > and all of my previously kept & watched messages > seem to be in place .... > Thanks for the update .... Thanks to you for testing it. :-) -- Backup not found: (A)bort, (R)etry, (M)assive heart failure? |\ | |HomePage : http://nem01.altervista.org | \|emesis |XPN (my nr): http://xpn.altervista.org From rschroev_nospam_ml at fastmail.fm Tue Oct 4 04:40:16 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Tue, 04 Oct 2005 08:40:16 GMT Subject: Reply-To header In-Reply-To: <86fyrijlqu.fsf@bhuda.mired.org> References: <2ECA6FE9-3C8F-4C60-9E89-70CC078B14EF@gmail.com> <7rc0f.11261$Un.585792@phobos.telenet-ops.be> <86oe66jpfj.fsf@bhuda.mired.org> <86fyrijlqu.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > Roel Schroeven writes: > >>Is that really the desired behaviour? IMO the least you can do if you're >>searching for help is subscribing to the mailing list on which you're >>looking for help. Me and many others don't like to receive replies >>directly instead of via the mailing list; it's of no use, since we're >>subscribed to the mailing list anyway. > > > Rather than asking everyone else to modify their behavior for your > convenience, why don't you fix the problem at your end? Check to see > if the list will filter duplicates for you. Check to see if your > mailer will filter duplicates for you. Or grit and bear it. You'll > almost certainly get less unwanted mail from people who send you > duplicates in reply to your messages than they would get from > subscsribing to the list. Don't overreact please -- I was just asking if what you described is really the desired behavior, along with some of the reasons why I'm not sure that it is. My experience of reading a number of mailing lists throughout the years seem to indicate that most people prefer that people looking for help subscribe to the mailing list. I might be wrong of course, that's why I stated it as a question. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From belred at gmail.com Tue Oct 18 00:03:02 2005 From: belred at gmail.com (Bryan) Date: Mon, 17 Oct 2005 21:03:02 -0700 Subject: tuple versus list In-Reply-To: References: <1129460775.484350.209520@g44g2000cwa.googlegroups.com> <1129475300.537237.131090@f14g2000cwb.googlegroups.com> Message-ID: >> >>i always use the structure analogy. if you view (width, height) as a >>structure, >>use a tuple. if you view it a sequence, use a list. in this example, i view >>it >>as a stucture, so i would use (width, height) as a tuple. > > > Right, but there's an unfortunate ambiguity in the term "sequence", > since in Python it is defined to include tuple. I gather you meant > more in the abstract sense of a data collection whose interesting > properties are of a sequential nature, as opposed to the way we are > typically more interested in positional access to a tuple. Maybe > a more computer literate reader will have a better word for this, > that doesn't collide with Python terminology. My semi-formal > operational definition is "a is similar to a[x:y], where > x is not 0 or y is not -1, and `similar' means `could be a legal > value in the same context.'" > > Donn Cave, donn at u.washington.edu yes, you are correct. i shouldn't have used the word "sequence" which is a python term. maybe structure vs. array. in any case, i think the *wrong* answer that is often given to this question is along the lines of if it's read only, make it a tuple. if it's read write, make it a list. a great trivial example is a point. a point is a structure (x, y). if you have many points then you have a list of structures: [(x, y), (x1, y1), (x2, y2), ...]. to me, it doesn't matter if you want to modify a point. if you do then create a new one, but don't make it a list just to make it modifiable. bryan From rrr at ronadam.com Mon Oct 3 16:11:08 2005 From: rrr at ronadam.com (Ron Adam) Date: Mon, 03 Oct 2005 20:11:08 GMT Subject: "no variable or argument declarations are necessary." In-Reply-To: References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> Message-ID: Steven D'Aprano wrote: > On Mon, 03 Oct 2005 06:59:04 +0000, Antoon Pardon wrote: > > x = 12.0 # feet > # three pages of code > y = 15.0 # metres > # three more pages of code > distance = x + y > if distance < 27: > fire_retro_rockets() > > And lo, one multi-billion dollar Mars lander starts braking either too > early or too late. Result: a new crater on Mars, named after the NASA > employee who thought the compiler would catch errors. Yes, and a reserved position in the unemployment line as well, I would bet. > Declared variables have considerable labour costs, and only marginal > gains. Since the steps you take to protect against other errors will also > protect against mistyping variables, declarations of variables is of > little practical benefit. Also checking types is not the same as checking values. In most cases where critical code is used you really want value testing not type checking. This is where self validating objects are useful and there is nothing preventing anyone from using them in Python. Cheers, Ron From grante at visi.com Tue Oct 18 11:21:01 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 18 Oct 2005 15:21:01 -0000 Subject: Installing Python at Work References: <1129561955.452114.53290@g44g2000cwa.googlegroups.com> Message-ID: <11la4mthu8tar46@corp.supernews.com> On 2005-10-17, Nikola wrote: > I'm considering installing it on a work laptop, knowing that > it is non-licensed, distributable software. > > However, does it access communication ports? Only if you tell it to. -- Grant Edwards grante Yow! I'm having BEAUTIFUL at THOUGHTS about the INSIPID visi.com WIVES of smug and wealthy CORPORATE LAWYERS... From bokr at oz.net Sat Oct 15 21:47:19 2005 From: bokr at oz.net (Bengt Richter) Date: Sun, 16 Oct 2005 01:47:19 GMT Subject: dis.dis question References: Message-ID: <4351affc.104308027@news.oz.net> On Sun, 09 Oct 2005 12:10:46 GMT, Ron Adam wrote: >Ron Adam wrote: >> >> Can anyone show me an example of of using dis() with a traceback? >> >> Examples of using disassemble_string() and distb() separately if >> possible would be nice also. > > [cliped] > >> But I still need to rewrite disassemble_string() and need to test it >> with tracebacks. >> >> Cheers, >> Ron > >It seems I've found a bug in dis.py, or maybe a expected non feature. >When running dis from a program it fails to find the last traceback >because sys.last_traceback doesn't get set. (a bug in sys?) It works >ok from the shell, but not from the program. > >Changing it to to get sys.exc_info()[2], fix's it in a program, but then >it doesn't work in the shell. So I replaced it with the following which >works in both. > > try: > if hasattr(sys,'last_traceback'): > tb = sys.last_traceback > else: > tb = sys.exc_info()[2] > except AttributeError: > raise RuntimeError, "no last traceback to disassemble" > >I'm still looking for info on how to use disassemble_string(). > One way to get dis output without modufying dis is to capture stdout: (ancient thing I cobbled together, no guarantees ;-) >>> class SOCapture: ... """class to capture stdout between calls to start & end methods, q.v.""" ... import sys ... def __init__(self): ... self.so = self.sys.stdout ... self.text = [] ... def start(self, starttext=None): ... """Overrides sys.stdout to capture writes. ... Optional starttext is immediately appended as if written to stdout.""" ... self.sys.stdout = self ... if starttext is None: return ... self.text.append(starttext) ... def end(self, endtext=None): ... """Restores stdout to value seen at contruction time. ... Optional endtext is appended as if written to stdout before that.""" ... self.sys.stdout = self.so ... if endtext is None: return ... self.text.append(endtext) ... def gettext(self): ... """Returns captured text as single string.""" ... return ''.join(self.text) ... def clear(self): ... """Clears captured text list.""" ... self.text = [] ... def write(self, s): ... """Appends written string to captured text list. ... This method is what allows an instance to stand in for stdout.""" ... self.text.append(s) ... >>> def foo(x): return (x+1)**2 ... >>> so = SOCapture() >>> import dis >>> so.start() >>> dis.dis(foo) >>> so.end() >>> print so.gettext() 1 0 LOAD_FAST 0 (x) 3 LOAD_CONST 1 (1) 6 BINARY_ADD 7 LOAD_CONST 2 (2) 10 BINARY_POWER 11 RETURN_VALUE Or safer: >>> def diss(code): ... try: ... so = SOCapture() ... so.start() ... dis.dis(code) ... finally: ... so.end() ... return so.gettext() ... >>> diss(foo) ' 1 0 LOAD_FAST 0 (x)\n 3 LOAD_CONST 1 (1)\ n 6 BINARY_ADD \n 7 LOAD_CONST 2 (2)\n 10 BINARY_POWER \n 11 RETURN_VALUE \n' >>> print diss(foo) 1 0 LOAD_FAST 0 (x) 3 LOAD_CONST 1 (1) 6 BINARY_ADD 7 LOAD_CONST 2 (2) 10 BINARY_POWER 11 RETURN_VALUE Regards, Bengt Richter From ms at cerenity.org Sat Oct 29 12:06:20 2005 From: ms at cerenity.org (Michael) Date: Sat, 29 Oct 2005 17:06:20 +0100 Subject: Expanding Python as a macro language References: <1130545600.925061.287390@g49g2000cwa.googlegroups.com> Message-ID: <43639d74$0$6497$ed2619ec@ptn-nntp-reader01.plus.net> qwweeeit at yahoo.it wrote: > But then I changed idea... Also if it is already one year that I try > to find a solution in Linux (mainly with Python or DCOP and KDE), This doesn't express the question you have anywhere clearly enough. Linux can run perfectly happily without any form of windowing environment. Many people run using Gnome. Many others using KDE. And the number of people who use *neither* of those but some window manager is still high. Do you want to replay against qt applications? KDE? wx? GTK? Or send raw X11 events? The answers to these questions aren't linux specific either... Michael. From prince_amir86 at yahoo.com Sat Oct 8 18:37:47 2005 From: prince_amir86 at yahoo.com (Brandon K) Date: Sat, 08 Oct 2005 17:37:47 -0500 Subject: new forum -- homework help/chit chat/easy communication In-Reply-To: <1128798687.305818.66010@g49g2000cwa.googlegroups.com> References: <1128798687.305818.66010@g49g2000cwa.googlegroups.com> Message-ID: <1128811227_124196@spool6-east.superfeed.net> csheppard91 at gmail.com wrote: > I've launched a new forum not too long ago, and I invite you all to go > there: www.wizardsolutionsusa.com (click on the forum link). We offer > all kinds of help, and for those of you who just like to talk, there's > a chit chat section just for you...Just remember that forum > communication is much easier, safer, and faster. > [.section Blurb] About me: My name is James (Cantley) Sheppard. I am a North Carolina resident, at the age of 16. I have been programming since the age of 12, and enjoy it as lifes[sic] greatest passion. In the future, I would love to become the leading Software Engineer at a fairly large company, and maybe someday own my own business. As of right now, I am currently in high school and planning on going to a four year college somewhere around the country. Well, that is my life story, and about all I got to say! [.section Commentary] Hrm, obviously hasn't had enough programming experience in 4 years to quite know what he's talking about. Before making random "assertions" James, you might want to take into account the community you're talking to. I don't know about you guys, but I've had enough teen start up webpages. They clog the web. No offense of course to the younger readers, its just...it's like E/N sites...junk most of the time. ----== Posted via Newsgroups.com - Usenet Access to over 100,000 Newsgroups ==---- Get Anonymous, Uncensored, Access to West and East Coast Server Farms! ----== Highest Retention and Completion Rates! HTTP://WWW.NEWSGROUPS.COM ==---- From gsakkis at rutgers.edu Sun Oct 9 22:22:06 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: 9 Oct 2005 19:22:06 -0700 Subject: Newbie Count Question References: <1128904984.744314.70870@g44g2000cwa.googlegroups.com> Message-ID: <1128910925.989005.53230@o13g2000cwo.googlegroups.com> "ProvoWallis" wrote: > I've managed to get this far thanks to looking at other > posts on the board but no matter waht I try all of the > sections end up being numbered for the total number of > sections in the document. e.g., if there are 100 sections > in the document the "no" attribute is "1.100" > for each one. Of course it is; the counter you compute is fixed and equal to len(all). What you need is a substitution function that keeps track of the counter and increments it by one for every substitution. This means that the counter becomes part of the function's state. When you hear "function" and "state" together, the typical solution is "class": import re class ReplaceSecMain(object): def __init__(self): self._count = 0 self._secmain_re = re.compile(r''' (?<= ) # positive lookahead assertion ''', re.IGNORECASE | re.VERBOSE) def sub(self, text): return self._secmain_re.sub(self._subNum, text) def _subNum(self, match): self._count += 1 return '%s.%.2d' % (match.group(1), self._count) print ReplaceSecMain().sub(open("myfile.txt").read()) I also cleaned up the regular expression a little; google for lookahead/lookbehind assertions if you haven't seen them before. HTH, George From steve at holdenweb.com Fri Oct 21 11:15:18 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 21 Oct 2005 16:15:18 +0100 Subject: Psycopg2 date problems: "Can't adapt" In-Reply-To: <1129904648.249591.40010@g14g2000cwa.googlegroups.com> References: <1129904648.249591.40010@g14g2000cwa.googlegroups.com> Message-ID: bonono at gmail.com wrote: > Steve Holden wrote: > >>I'm trying to copy data from an Access database to PostgreSQL, as the >>latter now appears to work well in the Windows environment. However I'm >>having trouble with date columns. >> >>The PostgreSQL table receiving the data has the following definition: >> >>CREATE TABLE Lines ( >> LinID SERIAL PRIMARY KEY, >> LinDate TIMESTAMP(0), >> LinQty INTEGER, >> LinPrdID INTEGER , >> LinPrice NUMERIC(8,2), >> LinInvoice INTEGER) >> >>Here's the problem in a nutshell: >> >> >>> d >> >> >>> ocurs.execute("DELETE FROMI Lines") >> >>> osql >>'INSERT INTO Lines(LinID, LinDate, LinQty, LinPrdID, LinPrice, >>LinInvoice) VALUES(%s, %s, %s, %s, %s, %s)' >> >>> ocurs.execute(osql, (1, d, 1, 1, 12500.0, 88)) >>Traceback (most recent call last): >> File "", line 1, in >>psycopg.ProgrammingError: can't adapt >> >>> ocurs.execute(osql, (1, None, 1, 1, 12500.0, 88)) >> >>> >> >>Since the date value's the only difference between the two, I deduce >>it's causing the problem. >> [...] >> > Is "None" a valid value for SQL ? Or should it be NULL ? May be it is > because your input is NULL which is being converted to None in python > but haven't been converted back to NULL on its way out. > Python's None is the way you communicate null values through the query parameterisation mechanism. You will observe that the statement with the None value for the date field runs fine, and the error occurs when I provide an actual date object. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From schwehr at gmail.com Sun Oct 16 12:48:41 2005 From: schwehr at gmail.com (schwehr at gmail.com) Date: 16 Oct 2005 09:48:41 -0700 Subject: keeping unit test info out of pydoc -w? Message-ID: <1129481321.133397.17130@f14g2000cwb.googlegroups.com> Hi All, Is there an easy way to keep the unittest stuff out of the documentation that gets generated by pydoc -w? I just want to exclude the "Methods inherited from unittest.TestCase:" section. Thanks! -kurt From peter at engcorp.com Tue Oct 25 04:37:06 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 25 Oct 2005 04:37:06 -0400 Subject: Tricky Areas in Python In-Reply-To: References: <1130097286.772836.94930@g44g2000cwa.googlegroups.com> Message-ID: Tim Roberts wrote: > "PyPK" wrote: >>What possible tricky areas/questions could be asked in Python based >>Technical Interviews? > > What's the point of asking "tricky" questions? Aren't you really more > interested in what applications they have worked on and whether they were > successful? > > I don't know. I'm not sure I need a job with a company that insists on > playing "Programming Jeopardy" during the interview. That's okay. Those companies don't need you either. ;-) Seriously though, the point of asking such questions is that with minimal effort they _can_ (not "definitely will") quickly qualify a candidate's level of expertise in a language. Novices, and those who while they might have programmed in a language for several years still don't really understand it deeply enough to be considered entirely safe on their own, will generally trip up on all or most such questions (where "trip up" means anything from giving wrong answers to giving you the "deer in the headlights" look). _Anyone_ could trip up on one or two of them, especially given the pressure of an interview situation. (And even seeing an expert trip up under pressure tells you something useful about the candidate.) In short, a true senior programmer will provide good correct answers to most such questions, while those less senior generally will not. Asking such questions in isolation, without also delving deeply into other background such as what applications you've worked on, is just as dangerous as asking _only_ about such applications. I've made the mistake of hiring people who had lengthy involvement -- apparently at a senior level -- in significant projects, only to discover that they clearly didn't understand some basic concepts of the languages supposedly used. My conclusion was that they were in that class of people who manage to interview well yet contribute little, but have lucked out repeatedly by working for companies who were incompetent at terminating for cause (and there are _many_ such companies). (We didn't make the same mistake and fired them reasonably quickly.) -Peter From http Thu Oct 27 07:47:27 2005 From: http (Paul Rubin) Date: 27 Oct 2005 04:47:27 -0700 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <3s6l8mFmj3fjU1@individual.net> <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> <7xwtjz3jc9.fsf@ruckus.brouhaha.com> <7xwtjzcyxo.fsf@ruckus.brouhaha.com> <7xbr1b74rf.fsf@ruckus.brouhaha.com> Message-ID: <7xhdb35ghc.fsf@ruckus.brouhaha.com> "David Schwartz" writes: > The appeals courts upheld that the trial court did not abuse its > discretion. However, both a finding of "yes, Microsoft had a monopoly" and a > finding of "no, Microsoft did not have a monopoly" would both have been > within the trial court's discretion. No, that finding would have been contradictory to the facts at hand. > They could just as easily have found that Linux, OSX, FreeBSD, and > other operating systems competed with Windows. Nice try, but those other OS's did not have enough market share to prevent the finding of monopoly under the law. > To call it an "established legal fact" is to grossly distort the > circumstances under which it was determined and upheld. Who is paying you to post such nonsense? If the trial court determines a fact and it's upheld on appeal, it's an established legal fact regardless of whether you or Microsoft likes it. From peter at engcorp.com Mon Oct 10 22:23:02 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 10 Oct 2005 22:23:02 -0400 Subject: Library functions In-Reply-To: <1128989170.017791.235100@z14g2000cwz.googlegroups.com> References: <1128973241.967119.199440@g43g2000cwa.googlegroups.com> <11klhlmas9nfm40@corp.supernews.com> <1128989170.017791.235100@z14g2000cwz.googlegroups.com> Message-ID: Tuvas wrote: > How exactly do you do that? Just to get some kind of an idea, perhaps > you could share bits of code? Thanks! Did you check out the ctypes web site before asking? See http://starship.python.net/crew/theller/ctypes/ and at least read through the helpful tutorial before asking questions which are almost certainly covered there. For example, right there near the top of the first screen in the tutorial is an example of opening a Linux .so file... -Peter From codecraig at gmail.com Mon Oct 24 13:24:34 2005 From: codecraig at gmail.com (jas) Date: 24 Oct 2005 10:24:34 -0700 Subject: Read/Write from/to a process In-Reply-To: <1130174259.472124.114790@f14g2000cwb.googlegroups.com> References: <1130163642.868252.148070@g44g2000cwa.googlegroups.com> <1130174259.472124.114790@f14g2000cwb.googlegroups.com> Message-ID: <1130174674.759464.197470@z14g2000cwz.googlegroups.com> actually, i can't check for ">" only because if you a dir, a line can end with a > but is not the end of the output jas wrote: > Thanks, that is certainly a start. As you mentioned, the "cd" could is > an issue. > > Perhaps checking to see if the line ends with ">" is sufficient? > > Dennis Lee Bieber wrote: > > On 24 Oct 2005 07:20:42 -0700, "jas" declaimed the > > following in comp.lang.python: > > > > > Hi, > > > I would like to start a new process and be able to read/write from/to > > > it. I have tried things like... > > > > > > import subprocess as sp > > > p = sp.Popen("cmd.exe", stdout=sp.PIPE) > > > p.stdin.write("hostname\n") > > > > > > however, it doesn't seem to work. I think the cmd.exe is catching it. > > > > One: you didn't read any of the "returned" output... > > > > Two: the output only seems to be available upon EOF, which means the > > spawned command processor has to exit first... Though you CAN read one > > character at a time, and then have to build lines and expected prompt > > strings... > > > > > > This seems to work: > > -=-=-=-=-=-=-=-=- > > import subprocess > > import os > > > > PROMPT = os.getcwd() + ">" > > > > def getLine(proc): > > ld = [] > > while True: > > c = proc.stdout.read(1) > > if c == "\r": continue #skip Windows > > if c != "\n": ld.append(c) #save all but > > if c is None or c == "\n" or c == ">": break > > ln = "".join(ld) > > return ln > > > > p = subprocess.Popen("cmd.exe", stdout=subprocess.PIPE, stdin = > > subprocess.PIPE) > > > > print "**** START of captured output" > > while True: > > ln = getLine(p) > > print ln > > if ln == PROMPT: break > > print "**** END of captured output" > > > > p.stdin.write("ipconfig\n") > > print "**** START of captured output" > > while True: > > ln = getLine(p) > > print ln > > if ln == PROMPT: break > > print "**** END of captured output" > > > > p.stdin.write("dir\n") > > print "**** START of captured output" > > while True: > > ln = getLine(p) > > print ln > > if ln == PROMPT: break > > print "**** END of captured output" > > > > p.stdin.write("exit\n") > > -=-=-=-=-=-=-=-=-=- > > E:\UserData\Dennis Lee Bieber\My Documents>python script1.py > > **** START of captured output > > Microsoft Windows XP [Version 5.1.2600] > > (C) Copyright 1985-2001 Microsoft Corp. > > > > E:\UserData\Dennis Lee Bieber\My Documents> > > **** END of captured output > > **** START of captured output > > ipconfig > > > > Windows IP Configuration > > > > > > Ethernet adapter Local Area Connection: > > > > Connection-specific DNS Suffix . : > > IP Address. . . . . . . . . . . . : 192.168.1.100 > > Subnet Mask . . . . . . . . . . . : 255.255.255.0 > > IP Address. . . . . . . . . . . . : fe80::211:11ff:fee1:f303%4 > > Default Gateway . . . . . . . . . : 192.168.1.1 > > > > Tunnel adapter Teredo Tunneling Pseudo-Interface: > > > > Connection-specific DNS Suffix . : > > IP Address. . . . . . . . . . . . : > > 3ffe:831f:4004:1956:0:fbde:bd0a:e50b > > IP Address. . . . . . . . . . . . : fe80::5445:5245:444f%5 > > Default Gateway . . . . . . . . . : :: > > > > Tunnel adapter Automatic Tunneling Pseudo-Interface: > > > > Connection-specific DNS Suffix . : > > IP Address. . . . . . . . . . . . : fe80::5efe:192.168.1.100%2 > > Default Gateway . . . . . . . . . : > > > > E:\UserData\Dennis Lee Bieber\My Documents> > > **** END of captured output > > **** START of captured output > > dir > > Volume in drive E is Data > > Volume Serial Number is 2626-D991 > > > > Directory of E:\UserData\Dennis Lee Bieber\My Documents > > > > 10/24/2005 09:23 AM > > . > > 10/24/2005 09:23 AM > > .. > > 07/25/2005 10:39 PM > > .metadata > > 10/06/2005 09:54 AM > > Ada Progs > > 08/13/2005 02:01 PM > > Agent Data > > 10/21/2005 09:29 AM 421,820 apress_offer.pdf > > 07/03/2005 11:36 AM 132 cp.py > > 07/17/2005 12:25 PM > > Cyberlink > > 07/06/2005 09:32 AM 102,400 db1.mdb > > 07/26/2005 12:20 AM 26,614 eclipse_code.xml > > 10/24/2005 01:08 AM > > Eudora > > 06/24/2005 08:50 PM 667 fake_oosums.ads > > 06/24/2005 08:50 PM 695 fake_oosums.ali > > 09/06/2005 09:01 PM > > Genealogy > > 07/13/2005 10:56 PM > > HomeSite > > 05/08/2005 01:05 PM > > Investing > > 10/21/2005 10:04 PM > > Java Progs > > 08/04/2005 10:13 PM 162 main.py > > 10/11/2005 10:43 PM > > My Downloads > > 05/01/2005 10:31 AM > > My eBooks > > 04/22/2005 12:09 AM > > My Music > > 07/10/2005 11:43 AM > > My Pictures > > 06/29/2005 11:55 PM > > My PSP Files > > 05/23/2005 09:30 AM > > My Videos > > 05/01/2005 12:49 PM > > Office Documents > > 06/27/2005 03:19 PM 7,961,778 > > org.eclipse.jdt.doc.user.I20050627-1435.pdf > > 06/27/2005 03:19 PM 6,791,109 > > org.eclipse.platform.doc.user.I20050627-1435.pdf > > 10/11/2005 10:52 PM 56 oth_tsr_rm_750.ram > > 07/20/2005 09:32 AM 108,457 parkerred15yc.jpg > > 09/03/2005 10:36 PM > > Python Progs > > 10/20/2005 10:38 PM > > Quicken > > 07/10/2005 12:09 PM 3,356,248 results.xml > > 06/11/2005 12:03 PM 935 Scout_Ship Database.lnk > > 07/03/2005 12:38 PM > > Scout_Ship My Documents > > 10/24/2005 09:23 AM 971 Script1.py > > 09/25/2005 12:40 PM 1,107 Script1_old.py > > 08/28/2005 11:47 AM > > SimpleMu Logs > > 06/24/2005 08:56 PM 1,201 student_pack.ads > > 06/24/2005 08:49 PM 1,144 student_pack.ads.0 > > 06/24/2005 08:56 PM 1,342 student_pack.ali > > 08/02/2005 11:39 PM 4,096 t.DOC > > 06/20/2005 10:11 AM 104 t.rx > > 08/05/2005 08:41 PM 66,452 Untitled-1.tif > > 08/05/2005 08:41 PM > > VCheck > > 10/03/2005 02:58 AM > > Visual Studio > > 10/03/2005 02:51 AM > > Visual Studio 2005 > > 21 File(s) 18,847,490 bytes > > 25 Dir(s) 267,162,845,184 bytes free > > > > E:\UserData\Dennis Lee Bieber\My Documents> > > **** END of captured output > > > > E:\UserData\Dennis Lee Bieber\My Documents> > > > > -=-=-=-=-=-=-=-=- > > > > Note that my "getLine()" has to return on either a real EOL, OR on > > the end of a command prompt ("stuff>"). I also had to initialize the > > prompt at the start. If someone issued a "cd" command to the subprocess, > > the prompt would be all out of sequence, and the code would hang. > > > > You'll also note that the prompt /ends/ a capture sequence, and the > > next command is the start of the /next/ capture sequence. > > > > -- > > > ============================================================== < > > > wlfraed at ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG < > > > wulfraed at dm.net | Bestiaria Support Staff < > > > ============================================================== < > > > Home Page: < > > > Overflow Page: < From steve at holdenweb.com Wed Oct 19 04:14:12 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 19 Oct 2005 09:14:12 +0100 Subject: how to return correct value of update stmt In-Reply-To: <1129680385.808139.97850@g47g2000cwa.googlegroups.com> References: <1129680385.808139.97850@g47g2000cwa.googlegroups.com> Message-ID: eight02645999 at yahoo.com wrote: > hi > i use odbc to update a table in a database but i always get return > value of -1 > even though i tried to return an integer. the table is updated though > ... > sql = """ > update table > set column = 0 > where col = "%s" > select @@rowcount > > """ % (var1) > .... > try: > s = odbc.odbc(connectstring) > cur = s.cursor() > res = cur.execute(sql) > s.commit() > s.close() > cur.close() > s = None > cur = None > print res > return res > except: > print 'error while processing ', sys.exc_type,sys.exc_value > > > how to properly get a positive return ? > thanks > Is the table actually being updated? The definition of the cursor.execute() method in http://www.python.org/peps/pep-0249.html specifically says "Return values are not defined". So if you are seeing the database do the right thing I'd stop worrying about the return value. If exceptions aren't being raised and the database is doing what you want, what's the problem? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From tuvas21 at gmail.com Thu Oct 20 00:21:59 2005 From: tuvas21 at gmail.com (Tuvas) Date: 19 Oct 2005 21:21:59 -0700 Subject: Extention Woes In-Reply-To: <1129780560.288676.177850@f14g2000cwb.googlegroups.com> References: <1129753094.056781.319720@z14g2000cwz.googlegroups.com> <1129777857.676019.263340@f14g2000cwb.googlegroups.com> <1129780560.288676.177850@f14g2000cwb.googlegroups.com> Message-ID: <1129782119.830390.235540@g47g2000cwa.googlegroups.com> Well, the point of declaring it as a char was to have it as an 8 bit integer, as is requested later on in the program. Anyways, I tried making the changes, similar results. The len value was always right, the problem seems to be in this com value. BTW, it doesn't give me one single warning, so I don't think it's a casting problem... I did a full check, and this can_han variable is right. Hmmm... Other ideas? From s_siegel at gmx.net Mon Oct 10 16:38:50 2005 From: s_siegel at gmx.net (Stefan Siegel) Date: Mon, 10 Oct 2005 22:38:50 +0200 Subject: how to check if file is in use? Message-ID: <434ad15a$0$26210$9b4e6d93@newsread2.arcor-online.net> Hi all, can anybody give me (a python newbie) give a hint how to check in python wether a file is in use by another program? Thanks for your effort, Stefan From twic at urchin.earth.li Fri Oct 21 13:43:30 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Fri, 21 Oct 2005 18:43:30 +0100 Subject: Python vs Ruby In-Reply-To: <1129903667.255441.133490@g47g2000cwa.googlegroups.com> References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> <1129853715.441205.322480@g49g2000cwa.googlegroups.com> <86wtk7ty71.fsf@bhuda.mired.org> <1129903667.255441.133490@g47g2000cwa.googlegroups.com> Message-ID: On Fri, 21 Oct 2005, vdrab wrote: > You can tell everything is well in the world of dynamic languages when > someone posts a question with nuclear flame war potential like "python > vs. ruby" and after a while people go off singing hymns about the beauty > of Scheme... +1 QOTW > I love this place. Someone should really try posting a similar question on c.l.perl and seeing how they react ... tom -- Transform your language. From skip at pobox.com Wed Oct 5 06:56:57 2005 From: skip at pobox.com (skip at pobox.com) Date: Wed, 5 Oct 2005 05:56:57 -0500 Subject: bug or feature? In-Reply-To: <1128508770.727391.313300@f14g2000cwb.googlegroups.com> References: <1128508770.727391.313300@f14g2000cwb.googlegroups.com> Message-ID: <17219.45433.420666.124143@montanaro.dyndns.org> beza1e1> class A: beza1e1> def __init__(self, lst=[]): beza1e1> self.lst = lst Lists are mutable and default args are only evaluated once, at function definition. If you want independent default args use: class A: def __init__(self, lst=None): if lst is None: lst = [] self.lst = lst The same scheme would work for other mutable types (dicts, sets, etc). This same question gets asked once a month or so. I'm sure this is in the Python FAQ (check the website), but it was faster to reply than to look it up... Skip From Jeremy.Martin at noaa.gov Wed Oct 26 23:55:57 2005 From: Jeremy.Martin at noaa.gov (Jeremy Martin) Date: Wed, 26 Oct 2005 21:55:57 -0600 Subject: urllib2 problem Message-ID: List, I'm relatively new to using python for interacting with webpages but Ive run into a problem that really has me stumped. I wrote a script that would figure out all the variables needed to request data from a website. I originally just used urllib.urlopen and everything worked fine on my Windows PC at work. I tried the same script at home on my Fedora COre 3 box using python 2.4, and whenever I try to connect to the site I get the (110, Connection Timed Out) Error. At first I thought my firewall was causing problems with the script but I noticed an odd patten. If the web site asked to accept cookies (like the site I need) the script times out), if I point it to a site that doesnt it works fine. Ive tried several attempts at using urllib2 and the HTTPCookieProccessor and I still have no luck. Can anyone give me any advice or pointers on what may be the problem here? I apologize if this is kind of a rookie question but Ive been searching for about a week with no luck. Thanks! Jeremy Martin NWS WFO GLD From jbellis at gmail.com Sat Oct 22 00:30:25 2005 From: jbellis at gmail.com (Jonathan Ellis) Date: 21 Oct 2005 21:30:25 -0700 Subject: C replacement for Queue module In-Reply-To: References: <1129934643.874242.37150@g47g2000cwa.googlegroups.com> <1129944777.362827.147670@g43g2000cwa.googlegroups.com> Message-ID: <1129955425.042466.227090@z14g2000cwz.googlegroups.com> jepler at unpythonic.net wrote: > does collections.deque have a blocking popleft()? If not, it's not very > suitable to replace Queue.Queue. It does not. -Jonathan From aleax at mail.comcast.net Sat Oct 8 04:28:23 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Sat, 8 Oct 2005 01:28:23 -0700 Subject: Google Not Universal Panacea [was: Re: Where to find python c-sources] References: Message-ID: <1h437z7.1wrgc6gzvvc1zN%aleax@mail.comcast.net> Steve Holden wrote: ... > >> Are people really too lazy to do elementary research on Google? > > goes a bit too far in imputing motives to the enquirer and overlooking > the fact that there are some very good reasons for *not* using Google. It's a good thing you don't actually name any of those reasons, tho:-). > we're talking male hormones here, since by and large women don't appear > to have embraced the Python community (except perhaps individually, but > that's no business of mine). Anna seems to be doing fine, though. She's currently taking a C class at college and claims "the more I know C, the more I love Python" - and I gather she's evangelizing (and the class is about 50/50 genderwise;-). > Also, many regular readers didn't grow up speaking English (I was Yep -- I'm one example of that. Didn't stop Google from hiring me, though;-). Alex From jstroud at mbi.ucla.edu Fri Oct 28 16:45:39 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Fri, 28 Oct 2005 13:45:39 -0700 Subject: Tkinter Frame Size In-Reply-To: <1130522431.305985.89720@g44g2000cwa.googlegroups.com> References: <1130521112.659385.148750@g47g2000cwa.googlegroups.com> <1130522431.305985.89720@g44g2000cwa.googlegroups.com> Message-ID: <200510281345.39999.jstroud@mbi.ucla.edu> On Friday 28 October 2005 11:00, Tuvas wrote: > Okay. I have alot of items that are put on the basic frame already, > using a grid method. Will this change anything? It shouldn't. For example from Tkinter import * app = Tk() app.geometry("%dx%d%+d%+d" % (600, 400, 0, 0)) f = Frame(app) f.pack() L1 = Label(f, text="Bob & Carol & Ted & Alice") L1.grid(row=0, column=0, columnspan=2) L2 = Label(f, text="Barney") L2.grid(row=1, column=0) L3 = Label(f, text="Betty") L3.grid(row=1, column=1) app.mainloop() Just grid everything in the frame then pack the frame in the Tk(). However do not mix grid and pack in the same frame or it will lock up your app. E.g. *dont* do this: L1 = Label(f, text="Bob & Carol & Ted & Alice") L1.grid(row=0, column=0, columnspan=2) L2 = Label(f, text="Barney") L2.pack() James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From email at christoph-haas.de Mon Oct 24 09:26:08 2005 From: email at christoph-haas.de (Christoph Haas) Date: Mon, 24 Oct 2005 15:26:08 +0200 Subject: difference after remove In-Reply-To: <1d987df30510240602j4916a088s63f4fe34857943d1@mail.gmail.com> References: <1d987df30510240602j4916a088s63f4fe34857943d1@mail.gmail.com> Message-ID: <200510241526.14213.email@christoph-haas.de> On Monday 24 October 2005 15:02, Shi Mu wrote: > Is there any difference if I remove the '/' > from the following statement? You probably mean '\' instead of '/'. > intMatrix2 = [[1,1,2,4,1,7,1,7,6,9],\ > [1,2,5,3,9,1,1,1,9,1],\ > [0,0,5,1,1,1,9,7,7,7]] > print intMatrix2 > I removed one '\' and it still works. > So what is the use of '\'? It's a line continuation character. But you can omit it if it's clear to the interpreter that the line must continue - like when using brackets. Christoph -- ~ ~ ".signature" [Modified] 1 line --100%-- 1,48 All From timr at probo.com Sun Oct 9 04:32:39 2005 From: timr at probo.com (Tim Roberts) Date: Sun, 09 Oct 2005 08:32:39 GMT Subject: Matching zero only once using RE References: <1128706522.319929.75310@g49g2000cwa.googlegroups.com> <86ll15nri1.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > >I think it's time to form a Committee for the Prevention of Regular >Expression Abuse. As I learned from personal experience, this is a disease which one contracts when moving to Python from Perl. Perl teaches you that the entire world is a string, and every operation is a regular expression match upon that string. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From ntamas at gmail.com Thu Oct 20 09:27:55 2005 From: ntamas at gmail.com (Tamas Nepusz) Date: 20 Oct 2005 06:27:55 -0700 Subject: KeyboardInterrupt vs extension written in C Message-ID: <1129814875.226834.10260@g49g2000cwa.googlegroups.com> Hi everyone, I have tried to do some googling before asking my question here, but I haven't found any suitable answer. I am developing a Python API for a graph library written in pure C. The library is doing an awful lot of math computations, and some of them can take a pretty long time (depending on the size of the input). If I invoke such calculation from Python using my own extension, the interpreter locks until the calculation is complete (I mean, it is not responding to Ctrl-C or SIGINT). My question is: is there any way to allow the user to use Ctrl-C to generate a KeyboardInterrupt and cancel such large computations? I'm assuming that although pressing Ctrl-C may generate a KeyboardInterrupt in Python, it is not propagated to the user level until the call into the graph library returns. I tried to add Py_BEGIN_ALLOW_THREADS before the call to the underlying C library and Py_END_ALLOW_THREADS after returning from it, but I had no luck. Thanks in advance for your answers, -- Tamas From joerg.schuster at gmail.com Tue Oct 25 05:16:15 2005 From: joerg.schuster at gmail.com (Joerg Schuster) Date: 25 Oct 2005 02:16:15 -0700 Subject: more than 100 capturing groups in a regex In-Reply-To: References: <1130160675.270886.208420@z14g2000cwz.googlegroups.com> Message-ID: <1130231775.770582.199690@g43g2000cwa.googlegroups.com> > What happens if you up the limit to whatever you need? Good idea. I just tried this. Nothing evil seems to happen. This seems to be a solution. Thanks. J?rg From steve at REMOVETHIScyber.com.au Fri Oct 7 22:38:09 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sat, 08 Oct 2005 12:38:09 +1000 Subject: noob question Letters in words? References: <1128733382.015447.231300@f14g2000cwb.googlegroups.com> Message-ID: On Fri, 07 Oct 2005 18:03:02 -0700, mensanator at aol.com wrote: > Why not just look at the first letter the user types instead of > the whole string? > > if choice1[0] in ('1', 'S', 's'): > #do first option > if choice1[0] in ('2', 'E', 'e'): > #do second option Is it *really* a good idea if the user types "STOP!!!" and it has the same effect as if they typed "Start please"? I've heard of "Do what I mean, not what I said" systems, which are usually a really bad idea, but this is the first time I've seen a "Do what I don't mean, not what I said" system. -- Steven. From schwehr at gmail.com Tue Oct 25 11:38:04 2005 From: schwehr at gmail.com (schwehr at gmail.com) Date: 25 Oct 2005 08:38:04 -0700 Subject: Math markup in code documentation? In-Reply-To: <435e4fe3$1@news.uni-ulm.de> References: <1130251116.027733.123750@g47g2000cwa.googlegroups.com> <435e4fe3$1@news.uni-ulm.de> Message-ID: <1130254684.031546.16930@g14g2000cwa.googlegroups.com> Awesome!!! When did doxygen start supporting python? I was really into doxygen last year, but stopped using it when I started doing a lot of coding in python. Thanks!!!! -kurt From john at castleamber.com Sat Oct 15 20:26:41 2005 From: john at castleamber.com (John Bokma) Date: 16 Oct 2005 00:26:41 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: "Matt Garrish" wrote: > > "Tim Roberts" wrote in message > news:a103l1tkejrc99s0385qjqqhm96d46dpc4 at 4ax.com... >> "Jeroen Wenting" wrote: >>> >>>Microsoft isn't evil, they're not a monopoly either. >>>If they were a monopoly they'd have 100% of the market and there'd be >>>no other software manufacturers at all. >> >> This is wrong. The dictionary definition of a monopoly is when a >> manufacturer has all or nearly all of a market. Microsoft DOES have >> a monopoly on PC operating systems. >> >> That, in itself, is not necessarily illegal. However, Microsoft then >> USED that monopoly power to stifle their competition, and that IS >> illegal. >> >> Part of their behavior really escape me. The whole thing about >> browser wars confuses me. Web browsers represent a zero billion >> dollar a year market. Why would you risk anything to own it? >> > > It may not be worth loads of money in-and-of itself now (don't forget > Netscape wasn't always free, though), but if you control how people > view the Internet you can make a lot of money in other ways, > especially if you build your browser into your operating system and > warp standards Which standards? W3C doesn't make standards (they talk about working drafts and recommendations), so nothing to warp there for MS. > so that people who design sites take advantage of the > proprietary features. Yup, Netscape did the same, remember LiveScript (renamed to JavaScript for obvious reasons), and the elements they added? (Like the, horror, blink) > Eventually the hope is that your OS and browser > will become the only means of accessing the internet. And if your OS > and browser are the only way to access the Internet, who in their > right mind would use another system? It's not happening, so what are you talking about? Any developer hoping the above has no clue what he/she is developing. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From http Tue Oct 4 18:22:21 2005 From: http (Paul Rubin) Date: 04 Oct 2005 15:22:21 -0700 Subject: how to get any available port References: <1128456405.664869.170530@g47g2000cwa.googlegroups.com> <11k5pgpp19v0ec@corp.supernews.com> <7xbr25xbot.fsf@ruckus.brouhaha.com> <11k5qpiri213s59@corp.supernews.com> <7xslvhj7xq.fsf@ruckus.brouhaha.com> <11k5tpkffpf1567@corp.supernews.com> Message-ID: <7xpsqkhqhu.fsf@ruckus.brouhaha.com> "Fredrik Lundh" writes: > Grant Edwards wrote: > > IIRC, you just call bind() with a port number of zero, and then > > use some method-or-other on the bound socket to find out what > > port it's bound to. > > >>> s = socket.socket() > >>> s.bind(("", 0)) > >>> s.getsockaddr() > ("0.0.0.0", 4711) Nice. Thanks. From neyfakh at uic.edu Fri Oct 28 23:00:31 2005 From: neyfakh at uic.edu (Alex Neyfakh) Date: Sat, 29 Oct 2005 03:00:31 -0000 Subject: pickling classes with __slots__ Message-ID: <6.1.0.6.2.20051128215226.01b9ff70@mailserv.uic.edu> I would greatly appreciate an advice on the following matter that was very much discussed circa 2002 but in all this discussion I could not find the final answer with a code example. I have a series of new classes with child-parent relationship and each has unique __slots__. They don't have __dict__ . I need to be able to pickle and unpickle them. As far as I could understand, I need to provide __getstate__ and __setstate__ methods for each class. Is there a universally accepted code for each method? If so, what is it? If there is no standard, what works? TIA Alex From none at none.com Fri Oct 28 03:25:23 2005 From: none at none.com (Wil Hadden) Date: Fri, 28 Oct 2005 08:25:23 +0100 Subject: a Haskell a Day References: <1130312303.713737.160830@g44g2000cwa.googlegroups.com> <3vmul1hli2t3cuquab99fnlg2g9abqkj3o@4ax.com> Message-ID: "steve" wrote in message news:djrg94071g at news3.newsguy.com... > > > Stupid newbi wants $1 if you spend more than 30 minutes on his webshite, > looking at it you would be hard pressed to spend 30 seconds. > Anyway at least we know where to find him. > > Broadcasting his antics in Las Vegas is funny though. Not from the text mind, more the ramifications is he were to say, quote his website in a job interview, for example. From sunspire at gmail.com Sun Oct 30 08:14:10 2005 From: sunspire at gmail.com (Max Rybinsky) Date: 30 Oct 2005 05:14:10 -0800 Subject: lambda functions within list comprehensions In-Reply-To: <1130677633.449893.131080@g44g2000cwa.googlegroups.com> References: <1130621124.101346.67750@g44g2000cwa.googlegroups.com> <1h57711.1t6uely1atckigN%aleaxit@yahoo.com> <1130624219.667062.290740@g47g2000cwa.googlegroups.com> <1h57c0h.kcl38fefrcdrN%aleaxit@yahoo.com> <1130677633.449893.131080@g44g2000cwa.googlegroups.com> Message-ID: <1130678050.197762.161660@g47g2000cwa.googlegroups.com> Valid link in my previews message is http://mail.python.org/pipermail/python-dev/2005-September/056669.html Sorry. From bokr at oz.net Mon Oct 3 04:09:32 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 03 Oct 2005 08:09:32 GMT Subject: Will python never intend to support private, protected and public? References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xd5mstqab.fsf@ruckus.brouhaha.com> <7xzmpwuxd0.fsf@ruckus.brouhaha.com> <20050930075313.67b9b676.jk@ospaz.ru> <7xbr2a6dlz.fsf@ruckus.brouhaha.com> <7xk6gyoibc.fsf@ruckus.brouhaha.com> <433f56a3.2969039483@news.oz.net> <1128274267.064255.306980@f14g2000cwb.googlegroups.com> <7x8xxbgj4h.fsf@ruckus.brouhaha.com> Message-ID: <4340dfd2.3069694347@news.oz.net> On 03 Oct 2005 00:22:22 -0700, Paul Rubin wrote: >"El Pitonero" writes: >> The thing is, there are two sides to every coin. Features surely can >> be viewed as "goodies", or they can be viewed as "handcuffs". > >Let's see, say I'm a bank manager, and I want to close my cash vault >at 5pm today and set its time lock so it can't be opened until 9am >tomorrow, including by me. Is that "handcuffs"? It's normal >procedure at any bank, for good reason. It's not necessarily some >distrustful policy that the bank CEO set to keep me from robbing the >bank. I might have set the policy myself. Java lets me do something >similar with instance variables. Why is it somehow an advantage for >Python to withhold such a capability? > >> Sure, in these very dynamic languages you can ACCIDENTALLY override >> the default system behavior. How many Python programmers have once >> upon a time done stupid things like: >> list = 3 > >That's just a peculiarity, not any deep aspect of Python. Try it for >'None' instead of 'list': > > >>> None = 3 > SyntaxError: assignment to None > >Why is 'list' somehow different from 'None'? I'd say there's a case >to be made for having the compiler protect 'list' and other builtins >the same way it protects 'None'. Python won't be any less dynamic >because of it. > I think I can write you a custom import that will prevent the assignment of a list of names you specify in the code of the imported module. Would that be useful? Or would it be more useful to put that detection in py/lint/checker/etc (where it probably already is?)? Would you want to outlaw 'None' as an attribute name? Python seems to be straddling the fence at this point: >>> class C(object): pass ... >>> c = C() >>> c.None = 'c.None' SyntaxError: assignment to None >>> vars(c)['None'] = 'c.None' >>> c.None 'c.None' ;-) >> The upside is exactly the same as the fact that you can override the >> "list()" function in Python. Python is dynamic language. > >That's not exactly an upside, and it has nothing to do with Python >being dynamic. C is static but you can override 'printf'. Overriding >'list' in Python is pretty much the same thing. > >> In Python, if you have a private variable: >> >> self._x = 3 >> >> and you, for curiosity reasons and DURING runtime (after the program is >> already up and running) want to know the exact moment the self._x >> variable is accessed (say, print out the local time), or print out the >> calling stack frames, you can do it. And I mean the program is running. > >So let's see: > > def countdown(): > n = 3 > while n > 0: > yield n > g = countdown() > print g.next() # 3 > print g.next() # 2 > >where's the Python feature that lets me modify g's internal value of n >at this point? How is that different from modifying a private >instance variable? "Python feature" means something in the language >definition, not an artifact of some particular implementation. Is >Python somehow deficient because it doesn't give a way to do that? Do >you want to write a PEP to add a way? Do you think anyone will take >it seriously? I could see it as part of a debugging interface that might let you mess more with frames in general. I wouldn't be surprised if a lot of the under-the-hood access we enjoy as it is was a byproduct of scratching debugging-tool-need itches. Regards, Bengt Richter From uval at rz.uni-karlsruhe.de Wed Oct 19 10:32:21 2005 From: uval at rz.uni-karlsruhe.de (Daniel Schüle) Date: Wed, 19 Oct 2005 16:32:21 +0200 Subject: parser question Message-ID: Hello *, I have one format with this structure A { x=1 y=3 B { z = "something here" } } C { } A { x=0 y=0 B { z = "other" } } are there parsers for this kind of structure? specially I am interested in all A blocks just now, I am trying to solve it with re, pattern = re.compile(r"^\s*A\s*{.*}\s*", re.MULTILINE | re.DOTALL) A_blocks = pattern.findall( file("myFile").read() ) but since there might be subblocks it will fail finding the closing "}" character Regards, Daniel From steve at REMOVETHIScyber.com.au Tue Oct 18 19:28:32 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Wed, 19 Oct 2005 09:28:32 +1000 Subject: Hygenic Macros References: Message-ID: On Tue, 18 Oct 2005 13:42:21 -0700, Robert Kern wrote: > Steven D'Aprano wrote: >> On Mon, 17 Oct 2005 22:23:43 -0700, David Pokorny wrote: >> >>>Hi, >>> >>>Just wondering if anyone has considered macros for Python. I have one >>>good use case. In "R", the statistical programming language, you can >>>multiply matrices with A %*% B (A*B corresponds to pointwise >>>multiplication). In Python, I have to type >>> >>>import Numeric >>>matrixmultiply(A,B) >>> >>>which makes my code almost unreadable. >> >> Yes, I see what you mean, it is pretty confusing. It almost looks like >> a function that multiplies two matrices and returns the result. >> >> Have you tried coming up with better names for your arguments than A and >> B? Many people find that using self-documenting variable names helps make >> code easier to understand. > > Well, to be fair, his example was trivial. When you have more > complicated matrix expressions with transposes and conjugations and more > matrixmultiplies than you can shake a stick at, it gets ugly pretty fast. > > F = dot(dot(Z, F),transpose(conjugate(Z))) No uglier than y = sin(poly(sqrt(x))) And of course it is allowed to do this: F = dot(Z, F) Z = transpose(conjugate(Z)) F = dot(F, Z) Not everything has to be a one-liner, not even in mathematics. > versus > > from scipy import * > F = mat(F) > Z = mat(Z) > F = Z*F*Z.H It's a matter of taste. But calling it "almost unreadable" is an exaggeration. -- Steven. From raims at dot.com Thu Oct 20 12:33:54 2005 From: raims at dot.com (Lawrence Oluyede) Date: Thu, 20 Oct 2005 18:33:54 +0200 Subject: How to retrieve the filename of a module References: <1129824268.735371.230910@g49g2000cwa.googlegroups.com> Message-ID: Il 2005-10-20, Lawrence Oluyede ha scritto: > Il 2005-10-20, mku ha scritto: >> Hi, >> >> there?s a function inside a module. How can these function retrieve >> the path+name of his module ? (The path is most important). >> That should also work if the module is part of a package. > > > rhymes at voodoo:~ $ cat > test.py > print __file__ > import os > print os.path.abspath(__file__) > > rhymes at voodoo:~ $ python test.py > test.py > /home/rhymes/test.py Also __name__ for the name of the module -- Lawrence http://www.oluyede.org/blog From steve at REMOVETHIScyber.com.au Tue Oct 4 19:38:49 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Wed, 05 Oct 2005 09:38:49 +1000 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> Message-ID: On Tue, 04 Oct 2005 17:14:45 +0000, Roedy Green wrote: > On Tue, 23 Aug 2005 08:32:09 -0500, l v wrote or quoted : > >>I think e-mail should be text only. > > I disagree. Your problem is spam, not HTML. Spam is associated with > HTML and people have in Pavlovian fashion come to hate HTML. Nonsense. I came to hate HTML emails long before I received spam. > But HTML is not the problem! Yes it is. HTML means that after I've specified my email client use my favourite font, in the size I like, people send me emails that over-ride my choice. Invariably they use a font I don't even have. Even more invariably, they set the point size directly rather than in relative terms, and they are on Windows, where point sizes are about 20% oversized. The consequences of this is that text generated on Windows appears approximately one fifth smaller on Linux, Macintosh and any other system that uses proper typesetter's point sizes. Invariably, the sort of people who use HTML emails end up sending you a forward of a forward of a forward of a forward of a forward of an email saying that Bill Gates will give you $10,000 for every copy of the email you forward, and it will be written in light blue text on a background picture of bluebirds eating blueberries, and at the end of every paragraph will be a row of thirty animated smileys. Almost the biggest predictor of whether I will want to trash somebody's email without reading it is whether they use HTML mail. > That is like hating all choirs because televangelists use them. > > HTML allows properly aligned table, diagrams, images, use of > colour/fonts to encode speakers. emphasis, hyperlinks. > > I try to explain Java each day both on my website on the plaintext only > newsgroups. It is so much easier to get my point across in HTML. > > Program listings are much more readable on my website. These are all valid uses of *formatted* text. But HTML is not formatted text. HTML is a web page markup language -- it is much more than merely formatting text. That's why HTML can be used for putting web-bugs into emails, allowing tracking of emails. That's a security hole that threatens privacy, and is enough of a reason to prohibit HTML emails alone. Then there is the issue of storage space. I tend to archive emails I receive. For the same content, HTML mails tend to be anything from four to one hundred times bigger than the plain text mail would have been, depending on just how bad the sending mail client is. Regardless of how cheap hard disks are, how many gigabytes they now hold, if everybody sent HTML mail, I would be able to store less than one quarter the number of emails than I could if people just used plain text. That's a significant drain for businesses that are required by law to store all emails for seven years (as they are business records). There is a good argument to be made that mail clients should support a subset of HTML so as to provide rich text. But even that comes at a serious cost (animated smileys, urgh) and in my opinion, the good things you can do with formatted text don't make that cost worth paying. -- Steven. From entropy at domain.invalid Sun Oct 23 08:39:20 2005 From: entropy at domain.invalid (entropy) Date: Sun, 23 Oct 2005 12:39:20 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <86k6g59ke6.fsf@bhuda.mired.org> <3EI6f.43974$MF6.5922@fe1.news.blueyonder.co.uk> Message-ID: entropy at domain.invalid wrote... > axel at white-eagle.invalid.uk wrote... > > In comp.lang.perl.misc David Schwartz wrote: > > > "Mike Meyer" wrote in message > > > > >> Sorry, but nobody but the government actually owns property. In most > > >> places, you can't make non-trivial changes to "your" property without > > >> permission from the government. They even charge you rent on "your" > > >> property, only they call it "property tax". > > > > > I see you are a totalitarianist or perhaps a communist. If you want to > > > live in America and discuss things that are relevent to America, let me > > > know. > > > > Why would you say that - Mike Meyer made a point to which you have > > obviously no answer. Or do you deny that his comments on this matter > > of property are true? > > Methinks David simply missed that Mike was being facetious. (Irony > and facetiousness don't translate well into print, as Frank Zappa > once noted.) Uh, you _were_ being facetious there, weren't you Mike? From spe.stani.be at gmail.com Sun Oct 16 10:24:25 2005 From: spe.stani.be at gmail.com (SPE - Stani's Python Editor) Date: 16 Oct 2005 07:24:25 -0700 Subject: tuple versus list References: <1129460775.484350.209520@g44g2000cwa.googlegroups.com> Message-ID: <1129472665.701780.222120@f14g2000cwb.googlegroups.com> It's simple: if you want to modify the data structure after it has been created, use lists, otherwise tuples. Tuples are much more memory efficient, so your program will consume less memory and probably run faster. So preferably use tuples. However with tuples you can't do: t[0] = 'new value' t.append('new value') These statements are possible with lists. Stani -- SPE - Stani's Python Editor (http://pythonide.stani.be) From no.mail.here.at.here at gmail.com Fri Oct 7 11:26:32 2005 From: no.mail.here.at.here at gmail.com (mike) Date: 7 Oct 2005 08:26:32 -0700 Subject: os.access with wildcards In-Reply-To: <1128698336.836590.96080@g44g2000cwa.googlegroups.com> References: <1128665933.923295.95580@f14g2000cwb.googlegroups.com> <1128698336.836590.96080@g44g2000cwa.googlegroups.com> Message-ID: <1128698792.787399.160460@g49g2000cwa.googlegroups.com> Test for the existence of one or more matches of the wildcard expression. For example: Are there any files that begin with 2005? This doesn't work (wish it did): os.access('2005*',os.F_OK) However, these work arounds do the job: glob.glob('2005*')==[] as does this bash command: os.system('[ -e 2005* ]' ) The 1st is not very readable and the 2nd has portability issues. From brp13 at yahoo.com Fri Oct 7 13:36:08 2005 From: brp13 at yahoo.com (Tuvas) Date: 7 Oct 2005 10:36:08 -0700 Subject: Extending Python In-Reply-To: References: <1128533901.767470.279220@z14g2000cwz.googlegroups.com> Message-ID: <1128706567.974729.248180@g14g2000cwa.googlegroups.com> Perhaps it would be nice if they could include in the python documents a link to download a sample code, the one that they were building in the whole program, or at least a page that puts it all together? I get a much better idea of how thing work when they are all put together personally, and then explained individually. That would be the simpliest thing that would help, and perhaps the files that are included in the source distribution. Perhaps I might be the only python user that didn't install the source code that wants to use extended C applications, but I doubt it. Thanks for all of the help! From sybrenUSE at YOURthirdtower.com.imagination Mon Oct 31 10:41:49 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Mon, 31 Oct 2005 16:41:49 +0100 Subject: Expanding Python as a macro language References: <1130545600.925061.287390@g49g2000cwa.googlegroups.com> <1130631958.683127.215300@g14g2000cwa.googlegroups.com> Message-ID: qwweeeit at yahoo.it enlightened us with: > I know, but nowadays almost any relevant application has a GUI. I can't think of any relevant server application running on Linux that has a GUI. My text processor, email client, Usenet client, IRC client, address book and agenda are all without GUI too. 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 gsakkis at rutgers.edu Sat Oct 15 03:01:56 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: 15 Oct 2005 00:01:56 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <1129343741.855770.220940@z14g2000cwz.googlegroups.com> Message-ID: <1129359716.908157.158720@g49g2000cwa.googlegroups.com> Keith Thompson wrote: > "kasimir.g at gmail.com" writes: > > Hm... What does this have to do with Perl? > > > > Why did you post this in comp.lang.perl.misc? > > He posted this in comp.lang.python, comp.lang.perl.misc, > comp.unix.programmer, comp.lang.java.programmer, *and* > comp.os.linux.misc because he's a troll. > > I wish I could say that he'll go away if we ignore him. I can say, > however, that ignoring him will minimize his impact. In the past, his > rants have led to long rambling arguments across multiple newsgroups, > none of them relevant to any point that might be made -- which is > probably exactly what he wants. Exactly, Mr. Lee is a self-proclaimed troll (http://xahlee.org/Netiquette_dir/troll.html). Actually he seems to be more than a plain troll; the style of many of his posts is indicative of one or more mental disorders, so he'll probably continue trolling even if he's ignored. Nevertheless, I agree that ignoring him will minimize his impact. From matt.keyes at gmail.com Thu Oct 6 02:23:18 2005 From: matt.keyes at gmail.com (matt.keyes at gmail.com) Date: 5 Oct 2005 23:23:18 -0700 Subject: _BLOCK_TYPE_IS_VALID error in MSVC 7.1 with Boost and Python Message-ID: <1128579798.623240.150680@g49g2000cwa.googlegroups.com> Hey all, i'm trying to create an application that both embeds and extends python through boost. i've got a rough framework up and running, but now that i'm finally to the python part i'm having troubles. Here's a rough run-down of my code: Base class (pure): template InputHandler { public: /*...*/ virtual void Enter(commandtype *pOutput) = 0; }; Derived class: class PythonInputHandler : public InputHandler { public: PythonInputHandler(PyObject *pSelf) : m_pSelf(pSelf) {} PythonInputHandler(const PythonInputHandler &rhs) : InputHandler(rhs) //doesn't really do anything , m_pSelf(rhs.m_pSelf) { if(m_pSelf) Py_XINCREF(m_pSelf); } virtual ~PythonInputHandler() {Py_XDECREF(m_pSelf);} //overriden pure function: virtual void Enter(std::string *pOutput) { //this is where the nasty heap crash comes in, more below *pOutput = call_method(m_pSelf, "Enter"); } } BOOST_PYTHON_MODULE(PyInputHandler) { class_, PythonInputHandler, boost::noncopyable>("PythonInputHandler"); } Now, when the executable runs, this happens: if( PyImport_AppendInittab( "PyInputHandler", initPyInputHandler ) == -1 ) throw runtime_error("blah"); Py_Initialize(); PyObject *pInit = PyImport_ImportModule("Python.MyTest"); if(pInit == NULL) //...error handling PythonInputHandler *pHandler = new PythonInputHandler(call_method(pInit, "CreateInputHandler")); std::string sTest; pHandler->Enter(&sTest); //big heap crash Py_XDECREF(pInit); /*...*/ Here is the Python code: from PyInputHandler import * class PyLogonHandler(PythonInputHandler): def Enter(Output): return "Welcome from Python!" def CreateInitialHandler(): return PyLogonHandler() Now then, if i change "Welcome from Python!" to a shorter string, like "Hiya!", then it works, no error. As it stands, i get a _BLOCK_TYPE_IS_VALID error in what looks like the destructor of the std::string during the *pOutput = call_method... portion of the code (i'm assuming the destructor before the assignment to pOutput occurs). However, in the destructor, i do see the data consisting of "Welcome from Python!" Now i'm also a complete noob to boost and python. i've only been working on this for about 5 hours or so (the python side of things at any rate), so any tips to improve what i'm doing in addition to helping with this error is greatly appreciated. i'm finding it difficult to find some boost.python tutorials that are comprehensive enough. If you can't tell, i'm trying to expose a version of my InputHandler class to python so that it can be overriden and created from scripts instead of being hard-coded into the C++. Thanks for the help!!!! From fccoelho at gmail.com Thu Oct 6 09:35:03 2005 From: fccoelho at gmail.com (Flavio) Date: 6 Oct 2005 06:35:03 -0700 Subject: updating local() In-Reply-To: References: <1128530014.323801.290360@g47g2000cwa.googlegroups.com> <1128603314.197733.119160@g47g2000cwa.googlegroups.com> Message-ID: <1128605703.628601.140890@g49g2000cwa.googlegroups.com> I wish all my problems involved just a couple of variables, but unfortunately the real interesting problems tend to be complex... As a last resort this problem could be solved by something like this: def fun(**kw): a = 100 for k,v in kw.items(): exec('%s = %s'%(k,v)) print locals() >>> fun(**{'a':1,'b':2}) {'a': 1, 'k': 'b', 'b': 2, 'kw': {'a': 1, 'b': 2}, 'v': 2} But that would be utterly stupid! So much for not being able to write to locals().... any better Ideas? From dont at spam.me Thu Oct 13 16:18:51 2005 From: dont at spam.me (Brendan Guild) Date: Thu, 13 Oct 2005 20:18:51 GMT Subject: Jargons of Info Tech industry References: <1124804082_1011@spool6-east.superfeed.net> <11krdosli1jgla7@corp.supernews.com> <11ktbum1ira9le4@corp.supernews.com> Message-ID: Gordon Burditt wrote in news:11ktbum1ira9le4 at corp.supernews.com: > Does the language allow Javascript to open a new window? Does the > language allow Javascript to trigger a function when a window is > closed? I believe the answer to both questions is YES. Then it > is possible to have a page that pops up two windows whenever you > close one. This was a problem, but modern browsers implement Javascript in such a way that it requires permission from the user before it will open a new window. > If it can reveal my email address to any web site, it's a bug. If > it can access or alter my personal files or address book, it's a > bug. If it can generate hits on web sites other than that specified > in the HTML, it's a bug. If it can open sockets, it's a bug. > If it can look at or set cookies stored on my system, it's a bug. > If it can look at or alter the list of previously visited URLs, it's > a bug. All of those things seem like major problems except the bit about cookies. What possible harm can reading and setting cookies do? I had always thought they were carefully and successfully designed to be harmless. That's not personal information in your cookies. That information is set by websites for the sole purpose of being read by websites. Plus, I'm pretty sure that browsers have always allowed us to disable cookies. From apardon at forel.vub.ac.be Mon Oct 3 09:58:33 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 3 Oct 2005 13:58:33 GMT Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> Message-ID: Op 2005-10-03, Duncan Booth schreef : > Antoon Pardon wrote: > >> A language where variable have to be declared before use, would allow >> to give all misspelled (undeclared) variables in on go, instead of >> just crashing each time one is encounterd. > > Wrong. It would catch at compile-time those misspellings which do not > happen to coincide with another declared variable. Fine, it is still better than python which will crash each time one of these is encountered. > It would give the > programmer a false sense of security since they 'know' all their > misspellings are caught by the compiler. It would not be a substitute for > run-time testing. I don't think anyone with a little bit of experience will be so naive. > Moreover, it adds a burden on the programmer who has to write all those > declarations, So? He has to write all those lines of code too. People often promote unittesting here. Writing all those unittest is an added burden too. But people think this burden is worth it. I think writing declaration is also worth it. The gain is not as much as with unittesting but neither is the burden, so that balances out IMO > and worse it adds a burden on everyone reading the code who > has more lines to read before understanding the code. Well maybe we should remove all those comments from code too, because all it does is add more lines for people to read. > Also there is > increased overhead when maintaining the code as all those declarations have > to be kept in line as the code changes over time. Which is good. Just as you have to keep the unittests in line as code changes over time. -- Antoon Pardon From martin at v.loewis.de Wed Oct 26 03:05:27 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 26 Oct 2005 09:05:27 +0200 Subject: How to statically link Python with ncurses and readline? In-Reply-To: <1130278044.241389.177210@o13g2000cwo.googlegroups.com> References: <1130263338.291061.50210@g49g2000cwa.googlegroups.com> <435e78d1$0$2680$9b622d9e@news.freenet.de> <1130265985.862970.185070@g47g2000cwa.googlegroups.com> <435ea4ca$0$16638$9b622d9e@news.freenet.de> <1130278044.241389.177210@o13g2000cwo.googlegroups.com> Message-ID: <435f2ab5$0$5596$9b622d9e@news.freenet.de> arve.knudsen at gmail.com wrote: > What do you mean? A static-only build does somehow exclude that I had > static libraries before? No, it doesn't. I misunderstood. It is quite unclear still what you had been doing: e.g. did you have shared versions of db and Tcl or not? Did you have linker scripts in place? What was your specific command line you have used to link the entire interpreter? In the absence of details, we have to take guesses on Usenet. Sometimes, the guesses are right, and sometimes they are wrong. Regards, Martin From mde at micah.elliott.name Sat Oct 15 21:46:40 2005 From: mde at micah.elliott.name (Micah Elliott) Date: Sat, 15 Oct 2005 18:46:40 -0700 Subject: Return Text from popen In-Reply-To: <34j823-jon.ln1@SuperServer.NerdWorld.org> References: <34j823-jon.ln1@SuperServer.NerdWorld.org> Message-ID: <20051016014640.GB4541@kitchen.client.attbi.com> On Oct 15, Casey Bralla wrote: > How do I return text from a standard Linux command? > > For example: I want to read the stdout results of a typical linux > command (such as "df") into a Python variable. >>> from os import popen >>> p = popen("df") >>> p >>> df_out = p.read() >>> p.close() >>> p >>> print df_out -- Micah Elliott From salvatore.didio at wanadoo.fr Sun Oct 2 06:40:50 2005 From: salvatore.didio at wanadoo.fr (salvatore.didio at wanadoo.fr) Date: 2 Oct 2005 03:40:50 -0700 Subject: Nufox : Xul + Python In-Reply-To: <433f051f$0$49786$ed2e19e4@ptn-nntp-reader04.plus.net> References: <1128163366.631178.74800@o13g2000cwo.googlegroups.com> <1128182754.232912.9980@z14g2000cwz.googlegroups.com> <433f051f$0$49786$ed2e19e4@ptn-nntp-reader04.plus.net> Message-ID: <1128249650.166566.81790@g44g2000cwa.googlegroups.com> Thank you for testing Indeed it is very interesting :-) I've had some problems with my ports forwarding and no-ip.org. Here is then the new address : http://artyprog.dyndns.org:8080 Regards Betwise, I live in France so the site is close when i'am at work From chrisgarland67 at hotmail.com Tue Oct 4 17:37:57 2005 From: chrisgarland67 at hotmail.com (Cigar) Date: 4 Oct 2005 14:37:57 -0700 Subject: Controlling who can run an executable In-Reply-To: <1128452293.752325.242520@g49g2000cwa.googlegroups.com> References: <1128395422.904212.318930@g44g2000cwa.googlegroups.com> <1128432188.408503.309280@f14g2000cwb.googlegroups.com> <1128449405.776337.251380@g44g2000cwa.googlegroups.com> <1128452293.752325.242520@g49g2000cwa.googlegroups.com> Message-ID: <1128461877.676915.113180@o13g2000cwo.googlegroups.com> Istvan Albert wrote: > > I could ask her, "If you can't break it is that good enough security?" > > Guess not. Most non-programmers think everyone else who knows some > programming is a some sort of hacker genius. > > Instead come up with a simple solution then explain her how it will > works. I think in the ensuing conversation you'll find out more on what > approach would put her mind at ease. > > Istvan. Sorry I forgot to put the happy face at the end of that last sentence. Yes I'll be a good boy. :) From appumail at gmail.com Thu Oct 6 05:21:31 2005 From: appumail at gmail.com (Murugesh) Date: Thu, 06 Oct 2005 14:51:31 +0530 Subject: Help-log in to a web page In-Reply-To: References: Message-ID: Laszlo Zsolt Nagy wrote: > Murugesh wrote: > >> Hi all, >> I'm a newbie to python.I need to login to a webpage after supplying >> usename and password. >> >> import urllib sock = urllib.urlopen("http://xop-pc.main.com") >> htmlSource = sock.read() >> sock.close() print >> htmlSource >> In the above code how can i supply username and password to that URL. >> Thanks for you time. >> >> > xop-pc.main.com is not an existing site. > Can you tell me what kind of authentication method it is using? > If that is the "basic authentication" (defined the standard HTTP > protocol) then you need to read this: > > http://docs.python.org/lib/urlopener-objs.html > > Basically, you need to subclass URLopener or FancyURLopener, and > overwrite its "prompt_user_passwd" method. > That method will be then called whenever the server needs authentication. > > Here is a template for you (untested): > > > from urllib import FancyURLOpener > class MyOpener(FancyURLOpener): > def prompt_user_passwd(host,realm): > return ('myusername','mypassword') > > opener = MyOpener({}) > f = opener.open("http://xop-pc.main.com") > try: > html_source = f.read() > finally: > f.close() > > > > Best, > > Les > > I tried to view the source,it has, .... .... src="/em/cabo/images /t.gif" height="80">
* *User Name
* Password The argument itself is a string, but has quotes inside too. Then use other quotes as string delimiters. Why would you use something else? 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 steve at REMOVETHIScyber.com.au Sun Oct 9 06:05:30 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 09 Oct 2005 20:05:30 +1000 Subject: Python's Performance References: <20051008040614.47429.qmail@web30607.mail.mud.yahoo.com> <1128791665.816053.268100@g43g2000cwa.googlegroups.com> Message-ID: On Sat, 08 Oct 2005 10:14:25 -0700, Phillip J. Eby wrote: > So, without meaning to, the benchmark author has demonstrated something > important about Python, which is that writing the obvious thing in > Python tends to work correctly, even if it sometimes takes longer to > run than it would take for another language to produce the wrong > answer. :) Which is of course demonstrates two different strategies of programming. The first is, "I don't care what answer I get, so long as I get it quickly!". The second is, "I don't care how long it takes, so long as I get the right answer!" The smart programmer will understand that both strategies can be the right one in different circumstances. For instance, the Apollo landers didn't have the computing power to calculate the right answer quickly enough to prevent the lander from burying itself deep beneath the moon's surface, so they used a strategy of calculating the wrong answer quickly, then incrementally improving it. I'm told that the Apollo 11 lander's computer rebooted something like 20 times in the few minutes it took to go from orbit to the surface. It would crash, reboot, and just pick up the calculations from the last one that completed. Try doing that with Wintel! :-) -- Steven. From iainking at gmail.com Wed Oct 26 05:12:16 2005 From: iainking at gmail.com (Iain King) Date: 26 Oct 2005 02:12:16 -0700 Subject: Looping Problem (Generating files - only the last record generates a file) In-Reply-To: <1130316544.381673.209190@g44g2000cwa.googlegroups.com> References: <1130316544.381673.209190@g44g2000cwa.googlegroups.com> Message-ID: <1130317936.377231.208250@g43g2000cwa.googlegroups.com> vasilijepetkovic at yahoo.com wrote: > Hello All, > > I have a problem with the program that should generate x number of txt > files (x is the number of records in the file datafile.txt). > > Once I execute the program (see below) only one file (instead of x > files) is created. The file created is based on the last record in > datafile.txt. > > The program is as follows: > ==================================== > #! python > > HEADER = "This page displays longitude-latitude information" > SUBHEADER = "City" > > for line in open("datafile.txt"): > > > town, latlong = line.split('\t') > > f = open(town + ".txt", "w+") > > f.write(HEADER + "\n") > f.write(SUBHEADER + ": " + town + "\n") > f.write("LAT/LONG" + ": " + latlong + "\n") > f.close() > > > # end > ==================================== > > > > > The datafile.txt is as follows (tab separated columns): > ==================================== > > NYC 1111-2222 > Lima 3333-4444 > Rome 5555-6666 > > ==================================== > > Once executed, the program will create a single file (named Rome.txt) > and it would not create files NYC.txt and Lima.txt as I would expect it > to do. > > I'd appreciate if you can pinpoint my error. > > Best, > > Vasa Did you try indenting the last five lines? Iain From reinhold-birkenfeld-nospam at wolke7.net Sat Oct 1 02:28:19 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Sat, 01 Oct 2005 08:28:19 +0200 Subject: [Info] PEP 308 accepted - new conditional expressions In-Reply-To: References: <3q4ro9Fd770nU3@individual.net> <0qh%e.20023$Ix4.15230@okepread03> Message-ID: <3q6ok3Fddg7eU2@individual.net> Erik Max Francis wrote: > Dave Benjamin wrote: > >> Hooray! After years of arguing over which syntax to use, and finally >> giving up since nobody could agree, the Benevolent Dictator did what >> only a dictator can do, and just made a damn decision already. >> >> Thank you, Guido! =) > > Yes, hear hear. > > So what made him change his mind? When the debates raged over PEP 308, > he seemed pretty dead set against it (at least by proxy) ... Raymond Hettinger proposed to change the behavior of and/or to return one of their arguments because he had been bitten by the common trap of C and X or Y when X is False. People were positive about it, but said that then a conditional would have to be introduced. So Guido considered it again. He says himself that the greatest problem last time was that no consensus over syntax was reached, and he solved the problem this time by deciding himself. Reinhold From trepca at gmail.com Sun Oct 23 16:03:10 2005 From: trepca at gmail.com (Sebastjan Trepca) Date: Sun, 23 Oct 2005 22:03:10 +0200 Subject: Localized strftime() In-Reply-To: References: Message-ID: Great, it works, thanks :) On 23/10/05, Fredrik Lundh wrote: > Sebastjan Trepca wrote: > > > I'm trying to get a localized date format from strftime() but it seems > > that is doesn't have any parameters for that or any information about > > this issue in Python docs. > > > > For example I want to turn this: > > 19 Oct, 2005 > > to this(slovene language): > > 19 Okt, 2005 > > you must call locale.setlocale first, to switch from the default C > locale to a locale of your choice. > > http://docs.python.org/lib/module-locale.html > > >>> import time > >>> print time.strftime("%a, %d %b %Y %H:%M:%S") > Sun, 23 Oct 2005 20:38:56 > >>> import locale > >>> locale.setlocale(locale.LC_TIME, "sv_SE") # swedish > 'sv_SE' > >>> print time.strftime("%a, %d %b %Y %H:%M:%S") > s?n, 23 okt 2005 20:39:15 > >>> locale.setlocale(locale.LC_TIME, "sl_SI") > 'sl_SI' > >>> print time.strftime("%a, %d %b %Y %H:%M:%S") > ned, 23 okt 2005 20:39:32 > > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From codecraig at gmail.com Thu Oct 13 09:40:09 2005 From: codecraig at gmail.com (Java and Swing) Date: 13 Oct 2005 06:40:09 -0700 Subject: When to free memory for C wrapper? Message-ID: <1129210809.038807.122340@z14g2000cwz.googlegroups.com> I have been posting lately about writing a C wrapper so Python can access my C functions. In my wrapper function I have something like... static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { PyObject *data; char *result; long *d; PyArg_ParseTuple(args, "O:wrap_doStuff", &data); d = get_long_array(data); result = doStuff(d); return PyString_FromString(result); } Now, do I need to use PyMem_Free to free up the "PyObject *data"? Thanks. From fredrik at pythonware.com Mon Oct 10 02:28:23 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 10 Oct 2005 08:28:23 +0200 Subject: non descriptive error References: <4346002C.3080504@open-networks.net><200510070240.56350.hancock@anansispaceworks.com> <4349A55C.90203@open-networks.net> Message-ID: Timothy Smith wrote: > i have reproduced the error in this code block > > #save values in edit > self.FinaliseTill.SaveEditControlValue() > if > Decimal(self.parent.TillDetails[self.TillSelection.GetStringSelection()]['ChangeTinBalance'])) > == Decimal('0'): > #box must be checked before continuing > if self.PlacedInSafe.GetValue() != 1: > self.parent.Popup("You must place the till draw back in the > safe","Till draw") > else: > #finalise the till draw > if Decimal(self.TillFloat.GetLabel().split('$')[1]) != Decimal('0'): > Prompt = wx.MessageDialog(self,"""The correct amount has not been > returned from the till draw float to the main float! > If you proceed please contact your manager""","Change tin doesn't > balance!",wx.YES_NO) > if Prompt.ShowModal() == wx.ID_YES: > self.Submit() > else: > self.parent.Popup('You have an outstanding change tin balance on this > till','Change tin') > > i have NO idea what in there could be making it have such a strange > error. it just says "error" when you try run it. there nothing terribly > strange being done. the snippet you posted gives $ python script.py File "script.py", line 2 self.FinaliseTill.SaveEditControlValue() ^ SyntaxError: invalid syntax on my python 2.3 install. are you sure you don't have some weird sitecustomize file on your machine? (more likely, it's a wxPython issue. can you reproduce this without using wxPython ?) From *firstname*nlsnews at georgea*lastname*.com Sun Oct 2 23:33:06 2005 From: *firstname*nlsnews at georgea*lastname*.com (Tony Nelson) Date: Mon, 03 Oct 2005 03:33:06 GMT Subject: Unicode charmap decoders slow Message-ID: <*firstname*nlsnews-69AACB.23331402102005@news.verizon.net> Is there a faster way to decode from charmaps to utf-8 than unicode()? I'm writing a small card-file program. As a test, I use a 53 MB MBox file, in mac-roman encoding. My program reads and parses the file into messages in about 3..5 seconds, but takes about 13.5 seconds to iterate over the cards and convert them to utf-8: for i in xrange(len(cards)): u = unicode(cards[i], encoding) cards[i] = u.encode('utf-_8') The time is nearly all in the unicode() call. It's not so much how much time it takes, but that it takes 4 times as long as the real work, just to do table lookups. Looking at the source (which, if I have it right, is PyUnicode_DecodeCharmap() in unicodeobject.c), I think it is doing a dictionary lookup for each character. I would have thought that it would make and cache a LUT the size of the charmap (and hook the relevent dictionary stuff to delete the cached LUT if the dictionary is changed). I thought of using U"".translate(), but the unicode version is defined to be slow. Is there some similar approach? I'm almost (but not quite) ready to try it in Pyrex. I'm new to Python. I didn't google anything relevent on python.org or in groups. ________________________________________________________________________ TonyN.:' *firstname*nlsnews at georgea*lastname*.com ' From lasse at vkarlsen.no Sat Oct 8 15:56:19 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Sat, 08 Oct 2005 21:56:19 +0200 Subject: new forum -- homework help/chit chat/easy communication In-Reply-To: References: <1128798687.305818.66010@g49g2000cwa.googlegroups.com> Message-ID: Fredrik Lundh wrote: > Lasse V?gs?ther Karlsen wrote: > > >>Don't think so matey. > > > oh, come on. a site run by some random guy in North Carolina has to be > safer, faster and more reliable than a distributed communication system that > has been around since that guy was born... Yes, of course, my mistake, it's rather obvious now that you point it out. -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From steve at holdenweb.com Fri Oct 14 11:37:59 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 14 Oct 2005 16:37:59 +0100 Subject: Help with creating a dict from list and range In-Reply-To: <910885da0510140626p2f395ae6rbdf69b62cb55a2@mail.gmail.com> References: <910885da0510140626p2f395ae6rbdf69b62cb55a2@mail.gmail.com> Message-ID: Echo wrote: > Hello, > Here is what I am trying to do. I am trying to make a dict that has a > key that is the value an element in a list and the value for the dict to > be the index. > This is the closest I have been able to get: > dict((d[0],i) for d in self.cu.description for i in > xrange(len(self.cu.description)-1)) > > That however does not work. the value for all the dict is 40. Not 1, 2, > 3, ... that I was hoping for. > > Am I even close at creating the dict that I want? Is there a better way > to go about it? > >>> description = ["first", "second", "third"] >>> for x in enumerate(description): ... print x ... (0, 'first') (1, 'second') (2, 'third') >>> dct = dict((x[1], x[0]) for x in enumerate(description)) >>> dct {'second': 1, 'third': 2, 'first': 0} regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From http Thu Oct 27 05:09:11 2005 From: http (Paul Rubin) Date: 27 Oct 2005 02:09:11 -0700 Subject: Sorting with only a partial order definition References: Message-ID: <7x64rjs4w8.fsf@ruckus.brouhaha.com> Lasse V?gs?ther Karlsen writes: > I have a list of items and a "rule" for ordering them. > > Unfortunately, the rule is not complete so it won't define the correct > order for any two items in that list. > > In other words, if I pick two random items from the list I may or may > not have a rule that dictates the order of those two items. The rule > could be "implicit" in that I got rules for other items, for instance: That's called topological sorting and any reference on graph algorithms will describe how to do it. I don't know of Python code offhand but it's easy to write. http://en.wikipedia.org/wiki/Topological_sorting gives a straightforward linear-time algorithm. From aa at bb.cc Fri Oct 28 09:55:56 2005 From: aa at bb.cc (Ladvánszky Károly) Date: Fri, 28 Oct 2005 15:55:56 +0200 Subject: OEM character set issue Message-ID: <1130507709.2923814103422110fb7a08568f0eb060@meganetnews2> On my hungarian Win2k, some of the accented characters of the file names appear incorrectly when Python is driven from the command line. However, they appear okay when the same script is running within an IDE. The same problem holds in the case of text files edited by GUI editors. Is there any solution in the Python arsenal? Thanks for any help, K?roly From listspam at flowtheory.net Thu Oct 6 16:18:15 2005 From: listspam at flowtheory.net (Joshua Ginsberg) Date: Thu, 06 Oct 2005 16:18:15 -0400 Subject: Lambda evaluation Message-ID: <1128629895.5816.5.camel@localhost.localdomain> So this part makes total sense to me: >>> d = {} >>> for x in [1,2,3]: ... d[x] = lambda y: y*x ... >>> d[1](3) 9 Because x in the lambda definition isn't evaluated until the lambda is executed, at which point x is 3. Is there a way to specifically hard code into that lambda definition the contemporary value of an external variable? In other words, is there a way to rewrite the line "d[x] = lambda y: y*x" so that it is always the case that d[1](3) = 3? Thanks! -jag From mwm at mired.org Wed Oct 12 10:54:20 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 12 Oct 2005 10:54:20 -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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <86y853mzmr.fsf@bhuda.mired.org> <86mzlil269.fsf@bhuda.mired.org> <434cd581$0$11068$e4fe514c@news.xs4all.nl> Message-ID: <86hdbmwztv.fsf@bhuda.mired.org> Casper H.S. Dik writes: > Steven D'Aprano writes: >>Can I remind you that spam is approximately 70% of all email traffic these >>days? Most of that is blocked by the ISPs, but even so you are obviously >>one of the lucky few. > > 95% - 99% of all email, not 70% (just ask your ISP). > > A large percentage of the cost of email is the cost of getting > rid of SPAM; and that cannot happen without colleteral damage in the > form of lost valid email, not just because of improper filtering but > also because the more layers are there to touch the email the bigger > the chances that it does not arrive. I'd like to take this opportunity to correct myself. I said that I (and another poster) "didn't have a spam problem". That's wrong. We don't *appear* to have a spam problem, but that's just an illusion. Our ISPs are spending money - as indicated by Mr. Dik - on filtering spam. They're also spending money to deal with complaints about spam from their customers - in both senses of the sentence, and to pay for the bandwidth the spam is eating up. The bulk providers they buy their bandwidth from also have higher costs to provide bandwidth for spam. These costs are passed on to us. So while we may not have an obvious spam problem, we have one in the sense that spam takes money from our pockets. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From ms at cerenity.org Fri Oct 14 20:58:20 2005 From: ms at cerenity.org (Michael) Date: Sat, 15 Oct 2005 01:58:20 +0100 Subject: Capturing audio from a microphone on Mac OS X Message-ID: <435053dd$0$15050$ed2619ec@ptn-nntp-reader02.plus.net> Hi, This might seem a dumb question, but every search I've done so far has come up blank - with the possible exception of Schtoom. I've seen Schtoom that does manage to capture audio under Mac OS X, but it's unclear whether the audio tools it uses can be used independently of Schtoom. So my question this: does anyone know of a library or simple approach to capturing audio (any quality :) from a microphone on Mac OS X ? Specifically something that works with Mac OS X 10.3, with python 2.3 . Ideally, something like the approach that pyalsaaudio [*] takes would be great, but at this stage I suspect that the number of available examples out there is small, so I'm more than happy to take something and adapt it. [*] http://sourceforge.net/projects/pyalsaaudio/ I haven't searched for something similar under windows yet, I'm hoping that's less problematic (famous last works). Thanks in advance to anyone who replies, Michael. From michele.petrazzo at TOGLIunipex.it Thu Oct 6 08:01:01 2005 From: michele.petrazzo at TOGLIunipex.it (Michele Petrazzo) Date: Thu, 06 Oct 2005 14:01:01 +0200 Subject: epydoc, variables and encoding In-Reply-To: References: Message-ID: <434511fe$0$8498$5fc30a8@news.tiscali.it> Kenneth Pronovici wrote: >> I found a "problem" on epydoc. If I specify an encoding, epydoc not >> find my global variables, and if I remove it, it work well. <-cut-> > > No, it's not normal, and I'm fairly sure it's a bug. <-cut-> > Otherwise, you can try applying the following patch: > <-cut-> > Maybe Edward won't like this patch, but since he seems to be > unreachable for the last six months , you'll have to settle for > my less-than-educated guess at a fix. :) I don't know why Edward won't like this parch :), in any case it work well for my source. > > KEN > Thanks, Michele From steve at holdenweb.com Tue Oct 4 09:02:47 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 04 Oct 2005 14:02:47 +0100 Subject: Dynamical loading of modules In-Reply-To: <1128430810.4070.55.camel@dot.uniqsys.com> References: <43418BF5.90504@gmail.com> <1128372108.4070.31.camel@dot.uniqsys.com> <1128372287.4070.33.camel@dot.uniqsys.com> <1128428782.4070.42.camel@dot.uniqsys.com> <43427640.3010707@holdenweb.com> <1128430810.4070.55.camel@dot.uniqsys.com> Message-ID: <43427D77.7020503@holdenweb.com> Carsten Haese wrote: > On Tue, 2005-10-04 at 08:32, Steve Holden wrote: > >>Carsten Haese wrote: >> >>>On Mon, 2005-10-03 at 17:37, Steve Holden wrote: >>> >>> >>>>Carsten Haese wrote: >>>> >>>> >>>>>On Mon, 2005-10-03 at 16:41, Carsten Haese wrote: >>>>> >>>>> >>>>> >>>>>>On Mon, 2005-10-03 at 15:52, Jacob Kroon wrote: >>>>>> >>>>>> >>>>>> >>>>>>>Hi, I'm having some problems with implementing dynamical module loading. >>>>>>>First let me >>>>>>>describe the scenario with an example: >>>>>>> >>>>>>>modules/ >>>>>>> fruit/ >>>>>>> __init__.py >>>>>>> apple.py >>>>>>> banana.py >>>>>>> >>>>>>>apple.py defines a class 'Apple', banana defines a class 'Banana'. The >>>>>>>problem lies in the >>>>>>>fact that I want to be able to just drop a new .py-file, for instance >>>>>>>peach.py, and not change >>>>>>>__init__.py, and it should automatically pickup the new file in >>>>>>>__init__.py. I've come halfway >>>>>>>by using some imp module magic in __init__.py, but the problem I have is >>>>>>>that the instantiated >>>>>>>objects class-names becomes fruit.apple.Apple/fruit.banana.Banana, whild >>>>>>>I want it to be >>>>>>>fruit.Apple/fruit.Banana. >>>>>>> >>>>>>>Is there a smarter way of accomplishing what I am trying to do ? >>>>>>>If someone could give me a small example of how to achieve this I would >>>>>>>be very grateful. >>>>>> >>>>>>How about something like this in fruit/__init__.py: >>>>>> >>>>>>import os >>>>>> >>>>>>fruit_dir = os.path.dirname(__file__) >>>>>>fruit_files = [x for x in os.listdir(fruit_dir) if (x[-3:]=='.py' and x!='__init__.py')] >>>>>>for fruit_file in fruit_files: >>>>>>module_name = fruit_files[:-3] >>>>> >>>>> ^^^^^^^^^^^ This should be fruit_file, of course. >>>>> >>>>> >>>>> >>>>> >>>>>>exec "from %s import *" % module_name >>>>>> >>>> >>>>Wouldn't >>>> >>>> __import__(module_name) >>>> >>>>be better. >>> >>> >>>I don't see how a working example that meets the OP's requirements can >>>be constructed using __import__, but that may easily be due to my lack >>>of imagination. How would you do it? >>> >> >>I was simply suggesting that you replace the exec statement with a call >>to __import__(). Wouldn't that work? > > > Not the way I tried it by simply replacing my line with your line. (If > it matters, I'm on python 2.2 here.) First of all, the __import__ > variant doesn't see the submodules unless I add fruit_dir to sys.path. > Secondly, the OP's requirements are that the classes that the submodules > implement be imported into fruit's namespace, and I don't see how to > make __import__ do that. > Please ignore my brainfart and proceed as per your plan :-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From kn0805 at hotmail.com Fri Oct 7 19:01:59 2005 From: kn0805 at hotmail.com (ktxn1020) Date: 7 Oct 2005 16:01:59 -0700 Subject: unable to import os Message-ID: <1128725698.453813.9280@g49g2000cwa.googlegroups.com> Hi Experts, I built a scrip file which cleans up the old log files starting from the oldest till the necessary free space on the drive reaches. The script ran well independently using Python's Integrated Development Environment version 2.4.1. When it is called from Borland C++ Builder 5 with python for delphi version 3.16, it is complained at the line "import os", but not at the line "import nt". How can I resolve this? I wonder if there is a built_in command in NT OS specific to get date and time of a file. The following command is what I used in my script mtime = os.stat(Path + file_name)[os.path.stat.ST_MTIME] From mrmaple at gmail.com Fri Oct 14 15:53:54 2005 From: mrmaple at gmail.com (Jim) Date: 14 Oct 2005 12:53:54 -0700 Subject: MS Word Outline -> reStructuredText script? Message-ID: <1129319634.407351.27080@z14g2000cwz.googlegroups.com> Hi, I'm using reStructuredText as a format for some group documentation, and often my co-workers take notes during meetings in Word's outline mode. Does anyone already have a python script that will convert from Word (or the Open Office file format version of a word document) to reStructured Text? If not I've got a fun project ahead of me. Thanks, -Jim From peter at engcorp.com Mon Oct 24 08:03:26 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 24 Oct 2005 08:03:26 -0400 Subject: testing '192.168.1.4' is in '192.168.1.0/24' ? In-Reply-To: <1130142091.327886.163710@g44g2000cwa.googlegroups.com> References: <1130131120.695320.180030@z14g2000cwz.googlegroups.com> <1130142091.327886.163710@g44g2000cwa.googlegroups.com> Message-ID: bonono at gmail.com wrote: > thanks, that is basically what I am doing and since it is a recipe, I > would assume there is no standard library module for it. Well, since a Google search for "site:docs.python.org subnet" turns up nothing, one would assume not, but it would be hard to prove it without an exhaustive review of the source code. ;-) -Peter From richie at entrian.com Thu Oct 20 09:31:44 2005 From: richie at entrian.com (Richie Hindle) Date: Thu, 20 Oct 2005 14:31:44 +0100 Subject: Accessing a dll from Python In-Reply-To: <1129814361.130127.255990@f14g2000cwb.googlegroups.com> References: <1129814361.130127.255990@f14g2000cwb.googlegroups.com> Message-ID: [Daniel] > I tried the ctypes module. ctypes is the right way to do it. You need to post your code and whatever errors you received. Here's an example of using ctypes to call a DLL: >>> from ctypes import * >>> windll.user32.MessageBoxA(None, "Hello world", "ctypes", 0); You use "windll" for stdcall functions (eg. the Windows API) and "cdll" for cdecl functions. I don't know which one VB defaults to. If you get it wrong, ctypes will give you an error talking about using the "wrong calling convention". -- Richie Hindle richie at entrian.com From tdwdotnet at gmail.com Mon Oct 10 17:43:11 2005 From: tdwdotnet at gmail.com (Tim Williams (gmail)) Date: Mon, 10 Oct 2005 22:43:11 +0100 Subject: Send password over TCP connection In-Reply-To: <1128976311.779178.304900@g14g2000cwa.googlegroups.com> References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> <7xd5md76kd.fsf@ruckus.brouhaha.com> <1128976311.779178.304900@g14g2000cwa.googlegroups.com> Message-ID: <9afea2ac0510101443i4ea5dff8n@mail.gmail.com> On 10 Oct 2005 13:31:51 -0700, dcrespo wrote: > Hi. I found TSL, a Python Library that supports SRP. > Do you know where can I find a sample client and server code? Thanks > for your help. http://trevp.net/tlslite/ It comes with examples. I use it in several servers and clients. Quite simple to impliment. HTH :) From gregpinero at gmail.com Sat Oct 8 00:48:37 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Sat, 8 Oct 2005 00:48:37 -0400 Subject: Pythoncard mental block In-Reply-To: References: <1128705924.303422.31650@o13g2000cwo.googlegroups.com> Message-ID: <312cfe2b0510072148s11633d59x6ae711f795a7a204@mail.gmail.com> The Python-Card guys are really helpful, < pythoncard-users at lists.sourceforge.net>, you may have to register on sourceforge to get on their list. In the meantime I went ahead and cc'd them on this. Python-Card guys, make sure to cc Steven as he may not be on the list. -Greg On 10/7/05, Steven D'Aprano wrote: > > On Fri, 07 Oct 2005 10:25:24 -0700, jlocc wrote: > > > Hi!! > > > > I am working on a school project and I decided to use PythonCard and > > wxPython for my GUI development. I need a password window that will > > block unwanted users from the system. I got the pop-up password > > question to work... > > I haven't seen any replies to this, so even though I don't actually > use Pythoncard I'll take a wild shot in the dark. > > > > def on_openBackground(self, event): > > > > result = dialog.textEntryDialog(self, > > 'System', > > 'Please enter your password: ', > > '') > > > > .....but I don't exactly remember how to check if the entered password > > is correct. Say I hard code the password to be 'hello', then how would I > > check if this was the input or if it wasn't??? > > Start with looking at result and seeing what is in it. If it is the input > string, then just say > > if result == 'hello': > # do whatever you need to > else: > # put up a dialog saying 'Password does not match!' > > But I'm guessing from the syntax that the dialog instance itself is stored > in result, so perhaps you need to look at some attribute of result: > > if result.userInput == "hello": # or something like that? > > Lastly, I might not have used Pythoncard, but years ago I used to use > Hypercard rather a lot. In Hypercard, the password dialog would use a > one-way hash function to encrypt the typed response into a large integer > value. I assume Pythoncard is designed to do the same thing as Hypercard. > > So, in rusty Hypercard syntax with Python-style comments: > > # retrieve the numeric value of the password > put field "hidden password" into userpassword > # put up a dialog asking the user to enter a password > ask password "Please enter your password:" > if the result is "" then: > # the user clicked Cancel, so just abort or go away or something > go home > else if the result is userpassword: > # we have a match! > go to card "Secret card" > else: > # password doesn't match > go to card "Password failure" > > > Hope this is of some help to you, and I haven't led you too far astray. > > > -- > Steven. > > -- > 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 sharidas at zeomega.com Wed Oct 5 04:46:56 2005 From: sharidas at zeomega.com (Satchidanand Haridas) Date: Wed, 05 Oct 2005 14:16:56 +0530 Subject: Confused with module and .py files In-Reply-To: References: Message-ID: <43439300.4070500@zeomega.com> Iyer, Prasad C wrote: >Actually I am bit confused between the modules and .py file >How do I differentiate between the 2. > > > A module 'name' is the same as the name of your file without the '.py' extension. >For example >I have a file import1.py, import2.py file >Which has few functions and classes >And if I have a class with same name "BaseClass" in both the file > >How would I use it if I declare it as given below in my 3rd class > >from import1.py import * >from import2.py import * > > > > You should say : from import1 import * from import2 import * If according to your earlier question, you have a class with the same name in two different modules, the better thing then (as others on the list have already pointed out) is to do the following: import import1, import2 c1 = import1.MyClass() c2 = import2.MyClass() regards, Satchit ---- Satchidanand Haridas (sharidas at zeomega dot com) ZeOmega (www.zeomega.com) Open Minds' Open Solutions > > >regards >prasad chandrasekaran > > > > > > > > > > >--- Cancer cures smoking > >#-----Original Message----- >#From: python-list-bounces+prasad.c.iyer=capgemini.com at python.org >#[mailto:python-list-bounces+prasad.c.iyer=capgemini.com at python.org] On >#Behalf Of python-list-request at python.org >#Sent: Wednesday, October 05, 2005 1:32 PM >#To: python-list at python.org >#Subject: Python-list Digest, Vol 25, Issue 65 ># >#Send Python-list mailing list submissions to ># python-list at python.org ># >#To subscribe or unsubscribe via the World Wide Web, visit ># http://mail.python.org/mailman/listinfo/python-list >#or, via email, send a message with subject or body 'help' to ># python-list-request at python.org ># >#You can reach the person managing the list at ># python-list-owner at python.org ># >#When replying, please edit your Subject line so it is more specific >#than "Re: Contents of Python-list digest..." > >This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. > > > From programmer.py at gmail.com Thu Oct 6 14:52:36 2005 From: programmer.py at gmail.com (Jaime Wyant) Date: Thu, 6 Oct 2005 13:52:36 -0500 Subject: So far In-Reply-To: References: Message-ID: On 10/6/05, CppNewB wrote: > I am absolutely loving my experience with Python. Even vs. Ruby, the syntax > feels very clean with an emphasis on simplification. > Yes. We all love python, welcome aboard! > My only complaint is that there doesn't appear to be a great commercial IDE > for the language. I've tried Komodo, etc and they are nice applications, > but they don't feel like they give me the "power" like a Visual Studio or > Delphi (I wish I could articulate better the differences). Finding a > descent GUI builder has been a challenge as well. Most of them have support > for Dialogs, but what about more complex UI's? I may need a resizable frame > within a resizable frame? I haven''t found a GUI builder with a great feel > yet. > wingide is really nice, but costs money. It supports auto-completion in a really intelligent way. However, it was just too resource hungry on my laptop - (1.4ghz Pentium(m), 512 mb ram). Sometimes autocompletion was just too slow (i noticed the HD spinning). You're probably not going to find a GUI builder that has a nice polished feel, like Delphi or Visual studio. The *closest* thing you may find to this would be Python's Boa-Constructor (http://boa-constructor.sourceforge.net/). If you choose to use wxPython as your GUI framework, then you may not need a fancy-schmancy IDE. I find that xemacs along with xrced work really well for me. The toughest thing about wxPython (and wxWidgets) is wrapping your brain around sizers. They're easy to understand -- until something doesn't quite layout the way you expected. Unusual layouts are always a programmer's misunderstanding of sizers (at least in my experience). I recommend trying either wxGlade/xrced for gui building (i find wxGlade's latest release to be *REALLY* unstable for me in windows). Next use xemacs or Stanni's python editor to edit your code. You'll be amazed at how productive you can be once you *learn* how to handle building guis with one app, and manually tieing in the event handlers in your editor of choice. This will also `not hide' a lot of things that goes on behind the scenes. > Other than that, my experience has been wonderful. Even after my > complaints, I plan on sticking with Python for a while. That's great! jw From prasad.c.iyer at capgemini.com Wed Oct 5 04:16:30 2005 From: prasad.c.iyer at capgemini.com (Iyer, Prasad C) Date: Wed, 5 Oct 2005 13:46:30 +0530 Subject: Confused with module and .py files Message-ID: Actually I am bit confused between the modules and .py file How do I differentiate between the 2. For example I have a file import1.py, import2.py file Which has few functions and classes And if I have a class with same name "BaseClass" in both the file How would I use it if I declare it as given below in my 3rd class from import1.py import * from import2.py import * regards prasad chandrasekaran --- Cancer cures smoking #-----Original Message----- #From: python-list-bounces+prasad.c.iyer=capgemini.com at python.org #[mailto:python-list-bounces+prasad.c.iyer=capgemini.com at python.org] On #Behalf Of python-list-request at python.org #Sent: Wednesday, October 05, 2005 1:32 PM #To: python-list at python.org #Subject: Python-list Digest, Vol 25, Issue 65 # #Send Python-list mailing list submissions to # python-list at python.org # #To subscribe or unsubscribe via the World Wide Web, visit # http://mail.python.org/mailman/listinfo/python-list #or, via email, send a message with subject or body 'help' to # python-list-request at python.org # #You can reach the person managing the list at # python-list-owner at python.org # #When replying, please edit your Subject line so it is more specific #than "Re: Contents of Python-list digest..." This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. From fredrik at pythonware.com Thu Oct 6 07:46:45 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 6 Oct 2005 13:46:45 +0200 Subject: /usr/bin/env python, force a version References: <1128597929.636452.223890@o13g2000cwo.googlegroups.com> Message-ID: "manatlan at gmail.com" wrote: > I've got a trouble, and i think that anybody there can help me > > I've got a python script which i distribute in somes packages for *nix. > This script is full of python and need python 2.4 ! And i'd like to > display a message when the user doesn't have a python2.4 version. > I'd like to make my script (or a starter script) > which will be able to detect all python versions of the machine. And > run my script with the good one ; py2.4, or display a message to the > user to say her it must install py2.4 ... the approach used in bzr might work for you: # # application boot script import os, sys try: version_info = sys.version_info except AttributeError: version_info = 1, 5 # 1.5 or older REINVOKE = "__MYAPP_REINVOKE" NEED_VERS = (2, 4) KNOWN_PYTHONS = ('python2.4',) if version_info < NEED_VERS: if not os.environ.has_key(REINVOKE): # mutating os.environ doesn't work in old Pythons os.putenv(REINVOKE, "1") for python in KNOWN_PYTHONS: try: os.execvp(python, [python] + sys.argv) except OSError: pass print >>sys.stderr, "error: cannot find a suitable python interpreter" print >>sys.stderr, " (need %d.%d or later)" % NEED_VERS sys.exit(1) if hasattr(os, "unsetenv"): os.unsetenv(REINVOKE) # # get things going! import myapp myapp.run() # end of boot script (the actual bzr source is shipped under the GPL, but 1) it's trivial, and 2) I contributed the code in the first place, so I'd say it's safe to "steal this code" ;-) From aleaxit at yahoo.com Sun Oct 23 20:37:16 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 23 Oct 2005 17:37:16 -0700 Subject: Syntax across languages References: <1130052687.396109.145420@o13g2000cwo.googlegroups.com> Message-ID: <1h4wbam.7po3qo1j2e8b5N%aleaxit@yahoo.com> Tom Anderson wrote: ... > What would approximate FP equality even mean? How approximate? In APL, it meant "to within [a certain quad-global whose name I don't recall] in terms of relative distance", i.e., if I recall correctly, "a=b" meant something like "abs(a-b)/(abs(a)+abs(b)) < quadEpsilon" or thereabouts. Not too different from Numeric.allclose, except the latter is "richer" (it takes both absolute and relative "epsilons", and also implies an "and-reduce" if the objects being compared are arrays). Alex From fredrik at pythonware.com Sat Oct 8 05:12:05 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 8 Oct 2005 11:12:05 +0200 Subject: PIL Image can't open png file with "I"? References: <90DEA7ED93F71A4580CEDF76A02682EA03ACBD@torexch.metrigenix.com> Message-ID: "James Hu" wrote: > I have png file with mode "I", 16 bit, > And I tried to open it with im=Image.open("output.png"), im.show() > I got all white image. > Don't why? because all of the PNG file are larger than 255 ? show doesn't support 16-bit images, so it clamps the values down to an 8-bit range. adding a print im.getextrema() will tell you what values you have in the image (it returns min and max). to scale things down before you display it, you can use something like: im = im.point(lambda x: x*(1.0/256)) or lo, hi = im.getextrema() if lo == hi: im = im.point(lambda x: 128) # or something else: scale = 255.0 / (hi - lo) offset = -lo * scale + 0.5 im = im.point(lambda x: x*scale + offset) From david.murmann at rwth-aachen.de Tue Oct 4 04:03:53 2005 From: david.murmann at rwth-aachen.de (David Murmann) Date: Tue, 04 Oct 2005 10:03:53 +0200 Subject: semi-newbie module namespace confusion In-Reply-To: References: <1128404572.837225.41870@g47g2000cwa.googlegroups.com> Message-ID: <3qer81FeldcmU1@news.dfncis.de> Fredrik Lundh wrote: > running a piece of python code as a script isn't the same thing as > importing it as a module: I ran into the same problem some time ago and even wanted to post here about it, but found out that it had been reported as a bug three times at sourceforge (if i remember correctly). The comments there explained it of course, but I still think that this behavior is somehow "wrong". I like to think of the import statement as a way to provide the names defined in a module to the current namespace, so there is no "this gets evaluated twice". Now i wonder how difficult it would be to "correct" the behavior? And would such a change break any code? David. From grante at visi.com Wed Oct 5 19:45:21 2005 From: grante at visi.com (Grant Edwards) Date: Wed, 05 Oct 2005 23:45:21 -0000 Subject: Can't get pylibpcap extension to build under 2.4 References: <11k8p2btca5m7e1@corp.supernews.com> Message-ID: <11k8pchpfu9e8a1@corp.supernews.com> On 2005-10-05, Grant Edwards wrote: > I've been using the pylibpcap extension module for several > years, but I can't get it to build under 2.4: It turns out the .tar.gz file being distributed is missing the file doc.i and the entire build-tools subdirectory. If you grab the missing stuff from CVS it builds and installs after you hack setup.py as shown in the previous post. Don't know if it _works_ yet... -- Grant Edwards grante Yow! I'll show you MY at telex number if you show visi.com me YOURS... From grante at visi.com Fri Oct 21 11:52:15 2005 From: grante at visi.com (Grant Edwards) Date: Fri, 21 Oct 2005 15:52:15 -0000 Subject: Compile C program -> .pyc file References: <1129905417.451369.114840@o13g2000cwo.googlegroups.com> Message-ID: <11li3lft3h46d38@corp.supernews.com> On 2005-10-21, Fredrik Lundh wrote: > >> Is there a way to compile a C program into a .pyc file that >> has the same behavior as the compiled C program? > > unless you find a C->Python compiler, no. Or a C->Python-byte-code compiler. > PYC files contain Python bytecode, C compilers usually > generate native code for a given machine platform. Generating byte-code for a stack-based virtual machine used to be fairly popular for Pascal. [I once typed in from a book a Pascal compiler in 8080 assembly language that generate P-code.] Generating Python byte code from Pascal wouldn't be terribly difficult, but doing so for C would be pretty tough because you'd have to figure out how to fake all the low-level pointer shenanigans which C allows (or some would say depends upon). -- Grant Edwards grante Yow! Are we live or at on tape? visi.com From sp1d3rx at gmail.com Thu Oct 27 16:48:25 2005 From: sp1d3rx at gmail.com (sp1d3rx at gmail.com) Date: 27 Oct 2005 13:48:25 -0700 Subject: help with sending data out the parallel port In-Reply-To: References: Message-ID: <1130446105.526862.54680@f14g2000cwb.googlegroups.com> You don't want to use Python for that task. You're much better off using the Microsoft DDK (driver development kit). From michele.simionato at gmail.com Fri Oct 7 11:29:49 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 7 Oct 2005 08:29:49 -0700 Subject: users of pycurl here? Message-ID: <1128698989.351313.90070@f14g2000cwb.googlegroups.com> I am having a hard time in finding out how to retrieve information about the *size* of files I want to download from an FTP site. Should I send a QUOTE SIZE command to the ftp server or is there an easier way? TIA, Michele Simionato From pink at odahoda.de Mon Oct 10 08:24:59 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Mon, 10 Oct 2005 14:24:59 +0200 Subject: Question about StringIO References: <1128849763.117104.34370@f14g2000cwb.googlegroups.com> <3qsacmFftrn5U1@uni-berlin.de> <1128940255.694551.318760@g14g2000cwa.googlegroups.com> Message-ID: Frank Millman wrote: > I will try to explain my experience with popen() briefly. > > I have some sql scripts to create tables, indexes, procedures, etc. At > present there are about 50 scripts, but this number will grow. I have > been running them manually so far. Now I want to automate the process. > > I am supporting PostgreSQL and MS SQL Server, and the syntax is > slightly different in some cases. Rather than maintain two sets of > scripts, I prefix some lines with -pg- or -ms- to indicate the > platform, and then use Python to parse the scripts and generate a > correct output for each platform, passing it to 'psql' and 'osql' > respectively, using popen(). > > I have had a few problems, but it would take too long to describe them > all, and I just want a working solution, so I will focus on my latest > attempt. > > I run through all the scripts and create a StringIO object with the > string I want to pass. It is about 250 000 bytes long. If I run psql > using popen(), and pass it the string via stdin, it works fine, but I > get all the messages on the screen. If I do the same, but end the > command with ' > fjm 2>&1' it works correctly and the messages end up > in the file fjm, which is about 40 000 bytes long. If I run it with > popen4(), it starts ok, but then hangs about 1/4 of the way through. > Exactly the same happens on MSW. It seems to be hitting a limit on the > size of the stdout file - is that possible? > > For my purposes, I will be happy to use popen() and a choice of no > redirection, redirect to a file, or redirect to /dev/null. The question > about popen4() is therefore academic, though I would be interested to > know the answer. That's probably a deadlock as described in > BTW, is there an equivalent of /dev/null on MSW? Dunno - but as a last resort, you could create a tempfile with a unique name (to be sure, not to override any existing data), dump your output there and later os.unlink() it... -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From buzzard at urubu.freeserve.co.uk Sat Oct 8 10:29:44 2005 From: buzzard at urubu.freeserve.co.uk (Duncan Smith) Date: Sat, 08 Oct 2005 15:29:44 +0100 Subject: When someone from Britain speaks, Americans hear a "Britishaccent"... In-Reply-To: References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kbgj7421kd560@corp.supernews.com> <4h5ck1hkqq0ls83pq0lodkb51tsda4053k@4ax.com> <4346c5a8.0@entanet> Message-ID: <4347d9ed.0@entanet> Steve Holden wrote: > Duncan Smith wrote: > >> Rocco Moretti wrote: > > [...] > >> >> So English is spoken only in the South East of England, except London? >> I think you should also disbar the queen (unless she's already >> classified as a Londoner), due to her apparent confusion between the 1st >> person singular and 1st person plural :-). >> > There are special rules for the monarchs, who are expected to refer to > themselves in the first person plural. > > Oscar Wilde understood this. When he boasted that he could speak > extempore for a minute on any subject of a challenger's choosing someone > shouted "The Queen", to which he replied "The Queen, sir, is not a > subject". > Yes, although I'm not actually sure where the 'royal we' comes from; and we (Brits) are technically subjects rather than citizens. But if northerners are not English speakers because we use words like 'aye' (although we say far less understandable things than that) I think the queen should be similarly classified for using the 'royal we' :-). Duncan From ptb at oboe.it.uc3m.es Wed Oct 26 16:07:39 2005 From: ptb at oboe.it.uc3m.es (Peter T. Breuer) Date: Wed, 26 Oct 2005 22:07:39 +0200 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <3s6l8mFmj3fjU1@individual.net> <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> Message-ID: In comp.os.linux.misc David Schwartz wrote: > "Peter T. Breuer" wrote in message > news:5am333-iia.ln1 at news.it.uc3m.es... >> In comp.os.linux.misc David Schwartz wrote: >>> "Peter T. Breuer" wrote in message >>> news:0hm233-0ut.ln1 at news.it.uc3m.es... >>> I don't know what drugs you're on, but the McDonald's corporation >>> most >>> certainly is in the business of the wholesale distribution of burger >>> patties. One key reason to become a franchisee is to access their >>> wholesale >>> distribution network. >> Then they are not in the wholesale business. So lock the drugs cabinet. >> (What they are marketting is a "brand", complete with clowns and >> arches, and a secret formula for making up patties in buns). > So is Microsoft, except the clowns write the software. No they aren't. A pc o/s is something you load on an IBM pc, and an IBM pc is an open format. There is no "microsoft computer", and there is no such thing as a "microsoft computer shop". The closest you can get to a complete closed branding in that field, is, coincidentally, an apple o/s, and an apple computer, and an apple computer shop. And that's because apple make the confusers in question, and their o/s. However, I don't think they can stop the shops which sell apples from mselling pcs too, but then I have never had the slightest inclination to buy a "brand" like an apple, so I have never looked, so I don't have an inkling if that is so or not. > When a shop sells > machines that ship with Microsoft Windows, it is to some extent the power of > Microsoft's brand that brings them into the shop. No it isn't. Quite the opposite - look at a computer shop or a computer advert, and you will see "Pentium 4 3.4GHz 1MB cache, 1GB DDR RAM", etc. etc. Really - bar all the argument-shifting and picking up from nonsense points, I wish I could find some kernel of sensibleness in your argument because at times in the past you have acted sane. But not here! If you have an argument, out with the bones of it. What is it? Something like "MS can do anything they like to make a profit"? No - they can't. Is it "MS can't be criticised for behaving like mad bad bullies"? Uh, uh, yes they can. And so on. What IS your line? Peter From whzhao at gmail.com Wed Oct 5 05:15:00 2005 From: whzhao at gmail.com (Wenhua Zhao) Date: Wed, 05 Oct 2005 17:15:00 +0800 Subject: How to create temp file in memory??? In-Reply-To: References: Message-ID: I have a list of lines. I want to feed these lines into a function. The input of this function is a file. I want to creat a temp file on disk, and write the list of lines into this temp file, then reopen the file and feed it to the function. Can I create a this temp file on memory??? Jeremy Jones wrote: > Wenhua Zhao wrote: > >> A.T.T >> >> Thanks a lot. >> >> > If you could elaborate a bit more, it might be helpful. I'm guessing > you want something like StringIO or cStringIO. > > > - jmj From bj_666 at gmx.net Wed Oct 19 16:54:16 2005 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Wed, 19 Oct 2005 22:54:16 +0200 Subject: Python variables are bound to types when used? References: <1129751462.061785.124830@g49g2000cwa.googlegroups.com> Message-ID: In <1129751462.061785.124830 at g49g2000cwa.googlegroups.com>, pranab_bajpai wrote: > So I want to define a method that takes a "boolean" in a module, eg. > > def getDBName(l2): > ... Is that a 12 or l2? > Now, in Python variables are bound to types when used, right? > > Eg. > x = 10 # makes it an INT > whereas > x = "hello" # makes it a string No, think of `x` as a *name*. The name has *no* type. The objects you bind to that name have a type. So 10 is an int and "hello" is a string. > I take it, the parameters to a function (in the above example "l2") are > bound in the definition, rather than as invoked. If you invoke the function then the parameter is bound to an object. This object has a type. > So, if I use "l2" thus: > > if (l2): # only then does it make it a boolean? Here `l2` is treated as a boolean. If it is an integer then 0 is false, everything else is true, if it is a list, dictionary or string then an "empty" object is false, everything else is true. Otherwise it depends on the existence and return value of either a `__nonzero__()` or the `__len__()` method. See the docs for details. > and if I did, > > if (l2 = "hello"): # would it become string? It would become a syntax error. No assignement allowed there. > and what if I never used it in the definition body? Again: The objects have types, the names not. A string that is never used remains a string. Ciao, Marc 'BlackJack' Rintsch From python_it at hotmail.com Wed Oct 12 06:03:43 2005 From: python_it at hotmail.com (Python_it) Date: 12 Oct 2005 03:03:43 -0700 Subject: mod_python mptest.py works publisher not Message-ID: <1129111423.099038.256560@g43g2000cwa.googlegroups.com> I'm going to work with mod_python. I install mod_python 3.2.2b for python 2.4. If i test my install with mptest.py see this link: http://www.modpython.org/live/mod_python-3.2.2b/doc-html/modpython.html IT WORKS! But if i try this: AddHandler mod_python .py PythonHandler mod_python.publisher PythonDebug On http://www.modpython.org/live/mod_python-3.2.2b/doc-html/tut-pub.html It don't work! I Get the following message: Mod_python error: "PythonHandler mod_python.publisher" Traceback (most recent call last): File "C:\Program Files\Python24\Lib\site-packages\mod_python\apache.py", line 299, in HandlerDispatch result = object(req) File "C:\Program Files\Python24\Lib\site-packages\mod_python\publisher.py", line 204, in handler module = page_cache[req] File "C:\Program Files\Python24\Lib\site-packages\mod_python\cache.py", line 77, in __getitem__ return self._checkitem(name)[2] File "C:\Program Files\Python24\Lib\site-packages\mod_python\cache.py", line 119, in _checkitem value = self.build(key, name, opened, entry) File "C:\Program Files\Python24\Lib\site-packages\mod_python\publisher.py", line 77, in build return ModuleCache.build(self, key, req, opened, entry) File "C:\Program Files\Python24\Lib\site-packages\mod_python\cache.py", line 367, in build module = new.module(re_not_word.sub('_',key)) AttributeError: 'module' object has no attribute 'module' HELP? From martin.witte at gmail.com Fri Oct 14 11:53:08 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 14 Oct 2005 08:53:08 -0700 Subject: Problems with properties In-Reply-To: References: Message-ID: <1129305188.746872.69980@g49g2000cwa.googlegroups.com> If you change it to this it works. You should provide a get and a set function for a property. class Task: def __init__(self, value): self._command = value def setCommand(self, value): self._command = value def getCommand(self): return self._command command=property(getCommand, setCommand) class taskTest(TestCase): def testTask(self): t = Task("dir c:") c = t.command self.assertEquals("dir c:", c) # should fail, but doesn't t.command = "foo Bar" self.assertEquals("dir c:", t.command) if __name__ == "__main__": unittest.main() From lasse at vkarlsen.no Fri Oct 7 15:56:01 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Fri, 07 Oct 2005 21:56:01 +0200 Subject: Merging sorted lists/iterators/generators into one stream of values... In-Reply-To: References: Message-ID: Lasse V?gs?ther Karlsen wrote: > I need to merge several sources of values into one stream of values. All > of the sources are sorted already and I need to retrieve the values from Ok, after working through the various sources and solutions, here's what I finally ended up with: def merge_sorted(comparison, *sources): iterables = [] for source in sources: try: source = iter(source) iterables.append([source.next(), source]) except StopIteration: pass iterables.sort(cmp=comparison, key=lambda x: x[0]) while iterables: yield iterables[0][0] try: iterables[0][0] = iterables[0][1].next() if len(iterables) > 1 and comparison(iterables[0][0], iterables[1][0]) > 0: iterables.sort(comparison, key=lambda x: x[0]) except StopIteration: iterables.pop(0) Thanks to Mike and George for the solutions and pointers. -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From peter at engcorp.com Wed Oct 12 20:31:42 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 12 Oct 2005 20:31:42 -0400 Subject: slots? SLOTS? In-Reply-To: <3r4s3cFhndjpU1@individual.net> References: <3r4s3cFhndjpU1@individual.net> Message-ID: tin gherdanarra wrote: > what is a "slot" in python? Google for "site:docs.python.org slots": http://www.google.ca/search?q=site%3Adocs.python.org+slots First hit... -Peter From dcrespo at gmail.com Wed Oct 19 09:10:18 2005 From: dcrespo at gmail.com (dcrespo) Date: 19 Oct 2005 06:10:18 -0700 Subject: How to get a raised exception from other thread In-Reply-To: <8MudnZpGf80SLMjeRVn-vQ@powergate.ca> References: <1129326320.914350.171460@o13g2000cwo.googlegroups.com> <1129571521.699077.224300@f14g2000cwb.googlegroups.com> <1129646761.521348.52230@o13g2000cwo.googlegroups.com> <8MudnZpGf80SLMjeRVn-vQ@powergate.ca> Message-ID: <1129727418.181264.161000@g49g2000cwa.googlegroups.com> > Now that may not be perfect, since I'm not familiar with the TCPServer() > call. I've sort of assumed it does something quickly and returns, or > raises an exception if the input is bad. If it doesn't actually return > if it starts successfully, you would need a little different approach. > Probably adding a simple timeout to the self.startEvent.wait() call > would work. It's perfect! Thank you very much. After the .start() call in the main thread, it just waits until was a succesfull thread start. It's just perfect. One more thing, I would like to catch the description string of the error, so I can show it to the user in a Message Box. How can I do that in the main threa, once that I allready catched the exception? Thank you so much From samrobertsmith at gmail.com Mon Oct 24 09:02:39 2005 From: samrobertsmith at gmail.com (Shi Mu) Date: Mon, 24 Oct 2005 06:02:39 -0700 Subject: difference after remove Message-ID: <1d987df30510240602j4916a088s63f4fe34857943d1@mail.gmail.com> Is there any difference if I remove the '/' from the following statement? intMatrix2 = [[1,1,2,4,1,7,1,7,6,9],\ [1,2,5,3,9,1,1,1,9,1],\ [0,0,5,1,1,1,9,7,7,7]] print intMatrix2 I removed one '\' and it still works. So what is the use of '\'? From dashkedar123 at yahoo.co.in Mon Oct 10 02:16:02 2005 From: dashkedar123 at yahoo.co.in (dashkedar123) Date: Mon, 10 Oct 2005 06:16:02 -0000 Subject: Python Programmer Urgently Required Message-ID: Job Description: The position holder will supplement the existing pool of application development and programming pool of OWSA technical team. In particular S/he will be responsible for developing Python based overlay application ? to be mounted on existing software tools and solutions. The position will report to Team Manager, Training & Technical Services. Required Skills: * A degree in Computer Application, Engineering or another numerate subject * 1+ years experience of web application development in Python or PHP * Good understanding of MySQL, PostGreSQL or another RDBMS platform. * Aptitude and experience of technical writing and process documentation * Good oral and written communication abilities; and ability to work in multi-disciplinary team To apply for any of these above positions, please send your latest resume along with details of your current role and how do your propose to contribute in this position. Women candidates with the requisite skills & qualifications are especially encouraged to apply. OneWorld South Asia is an equal opportunity employer. Applications along with a one page write up explaining the suitability to the job may be sent (preferably through email) to: Kedar Dash Team Leader, Web Development OneWorld South Asia, C-5 Qutab Institutional Area New Delhi ? 110016 Tel: 91 11 51689001 Ext 108 Fax: 91 11 51689001 Email : kedar.dash at oneworld.net From fredrik at pythonware.com Mon Oct 24 14:51:32 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 24 Oct 2005 20:51:32 +0200 Subject: Extention String returning References: <1130178503.498003.175810@f14g2000cwb.googlegroups.com> Message-ID: "Tuvas" wrote: > I have been writing a program that is designed to return an 8 byte > string from C to Python. Occasionally one or more of these bytes will > be null, but the size of it will always be known. How can I write an > extention module that will return the correct bytes, and not just until > the null? I would think there would be a fairly easy way to do this, > but, well... Thanks! return PyString_FromStringAndSize(buffer, bytes); or return Py_BuildValue("s#", buffer, bytes); From christian at spam.not Thu Oct 20 01:50:25 2005 From: christian at spam.not (Christian) Date: Thu, 20 Oct 2005 07:50:25 +0200 Subject: Set an environment variable Message-ID: <43573022$0$155$edfadb0f@dread16.news.tele.dk> Another question from a not even newbie: In Unix you can set an environment variable with the command export PYTHONPATH but I would like to set the variable from at .py script. So my question is: How do I export an environment variable in a .py script? Thanks Chris From tim.peters at gmail.com Fri Oct 28 12:04:35 2005 From: tim.peters at gmail.com (Tim Peters) Date: Fri, 28 Oct 2005 12:04:35 -0400 Subject: Is bytecode machine (in)dependent? In-Reply-To: References: Message-ID: <1f7befae0510280904g1a1b0089k58d0904032b7e37@mail.gmail.com> [Robert McLay] > I'm trying to understand bytecodes generated on different machines. > I understand that the bytecodes can change between version. But since > I'm told that .pyc files are version dependent but not machine > dependent, I'm wondering why the bytecodes are machine dependent. They aren't -- at least not particularly . > my friend and I created this simple example to explore the problem. > The example code is: > > #!/usr/bin/env python > # > import sys, os > > def main(): > x = 1.234 > print x > > if ( __name__ == '__main__'): > main() > > > Using sib.py from Vendorid 1.0 generates different bytecodes under linux > and sgi. At its core sib.py is using: > > # Compile the code using prefix and marshall it. > compiled_code = compile(source_code, prefix, 'exec') > marshalled_code = marshal.dumps(compiled_code) > > to get the bytecodes. Why do you believe that `prefix` had the same value in both runs? The output suggests it did not, but can't guess more than that from here since I don't know where `prefix` came from. > So why are the byte codes different? Is it that the intel-linux is > little endian and the SGI is big endian No; marshal format has fixed endianness. > and the numerical constant (1.234) is stored different depending on the > endian-ness? Python defers to the platform C library for string->float conversions, and it's *possible* that different platforms could convert "1.234" to a C double in slightly different ways. There's no evidence of that here, though. > This was generated under intel-linux using python 2.4.2 > > > > > /*==========================================================================*/ > /* Frozen main script for test */ > /* Generated from test.py */ > /* This is generated code; Do not modify it! */ > /*--------------------------------------------------------------------------*/ > unsigned char M___main__[] = > { > 99,0,0,0,0,0,0,0,0,2,0,0,0,64,0,0, > 0,115,55,0,0,0,100,0,0,107,0,0,90,0,0,100, > 0,0,107,1,0,90,1,0,100,1,0,132,0,0,90,2, > 0,101,3,0,100,2,0,106,2,0,111,11,0,1,101,2, > 0,131,0,0,1,110,1,0,1,100,0,0,83,40,3,0, > 0,0,78,99,0,0,0,0,1,0,0,0,1,0,0,0, > 67,0,0,0,115,15,0,0,0,100,1,0,125,0,0,124, > 0,0,71,72,100,0,0,83,40,2,0,0,0,78,102,5, > 49,46,50,51,52,40,1,0,0,0,116,1,0,0,0,120, > 40,1,0,0,0,82,0,0,0,0,40,0,0,0,0,40, > 0,0,0,0,116,23,0,0,0,47,104,111,109,101,47,118, /* This line */ > 112,97,114,114,47,115,105,98,47,116,101,115,116,46,112,121, > 116,4,0,0,0,109,97,105,110,5,0,0,0,115,4,0, > 0,0,0,1,6,1,116,8,0,0,0,95,95,109,97,105, > 110,95,95,40,4,0,0,0,116,3,0,0,0,115,121,115, > 116,2,0,0,0,111,115,82,2,0,0,0,116,8,0,0, > 0,95,95,110,97,109,101,95,95,40,3,0,0,0,82,4, > 0,0,0,82,2,0,0,0,82,5,0,0,0,40,0,0, > 0,0,40,0,0,0,0,82,1,0,0,0,116,1,0,0, > 0,63,3,0,0,0,115,6,0,0,0,18,2,9,4,13, > 1, > }; x > > And under SGI (python 2.4.2) it created : > > /*==========================================================================*/ > /* Frozen main script for test */ > /* Generated from test.py */ > /* This is generated code; Do not modify it! */ > /*--------------------------------------------------------------------------*/ > unsigned char M___main__[] = > { > 99,0,0,0,0,0,0,0,0,2,0,0,0,64,0,0, > 0,115,55,0,0,0,100,0,0,107,0,0,90,0,0,100, > 0,0,107,1,0,90,1,0,100,1,0,132,0,0,90,2, > 0,101,3,0,100,2,0,106,2,0,111,11,0,1,101,2, > 0,131,0,0,1,110,1,0,1,100,0,0,83,40,3,0, > 0,0,78,99,0,0,0,0,1,0,0,0,1,0,0,0, > 67,0,0,0,115,15,0,0,0,100,1,0,125,0,0,124, > 0,0,71,72,100,0,0,83,40,2,0,0,0,78,102,5, > 49,46,50,51,52,40,1,0,0,0,116,1,0,0,0,120, > 40,1,0,0,0,82,0,0,0,0,40,0,0,0,0,40, > 0,0,0,0,116,23,0,0,0,47,87,111,114,107,47,118, /* This line */ > 112,97,114,114,47,115,105,98,47,116,101,115,116,46,112,121, > 116,4,0,0,0,109,97,105,110,5,0,0,0,115,4,0, > 0,0,0,1,6,1,116,8,0,0,0,95,95,109,97,105, > 110,95,95,40,4,0,0,0,116,3,0,0,0,115,121,115, > 116,2,0,0,0,111,115,82,2,0,0,0,116,8,0,0, > 0,95,95,110,97,109,101,95,95,40,3,0,0,0,82,4, > 0,0,0,82,2,0,0,0,82,5,0,0,0,40,0,0, > 0,0,40,0,0,0,0,82,1,0,0,0,116,1,0,0, > 0,63,3,0,0,0,115,6,0,0,0,18,2,9,4,13, > 1, > }; > > > The difference between the two is very slight: > > 18c18 > < 0,0,0,0,116,23,0,0,0,47,104,111,109,101,47,118, > --- > > 0,0,0,0,116,23,0,0,0,47,87,111,114,107,47,118, Stare at this: >>> ''.join(map(chr, [47,104,111,109,101,47,118])) '/home/v' >>> ''.join(map(chr, [47,87,111,114,107,47,118])) '/Work/v' It _suggests_ that `prefix` contained the substring "/home/" on one box but ""/Work/" on the other. From steve at REMOVETHIScyber.com.au Tue Oct 11 09:22:09 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Tue, 11 Oct 2005 23:22:09 +1000 Subject: Python's Performance References: <20051008040614.47429.qmail@web30607.mail.mud.yahoo.com> <178B879D-FDB6-458C-BE00-A03820D98703@advfn.com> <1128888628.643764@yasure> <1128988055.798016.147970@g49g2000cwa.googlegroups.com> Message-ID: On Mon, 10 Oct 2005 16:47:35 -0700, Paul Boddie wrote: >> The difficulty is that the target architecture in not realized in hardware. > > Or isn't perhaps feasible/viable for hardware realisation: one of the > EuroPython speakers dangled the promise of hardware support for > high-level languages (the classic "Python on a chip" concept), but > there are probably plenty of areas where hardware support can assist > software virtual machines without going to all the trouble of > implementing such virtual machines in hardware completely. I remember back in the mid 1980s, Apple and Texas Instruments collaborated to build a hybrid dual-processor machine. It had a standard Motorola 68000 CPU like the Macintosh, plus a custom TI processor that executed Lisp code in hardware. I'm told that the reason they never sold was that the Lisp machine was considerably slower than the software Lisp solution of the time. On the other hand, there were Forth enthusiasts who hacked their Macintoshes with Forth chips, and they went like a rocket. -- Steven. From fredrik at pythonware.com Thu Oct 13 13:08:06 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 13 Oct 2005 19:08:06 +0200 Subject: ImportError: No module named dbm References: <2229.131.123.36.10.1129218983.squirrel@webmail.cs.kent.edu> Message-ID: mhardas at cs.kent.edu wrote: > Can you tell me how do I go about getting the dbm module and install > it.?? http://www.google.com/search?q=trustix+python+dbm From http Thu Oct 13 13:08:15 2005 From: http (Paul Rubin) Date: 13 Oct 2005 10:08:15 -0700 Subject: Let My Terminal Go References: <1129010288.251817.147690@z14g2000cwz.googlegroups.com> <1129012665.29863.2.camel@blackwidow> <1129026623.319531.97420@g43g2000cwa.googlegroups.com> <7x4q7lmk6j.fsf@ruckus.brouhaha.com> <11kt4ormimmute2@corp.supernews.com> Message-ID: <7xd5m9qr9c.fsf@ruckus.brouhaha.com> Grant Edwards writes: > Since the NT kernel is descended from VMS, I'm not surprised > that a fork is expensive. Apache 2.x supports concurrency via threading as an alternative to forking, basically in order to get acceptable performance on Windows. From bedouglas at earthlink.net Sun Oct 2 11:23:22 2005 From: bedouglas at earthlink.net (bruce) Date: Sun, 2 Oct 2005 08:23:22 -0700 Subject: python guru.. for a short conversation regarding bittorrent.. Message-ID: <009001c5c765$3aa4cb70$0301a8c0@Mesa.com> hi.. i'm not a python developer, but i have a few questions regarding python (some quite basic), and bittorrent. i'm looking to talk to someone/anyone who has experience with the infrastructure of bittorrent, not just running a bittorrent client app... the bittorrent mailing lists/groups haven't been responsive, so i figured i'd try here... if there's anyone here that i could talk with (phone) who's knowledgable about these areas, i'd appreciate it. i'm trying to get a much better understanding of the actual underlying app. thanks -bruce bedouglas at earthlink.net From fredrik at pythonware.com Wed Oct 19 04:45:30 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 19 Oct 2005 10:45:30 +0200 Subject: "dynamical" importing References: <1129711017.413612.60350@f14g2000cwb.googlegroups.com> Message-ID: Joerg Schuster wrote: > I need to import modules from user defined paths. I.e. I want to do > something like: > > module_dir = sys.argv[1] > > my_path = os.path.join(module_dir, 'bin', 'my_module') > > from my_path import my_object > > Obviously, it doesn't work this way. How would it work? some alternatives: - if you want the modules to remain imported: try: sys.path.insert(0, os.path.join(module_dir, "bin")) module = __import__("my_module") finally: del sys.path[0] object = module.my_object - if you're only interested in the object: namespace = {} execfile(os.path.join(module_dir, "bin", "my_module" + ".py"), namespace) object = namespace["my_object"] From gdridi at club-internet.fr Thu Oct 13 12:39:24 2005 From: gdridi at club-internet.fr (Gilles DRIDI) Date: Thu, 13 Oct 2005 18:39:24 +0200 Subject: wxPython & Cygwin Message-ID: <434e8dbf$0$452$7a628cd7@news.club-internet.fr> Does someone has installed wxPython on the Cygwin platform, environment ? Thank you Gilles DRIDI http://cdridi.club.fr From aleaxit at yahoo.com Sat Oct 22 21:56:25 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 22 Oct 2005 18:56:25 -0700 Subject: Python vs Ruby References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> <1129883505.814349.306860@g44g2000cwa.googlegroups.com> <86fyqt9j9x.fsf@bhuda.mired.org> Message-ID: <1h4ukde.1gc4cgu1a252ggN%aleaxit@yahoo.com> Mike Meyer wrote: > > Every line = more labour for the developer = more cost and time. > > Every line = more places for bugs to exist = more cost and time. > > There were studies done in the 70s that showed that programmers > produced the same number of debugged lines of code a day no matter > what language they used. So a language that lets you build the same > program with fewer lines of code will let you build the program in > less time. Of course, these results only apply where the "complexity" (e.g., number of operators, for example) in a single line of code is constant. There is no complexity advantage to wrapping up code to take fewer LINES, as such -- e.g., in Python: for item in sequence: blaap(item) or for item in sequence: blaap(item) are EXACTLY as easy (or hard) to write, maintain, and document -- it's totally irrelevant that the number of lines of code has "doubled" in the second (more standard) layout of the code!-) This effect is even more pronounced in languages which allow or encourage more extreme variation in "packing" of code over lines; e.g., C, where for(x=0; x<23; x++) { a=seq[x]; zap(a); blup(a); flep(a); } and for(x=0; x<23; x++) { a=seq[x]; zap(a); blup(a); flep(a); } are both commonly used styles -- the order of magnitude difference in lines of code is totally "illusory". Alex From gsakkis at rutgers.edu Sat Oct 8 14:14:39 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Sat, 8 Oct 2005 14:14:39 -0400 Subject: Merging sorted lists/iterators/generators into one stream of values... References: <1128667968.421469.180910@g47g2000cwa.googlegroups.com> <1128691708.c6930b5cb9f3673ed3abe8755178d163@teranews> <1128692196.410209.252100@g14g2000cwa.googlegroups.com> <1128695317.c6a5acb3e62787f011310c96f0c7cc35@teranews> <1h439qe.pz7c451jcec6hN%aleax@mail.comcast.net> Message-ID: <1128795319.09c32ac9943b0580a86b7bcada7facc1@teranews> "Lasse V?gs?ther Karlsen" wrote: > Alex Martelli wrote: > > George Sakkis wrote: > > >>Yes, it's a little inconvenient that the builtin heap doesn't take a > >>comparison operation but you can easily roll your own heap by transforming > >>each item to a (key,item) tuple. Now that I'm thinking about it, it might > >>be a good addition to the cookbook. > > > > > > I believe Python 2.5 adds a key= argument to heapq's functions... > > > I will revisit the heapq solution when 2.5 is released then. > > Thanks for the heads up. For the moment I will stay with the list > solution that Mike came up with slightly changed to accomodate tips and > pointers from others in this thread. Just added a recipe at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440673. You can try both and see if there's any significant performance difference for your data. George From prlgarg at gmail.com Wed Oct 5 09:38:04 2005 From: prlgarg at gmail.com (parul garg) Date: Wed, 5 Oct 2005 19:08:04 +0530 Subject: regarding python and c++ interaction Message-ID: hi i am new to python.i hav to call function of c++ .so file(shared library)on linux. any how i am not able to do that. i had made one zoo.so file.when i import it this gives the following error... >>> import zoo Traceback (most recent call last): File "", line 1, in ? ImportError: ./zoo.so: undefined symbol: _Znwj can u plz help me in that matter rdgs parul From codecraig at gmail.com Thu Oct 6 12:22:22 2005 From: codecraig at gmail.com (Java and Swing) Date: 6 Oct 2005 09:22:22 -0700 Subject: Swig and pointers In-Reply-To: References: <1128541976.495441.46140@f14g2000cwb.googlegroups.com> Message-ID: <1128615742.025901.241700@z14g2000cwz.googlegroups.com> (reposting, i was just told how I should properly reply via groups.google.com) im sorry, why would it be md_ptr? what is md_ptr? i tried.. %include cpointer.i %pointer_functions(MY_DIGIT, digit_ptr) ptr = new_digit_ptr() doIt("a message", ptr) ...doesnt work..still needs a DIGIT ** Miki Tebeka wrote: > Hello Java, > > > ... > > extern int doIt(char *a, MY_DIGIT **digit); > > %include cpointer.i > > %pointer_functions(MY_DIGIT, md_prt); > Don't you mean md_ptr? > > > %typemap(in) (char *a, MY_DIGIT **argv) { > > /* Check if is a list */ > > if (PyList_Check($input)) { > > int i; > > $1 = PyList_Size($input); > > $2 = (MY_DIGIT **) malloc(($1+1)*sizeof(long *)); > > for (i = 0; i < $1; i++) { > > PyObject *o = PyList_GetItem($input,i); > > if (PyString_Check(o)) > > $2[i] = PyString_AsString(PyList_GetItem($input,i)); > > else { > > PyErr_SetString(PyExc_TypeError,"list must contain strings"); > > free($2); > > return NULL; > > } > > } > > $2[i] = 0; > > } else { > > PyErr_SetString(PyExc_TypeError,"not a list"); > > return NULL; > > } > > } > > > > %typemap(freearg) (char *a, MY_DIGIT **argv) { > > free((MY_DIGIT *) $2); > > } > > > > > > ..from Python I am trying > > > > >> ptr = [] > > >> doIt("blah", ptr) > > > > I thought this was the correct approach as described here: > > http://www.swig.org/Doc1.3/SWIGDocumentation.html#Python_nn59 > > > > However, python comes back and says "TypeError: argument number 2: a > > 'MY_DIGIT **' is expected, 'list([])' is received" > > > > ..any ideas? > Didn't check it but from http://www.swig.org/Doc1.3/Library.html it looks > like you need to do: > ptr = new_md_prt() > > HTH. > -- > ------------------------------------------------------------------------ > Miki Tebeka > http://tebeka.bizhat.com > The only difference between children and adults is the price of the toys From aisaac0 at verizon.net Tue Oct 25 02:49:29 2005 From: aisaac0 at verizon.net (David Isaac) Date: Tue, 25 Oct 2005 06:49:29 GMT Subject: calling matlab References: <1129138120.654955.167760@o13g2000cwo.googlegroups.com> Message-ID: "hrh1818" wrote in message news:1129138120.654955.167760 at o13g2000cwo.googlegroups.com... > There is a module named pymat avvailable from > http://sourceforge.net/projects/pymat that provides a limited set of > functions for intertfacing Python to Matlab. I think that pymat was superceded by mlabwrap http://mlabwrap.sourceforge.net/ Alan Isaac From i3x9mdw at j9n35c.invalid Sun Oct 23 18:47:30 2005 From: i3x9mdw at j9n35c.invalid (Alan Connor) Date: Sun, 23 Oct 2005 22:47:30 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <86k6g59ke6.fsf@bhuda.mired.org> <3EI6f.43974$MF6.5922@fe1.news.blueyonder.co.uk> <86irvo861u.fsf@bhuda.mired.org> Message-ID: "Matt Garrish" wrote: That does it. From this point on my newsfilter is killing (leaving on the server) any articles cross-posted to more than three groups. To all of the snivelling punks polluting the Usenet with their verbal diarrhea here: Shut up and go away. Done. (I haven't read a single post here, but don't need to. A bunch of aliases with no posting histories equals trolls equals verbal diarrhea.) And my killfile thanks you for the sumptuous feast all of the aliases used on this thread have given it. Do your Mommy's know that you are playing with their computers again? AC -- Homepage: http://home.earthlink.net/~alanconnor/ Fanclub: http://www.pearlgates.net/nanae/kooks/alanconnor.shtml From xah at xahlee.org Wed Oct 26 03:38:23 2005 From: xah at xahlee.org (Xah Lee) Date: 26 Oct 2005 00:38:23 -0700 Subject: a Haskell a Day Message-ID: <1130312303.713737.160830@g44g2000cwa.googlegroups.com> A Haskell A Day: Manifesto This is my learning notes on Haskell. I call it a-Haskell-a-day. I've been programing since 1992, and am a top expert at the Mathematica? language. I've long wanted to learn Haskell. It is my habit to write down what i'm learning. I will send out a small tip of what i have learned every day. If you are experienced industrial programer, especially if you also have experience in a functional language, this group may be useful to you. I hope you will join me in learning Haskell. Note: this is not a tutorial. The daily notes serve best as a motivation for your own learning processes. Links to appropriate sections in other reliable texts will usually be included daily. Daily tips will be gradually collected and organized at: http://xahlee.org/haskell/haskell.html My goal is to eventually form a example-based tutorial. I'm running a mailing list at Yahoo.com. To see the mailing list, go to: http://groups.yahoo.com/group/haskell-a-day To subscribe, send a email to: haskell-a-day-subscribe @ yahoogroups.com Xah xah at xahlee.org ? http://xahlee.org/ From fredrik at pythonware.com Thu Oct 27 05:45:30 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 27 Oct 2005 11:45:30 +0200 Subject: Sorting with only a partial order definition References: Message-ID: Bryan Olson wrote: > The usual tools to deal with partial orderings are directed acyclic graphs, > and "topological sorting". Try Googling the terms along with "Python". here's a rather powerful timbot implementation: http://mail.python.org/pipermail/python-list/1999-July/006625.html From gene.tani at gmail.com Mon Oct 3 08:45:32 2005 From: gene.tani at gmail.com (gene tani) Date: 3 Oct 2005 05:45:32 -0700 Subject: Python based unacceptable language filter In-Reply-To: References: Message-ID: <1128343532.940966.202260@g44g2000cwa.googlegroups.com> Good question, but Y'know, i don't think i'm the only one using a threaded mail reader. Pls don't hijack others' threads. David Pratt wrote: > Hi. Is anyone aware of any python based unacceptable language filter > code to scan and detect bad language in text from uploads etc. > > Many thanks. > David From scapt at unil.ch Fri Oct 21 02:08:33 2005 From: scapt at unil.ch (=?iso-8859-1?B?U+li?=) Date: 20 Oct 2005 23:08:33 -0700 Subject: Sequence and/or pattern matching References: <1129710091.400262.139440@g14g2000cwa.googlegroups.com> <1h4ocwa.184dksqmnv1q1N%aleaxit@yahoo.com> <1129712258.200656.202440@g43g2000cwa.googlegroups.com> <86fyqxw7ev.fsf@bhuda.mired.org> <1129801276.626944.96230@g44g2000cwa.googlegroups.com> <86oe5kuvg5.fsf@bhuda.mired.org> Message-ID: <1129874913.659158.174720@z14g2000cwz.googlegroups.com> Sorry for the confusion, I think my example was unclear. Thank you Mike for this piece of code who solves a part of my problem. In fact, the sequences are unknown at the beginning, so the first part of the code has to find possible sequences and if those sequences are repeated, counts how many time they appear (as your code does). I have found this morning that there's a software produced by i2 software who does this kind of job, but for telephone call analysis. Maybe the description could help to better understand my goal : http://www.i2.co.uk/products/Pattern_Tracer/default.asp S?b From skip at pobox.com Sun Oct 23 13:23:57 2005 From: skip at pobox.com (skip at pobox.com) Date: Sun, 23 Oct 2005 12:23:57 -0500 Subject: Syntax across languages In-Reply-To: <1h4vprp.6l0d8o1yvhiyiN%aleaxit@yahoo.com> References: <1130052687.396109.145420@o13g2000cwo.googlegroups.com> <1h4vprp.6l0d8o1yvhiyiN%aleaxit@yahoo.com> Message-ID: <17243.50989.915419.314737@montanaro.dyndns.org> Alex> I've seen enough occurrences of "lambda x: x" in Python code with Alex> a generally functional style that I'd love to have Alex> operator.identity (and a few more trivial functions like that) for Alex> readability;-) But, but, but [Skip gets momentarily apoplectic, then recovers...] "operator.identity" is way more to type than "lambda x: x". Plus you have to remember to import the operator module. <0.5 wink> Not to mention which (from "pydoc operator"): [The operator module] exports a set of functions implemented in C corresponding to the intrinsic operators of Python. Last time I checked, Python didn't have an intrinsic "identity" operator. For which reason, I'd be -1 on the idea of an identity function, certainly in the operator module. Skip From james at colannino.org Mon Oct 24 13:33:41 2005 From: james at colannino.org (James Colannino) Date: Mon, 24 Oct 2005 10:33:41 -0700 Subject: output from external commands In-Reply-To: <435cc914$1_2@newspeer2.tds.net> References: <435C6642.8020504@colannino.org> <435cc914$1_2@newspeer2.tds.net> Message-ID: <435D1AF5.20403@colannino.org> Kent Johnson wrote: >import os >files = os.listdir('.') > Thanks, that's good to know. I still need to use os.popen() for a few things, but I'll be needing filenames also, so when I try to get filenames I'll use the above. James -- My blog: http://www.crazydrclaw.com/ My homepage: http://james.colannino.org/ "If Carpenters made houses the way programmers design programs, the first woodpecker to come along would destroy all of civilization." --Computer Proverb From fredrik at pythonware.com Wed Oct 5 07:55:55 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 5 Oct 2005 13:55:55 +0200 Subject: Help with chaos math extensions. References: <43433982.8080008@yahoo.com> Message-ID: Brandon Keown wrote: > I have programmed a fractal generator (Julia Set/Mandelbrot Set) in > python in the past, and have had good success, but it would run so > slowly because of the overhead involved with the calculation. I > recently purchased VS .NET 2003 (Win XP, precomp binary of python > 2.4.2rc1) to make my own extensions. I was wondering if anyone could > help me figure out why I'm getting obscure memory exceptions (runtime > errors resulting in automatic closing of Python) with my extension. It > seems to run okay if imported alone, but when accompanied in a list of > instructions such as a function it crashes. a short script or interpreter session that illustrates how to get the errors would help. From nil at dev.nul Sun Oct 16 14:28:55 2005 From: nil at dev.nul (Christian Stapfer) Date: Sun, 16 Oct 2005 20:28:55 +0200 Subject: Comparing lists - somewhat OT, but still ... References: <1128930699.799657.146210@g47g2000cwa.googlegroups.com> <1128952417.0544cc73190bbbd4e683448c137969c8@teranews> <434ba977@nntp0.pdx.net> <1129216693.445956.155490@g47g2000cwa.googlegroups.com> Message-ID: "Steven D'Aprano" wrote in message news:pan.2005.10.16.16.01.43.591166 at REMOVETHIScyber.com.au... > On Sun, 16 Oct 2005 15:16:39 +0200, Christian Stapfer wrote: > >> Come to think of an experience that I shared >> with a student who was one of those highly >> creative experimentalists you seem to have >> in mind. He had just bought a new PC and >> wanted to check how fast its floating point >> unit was as compared to our VAX. After >> having done his wonderfully creative >> experimenting, he was utterly dejected: "Our (old) >> VAX is over 10'000 times faster than my new PC", >> he told me, almost in despair. > > Which it was. It finished executing his code in almost 1/10,000th of the > time his PC could do. > >> Whereupon I, >> always the uncreative, dogmatic theoretician, >> who does not believe that much in the decisiveness >> of the outcome of mere experiments, told him >> that this was *impossible*, that he *must* have >> made a mistake... > > It wasn't a mistake and it did happen. Yes, yes, of course, it was a mistake, since the conclusion that he wanted to draw from this experiment was completely *wrong*. Similarly, blind experimentalism *without* supporting theory is mostly useless. > The VAX finished the calculation > 10,000 times faster than his PC. >You have a strange concept of "impossible". What about trying, for a change, to suppress your polemical temperament? It will only lead to quite unnecessarily long exchanges in this NG. >> It turned out that the VAX compiler had been >> clever enough to hoist his simple-minded test >> code out of the driving loop. But, mind you, his test was meant to determine, *not* the cleverness of the VAX compiler *but* the speed of the floating-point unit. So his experiment was a complete *failure* in this regard. > > Optimizations have a tendency to make a complete mess of Big O > calculations, usually for the better. How does this support your > theory that Big O is a reliable predictor of program speed? My example was meant to point out how problematic it is to assume that experimental outcomes (without carefully relating them back to supporting theory) are quite *worthless*. This story was not about Big-Oh notation but a cautionary tale about the relation between experiment and theory more generally. - Got it now? > For the record, the VAX 9000 can have up to four vector processors each > running at up to 125 MFLOPS each, or 500 in total. A Pentium III runs at > about 850 Mflops. Comparing MIPS or FLOPS from one system to another is > very risky, for many reasons, but as a very rough and ready measure > of comparison, a four processor VAX 9000 is somewhere about the > performance of a P-II or P-III, give or take some fudge factor. Well, that was in the late 1980s and our VAX certanly most definitely did *not* have a vector processor: we were doing work in industrial automation at the time, not much number-crunching in sight there. > So, depending on when your student did this experiment, it is entirely > conceivable that the VAX might have been faster even without the > optimization you describe. Rubbish. Why do you want to go off a tangent like this? Forget it! I just do not have the time to start quibbling again. > Of course, you haven't told us what model VAX, That's right. And it was *not* important. Since the tale has a simple moral: Experimental outcomes *without* supporting theory (be it of the Big-Oh variety or something else, depending on context) is mostly worthless. > or how many processors, or what PC your student had, > so this comparison might not be relevant. Your going off another tangent like this is certainly not relevant to the basic insight that experiments without supproting theory are mostly worhtless, I'd say... >> In fact, our VAX >> calculated the body of the loop only *once* >> and thus *immediately* announced that it had finished >> the whole test - the compiler on this student's >> PC, on the other hand, had not been clever enough >> for this type of optimization: hence the difference... > > Precisely. And all the Big O notation is the world will not tell you that. > Only an experiment will. Now, perhaps in the simple case of a bare loop > doing the same calculation over and over again, you might be able to > predict ahead of time what optimisations the compiler will do. But for > more complex algorithms, forget it. > > This is a clear case of experimentation leading to the discovery > of practical results which could not be predicted from Big O calculations. The only problem being: it was *me*, basing myself on "theory", who rejected the "experimental result" that the student had accepted *as*is*. (The student was actually an engineer, I myself had been trained as a mathematician. Maybe that rings a bell?) > I find it quite mind-boggling that you would use as if it was a triumph > of abstract theoretical calculation when it was nothing of the sort. This example was not at all meant to be any such thing. It was only about: "experimenting *without* relating experimental outcomes to theory is mostly worthless". What's more: constructing an experiment without adequate supporting theory is also mostly worthless. >> I think this is really a cautionary tale for >> experimentalists: don't *believe* in the decisiveness >> of the outcomes your experiments, but try to *understand* >> them instead (i.e. relate them to your theoretical grasp >> of the situation)... > > Or, to put it another way: your student discovered No. You didn't read the story correctly. The student had accepted the result of his experiments at face value. It was only because I had "theoretical" grounds to reject that experimental outcome that he did learn something in the process. Why not, for a change, be a good loser? > something by running an experimental test of his code > that he would never have learnt in a million > years of analysis of his algorithm: the VAX compiler > was very cleverly optimized. Ok, he did learn *that*, in the end. But he did *also* learn to thoroughly mistrust the outcome of a mere experiment. Experiments (not just in computer science) are quite frequently botched. How do you discover botched experiments? - By trying to relate experimental outcomes to theory. Regards, Christian From skip at pobox.com Tue Oct 4 21:38:27 2005 From: skip at pobox.com (skip at pobox.com) Date: Tue, 4 Oct 2005 20:38:27 -0500 Subject: python plotting with greek symbols within labels recommendations? In-Reply-To: <1128469278.622461.249550@g49g2000cwa.googlegroups.com> References: <1128469278.622461.249550@g49g2000cwa.googlegroups.com> Message-ID: <17219.11923.306205.333546@montanaro.dyndns.org> mike> thus far, i've found that matplotlib mike> (http://matplotlib.sourceforge.net/) can do this, albeit the mike> implementation is so poor that you cannot mix standard text with mike> symbols on the same plot element. That seems a bit harsh. Have you asked on the matplotlib mailing list to see if it can do what you want? Skip From mwm at mired.org Mon Oct 31 14:01:13 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 31 Oct 2005 14:01:13 -0500 Subject: Expanding Python as a macro language References: <1130545600.925061.287390@g49g2000cwa.googlegroups.com> <1130631958.683127.215300@g14g2000cwa.googlegroups.com> Message-ID: <86mzkp3406.fsf@bhuda.mired.org> Jorgen Grahn writes: > On 29 Oct 2005 17:25:58 -0700, qwweeeit at yahoo.it wrote: > ... >> Michel wrote: > ... >> > Linux can run perfectly happily without any form of windowing >> > environment. >> >> I know, but nowadays almost any relevant application has a GUI. > > Side note: lots of people would disagree with that. For example, from my > perspective, almost all relevant applications /lack/ a GUI. (And some that > has one would be better off without it.) This brings up an interesting point for scripting unix applications. One common approach is to provide the application functionaliity in a library, then wrap that in various ways, of which a GUI is only one. You "script" the application by wrapping the library for your favorite scripting language, and the script will never open a GUI. In fact, it'll work fine in an environment where the GUI couldn't open at all. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From steve at REMOVEMEcyber.com.au Mon Oct 24 04:57:02 2005 From: steve at REMOVEMEcyber.com.au (Steven D'Aprano) Date: Mon, 24 Oct 2005 18:57:02 +1000 Subject: Tricky Areas in Python References: <1130097286.772836.94930@g44g2000cwa.googlegroups.com> <1h4wbvb.1dblc4317zeuw2N%aleaxit@yahoo.com> Message-ID: <435CA1DE.2060101@REMOVEMEcyber.com.au> Alex Martelli wrote: > I like to present code that seems like it should work, but has some kind > of relatively subtle problem, either of correctness in some corner case, > or of performance, etc -- and I ask them what they would say if they > were to code-review that code, or how they would help a student who came > to them with that code and complaints about it not working, &c. [snip] > Not sure whether you think this count as "tricky"... they're typically > problems that do come up in the real world, from (e.g.): > for string_piece in lots_of_pieces: > bigstring += string_piece > (a typical performance-trap) to > for item in somelist: > if isbad(item): > somelist.remove(item) > (with issues of BOTH correctness and performance), to Those two are easy. However, and this is where I show my hard-won ignorance, and admit that I don't see the problem with the property examples: > class Sic: > def getFoo(self): ... > def setFoo(self): ... > foo = property(getFoo, setFoo) > to > class Base(object) > def getFoo(self): ... > def setFoo(self): ... > foo = property(getFoo, setFoo) > > class Derived(Base): > def getFoo(self): .... Unless the answer is "Why are you using setters and getters anyway? This isn't Java you know." Oh wait! Yes I do... the setter doesn't actually take an argument to set the property too. Is that it, or have a missed a cunningly hidden deeper problem? -- Steven. From spamtrap at library.lspace.org.invalid Fri Oct 28 07:38:34 2005 From: spamtrap at library.lspace.org.invalid (Shmuel (Seymour J.) Metz) Date: Fri, 28 Oct 2005 08:38:34 -0300 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: <43621bca$19$fuzhry+tra$mr2ice@news.patriot.net> In , on 10/25/2005 at 09:56 AM, joe at invalid.address said: >Yes, I know, they can do whatever they want, it's not a crime, Actually, it is a crime and they've been convicted. -- Shmuel (Seymour J.) Metz, SysProg and JOAT Unsolicited bulk E-mail subject to legal action. I reserve the right to publicly post or ridicule any abusive E-mail. Reply to domain Patriot dot net user shmuel+news to contact me. Do not reply to spamtrap at library.lspace.org From roy at panix.com Wed Oct 12 13:26:58 2005 From: roy at panix.com (Roy Smith) Date: Wed, 12 Oct 2005 17:26:58 +0000 (UTC) Subject: [Info] PEP 308 accepted - new conditional expressions References: <3q4ro9Fd770nU3@individual.net> <87irw3l0qb.fsf@bigfoot.com> Message-ID: Chris Smith wrote: >What I really want to do is take four lines of conditional, and put >them into one, as well as blow off dealing with a 'filler' variable: > >return "the answer is " + "yes" if X==0 else "no" I would write this as: return "the answer is " + ("yes" if X==0 else "no") Adding the parens makes it clearer. I've long since given up trying to remember operator precedence (except for the most basic like multiplication is stronger than addition) and use parens with wild abandon. From steve at REMOVETHIScyber.com.au Tue Oct 25 13:14:55 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Wed, 26 Oct 2005 03:14:55 +1000 Subject: Newbie question: string replace References: <1130258229.662596.228630@g49g2000cwa.googlegroups.com> Message-ID: On Tue, 25 Oct 2005 09:37:09 -0700, usgog at yahoo.com wrote: > I have a config file with the following contents: > service A = { > params { > dir = "c:\test", > username = "test", > password = "test" > } > } > > I want to find username and replace the value with another value. I > don't know what the username value in advance though. How to do it in > python? Your config file looks like a cut-down mutated version of XML. Maybe you should use real XML and the tools for working with it? Or perhaps you should use module ConfigParser? Despite the temptation to reinvent the wheel, it is rarely a good idea. If you have already read the config file into a nested dictionary, then all you need to do is: py> service_A = ReadConfigFile() # you must write this function py> print service_A["params"] {'dir': 'c:\test', 'username': 'test', 'password': 'test'} py> service_A['params']['username'] = 'J. Random User' py> WriteConfigFile(service_A) Or if you insist on treating the config file as a string, try something like this: py> s = open('filename', 'r').read() py> print s service A = { params { dir = "c:\test", username = "test", password = "test" } } py> target = 'username = ' py> p1 = s.find(target) + len(target) py> p2 = s.find(',\n', p1) py> s = s[:p1] '"J. Random User"' + s[p2:] That's not good enough for professional code, but it will get you started. -- Steven. From gene.tani at gmail.com Sun Oct 23 22:12:44 2005 From: gene.tani at gmail.com (gene tani) Date: 23 Oct 2005 19:12:44 -0700 Subject: High Order Messages in Python In-Reply-To: <1130118446.643842.178950@g47g2000cwa.googlegroups.com> References: <1130015536.273136.295800@g43g2000cwa.googlegroups.com> <435bb315$0$15040$ed2619ec@ptn-nntp-reader02.plus.net> <1130118446.643842.178950@g47g2000cwa.googlegroups.com> Message-ID: <1130119964.781740.165780@z14g2000cwz.googlegroups.com> http://www.artima.com/intv/closures.html http://www.rubyist.net/~matz/slides/oscon2005/index.html It's a read-write closure, a co-routine, sort of a continuation (tho Kernel.callcc is considered the real continuation mechanism). And you can make it a Proc object (basically an unbound object you can pass to methods) with Proc#new or lambda. HTH vdrab wrote: > On a (somewhat) related note, > I've always wondered whether it is possible to emulate ruby blocks > using a python generator '+ alpha'. In my limited understanding of the > ruby block, the generator can inject values into a block, I suppose, > but what is the block itself? can it be a function? a class instance? > what would it look like? I am sure someone must have played around with > this. > any pointers? > cheers, > v. From michele.simionato at gmail.com Fri Oct 7 10:00:51 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 7 Oct 2005 07:00:51 -0700 Subject: Can't extend function type In-Reply-To: <7xoe61g4p7.fsf_-_@ruckus.brouhaha.com> References: <7xoe61g4p7.fsf_-_@ruckus.brouhaha.com> Message-ID: <1128693651.822764.321010@g44g2000cwa.googlegroups.com> If you google a bit on the newsgroup, you should find a message from me asking about the ability to subclass FunctionType, and a reply from Tim Peters saying that the only reason why this was not done is lack of developer time and the fact that this was not considered an important priority. Michele Simionato From jbellis at gmail.com Fri Oct 21 18:44:03 2005 From: jbellis at gmail.com (Jonathan Ellis) Date: 21 Oct 2005 15:44:03 -0700 Subject: C replacement for Queue module Message-ID: <1129934643.874242.37150@g47g2000cwa.googlegroups.com> I'm working on an application that makes heavy use of Queue objects in a multithreaded environment. By "heavy" I mean "millions of calls to put and get, constituting ~20% of the app's run time." The profiler thinks that a significant amount of time is spent in this code -- not just a consumer waiting for a producer, but actual _empty, notify calls, etc. Would it be worth the time to write a CQueue module with pthread_cond instead of Python Condition objects, etc? I don't really have a gut feeling for how much bang-for-the-loc C optimization might give: twice as fast? 5x as fast? thanks, -Jonathan From http Thu Oct 13 12:54:44 2005 From: http (Paul Rubin) Date: 13 Oct 2005 09:54:44 -0700 Subject: Let My Terminal Go References: <1129010288.251817.147690@z14g2000cwz.googlegroups.com> <1129012665.29863.2.camel@blackwidow> <1129026623.319531.97420@g43g2000cwa.googlegroups.com> Message-ID: <7x4q7lmk6j.fsf@ruckus.brouhaha.com> Jorgen Grahn writes: > It depends on what you mean by expensive -- web servers can fork for each > HTTP request they get, in real-world scenarios, and get away with it. This is OS dependent. Forking on Windows is much more expensive than forking on Linux. From mwm at mired.org Sat Oct 8 19:56:50 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 08 Oct 2005 19:56: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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> Message-ID: <86psqfmukd.fsf@bhuda.mired.org> Roedy Green writes: > This is one of the marvels of CSS once you get the hang of it. If you > don't like bright red letters on green backgrounds, you can CHANGE > that. You can change the fonts, sizes etc etc. You can if you want get > something very like plain ASCII text. Show us *examples*! Do you create a style sheet for every site you visit that overrides there classes? What? > So from an aesthetic point of view, once people learn how it works, > CSS lets sender and receiver compromise on what the message looks > like. No other medium gives ANY control to the receiver about how a > message is formatted. Sorry, but that's bullshit. The receiver controls the viewer software, and hence ultimately has complete control over *everything*. If I use ghostscript as the viewer for ps and pdf files, I can install font map files to replace all the standardd sans serif fonts with serifed fonts, and so on. Some viewer applications may require editing the magic .c, .cpp, etc. configuration files, but that's possible so long as you're sending something other than pictures of words. > There is also the philosophical question. When my nephew sends me a > message, do I have a right to warp his intent even if I don't like the > aesthetics? That is part of his message. If HTML is a medium, only someone really ignorant of the medium will think that their presentation is preserved. As has been pointed out, moving the file from Windows to other platforms changes the font sizes. The physical monitor size, the screen size, the readers window size, the dpi on the monitor, even the color depth on low-end devices all change the presentation. The fonts you use may not be installed on the recipients platform - I particularly like the idea that if you use a font installed by some application, the only person who'll see it the way you intended is the guy who bought the other copy of that application. So what you're really asking is if you have the right to read his message on anything but his favorite rendering agent configured the way he likees it, on his favorite computer configured the way he likes it. > Should my email reader fix the spelling mistakes in the emails sent me > by angry US soldiers? Or is that part of the message? I say let Harlan Ellison decide. > There are three different issues getting muddled together: > > 1. avoiding spam I think what you mean here is "avoiding malware". Spam should be dealt with before it gets to your mail reader. > 2. making mail from well meaning but inept friends more readable. > > 3. what constitutes a good general style for general correspondence. > How should you use rich text appropriately. Well, if you want your presentation preserved, you don't send rich text, you send pictures of words. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From richard at zync.co.uk Sun Oct 16 12:47:50 2005 From: richard at zync.co.uk (Richard Gration) Date: Sun, 16 Oct 2005 16:47:50 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: On Sun, 16 Oct 2005 11:51:16 +0000, Tim Tyler wrote: > Acorn computers. Manufacturers of the best computer I ever owned. I'm willing to bet that was an Arc ... ? I never used one but everyone I've ever talked to who used one said it was fantastic. Myself I was pretty impressed with the BBC B ... From tzot at sil-tec.gr Tue Oct 4 04:27:07 2005 From: tzot at sil-tec.gr (Christos Georgiou) Date: Tue, 04 Oct 2005 11:27:07 +0300 Subject: Spoiler to Python Challenge (help!!!) References: Message-ID: On Tue, 27 Sep 2005 10:42:20 -0500, rumours say that Terry Hancock might have written: >This works: > >>>> bz2.decompress(eval(repr(user))) >'huge' >This may have some security issues, though, since it evaluates essentially >any expression given for user. I'd be interested to know if someone >knows a more secure way. given a = "a tab\\x09between" this is more secure than eval: b= a.decode("string_escape") -- TZOTZIOY, I speak England very best. "Dear Paul, please stop spamming us." The Corinthians From steve at aol.com Sat Oct 15 18:42:31 2005 From: steve at aol.com (steve) Date: Sun, 16 Oct 2005 06:42:31 +0800 Subject: Microsoft Hatred FAQ (TROLL DONT REPLY) References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> Message-ID: TROLLLLLLLLLLLLLL From tdickenson at devmail.geminidataloggers.co.uk Thu Oct 27 06:32:32 2005 From: tdickenson at devmail.geminidataloggers.co.uk (Toby Dickenson) Date: Thu, 27 Oct 2005 11:32:32 +0100 Subject: Sorting with only a partial order definition In-Reply-To: References: Message-ID: <200510271132.32831.tdickenson@devmail.geminidataloggers.co.uk> On Thursday 27 October 2005 11:08, Lasse V?gs?ther Karlsen wrote: > What I was wondering about is if there is an algorithm that would do > what I want? Ie. help me pick the nodes so as to minimize the number of > edges. To rephrase your question, you want a sorting algorithm that minimises the number of comparisons (because a comparison involves asking a human), and which takes advantage of any pre-existing rough ordering. You need timsort - the algorithm behind python lists sort() method. -- Toby Dickenson From bonono at gmail.com Fri Oct 21 13:27:58 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 21 Oct 2005 10:27:58 -0700 Subject: Binding a variable? In-Reply-To: References: Message-ID: <1129915678.580934.275290@g44g2000cwa.googlegroups.com> I think not. temp is a name, not a variable. I believe temp=5 means it points to an immutable object 5. temp=6 means now it points to another immutable object 6. list=[temp] would resolve to whatever object temp is pointed to at that moment. You can try temp=[1]. Paul Dale wrote: > Hi everyone, > > Is it possible to bind a list member or variable to a variable such that > > temp = 5 > > list = [ temp ] > > temp == 6 > > list > > would show > > list = [ 6 ] > > Thanks in advance? > > Paul From http Tue Oct 11 17:42:51 2005 From: http (Paul Rubin) Date: 11 Oct 2005 14:42:51 -0700 Subject: Python's garbage collection was Re: Python reliability References: <7xr7au1hr5.fsf@ruckus.brouhaha.com> <7xwtkl21hn.fsf@ruckus.brouhaha.com> <7xll11twc2.fsf@ruckus.brouhaha.com> <1h4a5l4.13vx8k7etyxy1N%aleax@mail.comcast.net> Message-ID: <7xu0fn6884.fsf@ruckus.brouhaha.com> aleax at mail.comcast.net (Alex Martelli) writes: > > Has anyone looked into using a real GC for python? ... > > lot more complexity in the interpreter itself, but it would be faster, > > more reliable, and would reduce the complexity of extensions. > > ??? It adds no complexity (it's already there), it's slower, it is, if > anything, LESS reliable than reference counting (which is way simpler!), > and (if generalized to deal with ALL garbage) it might make it almost > impossible to write some kinds of extensions (ones which need to > interface existing C libraries that don't cooperate with whatever GC > collection you choose). Are we talking about the same thing?! I've done it both ways and it seems to me that a simple mark/sweep gc does require a lump of complexity in one place, but Python has that anyway to deal with cyclic garbage. Once the gc module is there, then extensions really do seem to be simpler to right. Having extensions know about the gc is no harder than having them maintain reference counts, in fact it's easier, they have to register new objects with the gc (by pushing onto a stack) but can remove them all in one go. Take a look at how Emacs Lisp does it. Extensions are easy to write. From secun at yahoo.com Fri Oct 21 17:13:38 2005 From: secun at yahoo.com (Chris) Date: Fri, 21 Oct 2005 17:13:38 -0400 Subject: HELP! py2exe error - No module named decimal References: <43590E20.5020908@websafe.com> Message-ID: That was it. Thank you so much! Chris In article <43590E20.5020908 at websafe.com>, larry.bates at websafe.com says... > FYI there is a separate newsgroup for py2exe at > gmane.comp.python.py2exe. You may want to post > there also. > > Just as a suggestion, put an import decimal at > the top of your program. It looks like _mssql > might be doing dynamic imports in __load method > which will "confuse" py2exe because it can't > know about dynamic imports which happen at > runtime. > > -Larry Bates > > Chris wrote: > > I've just completed a project using the following (Windows XP, python > > 2.4.1, wxpython 2.6, and pymssql 0.7.3). The program runs great, but > > after I convert it to an exe (required for this project), it gives me > > the following error when I try to run it. > > > > Traceback (most recent call last): > > File "EstUpdate.py", line 6, in ? > > File "frmSplash.pyc", line 9, in ? > > File "pymssql.pyc", line 23, in ? > > File "_mssql.pyc", line 9, in ? > > File "_mssql.pyc", line 7, in __load > > ImportError: No module named decimal > > > > However, when I look in c:\python24\lib on the machine which ran py2exe, > > I see decimal.py and decimal.pyc. > > > > Can someone please help with this? I'm supposed to start testing the > > program today and I can't seem to move past this first step. > > > > Thanks!! > > Chris > From cedmunds at spamless.rochester.rr.com Sun Oct 16 14:44:18 2005 From: cedmunds at spamless.rochester.rr.com (Cy Edmunds) Date: Sun, 16 Oct 2005 18:44:18 GMT Subject: Problem with Win32all Message-ID: <6cx4f.48710$Xl2.9739@twister.nyroc.rr.com> I am running Python 2.4 on Windows XP. My Win32all was working fine until recently. Now whenever I run the UI, no other application will start! I did all the obvious things like uninstall and reinstall win32all, reboot, etc. Any ideas? -- Cy http://home.rochester.rr.com/cyhome/ From mde at micah.elliott.name Wed Oct 26 11:47:24 2005 From: mde at micah.elliott.name (Micah Elliott) Date: Wed, 26 Oct 2005 08:47:24 -0700 Subject: suggestions between these two books In-Reply-To: References: Message-ID: <20051026154724.GA2575@kitchen.client.attbi.com> On Oct 26, John Salerno wrote: > Hi all. I'm fairly new to programming and I thought I'd like to try > Python. I'm trying to decide between these two books: > > Learning Python (O'Reilly) > Beginning Python: From Novice to Professional (APress) Consider first reading the tutorial. If you prefer to read from paper there is a PDF version . There is also the "Python in a Nutshell" book which only covers Python 2.2 but has a very concise language intro, and will become an invaluable reference. I wish I had started with this book; then I wouldn't have needed to buy some of the others. -- _ _ ___ |V|icah |- lliott http://micah.elliott.name mde at micah.elliott.name " " """ From my_email_is_posted_on_my_website at munged.invalid Sun Oct 23 19:16:24 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sun, 23 Oct 2005 23:16:24 GMT Subject: Microsoft Hatred FAQ References: <11l16dst501kjdd@corp.supernews.com> <11l48meji6u4e69@corp.supernews.com> <2X95f.14513$vV4.3483@fe08.lga> <435ad152$17$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: On Sat, 22 Oct 2005 19:54:58 -0300, "Shmuel (Seymour J.) Metz" wrote or quoted : >As well as blame. The commercialization of the Internet was grossly >mismanaged. Take the InterNIC - please! As global bureaucracies go, I think they have done a good job. Can you imagine herding the cats of egotistical dictators and politicians from every country on earth who have not a clue about what the function of domain are? -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From scooterm at hotmail.com Thu Oct 27 20:43:42 2005 From: scooterm at hotmail.com (scooterm at hotmail.com) Date: 27 Oct 2005 17:43:42 -0700 Subject: specify arbitrary library directory directly in code? Message-ID: <1130460222.700509.195130@g47g2000cwa.googlegroups.com> ### Background In [other programming language] it is possible to specify any special and arbitrary directory (or set of directories) to use as a source for custom, user-designed modules. For example, one can do: ### begin script ### (located in ../faa/faa_script.xyz) ### init script use lib "../foo"; use FooLibModule; use lib "../fee"; use FeeLibModule; ### run script print FooLibModule::SayHelloWorld(); print FeeLibModule::SayHelloWorld(); ### Initial Findings After searching around a bit, it appears that python does not have a built-in mechanism for specifying arbitrary directories as the first place to look for module code. There are options that allow one to specify alternate directories, but all these options require changes to environment variables, or changes (or additions) to the files in the standard package directories. But if you define 'built-in mechanism' meaning a change that only requires modifying the code in 'faa_script.py' ... then there is no 'built-in mechanism'. ### Question Are the initial findings correct? If not, can you specify the code (or the link to the documentation) that specifies how to do what I am trying to do? If the initial findings are correct, are there any alternative workarounds to allow faa_script.py to automatically discover module code in specific sibling directories? ### Constraints Assume changing or adding environment variables is not an option. Assume adding files to the standard python module directories is not an option. Assume the only option is to change the code in faa_script.py From exarkun at divmod.com Sat Oct 22 18:37:19 2005 From: exarkun at divmod.com (Jp Calderone) Date: Sat, 22 Oct 2005 18:37:19 -0400 Subject: High Order Messages in Python In-Reply-To: <1130019099.772664.103360@g47g2000cwa.googlegroups.com> Message-ID: <20051022223719.27584.958044380.divmod.quotient.2814@ohm> On 22 Oct 2005 15:11:39 -0700, "eduardo.padoan at gmail.com" wrote: >Hum... I thnk you dont get the ideia: I'm not talking abou High Order >Functions. >What ho call "High Order Methods is some like "connecting" some >'generic' methods created to do things like this: > claimants.where.retired?.do.receive_benefit 50 >The 2nd and 3rd links that in the first post is the most relevant to >undestand the concept. Read this too: >http://www.metaobject.com/papers/Higher_Order_Messaging_OOPSLA_2005.pdf These are just more involved applications of the same idea. They're easily implemented in Python, using primitives such as HOF, if one desires. However, I don't see why one would want to write the above mish-mash, rather than: for cl in claimaints: if cl.retired(): cl.receive_benefit(50) Or: [cl.receive_benefit(50) for cl in claimaints if cl.retired()) Or: map( ClaimaintType.receive_benefit, filter( ClaimaintType.retired, claimaints), itertools.repeat(50)) Or: claimaintGroup.disburse() Jp From my_email_is_posted_on_my_website at munged.invalid Sun Oct 9 03:40:55 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sun, 09 Oct 2005 07:40:55 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> Message-ID: On Sat, 08 Oct 2005 23:35:40 GMT, Rich Teer wrote or quoted : >If people want me to read their email, they should send it to me >in an open, universal format, which for email is plain text. It's >as simple as that. This is pulling a King Canute. There is not even a mechanism in email protocols to warn your correspondents of your demand. I have been bugging Eudora for years for at least a bit in the address book to record the recipient's preference for plain or formatted emails. They have so far ignored me. There is nothing wrong with formatted text. You are confusing formatted text with spam. You think you hated formatted text, but you really hate spam. If your lover sent you a message with photo, and even musical accompaniment, I doubt you would feel offended. It is the CONTENT bugging you, not the HTML. You imagine that the two are inexplicably linked. That is just because the technology is immature. There is no fundamental reason that formatted spam should have an easier time penetrating your defenses than plain text spam. I am using Spamnix. It think it leaks about 50/50 formatted and plain text spam. Eudora warns you of deceptive links in HTML. There are many more such things that have yet to be done to deal with malicious emails. I think we should focus on those rather than reverting to the days of the TTY.I don't think it would buy you much. Formatted emails can't hurt you if you don't allow them to automatically run any code. It is unfair to blame formatting for the foolish practice off allowing untrusted code to run without even an ok. They have nothing to do with each other. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From davids at webmaster.com Wed Oct 26 14:38:43 2005 From: davids at webmaster.com (David Schwartz) Date: Wed, 26 Oct 2005 11:38:43 -0700 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> <3s8t89FmdnriU1@individual.net> Message-ID: "Eike Preuss" wrote in message news:3s8t89FmdnriU1 at individual.net... >> Right, except that's utterly absurd. If every vendor takes their tiny >> cut of the 95%, a huge cut of the 5% is starting to look *REALLY* good. > Sure, that would be true if the market would be / would have been really > global. In practice if you have a shop you have a limited 'region of > influence'. Optimally you are the only shop in this region that sells > the stuff, or perhaps there are a few shops that compete with you. Lets > say in your region are two shops competing with you, and you must decide > wether to sell product A (95%) or B (5%), but you may not sell both. > Decision 1: Sell A, share the 95% of the local market with two -> about > 32% of the local market for all of you, if all perform equally good > Decision 2: Sell B -> you get the 5% of the market, the others 47% each > > This calculation is probably still a very bad approximation of the > truth, but things are definitely not as easy as you state them. It depends upon how different the products are and how easy it is to shop out of your local market. If the products are equally good and reasonably interchangeable and it's hard to shop out of your local market, then you're right. The more the smaller product is better than the larger product, the less interchangeable they are, and the easier it is to shop out of your local market, the more wrong you are. How often do you hear, "I'd like to use Linux, but I just can't get ahold of it"? And how many people do you hear saying, "I'd like to use Linux, but I'm not willing to shell out the bucks to buy it since I already bought Windows with my computer". On the other hand, where you might be right is in the possibility that Microsoft's lock on the market prevented other companies from making operating systems at all. That is, that had Microsoft used different policies, other companies would have introduced operating systems to compete with Microsoft, and we'd all have better operating systems for it. If Microsoft's conduct was legal, this argument establishes that the conduct was necessary. DS From deets at nospam.web.de Thu Oct 20 15:09:58 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 20 Oct 2005 21:09:58 +0200 Subject: A macro editor In-Reply-To: References: Message-ID: <3rq8c5Fl3m4bU1@uni-berlin.de> > My teammates and I were talking about to use one of Python, Ruby or > Groovy. But, we haven't decided which to use. > > What seems to be easier is to use Python, you know.. because of the > Jython thing. But, it is probably a mistake to take Jython without a > extensive analysis of the all possibilities. There seems to exist a Ruby java port, conveniently called jruby. Additionally, you might consider beanshell. > > From my point of view, the best choice will be those that allow the > average user getting results as fast as possible rather than the power > of the language itself. At the end, what we will write is a gateway to > access to our application's Java API through the scripts written by our > users. > > In this sense, I'd like to ask if someone knows if any of these > languages have a Java implementation that supports code auto-complete > and class navigation or any kind of functionality that would ease and > speed up the user's learning curve and productivity. > > In other words, is it possible to have a small and lightly intelligent > workbench window (a mini-Eclipse for example) for our future "macro > editor" within our application? I doubt that will be possible. A language that has no type-declarations - that is true for ruby & python (regardless of their respective VM implementations) - can't possibly deliver that feature. And it looks as if the same is true for groovy. The only thing I can imagine is that you try and recognize the "gateways" to your API-model and provide calltips for names that are bound to values from that model. E.g. if you have a module called "core" that contains an application-object that represents your application, you could try and identify code like this: app = core.applikation app. However, if the user does fancy tricks like this: setattr(self, "app", core.application) self.app. So - _I_ think the better user-experience comes froma well-working easy to use REPL to quickly give the scripts a try. Regards, Diez From timothy at open-networks.net Fri Oct 7 00:57:16 2005 From: timothy at open-networks.net (Timothy Smith) Date: Fri, 07 Oct 2005 14:57:16 +1000 Subject: non descriptive error Message-ID: <4346002C.3080504@open-networks.net> i try to run my app and i get this %python DutyShift.py error thats it. thats the error. mya pp was previously working, and i did make some fairly large changes to it, but i'd expect a more descriptive message then just "error". anyidea where i need to start looking? From martin.witte at gmail.com Tue Oct 11 16:43:08 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 11 Oct 2005 13:43:08 -0700 Subject: datetime and daylight savings problem In-Reply-To: References: Message-ID: <1129063388.896602.260160@g14g2000cwa.googlegroups.com> When working with timezones datetime objects are represented in the tzinfo object you supply, eg. when you define these classes (and run them on a system set to Paris time): from datetime import tzinfo, timedelta, datetime import time class UTC(tzinfo): """UTC timezone""" def utcoffset(self, dt): return timedelta(0) def tzname(self, dt): return "UTC" def dst(self, dt): return timedelta(0) class CET(tzinfo): """CET timezone""" def utcoffset(self, dt): return timedelta(seconds = -time.timezone) def dst(self, dt): return timedelta(0) def tzname(self, dt): return "CET" class CEST(tzinfo): """CET timezone with DST""" def utcoffset(self, dt): return timedelta(seconds = -time.altzone) def dst(self, dt): return timedelta(seconds = -time.altzone) - \ timedelta(seconds = -time.timezone) def tzname(self, dt): return "CEST" And you create these objects: utc = UTC() cet = CET() cest = CEST() d = datetime(2005,06,01,16,59,tzinfo=utc) This statement print 'UTC %s' % d Will print: UTC 2005-06-01 16:59:00+00:00 And this one: print 'As CET %s' % d.astimezone(cet) Will print: As CET 2005-06-01 17:59:00+01:00 And this one: print 'As CET with DST %s' % d.astimezone(cest) Will print: As CET with DST 2005-06-01 18:59:00+02:00 Additional: This: d = datetime(2005,06,01,16,59,tzinfo=cet) print cet, d Will print: <__main__.CET object at 0xb7d3aaac> 2005-06-01 16:59:00+01:00 And this: d = datetime(2005,06,01,16,59,tzinfo=cest) print cest, d Will print: <__main__.CEST object at 0xb7d3aaec> 2005-06-01 16:59:00+02:00 So at least with these tzinfo objects everything is as expected, I'm not sure where your actual problem is, is it in the pytz module (with which I do not have experience)? From robin at SPAMREMOVEjessikat.fsnet.co.uk Sat Oct 22 04:44:28 2005 From: robin at SPAMREMOVEjessikat.fsnet.co.uk (Robin Becker) Date: Sat, 22 Oct 2005 08:44:28 +0000 Subject: override a property In-Reply-To: <1h4s9ug.k3op7dg6c66hN%aleaxit@yahoo.com> References: <43542065$0$21621$636a15ce@news.free.fr> <4354ABB3.1030203@jessikat.fsnet.co.uk> <4354b324$0$21023$636a55ce@news.free.fr> <1h4s9ug.k3op7dg6c66hN%aleaxit@yahoo.com> Message-ID: <4359FBEC.3040902@jessikat.fsnet.co.uk> Alex Martelli wrote: ...... > If (e.g.) __set__ needs to behave differently when applied to certain > instances rather than others, then it had better be "messed with" > (overridden) compared to property.__set__ since the latter has no such > proviso. Of course, your architecture as sketched below (taking > advantage of the fact that property.__set__ always calls a certain > callable, and you get to control that callable) is OK too. ..... I think I at last got this ...... > > Why not just fset=self.__notify_fset ? I fail to see the added value of > this lambda. Anyway...: duh just being Homerish >> def __notify_fset(self,inst,value): >> value = self._validator(value) ....... >> def add(self,obs): >> self._observers.append(obs) > > > ...this class only offers sets of observers *per-descriptor instance*, > not ones connected to a specific 'inst' being observed. My point is, > you could add the latter pretty easily. ...... ........ > You can, if you have a way to call, say, b.x.add_per_inst(b, obs1). > Such as, adding within ObserverProperty: > > self._observers_per_inst = {} > > in the init, and changing the notification method to do: > > def __notify_fset(self,inst,value): > value = self._validator(value) > observers = self._observers_per_inst.get(inst) > if not observers: observers = self._observers > for obs in observers: > obs(inst,self._pName,value) > inst.__dict__[self._pName] = value > > and a new method add_per_inst: > > def add_per_inst(self, inst, obs): > self._observers_per_inst.setdefault(inst,[]).append(obs) > > Of course, you most likely want to use weak rather than normal > references here (probably to both instances and observers), but that's a > separate issue. ...... yes I begin at last to see the full complexity of this. There are really three possible attachments, the descriptor, instance class and the instance. Since the descriptor is attached to the class or a base class one could argue about whether observers should be inherited etc etc, but perhaps that's a step too far. Thanks to Alex and Bengt and others for clarifying a bunch of issues. -- Robin Becker From bronger at physik.rwth-aachen.de Sun Oct 23 07:54:12 2005 From: bronger at physik.rwth-aachen.de (Torsten Bronger) Date: Sun, 23 Oct 2005 13:54:12 +0200 Subject: Problem with subprocess.call and cp Message-ID: <87wtk430uz.fsf@wilson.rwth-aachen.de> Hall?chen! The following code from subprocess import call call(['cp', 'subdir/*.jpg', 'othersubdir/']) yields cp: call of stat for "subdir/*.jpg" not possible: File or directory not found (This may not be the real error message since it's back-translated from German.) I could use shell=True, however, what's going wrong here? Tsch?, Torsten. -- Torsten Bronger, aquisgrana, europa vetus ICQ 264-296-646 From sjdevnull at yahoo.com Fri Oct 21 14:23:28 2005 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: 21 Oct 2005 11:23:28 -0700 Subject: Execute C code through Python In-Reply-To: <11li3b2hsa3lhb5@corp.supernews.com> References: <1129844737.586396.61080@g47g2000cwa.googlegroups.com> <1129861083.010702.6770@g49g2000cwa.googlegroups.com> <1129906892.696582.288010@g43g2000cwa.googlegroups.com> <11li3b2hsa3lhb5@corp.supernews.com> Message-ID: <1129919008.772705.101920@g43g2000cwa.googlegroups.com> Grant Edwards wrote: > On 2005-10-21, Ernesto wrote: > > > Thanks. Can anyone provide an example of using *subprocess* to run > > helloWorld.C through the python interpreter. > > No. You can't run a .C file Unless you have a C interpreter installed. e.g.: import os os.system("eic helloWorld.C") (Requires eic to be in your PATH.) I doubt it's what the OP was looking for, though. http://eic.sourceforge.net/ From kent37 at tds.net Sat Oct 22 22:08:31 2005 From: kent37 at tds.net (Kent Johnson) Date: Sat, 22 Oct 2005 22:08:31 -0400 Subject: Question about inheritance... In-Reply-To: <1130030731.105360.92200@o13g2000cwo.googlegroups.com> References: <1130017209.078943.119990@g43g2000cwa.googlegroups.com> <_My6f.1423$Zd.1063@tornado.tampabay.rr.com> <1130030731.105360.92200@o13g2000cwo.googlegroups.com> Message-ID: <435aee91$1_3@newspeer2.tds.net> KraftDiner wrote: > This is what I've got so far: > class Rect(Shape): > def __init__(self): > super(self.__class__, self).__init__() Should be super(Rect, self).__init__() > def render(self): > super(self.__class__, self).render() ditto In this example it doesn't make any difference but with a deeper inheritance hierachy it does. See http://www.python.org/2.2.3/descrintro.html#cooperation Kent From kent37 at tds.net Sat Oct 1 08:13:52 2005 From: kent37 at tds.net (Kent Johnson) Date: Sat, 01 Oct 2005 08:13:52 -0400 Subject: Not defined In-Reply-To: References: Message-ID: <433e7bdf$1_1@newspeer2.tds.net> Rob wrote: > When trying the basic tutorial for cgkit I always seem to get a not defined > error as follows. > > Pythonwin GUI > > >>>>from cgkit import * >>>>Sphere() > > Traceback (most recent call last): > File "", line 1, in ? > NameError: name 'Sphere' is not defined Which version of cgkit are you using? Kent From jstroud at mbi.ucla.edu Fri Oct 28 17:42:51 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Fri, 28 Oct 2005 14:42:51 -0700 Subject: newstyle classes and __getattribute__ In-Reply-To: <4362977f$0$7227$9b622d9e@news.freenet.de> References: <4362977f$0$7227$9b622d9e@news.freenet.de> Message-ID: <200510281442.51297.jstroud@mbi.ucla.edu> On Friday 28 October 2005 14:26, Stefan Sonnenberg-Carstens wrote: > Hi there, [..clip..] > Now, I do this: > > class T(object): > def __init__(self,name='',port=80): > self.name=name > self.port=port > def __getattribute__(self,key): > if key=='somekey': > return None [..snip..] > But, then surprise: > >>> t = T(name="test123",port=443) > >>> dir(t) > > [] > > What the hell is going wrong here ? __getattribute__ is returning None in all cases and dir() is converting None to []. Anyway, you should have done this: py> class T(object): ... def __init__(self,name='',port=80): ... self.name=name ... def __getattribute__(self,key): ... if key=='somekey': ... return None ... else: ... return object.__getattribute__(self, key) ... py> t = T(name="test123",port=443) py> dir(t) ['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', 'name'] James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From greg.steffensen at gmail.com Thu Oct 20 22:18:03 2005 From: greg.steffensen at gmail.com (gsteff) Date: 20 Oct 2005 19:18:03 -0700 Subject: Execute C code through Python In-Reply-To: <1129844737.586396.61080@g47g2000cwa.googlegroups.com> References: <1129844737.586396.61080@g47g2000cwa.googlegroups.com> Message-ID: <1129861083.010702.6770@g49g2000cwa.googlegroups.com> import subprocess subprocess.call("cmd") From duncan.booth at invalid.invalid Thu Oct 6 04:40:21 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 6 Oct 2005 08:40:21 GMT Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> <434245F5.6060500@REMOVEMEcyber.com.au> <7xr7b14lk0.fsf@ruckus.brouhaha.com> <7xu0fx9l7y.fsf@ruckus.brouhaha.com> Message-ID: Antoon Pardon wrote: >> from xml.dom import * >> >> def do_add(x, y): >> return '%s://%s' % (x, y) >> >> def do_something(node): >> if node.namespace == XML_NAMESPACE: >> return do_add('http://', node.namespace) >> elif node.namespace == ... >> ... >> > > IMO your variable are already mostly declared. The x and y in > the do_add is kind of a declarartion for the parameters x and > y. I think you missed his point, though I'm not surprised since unless you are familiar with the internals of the xml package it isn't obvious just how complex this situation is. The value XML_NAMESPACE was imported from xml.dom, but the xml package is kind of weird. XML_NAMESPACE defined both in xml.dom and in the _xmlplus.dom package. The _xmlplus package is conditionally imported by the xml package, and completely replaces it, but only if _xmlplus is present and at least version 0.8.4 (older versions are ignored). This is precisely the kind of flexibility which gives Python a lot of its power, but it means that you cannot tell without running the code which package actually provides xml.dom. Of course, I would expect that if you enforced strict variable declarations you would also disallow 'from x import *', but you still cannot tell until runtime whether an particular module will supply a particular variable, not what type it is. From mscottschilling at hotmail.com Mon Oct 17 00:35:50 2005 From: mscottschilling at hotmail.com (Mike Schilling) Date: Mon, 17 Oct 2005 04:35:50 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: "John Bokma" wrote in message news:Xns96F1E4E128EA8castleamber at 130.133.1.4... > "Mike Schilling" wrote: > >> "John Bokma" wrote in message > >>> No, it's a recommendation, an advise, nothing else. Otherwise they >>> would call it a standard. Why do you think W3C calls it >>> recommendations? Because it are no standards. There is an ISO HTML >>> standard though, but when people babble about HTML standards they >>> talk about W3C *recommendations*. >> >> In that sense there are no standards in software. The ISO C++ >> "standard" and the XML "recommendation" have the same amount of force >> behind them. > > Yup, but ISO C++ is a standard, and XML is a recommendation. And the practical difference between the two is.... That's right, nil. From qwweeeit at yahoo.it Mon Oct 31 03:52:19 2005 From: qwweeeit at yahoo.it (qwweeeit at yahoo.it) Date: 31 Oct 2005 00:52:19 -0800 Subject: Expanding Python as a macro language In-Reply-To: <1130631958.683127.215300@g14g2000cwa.googlegroups.com> References: <1130545600.925061.287390@g49g2000cwa.googlegroups.com> <1130631958.683127.215300@g14g2000cwa.googlegroups.com> Message-ID: <1130748738.972157.177070@o13g2000cwo.googlegroups.com> I am further commenting on new replies. Mike Meyer wrote: > In general, application scripting facilities are one thing that Unix > hasn't dealt with well. > ...so each application is left up to it's own devices. > Some of them now export APIs that can be hooked up to a variety of > languages. Now I understand why I have found so many difficulties!... An example of APIs is those available for better controlling Google search engine. Unfortunately all that leaves the need of specific programming for each case... I am obliged to learn C++ and Qt (in particular inter-process communication). About SPE, he is a little beside the point, but I insisted so much on web examples... Alex Martelli wrote: > "General purpose" is, I believe, an overbid here -- Perhaps you are right, but for me a macro language (like for ex. AutoIt) is very general, being only a mean of emulating the user, running automatically external applications. > applications are able to detect as being simulated, if they > want to implement very strong security. > If you want security, don't complain about the existence of security. Never complained... I was only favorably impressed by the sophistication reached for assuring stronger security. At last a new entry (has) completely off the point (FWIW > FICCL!...). Bye. From loris at caren.demon.co.uk Thu Oct 27 05:47:05 2005 From: loris at caren.demon.co.uk (Loris Caren) Date: Thu, 27 Oct 2005 10:47:05 +0100 Subject: assignment to reference References: <1130363816.457178.320790@f14g2000cwb.googlegroups.com> Message-ID: Thank you all for your replies. They have helped me understand that immutable means just that! Blame my c heritage where a pointer allows you to scribble over anything. From rossreyes at rcn.com Mon Oct 17 21:02:10 2005 From: rossreyes at rcn.com (Ross Reyes) Date: Mon, 17 Oct 2005 21:02:10 -0400 Subject: How do I pass args using Python Windows Message-ID: <001f01c5d37f$9233e8f0$a100a8c0@reyesr2> Hi - I wonder if someone might be able to lend a quick answer to this. I have a python script that I normally run from the command line on Solaris. i.e. %pythonscript > I decided to try IDLE on Windows to do some debugging with the debugger (which I unfortunately dont' have on Solaris 5.7 ) So my question is: How do I pass the command line args when using the Windows IDLE/Python environment? Thanks for any tips. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gandalf at designaproduct.biz Wed Oct 12 10:49:03 2005 From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy) Date: Wed, 12 Oct 2005 16:49:03 +0200 Subject: Very dumb question In-Reply-To: <434d1558$0$21685$626a54ce@news.free.fr> References: <434d1558$0$21685$626a54ce@news.free.fr> Message-ID: <434D225F.1070404@designaproduct.biz> > >I assume the code snippets are exact copy/paste so this is not a typo >(like print data[51:] ...) - and I can't reproduce it here... even with >a string of 20381 characters. > > Yes, they were cut out. type(data) returns ''. The data was downloaded from a website, it starts with Even if it had special control characters in it, I do not understand the effect (printing only the first 50 chars). But probably it is an issue with the terminal, since it is working fine on Windows. Les From xah at xahlee.org Sat Oct 1 10:23:57 2005 From: xah at xahlee.org (Xah Lee) Date: 1 Oct 2005 07:23:57 -0700 Subject: A Moronicity of Guido van Rossum In-Reply-To: <1128013745.763757.144280@g44g2000cwa.googlegroups.com> References: <1128003857.930444.47650@g14g2000cwa.googlegroups.com> <1128013745.763757.144280@g44g2000cwa.googlegroups.com> Message-ID: <1128176637.146092.314200@o13g2000cwo.googlegroups.com> the programers in the industry, including bigwigs such as Guido or that Larry Wall fuckhead, really don't know shit about computer languages. Sometimes i get pissed by Stephen Wolfram's megalomaniac cries, but in many ways, i think his statements about the fucking moronicities of the academicians and otherwise dignitaries are justified. here i will try to illuminate some miscellaneous things regarding the lambda in Python issue. as i have hinted ( http://xahlee.org/perl-python/list_comprehension.html ), the so-called List Comprehension is just a irregular syntax to facilitate generating lists. The name is a terrible jargon, and the means is also quite fucked up. The proper name should be something like ListGenerator, and the proper means should be the plain function. For instance, Python's range() is such a list generator, only that it is limited in scope. For a example of a powerful list generator, see Mathematica's Table function: http://documents.wolfram.com/mathematica/functions/Table i'm running a project that will code Table in Perl and Python and Java. You can read about the spec and source code here: http://xahlee.org/tree/Table.html (note: the Python version there isn't complete) Note Table's power in generating not just flat lists, but trees. And if one really want flat lists, there's the Flatten function that flats any nested lists. (Python should have this too) Python's reduce() is Mathematica's Fold. See http://documents.wolfram.com/mathematica/functions/Fold Besides Fold, there's FoldList, FixedPoint, FixedPointList, Nest, NestList and others. In Python's terms, FoldList is like reduce() except it returns a list of each steps. FixedPoint recursively applies a function to itself until the result no longer changes (or when a optional function returns true) Nest is similar except it limits the iteration by a number. The NestList and FixedPointList are similar except that they return a list, containing all the steps. All these can be written as a loop, but they make the code condensed and meaning clear. More so, they are important when programing in a functional style. In functional programing, you don't litter lots of variables or temporary functions or intermediate loops here or there on every other line. The code is usually tight and inline. When sequencing a series of functions, you can't stop in the middle and do some loop or auxiliary calculation. All these are made inline into a function. (that is: constructed as lambda) A block of code usually corresponds to a unit of the algorithm used, as opposed to the particular unit of the implementation of the algorithm. You don't read the minute details of the code. You read the algorithmic unit's comments, or just the input and output of a code block. Also, these inline loop constructs are not just for computing numbers as Guido likes to ignorantly think. They are specialized forms of generic loop constructs. Their first argument is a function, and second argument is a list. Their generality lies with the fact that their first argument is a function. If a language does not provide a convenient way to represent the concept of a function, than these functional loop constructs will suffer in usability. The Python morons, did not provide a convenient way to represent a function. (they tried, with their limited implementation of lambda and shun it like a plaque) The way Guido puts it gives us a nice glimpse of their retarded mentality: ?Also, once map(), filter() and reduce() are gone, there aren't a whole lot of places where you really need to write very short local functions;? As we can see here, in Pythoner's mind, lambda is for ?very short local functions?. Python's limited lambda coupled with their lambda attitude problem among imperative morons, therefore functional programing suffers in Python, and consequently one becomes so stupid as to come up with a bunch of feelings about lambda, map, reduce, filter. For Python's map(), look at Mathematica's Map on how it might be extended. http://documents.wolfram.com/mathematica/functions/Map Note the ability to map to not just flat lists but trees (nested lists). Note the power of expressing the concept of levels of a tree. For Python's filter(), check out the equivalent in Mathematica's Select: http://documents.wolfram.com/mathematica/functions/Select Note how it provides a third option for picking just the first n items. Also note, that Select is just a way to pick elements in a list. Mathematica provides a set to do these: Part, Take, Drop, Select, Cases. All uniformly uses the function syntax and all operate semantically by returning a new list. In Python and other imperative clown's language, usually they provide a limited varieties to do such a task, and also inconsistent like piled on. (e.g. alist[5:9], filter(), alist.remove(...), del alist[...]). Some modify the list in-place, some returns a new list. ----------------- one is quite sorry to read a big shot contemplating on petty issues with a ambitious name Python THREE THOUSAND. For the grand Python THREE THOUSAND, what about supporting non-trivial things such as built-in transparent fractions? What about a smart exact-arithmetics once for all? What about supporting pattern matching? (not textual pattern matching (e.g. regex) as Imperative Morons wont to understand, but patterns of list structures and data types.) the features of Mathematica mentioned above existed over a decade ago. But today, OpenSourcing bigwigs can contemplate and dither nothing but which lipstick to use. A good number of the industrial dignitaries are just fucking liers. And today we have the fucking Java and fucking Perl and their bosses trumpeting their fucking state-of-the-art-ness. Go fuck your wifes. (disclaimer: all mentions of any real person are just opinion.) ----- See also: http://xahlee.org/perl-python/python_3000.html Xah xah at xahlee.org ? http://xahlee.org/ From superprad at gmail.com Sun Oct 23 18:02:42 2005 From: superprad at gmail.com (PyPK) Date: 23 Oct 2005 15:02:42 -0700 Subject: Tricky Areas in Python In-Reply-To: References: <1130097286.772836.94930@g44g2000cwa.googlegroups.com> Message-ID: <1130104962.547011.277540@g47g2000cwa.googlegroups.com> hmm Thats one thing. Also I was thinking of something like benefites of python over other languages. Probably that coould be one ? From joerg.schuster at gmail.com Wed Oct 26 04:45:26 2005 From: joerg.schuster at gmail.com (Joerg Schuster) Date: 26 Oct 2005 01:45:26 -0700 Subject: more than 100 capturing groups in a regex In-Reply-To: <1130316263.790812.13440@g14g2000cwa.googlegroups.com> References: <1130160675.270886.208420@z14g2000cwz.googlegroups.com> <1130231775.770582.199690@g43g2000cwa.googlegroups.com> <1130316263.790812.13440@g14g2000cwa.googlegroups.com> Message-ID: <1130316326.790653.154480@f14g2000cwb.googlegroups.com> ... solution From jabel at plus.net Wed Oct 26 05:15:15 2005 From: jabel at plus.net (John Abel) Date: Wed, 26 Oct 2005 10:15:15 +0100 Subject: Looping Problem (Generating files - only the last record generates a file) In-Reply-To: <1130316544.381673.209190@g44g2000cwa.googlegroups.com> References: <1130316544.381673.209190@g44g2000cwa.googlegroups.com> Message-ID: <435F4923.4050501@plus.net> vasilijepetkovic at yahoo.com wrote: >Hello All, > >I have a problem with the program that should generate x number of txt >files (x is the number of records in the file datafile.txt). > >Once I execute the program (see below) only one file (instead of x >files) is created. The file created is based on the last record in >datafile.txt. > >The program is as follows: >==================================== >#! python > >HEADER = "This page displays longitude-latitude information" >SUBHEADER = "City" > >for line in open("datafile.txt"): > > > town, latlong = line.split('\t') > >f = open(town + ".txt", "w+") > >f.write(HEADER + "\n") >f.write(SUBHEADER + ": " + town + "\n") >f.write("LAT/LONG" + ": " + latlong + "\n") >f.close() > > > These lines need to be within your loop. J From grante at visi.com Fri Oct 7 10:28:42 2005 From: grante at visi.com (Grant Edwards) Date: Fri, 07 Oct 2005 14:28:42 -0000 Subject: Python, alligator kill each other References: <1128635767.068104.232190@g14g2000cwa.googlegroups.com> Message-ID: <11kd1gqmg446vf2@corp.supernews.com> On 2005-10-07, Roel Schroeven wrote: >> ... It is unknown how many pythons are competing with the thousands of >> alligators in the Everglades, but at least 150 have been captured in >> the past two years ... > > When I read the title 'Python vs. Alligator' on Slashdot, I > thought it was about some comparison between Python and an > unknown-to-me programming language Alligator. Or a reference to an O'Reilly book with an Alligator on its cover. -- Grant Edwards grante Yow! Let me do my TRIBUTE at to FISHNET STOCKINGS... visi.com From fredrik at pythonware.com Fri Oct 21 11:30:34 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 21 Oct 2005 17:30:34 +0200 Subject: Compile C program -> .pyc file References: <1129905417.451369.114840@o13g2000cwo.googlegroups.com> Message-ID: Steve Holden wrote: > Here's a start: > > http://codespeak.net/pipermail/pypy-dev/2003q1/000198.html if anyone could turn ideas that only exist in Christian's brain into working systems, the world would look a lot different. From hyakugei at gmail.com Thu Oct 6 00:01:39 2005 From: hyakugei at gmail.com (Jos) Date: 5 Oct 2005 21:01:39 -0700 Subject: Using Asyncore/chat for game server question. In-Reply-To: <1128021543.080543.29570@g49g2000cwa.googlegroups.com> References: <1128021543.080543.29570@g49g2000cwa.googlegroups.com> Message-ID: <1128571299.353753.72950@g14g2000cwa.googlegroups.com> Thanks to Matt Hammond and Jonathan LaCour for getting back to me! Jonathan sent me some code which took me several days to figure out, but does _exactly_ what i wanted. You can find the code he sent (dug out of the medusa distro) here: http://www.thethirdplace.org/grabbag/pyasynccpl/select_trigger.py And how i warped it to my needs here: http://www.thethirdplace.org/grabbag/pyasynccpl/test.py (please don't laugh at the rough code! :) Jonathan's original reply, via email, is quoted here with his permission. Thanks! jos I saw your post to comp.lang.python about asyncore and making a bit more of an "active" process. The problem with asyncore, as you stated, is that it "reacts" to events on file descriptors (through select/poll). If you have something that occurs in a second thread that could cause data to be available (ie, sending a "pulse" every second), you can use some old code from the medusa web server to do this, which I will attached to this email. You will need to do something like this (I haven't tested this code): from select_trigger import trigger from threading import Thread import time class pulse_thread(Thread): def __init__(self, interval, thunk): Thread.__init__(self) self.trigger = trigger() self.thunk = thunk self.interval = interval def run(self): while True: self.trigger.pull_trigger(self.thunk) time.sleep(self.interval) The pulse thread will pull the trigger how ever often you like, thus waking up the asyncore loop for events being fired. I hope this helps. -- Jonathan From steve.horsley at gmail.com Mon Oct 31 15:50:18 2005 From: steve.horsley at gmail.com (Steve Horsley) Date: Mon, 31 Oct 2005 20:50:18 +0000 Subject: Why the nonsense number appears? In-Reply-To: References: <1130749726.707175.293040@g43g2000cwa.googlegroups.com> Message-ID: Ben O'Steen wrote: > On Mon, October 31, 2005 10:23, Sybren Stuvel said: >> Ben O'Steen enlightened us with: >>> Using decimal as opposed to float sorts out this error as floats are >>> not built to handle the size of number used here. >> They can handle the size just fine. What they can't handle is 1/1000th >> precision when using numbers in the order of 1e10. >> > > I used the word 'size' here incorrectly, I intended to mean 'length' > rather than numerical value. Sorry for the confusion :) > Sybren is right. The problem is not the length or the size, it's the fact that 0.039 cannot be represented exactly in binary, in just the same way that 1/3 cannot be represented exactly in decimal. They both give recurring numbers. If you truncate those recurring numbers to a finite number of digits, you lose precision. And this shows up when you convert the inaccurate number from binary into decimal representation where an exact representation IS possible. Steve From spe.stani.be at gmail.com Mon Oct 17 14:13:32 2005 From: spe.stani.be at gmail.com (SPE - Stani's Python Editor) Date: 17 Oct 2005 11:13:32 -0700 Subject: override a property In-Reply-To: References: Message-ID: <1129572812.400706.62190@g44g2000cwa.googlegroups.com> No, you can just do it on the fly. You can even create properties (attributes) on the fly. class Dummy: property = True d = Dummy() d.property = False d.new = True Stani -- SPE - Stani's Python Editor http://pythonide.stani.be From steve at REMOVETHIScyber.com.au Sun Oct 9 19:13:20 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 10 Oct 2005 09:13:20 +1000 Subject: Python reliability References: Message-ID: On Sun, 09 Oct 2005 23:00:04 +0300, Ville Voipio wrote: > I would need to make some high-reliability software > running on Linux in an embedded system. Performance > (or lack of it) is not an issue, reliability is. [snip] > The software should be running continously for > practically forever (at least a year without a reboot). > Is the Python interpreter (on Linux) stable and > leak-free enough to achieve this? If performance is really not such an issue, would it really matter if you periodically restarted Python? Starting Python takes a tiny amount of time: $ time python -c pass real 0m0.164s user 0m0.021s sys 0m0.015s If performance isn't an issue, your users may not even care about ten times that delay even once an hour. In other words, built your software to deal gracefully with restarts, and your users won't even notice or care if it restarts. I'm not saying that you will need to restart Python once an hour, or even once a month. But if you did, would it matter? What's more important is the state of the operating system. (I'm assuming that, with a year uptime the requirements, you aren't even thinking of WinCE.) -- Steven. From ptb at oboe.it.uc3m.es Wed Oct 26 20:23:01 2005 From: ptb at oboe.it.uc3m.es (Peter T. Breuer) Date: Thu, 27 Oct 2005 02:23:01 +0200 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <3s6l8mFmj3fjU1@individual.net> <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> Message-ID: <58j533-40o.ln1@news.it.uc3m.es> In comp.os.linux.misc David Schwartz wrote: > . Microsoft said you can sell Windows and other > operating systems, but there will be a charge for every machine you sell > without Windows -- if you want to be able to buy Windows wholesale. Someone > could comply with this by not selling any other operating systems at all and > never pay the fee. Therefore, this is a lesser restriction than saying you > can only sell Windows wholesale if you don't sell or offer any competing > systems. No - you claim that allowing somebody (by contract?) to do Z at a penalty is "lesser" than disallowing them from doing Z. Sorry - both are equal in market economics (where the financial imperatve rules). Indeed, no contract can "disallow" somebody from doing Z - you are always at liberty to break a contract! (See the RH Enterprise licence as an example of a contract that you are at liberty to break by copying RHE to more machines at the penalty of losing RH maintenance support- I recently had this argument with Rick Moen). The penalty for doing so is what is at issue. So your definitions are anyway without semantic content, and hence the argument cannot proceed. And even if the argument were too proceed, your use of "lesser" would fail, because it appears to mean "is a (proper) subset of the ways that" without having established what different (i.e. same) means, and I'd submit that there is no diffence between the elements you exhibit in the setting of market regulation law. Peter From uche.ogbuji at gmail.com Wed Oct 26 13:28:27 2005 From: uche.ogbuji at gmail.com (uche.ogbuji at gmail.com) Date: 26 Oct 2005 10:28:27 -0700 Subject: XML Tree Discovery (script, tool, __?) In-Reply-To: <1130193322.138313.320480@o13g2000cwo.googlegroups.com> References: <1130183060.195730.178330@g47g2000cwa.googlegroups.com> <1130189785.358171.307700@o13g2000cwo.googlegroups.com> <1130193322.138313.320480@o13g2000cwo.googlegroups.com> Message-ID: <1130347707.512800.265730@g14g2000cwa.googlegroups.com> """ The output I was contemplating was a DOM "DNA" - that is the DOM without the instances of the elements or their data, a bare tree, a prototype tree based on what is in the document (rather than what is legal to include in the document). Just enough data that for an arbitrary element I would know: 1) whether the element was in a document 2) where to find it (the chain of parents) """ This is easy to do in SAX. For some hints, see page 2 of my article: http://www.xml.com/pub/a/2004/11/24/py-xml.html -- Uche Ogbuji Fourthought, Inc. http://uche.ogbuji.net http://fourthought.com http://copia.ogbuji.net http://4Suite.org Articles: http://uche.ogbuji.net/tech/publications/ From bonono at gmail.com Sun Oct 23 05:25:44 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 23 Oct 2005 02:25:44 -0700 Subject: execution order in list/generator expression Message-ID: <1130059544.215010.318610@g44g2000cwa.googlegroups.com> Hi, I am wondering how this is evaluated. a=(x for x in [1,2,3,4]) p=[4,5] c=[x for x in p if x in list(a)] c is [] but if I expand a first, like a = list(a) c is [4] So it seems that the "if" part don't get expanded ? From codecraig at gmail.com Wed Oct 12 09:13:08 2005 From: codecraig at gmail.com (Java and Swing) Date: 12 Oct 2005 06:13:08 -0700 Subject: C Wrapper Function, crashing Python? In-Reply-To: <1129122573.198977.245810@g49g2000cwa.googlegroups.com> References: <1129122046.417746.100120@g47g2000cwa.googlegroups.com> <1129122573.198977.245810@g49g2000cwa.googlegroups.com> Message-ID: <1129122788.882046.4270@o13g2000cwo.googlegroups.com> one more update... if I remove PyMem_Free and free(...) ...so no memory clean up...I can still only call doStuff 4 times, the 5th attemp crashes Python. Java and Swing wrote: > update: > if I use C's free(result), free(a) free(b) instead of PyMem_Free...I > only get one successfuly use/call of doStuff. > > i.e. > // this works > doStuff(...) > > // python crashes here > doStuff(...) > > Java and Swing wrote: > > static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { > > // this will store the result in a Python object > > PyObject *finalResult; > > > > // get arguments from Python > > char *result = 0; > > char *in= 0; > > char *aString = 0; > > char *bString = 0; > > MY_NUM *a; > > MY_NUM *b; > > int ok = PyArg_ParseTuple(args, "sss", &in, &aString, &bString); > > if (!ok) return 0; > > > > // do work to get a and b > > // count - returns an int; GetVal - returns a char * > > a = GetVal(aString, count(aString, ",")); > > b = GetVal(bString, count(bString, ",")); > > > > // make function call, which returns a char * > > result = doStuff(in, a, b); > > > > // save result in Python string > > finalResult = PyString_FromString(result); > > > > // free memory > > PyMem_Free(result); > > PyMem_Free(a); > > PyMem_Free(b); > > > > // return the result as a Python string > > return finalResult; > > } > > > > ...from python I can call this function 4 times...works fine. WHen I > > call it for the fifth time python.exe crashes. im thinking some memory > > problem in the wrapper function perhaps...but I am not sure. The > > actually C function, doStuff can be called 5, 6,7...N times without a > > problem > > so i know its gotta be my wrapper. > > > > Any ideas? Thanks! From dakman at gmail.com Mon Oct 31 09:23:12 2005 From: dakman at gmail.com (dakman at gmail.com) Date: 31 Oct 2005 06:23:12 -0800 Subject: Arguments for button command via Tkinter? In-Reply-To: <1130768146.414955.106780@g47g2000cwa.googlegroups.com> References: <1130768146.414955.106780@g47g2000cwa.googlegroups.com> Message-ID: <1130768592.010756.97890@g49g2000cwa.googlegroups.com> And yet the stupidity continues, right after I post this I finnally find an answer in a google search, It appears the way I seen it is to create a class for each button and have it call the method within that. If anyone else has any other ideas please tell. From nil at dev.nul Fri Oct 14 00:32:43 2005 From: nil at dev.nul (Christian Stapfer) Date: Fri, 14 Oct 2005 06:32:43 +0200 Subject: Yes, this is a python question, and a serious one at that (moving to Win XP) References: Message-ID: "John J. Lee" wrote in message news:mailman.2039.1129247775.509.python-list at python.org... > Kenneth McDonald writes: > [...] >> absolutely preventing me from making the switch. Number one is the >> lack of a decent command line and command-line environment, and I'm >> wondering (hoping) if perhaps someone has written a "Python shell"-- >> something that will look like a regular shell, let users type in >> commands, maybe have some of the nice features of bash etc. like tab >> completion, etc, and will then execute an underlying python script >> when the command is entered. I'm not thinking of IDLE, but something >> that is really aimed more at being a system terminal, not a Python- >> specific terminal. > [...] > > cmd.exe can be made bearable. I just got a new machine, so I'll have > to do this myself in the next few days... > > 0. Make a shortcut to cmd.exe, stick it somewhere get-at-able, > eg. quick launch toolbar 0.0. ... and add an item to your SendTo folder that allows you to have Windows Explorer open a terminal window with its current directory set to the currently displayed folder (= "Open terminal here"). Regards, Christian From fredrik at pythonware.com Sun Oct 9 11:12:00 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 9 Oct 2005 17:12:00 +0200 Subject: Function decorator that caches function results References: Message-ID: Ron Adam wrote: > In effect, 'cache' and 'fn' are replaced by the objects they reference > before the cached_result function is returned. not really; accesses to "free variables" always go via special cell objects (rather than direct object references), and the compiler uses special byte codes for all accesses to such objects. this snippet illustrates the differences: def func1(): return a def func2(a): return a def wrapper(a): def func3(): return a return func3 def decode(func): import dis print func.__name__ + ":" dis.dis(func) print "co_freevars =", func.func_code.co_freevars print "func_closure =", func.func_closure print decode(func1) decode(func2) decode(wrapper(10)) if you run this on a recent version of Python, you get something like: func1: 2 0 LOAD_GLOBAL 0 (a) 3 RETURN_VALUE co_freevars = () func_closure = None func2: 5 0 LOAD_FAST 0 (a) 3 RETURN_VALUE co_freevars = () func_closure = None func3: 9 0 LOAD_DEREF 0 (a) 3 RETURN_VALUE co_freevars = ('a',) func_closure = (,) note the use of LOAD_DEREF for the variable access. Other opcodes include STORE_DEREF (that updates a local variable through a cell, used inside the "defining" scope), and MAKE_CLOSURE (which sets up the function object for functions that actually uses nested scopes; this is where the func_closure attribute is initialized). (now, if I weren't limited to plain text, I could have drawn a nice little diagram for you, but that's an entirely different thread...) From steve at REMOVETHIScyber.com.au Sun Oct 30 04:02:27 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 30 Oct 2005 20:02:27 +1100 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <87ek65kbw5.fsf@lucien.dreaming> <1h57cu1.1jywbjibu87obN%aleaxit@yahoo.com> Message-ID: On Sat, 29 Oct 2005 16:41:42 -0700, Alex Martelli wrote: > Steven D'Aprano wrote: > ... >> I should also point out that for really serious work, the idiom: >> >> f = file("parrot") >> handle(f) >> f.close() >> >> is insufficiently robust for production level code. That was a detail I >> didn't think I needed to drop on the original newbie poster, but depending >> on how paranoid you are, or how many exceptions you want to insulate the >> user from, something like this might be needed: >> >> try: >> f = file("parrot") >> try: >> handle(f) >> finally: >> try: >> f.close() >> except: >> print "The file could not be closed; see your sys admin." >> except: >> print "The file could not be opened." > > The inner try/finally is fine, but both the try/except are total, utter, > unmitigated disasters: they will hide a lot of information about > problems, let the program continue in a totally erroneous state, give > mistaken messages if handle(f) causes any kind of error totally > unrelated to opening the file (or if the user hits control-C during a > lengthy run of handle(f)), emit messages that can erroneously end up in > the redirected stdout of your program... VERY, VERY bad things. Of course. That's why I said "something like this" and not "do this" :-) I don't expect people to "handle" exceptions with a print statement in anything more serious than a throw-away script. For serious, production-level code, more often than not you will end up spending more time and effort handling errors than you spend on handling the task your application is actually meant to do. But I suspect I'm not telling Alex anything he doesn't already know. > Don't ever catch and ``handle'' exceptions in such ways. In particular, > each time you're thinking of writing a bare 'except:' clause, think > again, and you'll most likely find a much better approach. What would you -- or anyone else -- recommend as a better approach? Is there a canonical list somewhere that states every possible exception from a file open or close? -- Steven. From nntp.20.drfarina at recursor.net Tue Oct 18 00:31:32 2005 From: nntp.20.drfarina at recursor.net (Dan Farina) Date: Mon, 17 Oct 2005 21:31:32 -0700 Subject: Vim capable IDE? In-Reply-To: <1129603486.291175.167860@f14g2000cwb.googlegroups.com> References: <1129603486.291175.167860@f14g2000cwb.googlegroups.com> Message-ID: Chris Lasher wrote: > Hello, > Is there a Python-sensitive, Linux compatible IDE out there with > standard bells and whistles (source browser, symbolic debugger, etc.) > but with the action-per-keystroke editing capabilities of Vim? I have > failed to turn up such an IDE in my Googling and IDE project-page > browsing. :-( > > Thanks very much in advance, > Chris > If you don't have religious feelings on Java (or are able to ignore them for the time being) you could try Eclipse and pydev (see pydev.sourceforge.net) I use it. I think it works well. df From leszczynscyATnospam.yahoo.com.nospam Wed Oct 12 00:27:35 2005 From: leszczynscyATnospam.yahoo.com.nospam (Andy Leszczynski) Date: Tue, 11 Oct 2005 23:27:35 -0500 Subject: piping out binaries properly In-Reply-To: <86u0fnwes2.fsf@bhuda.mired.org> References: <86u0fnwes2.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > It's not normal to write binary content to stdout - you normally write Well, I grew up in the Unix world and it is normal over there. I am still curious which layer adds that 0xd. Is it python, cygwin, windows ... Thx for reply, Andy From tim.peters at gmail.com Thu Oct 6 12:09:47 2005 From: tim.peters at gmail.com (Tim Peters) Date: Thu, 6 Oct 2005 12:09:47 -0400 Subject: Absolultely confused... In-Reply-To: <1128566897.3513.18.camel@localhost.localdomain> References: <7jcqbu2h.fsf@python.net> <1128566897.3513.18.camel@localhost.localdomain> Message-ID: <1f7befae0510060909r4c2028ebqe1b4be270ce1ab6d@mail.gmail.com> [Jeremy Moles] > ... > I may be missing something critical here, but I don't exactly grok what > you're saying; how is it even possible to have two instances of > PyType_vector3d? It is (like all the examples show and all the extension > modules I've done in the past) a static structure declared and assigned > to all at once, only once. The most common cause is inconsistent import statements, with one place using package-relative import but another place explicitly specifying the package. Here's a simple pure Python example, with this directory structure: playground/ package_dir/ __init__.py source.py module.py __init__.py is empty; it just serves to make `package_dir` a package. source.py defines a single type, named Type: class Type(object): pass module.py imports source.Type in two different ways, then prints various stuff: from source import Type as one_way # package-relative import from package_dir.source import Type as another_way print one_way is another_way print one_way.__name__, another_way.__name__ print repr(one_way), repr(another_way) import sys for k, v in sys.modules.items(): if "source" in k: print k, v Now _from_ playground, run module.py: python playground/module.py This is the output, with annotations; I ran this on Windows, so expect to see backslashes : False That is, one_way is not the same object as another_way: there are two distinct instances of the Type object. Type Type Although they're distinct, they have the same __name__, "Type". Their reprs differ, though, showing the path via which they were imported. source package_dir.source That's two lines of output from crawling over sys.modules: there are two distinct instances of the entire `source` module. That's the real cause of the multiple `Type` instances. package-relative import is rarely a good idea. Are you doing that anywhere? From csubich.spam.block at spam.subich.block.com Tue Oct 25 09:25:09 2005 From: csubich.spam.block at spam.subich.block.com (Christopher Subich) Date: Tue, 25 Oct 2005 09:25:09 -0400 Subject: Would there be support for a more general cmp/__cmp__ In-Reply-To: References: Message-ID: Antoon Pardon wrote: > It *is* a definition of an ordering. > > For something to be an ordering it has to be anti symmetric and transitive. > > The subset relationships on sets conform to these conditions so it is a (partial) > ordering. Check your mathematic books, Why you would think this is abuse is beyond me Which is exactly why a < b on sets returns True xor False, but cmp(a,b) throws an exception. a b is a local comparison, asking only for the relationship between two elements. In some bases, like the complex numbers, some comparisons are ill-defined.; in others, like sets, they're well-defined but don't give a total ordering. cmp(a,b) asks for their relative rankings in some total ordering. For a space that does not have a total ordering, cmp(a,b) is meaningless at best and dangerous at worst. It /should/ throw an exception when the results of cmp aren't well-defined, consistent, antisymmetric, and transitive. From ddelay at club-internet.fr Sat Oct 8 14:30:30 2005 From: ddelay at club-internet.fr (ddelay at club-internet.fr) Date: Sat, 8 Oct 2005 20:30:30 +0200 Subject: What about letting x.( ... ? ... ) be equivalent to ( ... x ... ) Message-ID: An HTML attachment was scrubbed... URL: From david at jotax.com Sat Oct 29 03:01:59 2005 From: david at jotax.com (David Poundall) Date: 29 Oct 2005 00:01:59 -0700 Subject: Counting Threads References: <1130435220.846203.86320@g44g2000cwa.googlegroups.com> <1130435796.917475.295830@g14g2000cwa.googlegroups.com> <1130456316.569328.323480@f14g2000cwb.googlegroups.com> <1130484088.324170.269810@g43g2000cwa.googlegroups.com> <2bk4m15ric4tbjm1hlu1e2cub8d99fbrp1@4ax.com> Message-ID: <1130568598.958879.121490@g14g2000cwa.googlegroups.com> After much optimisation it turns out the following code does the job for me. In the end using count didn't give me the flexibility I needed. Instead I now name each thread and track them accordingly. It's arguable if I need the thread locking now though, however I have left it in to remind me of the syntax. Thank you for posting back Dennis. Much appreciated. # -------------------------------------------------------- class ServerThreads: """ Wrapper for thread handling. These threads are not dynamic, that is to say once the application is fully loaded the number of threads running is determined by the size of the application - and is fixed. """ # --------------------- Class Attributes # Dict holds object references to all threads # created in the server (running or not) thr_objects = {} # Dict holds status of all running threads # 0 = stopped, 1 = running thr_running = {} # Lock object lck = Lock() def launch(self, ThrName, SubToLaunch, SubsArgs=(), SubsKwargs={}, AsDaemon=True): """ Kickoff a thread. thr_objects : Dictionary using ThreadTitle as the key which holds references to the thread object thr_running : Dictionary holding the status of each thread """ s = ServerThreads # --------------------- s.lck.acquire() try: t = Thread(name = ThrName, target=SubToLaunch, args = SubsArgs, kwargs = SubsKwargs) t.setDaemon(AsDaemon) # Must be set before start s.thr_objects[ThrName] = t s.thr_running[ThrName] = 1 if ag.gb_Appdebug: print 'Thread Started ------------- ', ThrName t.start() finally: s.lck.release() # --------------------- def stoprequest(self,thr_name): """ Thread stop request - stop is pending. Join is not needed because the main code body drops out of the thread loops once the thr_running = true condition has been removed.""" s = ServerThreads # --------------------- s.lck.acquire() s.thr_running[thr_name] = 0 # Flag to tell running thread to please terminate if ag.gb_Appdebug: print 'Thread Stopping ----------- ' + thr_name s.lck.release() # --------------------- def allOK(self): """ Returns a list of all threads that are down when they shouldn't be (if any) """ s = ServerThreads ThreadsDown = [] for thr_name in s.thr_objects: if not s.thr_objects[thr_name].isAlive() and s.thr_running[thr_name]: # If a thread has an unscheduled stop indicate this by returning the # threads name otherwise return None. ThreadsDown.append(thr_name) return ThreadsDown From mwm at mired.org Tue Oct 4 12:59:52 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 04 Oct 2005 12:59:52 -0400 Subject: Reply-To header References: <2ECA6FE9-3C8F-4C60-9E89-70CC078B14EF@gmail.com> <7rc0f.11261$Un.585792@phobos.telenet-ops.be> <86oe66jpfj.fsf@bhuda.mired.org> <43423EAA.9060600@REMOVEMEcyber.com.au> Message-ID: <86ll19i5fb.fsf@bhuda.mired.org> Steven D'Aprano writes: > Mike Meyer wrote: >> When I notice that a list is broken (RFC 2822 says that >> reply-to is for the *author* of the message; anyone else setting it is >> doing so in violation of the RFC, and hence broken, no matter how >> useful it may be), > Since when did obeying the RFC become important in and of itself? Since we started worrying about software being interoperable. If you only use software from one monopolistic vendor, then that won't matter to you, and you'll create pain and suffering for everyone who doesn't drink the same koolaide. But such attitudes seem endemic on the internet these days. > That's what reply to means, surely? What is the point of a reply-to > header that must be the sender, since you already have a header that > gives you the sender. You misunderstood. By "for the *author*", I meant that it's for the *author* to set, not for someone else to set. I did not mean that it had to be set to a specific value. Saying that anyone else setting it is broken should have made that clear. > I have been known to change the reply-to address from the address I am > sending from (me at work for example) to the address I want the reply to > go to (me at home). There are many times I'm emailing people I know can't > cope with the complicated task of changing the To address of their > reply, so I change the reply-to header so that their reply goes where > I want it to go to (which might be another email address of mine, or a > different person, or a mailing list). And these are perfectly valid uses of reply-to. You're the author, you're the one that reply-to is there for. > If the RFC says that the reply-to header doesn't actually mean the > address the reply should go to, but only the sender, then the RFC is > broken. "Where the reply goes to" is a *human* decision, not a > technical one. If I send you an email saying "Please reply to > president at whitehouse.gov" then your mailer should honour that > (although, since we are all adults, you should have the freedom to > ignore my request and make a nuisance of yourself by emailing your > reply to a different address). That isn't what the RFC says, as you could have easily checked. It's also not what I said. > Likewise, if I set the reply address to the list, then your mailer > should reply to the list. Perhaps you can argue that *my decision* to > have replies go to the list is a bad one, but that's a social issue, > not a technical one. You're the author of the message. If you set the reply-to, that's fine. If anyone other than you sets the reply-to, that's broken. >> I tell my mailer to ignore reply-to on mail from >> that list. Similarly, I no longer try and explain to people how long >> lines violate RFCs and are a pain to read in well-behave mail readers, > By "well-behaved", do you mean "can't cope with long lines"? How > curious -- that's precisely the opposite definition of well-behaved I > use. >> or why mail readers that wrap text/plain content are broken. > Curiouser and curiouser. Again that's the exact opposite of my > definition of broken. Like I said, I gave up on this fight. Ignorant people are going to continue generating ugly, hard-to-read messages and complaining when they get a message that demonstrates why their software is broken. That's life on the internet these days. The internet used to be a nice neighborhood. Now it's full of selfish jerks, and there are to many of them to fight. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From mwm at mired.org Fri Oct 14 11:39:08 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 14 Oct 2005 11:39:08 -0400 Subject: UI toolkits for Python References: Message-ID: <86br1st8f7.fsf@bhuda.mired.org> "Adriaan Renting" writes: [On Qt] > I don't know how it performs on OSX, I think it works fine, as Qt is > available on OSX. Qt on OS X is halfway there. It looks - and acts - like an aqua application. However, to support the Command key, they hacked things so that it is reported to the upper layers as the Control key. This means that there's no way to get to use the control key in the UI for qt apps on OS X. This really rapes apps with configurable shortcuts. For instance, LyX comes with a couple of emacsish bindings. You can turn them on, but you have to use Command-key instead of Control-key, which pretty thoroughly defeats the purpose. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From ms at cerenity.org Sun Oct 23 12:00:06 2005 From: ms at cerenity.org (Michael) Date: Sun, 23 Oct 2005 17:00:06 +0100 Subject: High Order Messages in Python References: <1130015536.273136.295800@g43g2000cwa.googlegroups.com> Message-ID: <435bb315$0$15040$ed2619ec@ptn-nntp-reader02.plus.net> eduardo.padoan at gmail.com wrote: > I'm reading about "high order messages" in Ruby by Nat Pryce, and > thinking if it could be util and if so, if it could be done in Python. Nice sunday afternoon exercise. Yes, you can do this in python. This is based on a relatively naive translation of the ruby version: class HigherOrderMessage(object): def __init__(self,handler): self.handler = handler class Do(HigherOrderMessage): def __HOM__(self, methname, *args): "implement ruby's method_missing idea" try: for e in self.handler: meth = getattr(e, methname) meth(*args) except TypeError: # Handle non-iterator, could be nicer if self.handler is not None: meth = getattr(self.handler, methname) meth(*args) def __getattribute__(self, methname): try: return super(Do,self).__getattribute__(methname) except AttributeError: def myHom(*args): return self.__HOM__(methname, *args) return myHom class Where(HigherOrderMessage): def __HOM__(self, methname, *args): "implement ruby's method_missing idea" try: r = List() for e in self.handler: meth = getattr(e, methname) if meth(*args): r.append(e) return r except TypeError: r = List() if self.handler is not None: meth = getattr(self.handler, methname) if meth(*args): r.append(self.handler) return r # def __getattribute__(self, methname): "Probably belongs in the baseclass" try: return super(Where,self).__getattribute__(methname) except AttributeError: def myHom(*args): return self.__HOM__(methname, *args) return myHom class enumerable(object): def do(self): return Do(self) def where(self): return Where(self) class List(enumerable,list): "List using enumerable as a mixin" class Claimant(enumerable): def __init__(self, name, age, gender): self.name = name self.age = age self.gender = gender self.benefits = 0 def retired(self): return (self.gender == "male" and self.age >= 65) or \ (self.gender == "female" and self.age >= 60) def receive_benefit(self,amount): self.benefits = self.benefits + amount def __str__(self): return "%s,%s age: %s benefits: %s" % ( self.name, self.gender, str(self.age), str(self.benefits) ) # # Create an enumerable list capable of responding to # claimants = List([ # Just a list which is enumerable as well Claimant("tom", 32, "male"), Claimant("dick", 64, "male"), Claimant("harry", 128, "male"), Claimant("Ivanova", 32, "female"), Claimant("Kochansky", 64, "female"), Claimant("Sung", 128, "female"), ]) # First the normal python way I prefer this) for claimant in claimants: if claimant.retired(): claimant.receive_benefit(50) # Display the results for claimant in claimants: print str(claimant) print # The more direct translation of : # claimants.select {|e| e.retired?}.each {|e| e.receive_benefit 50} [ e.receive_benefit(50) for e in claimants if e.retired() ] # Display the results for claimant in claimants: print str(claimant) print # The single claimant version of the higher order message approach # re-uses the last claimant from above. This one unconditionally # grants benefits. # claimant.do().receive_benefit(50) print claimant print # Iterating over a bunch of Claimants with the higher order message # approach. This conditionally updates the claimaints claimants.where().retired().do().receive_benefit(50) # display results for claimant in claimants: print str(claimant) I'm not convinced I'd actually *use* this approach(*), but it does show that you can certainly take this approach in python. It's certainly interesting though. (*) Largely because there's a bunch of magic happening as far as the user (next programmer to edit the file) is concerned. After all you can't find the definition of retried in "where" or "claimant"; you can't find the definition of "receive_benefit" in "do", "retired", "where" or "claimants". I'm also pretty sure there's other things you'd want to do more than the above generally speaking if you wanted to handle inheritance/etc nicely. (That does make me wonder as well if you'd need to do more in ruby as well) However, this certainly isn't a case of "ruby can do this, and python can't", because clearly python CAN do it :-) Regards, Michael From webb.sprague at gmail.com Sat Oct 8 14:26:09 2005 From: webb.sprague at gmail.com (Fried Egg) Date: 8 Oct 2005 11:26:09 -0700 Subject: Codetags (also Pylint/Pychecker + Variable declarations) Message-ID: <1128795969.572378.327440@g43g2000cwa.googlegroups.com> * Codetag PEP: ** I would like to comment on the codetags PEP, which I give a 0+. I think the end "<>" is bad; I would be in favor of a block system or something that looks more like regular Python (e.g. "# :FIXME(line_count=10, date='2005-08-09', ...) "). ** As to the comments that say "Trac does the same functionality" or "Eclipse/Eric/Emacs... has the same functionality" I think codetags are orthogonal to that. Also, some of us still use the old vi to edit a system script in an emergency, and relying on bloated silliness like Eclipse for documenting code seems, well, against all that is good and true. * Pylint: ** I also agree that a lint system is the place to enforce or otherwise use things like codetags. A useful implementation would go a long way to creating a standard organically. * Variable declarations--a synthesis of codetags and lint: ** Perhaps a codetag system is the place to put variable declarations, type checking, and the like. The lint system could grab these and evaluate the code with them without messing with the compiler or quick and dirty code styles. (Inferring properties of code from static listings is for geniuses--not for me--so forgive any unrealistic examples below). As an added benefit, there wouldn't be any non-explicit checking to impede performance (but if you want, you can always add assert's to your heart's content when it really matters, which is rarely). ** Example
str_var = '' # :DECLARE(type='string')
flt_var = 0 # :DECLARE(type='float')
line_index = 0 # :DECLARE(type='int', min=0, max=10)
for line_index in range(-10, 10) # "maximum exceeded" warning
    mispelled_flt_var = 1ine_index / 2.5 # "undeclared variable"
warning
    str_var = var + 1      # "type mismatch" warning
Thanks for everyone's patience in reading this--I hope it helps further the Pythonic cause of graceful programming. From michele.simionato at gmail.com Fri Oct 14 03:44:45 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 14 Oct 2005 00:44:45 -0700 Subject: Well written open source Python apps In-Reply-To: <1129214592.342917.100090@g43g2000cwa.googlegroups.com> References: <1129214592.342917.100090@g43g2000cwa.googlegroups.com> Message-ID: <1129275885.703931.326020@g49g2000cwa.googlegroups.com> > Could anyone suggest an open source project that has particularly well > written Python? I am especially looking for code that people would > describe as "very Python-ic". I vote for the "doctest" code in the standard library. Michele Simionato From sybrenUSE at YOURthirdtower.com.imagination Mon Oct 31 04:39:00 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Mon, 31 Oct 2005 10:39:00 +0100 Subject: Why the nonsense number appears? References: <1130749726.707175.293040@g43g2000cwa.googlegroups.com> Message-ID: Johnny Lee enlightened us with: > Why are there so many nonsense tails? thanks for your help. Because if the same reason you can't write 1/3 in decimal: http://docs.python.org/tut/node16.html 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 tzot at sil-tec.gr Tue Oct 4 04:26:29 2005 From: tzot at sil-tec.gr (Christos Georgiou) Date: Tue, 04 Oct 2005 11:26:29 +0300 Subject: Python 3! Finally! References: Message-ID: On Fri, 30 Sep 2005 20:50:06 +0200, rumours say that Stefan Behnel might have written: >Weird, though, the md5sum is the same as for the Python-2.4.2.tar.bz2 that I >downloaded late (late!) yesterday evening and had forgotten in my download >directory... just found it next to the new one... was still there, not >overwritten... > >Well, maybe the changes needed to merit a V3 weren't that big after all... No, it's just proof that the MD5 checksum isn't reliable and we should move forward to SHA checksums. Amazing coincidence. Let's xpost to some security newsgroup. -- TZOTZIOY, I speak England very best. "Dear Paul, please stop spamming us." The Corinthians From deets at nospam.web.de Fri Oct 7 21:17:47 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 08 Oct 2005 03:17:47 +0200 Subject: Python, alligator kill each other In-Reply-To: <1128635767.068104.232190@g14g2000cwa.googlegroups.com> References: <1128635767.068104.232190@g14g2000cwa.googlegroups.com> Message-ID: <3qol1qFg33peU1@uni-berlin.de> infidel wrote: > By Denise Kalette > Associated Press > > MIAMI - The alligator has some foreign competition at the top of the > Everglades food chain, and the results of the struggle are horror-movie > messy. > > A 13-foot Burmese python recently burst after it apparently tried to > swallow a live 6-foot alligator whole, authorities said. > > ... > > ... It is unknown how many pythons are competing with the thousands of > alligators in the Everglades, but at least 150 have been captured in > the past two years ... > Some Photos: http://www.spiegel.de/fotostrecke/0,5538,PB64-SUQ9MTExOTEmbnI9Mg_3_3,00.html Diez From larry.bates at websafe.com Fri Oct 14 09:26:31 2005 From: larry.bates at websafe.com (Larry Bates) Date: Fri, 14 Oct 2005 08:26:31 -0500 Subject: get_payload problem with large mail attachments In-Reply-To: <1129286221.172200.217160@o13g2000cwo.googlegroups.com> References: <1129286221.172200.217160@o13g2000cwo.googlegroups.com> Message-ID: <434FB207.9000403@websafe.com> While I don't intend to stir up a hornet's nest, I feel an obligation to point out that an 8Mb email attachment should set off warning bells. I don't believe that SMTP email is very efficient at moving such large files around and that there are other methods for moving them more efficiently. I've found that most email servers are configured to reject email messages that are larger than 2-4Mb. Maybe it is time to back up and look at WHY you even have attachments that are that large? Just a suggestion. -Larry hungryblank at gmail.com wrote: > I'm having troubles with a script that uses the get_payload function. > My script just works perfectly if I use it with attachment up to 8 Mb. > If the attachment are more than 8 Mb large, the script exits with a > TypeError exception. > IMHO when get_payload try to convert the attachment in a single string > it occours in some size limit. > How can I fix it? > > I'm using python-2.3.3 on a SuSE 9.1 distro > > The error raised is > > Traceback (most recent call last): > File "/usr/local/sbin/mailbox2home.py", line 44, in ? > fp.write(part.get_payload(decode=1)) > TypeError: argument 1 must be string or read-only buffer, not None > > and this is the slice of code where the error occours. > > for message in messages: > for part in message.walk(): > # multipart/* are just containers > if part.get_content_maintype() == 'multipart': > continue > # Applications should really sanitize the given filename so > that an > # email message can't be used to overwrite important files > filename = part.get_filename() > if not filename: > ext = mimetypes.guess_extension(part.get_type()) > if not ext: > # Use a generic bag-of-bits extension > ext = '.bin' > filename = 'part-%03d%s' % (counter, ext) > counter += 1 > fp = open(os.path.join(dir, filename), 'wb') > fp.write(part.get_payload(decode=1)) > fp.close() > From kn0805 at hotmail.com Tue Oct 11 15:34:54 2005 From: kn0805 at hotmail.com (ktxn1020) Date: 11 Oct 2005 12:34:54 -0700 Subject: unable to import os In-Reply-To: <1129054769.405747.170570@o13g2000cwo.googlegroups.com> References: <1129054769.405747.170570@o13g2000cwo.googlegroups.com> Message-ID: <1129059294.346530.19780@g47g2000cwa.googlegroups.com> I had the following code run with Python for Delphi. It works. while IsCDriveNotEnoughSpace(): dirlist = nt.listdir(CPath) listsize = len(dirlist) if listsize > 2: file = dirlist[0] nt.remove(CPath + dirlist[0]) PyLog(file + " in C:\logs has been deleted.") if listsize == 2: break When I added the line "mtime = nt.stat(CPath+file)[8]", it failed. Do you have any idea or suggestion? ktxn1020 wrote: > It works fine independently, but still not work when run with Python > for Delphi. From http Sun Oct 9 08:21:22 2005 From: http (Paul Rubin) Date: 09 Oct 2005 05:21:22 -0700 Subject: new forum -- homework help/chit chat/easy communication References: <1128798687.305818.66010@g49g2000cwa.googlegroups.com> <1128810677_124183@spool6-east.superfeed.net> Message-ID: <7xu0fqop8d.fsf@ruckus.brouhaha.com> "Fredrik Lundh" writes: > Tcl is an early example of a something that started as a "reusable > command language" and turned into a "real programming language" > along the way: Yes, that's why tcl is such an awful language. And it happens all the time. It's better to just start with a powerful language, e.g., Python, Guile, etc. From the Guile blurb: http://www.gnu.org/software/guile/guile.html#whatisit The true cost of doing it yourself ================================== When you get to the point in your project where you need a scripting language or a configuration file format and reader, the normal course of things is to say ``I'll just do something clean and simple.'' This is a good decision. Adding a full programming language is just a distraction from your project. But simple languages don't seem capable of staying simple. For example, early releases of PHP, a language for generating web pages dynamically, enjoyed its minute memory footprint and simplicity. However over time PHP has grown, with the latest releases giving PHP an object system and other features that have grown it to a much larger size. Compare Tcl from its 1988 origins with the modern, sizable language. Broadly, the same progression has occurred with Perl. ... Guile has the fundamentals you need; you simply specialize it for your application. It has arrays and lists; modules; objects; and first-class functions. It has garbage collection --- which makes using Guile especially simple. Using Guile, your application has a full-featured scripting language right from the beginning, so you can focus your manpower on the novel and attention-getting parts of your application. From jepler at unpythonic.net Wed Oct 5 10:58:15 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Wed, 5 Oct 2005 09:58:15 -0500 Subject: How to create temp file in memory??? In-Reply-To: References: Message-ID: <20051005145814.GD13147@unpythonic.net> Here's how: 1. open your web browser 2. visit the url http://docs.python.org 3. click the link "Library Reference" (keep this under your pillow) 4. scan down the list of modules until you see these two items: 4.6 StringIO -- Read and write strings as files 4.7 cStringIO -- Faster version of StringIO 5. ????? 6. profit Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From larry.bates at websafe.com Wed Oct 19 10:50:34 2005 From: larry.bates at websafe.com (Larry Bates) Date: Wed, 19 Oct 2005 09:50:34 -0500 Subject: Dealing with Excel In-Reply-To: <1129670191.061006.146320@g47g2000cwa.googlegroups.com> References: <1129670191.061006.146320@g47g2000cwa.googlegroups.com> Message-ID: Using ODBC interface to Oracle Excel can do this without any external (Python) program. Just: 1) Create a ODBC DSN that interfaces with Oracle 2) In Excel do Data-Get External Data-New Database Query 3) Tell Excel what tables/columns/order/filtering you want You can even save the Database Query for later re-use. If you want, you can automate this process using Python COM+ interface to Excel. Larry Bates Robert Hicks wrote: > I need to pull data out of Oracle and stuff it into an Excel > spreadsheet. What modules have you used to interface with Excel and > would you recommend it? > > Robert > From gsakkis at rutgers.edu Sat Oct 29 10:51:04 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: 29 Oct 2005 07:51:04 -0700 Subject: XML Tree Discovery (script, tool, __?) References: <1130183060.195730.178330@g47g2000cwa.googlegroups.com> <1130491182.405885.49010@g14g2000cwa.googlegroups.com> <1130531839.145106.287950@g44g2000cwa.googlegroups.com> Message-ID: <1130597464.844648.231940@g44g2000cwa.googlegroups.com> wrote: > """ > I was looking for something similar (XML to DTD inference) but I didn't > find anything related in python. Trang > (http://www.thaiopensource.com/relaxng/trang-manual.html#introduction), > on the other hand seems impressive after a few non-trivial tests. It > would be neat to have it ported in python, at least the inference part. > > """ > > If you're OK with RELAX NG rather than DTD as the schema output > (probably a good idea if you're using namespaces), consider > Examplotron, which I've used on many such production tasks. > > http://www-128.ibm.com/developerworks/xml/library/x-xmptron/ > > It's XSLT rather than Python, but the good news is that XSLT is easy to > invoke from Python using tools such as 4Suite. > > http://uche.ogbuji.net/tech/akara/nodes/2003-01-01/python-xslt Neat, though non-trivial XSLT makes my head spin. Just for kicks, I rewrote in python Michael Kay's DTDGenerator (http://saxon.sourceforge.net/dtdgen.html), though as the original it has several limitations on the accuracy of the inferred DTD. George From fairwinds at eastlink.ca Mon Oct 3 08:46:08 2005 From: fairwinds at eastlink.ca (David Pratt) Date: Mon, 03 Oct 2005 09:46:08 -0300 Subject: Python based unacceptable language filter In-Reply-To: <11k13a57dtm2u0d@news.supernews.com> Message-ID: Hi. Thank you for the links. I am looking for something that would function in a similar way to Yahoo's filter for it's message boards. Perhaps I should have used the term profanity instead of unacceptable language. I am not concerned about correcting sentence structure or poor grammar. I realize screening profanity can be accomplished by simply looping over regular expressions from a database or dictionary to search the text to check against possibilities . I thought it possible that there may be something like this already in existence, perhaps already in a module since it is likely (despite how absurd) - that someone has developed a dictionary of profane word expressions I suspect. What's is perhaps more crazy, is that one has to consider including something like this in an application - but you have to conclude the Internet is what it is. Regards David From Yahoo: "The Profanity Filter allows you to control how you want to view messages with profanity in two ways. You can choose to view the messages with the profanity masked with italcized symbols (@$&% ), or you can have the messages containing profanity hidden entirely. You can also choose between a weak setting for exact word matches or a strong setting that will filter spelling variations." Well I know this thread is a On Sunday, October 2, 2005, at 10:45 PM, Nigel Rowe wrote: > David Pratt wrote: > >> Hi. Is anyone aware of any python based unacceptable language filter >> code to scan and detect bad language in text from uploads etc. >> >> Many thanks. >> David > > You might be able to adapt languagetool. > http://www.danielnaber.de/languagetool/features.html > > Later versions have been ported to Java, but the old python version of > languagetool is at http://tkltrans.sourceforge.net/#r03 > > His thesis paper is at > http://www.danielnaber.de/languagetool/download/ > style_and_grammar_checker.pdf > > Mind you, given the poor language skills of many native english > speakers > (not to mention those for whom english is a second language) relying on > automated filters to enforce 'good' language seems a trifle extreme. > This > post for example would probably not pass. From steve at REMOVETHIScyber.com.au Tue Oct 11 09:47:47 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Tue, 11 Oct 2005 23:47:47 +1000 Subject: Learning Python References: Message-ID: On Tue, 11 Oct 2005 18:26:58 +0900, Chris Dewin wrote: > On Mon, 10 Oct 2005 17:20:35 +0000, dannypatterso wrote: > > [snip] > >>> I'm a hobby programmer using mostly BASIC(s) and some Java. I know >>> procedural programming and I know what encapsulation, inheritance and >>> polymorphism are but I have very little experience in using them as >>> I've written just a few Java programs (i.e., I guess I could use a >>> primer in OO programming). > > There was an excellent such primer on devshed, by Icarus, but they appear > to have taken it down. > > I saved a copy of it to my HD. Would there be anything morally, or legally > wrong with me uploading it to my site? What licence was the primer published under? Unfortunately, under copyright law, it isn't enough for the copyright owner to merely not prohibit redistribution, but they must explicitly allow it, e.g. under a Creative Commons licence. That is because when you redistribute it, you are effectively making a copy. I should also point out that copyright infringement not only opens you to law suits, but in many countries is now a felony crime. For instance, here in Australia thanks to the wonderful "Free" Trade Agreement with the USA, the BSAA (our local branch of the American Business Software Alliance) is trumpeting the fact that they can now have company CEOs jailed for not buying enough software licences -- or, as the case may be, buying them but not being able to find them when the BSAA comes a knocking. Having said all that, if you are aware of the risks, you may make a value judgement that the copyright owner won't mind if you republish the work, e.g. because they were giving it away for free to start with. If so, I see nothing morally wrong with putting it up on your website. (The law may disagree.) -- Steven. From email at christoph-haas.de Tue Oct 25 18:05:26 2005 From: email at christoph-haas.de (Christoph Haas) Date: Wed, 26 Oct 2005 00:05:26 +0200 Subject: simple send only command line jabber client in python? In-Reply-To: <1130275939.113598.194000@z14g2000cwz.googlegroups.com> References: <1130275939.113598.194000@z14g2000cwz.googlegroups.com> Message-ID: <200510260005.27248.email@christoph-haas.de> On Tuesday 25 October 2005 23:32, fuzzylollipop wrote: > I want to be able to send jabber messages from an subversion > post-commit hook script. All I need is a simple library to connect to a > server and send a message. > > I looked at all the half-finished and overly complex projects and can't > find anything that fits the bill. What I did find I can't get to work > correctly, probably because everything is 2 years old and out of date. Try http://xmpppy.sourceforge.net/ Christoph -- ~ ~ ".signature" [Modified] 1 line --100%-- 1,48 All From aleaxit at yahoo.com Sat Oct 29 13:50:38 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 29 Oct 2005 10:50:38 -0700 Subject: py.log using decorators for DRY References: <1130606608.107621.138650@z14g2000cwz.googlegroups.com> Message-ID: <1h56wng.106v8tn1lk8f2rN%aleaxit@yahoo.com> yoda wrote: > I'm using py.log for logging and I find that I end up having the following > pattern emerge within my code (influenced by > http://agiletesting.blogspot.com/2005/06/keyword-based-logging-with-py-lib > rary.html): > > def foo(**kwargs): > log.foo(kwargs) > #body form > > This led me to believe that I could simplify that pattern with the > following idiom : > > > def logit (fn): > ''' > decorator to enable logging of all tagged methods > ''' > def decorator (**kwargs): > # call a method named fn.func_name on log with kwargs > #should be something like: log.func_name (kwargs) > > return decorator Assuming the attributes of object 'log' don't change at runtime (i.e., you're OK with early binding), I'd code: def logit(fn): method = getattr(log, fn.func_name) def callit(**kwargs): return method(kwargs) return callit If you need to do late binding instead, you can move the getattr to inside the body of callit. Alex From benji at benjiyork.com Thu Oct 6 11:35:31 2005 From: benji at benjiyork.com (Benji York) Date: Thu, 06 Oct 2005 11:35:31 -0400 Subject: So far In-Reply-To: References: Message-ID: <43454443.7090908@benjiyork.com> CppNewB wrote: > Most of them have support for Dialogs, but what about more complex > UI's? I may need a resizable frame within a resizable frame? I > haven''t found a GUI builder with a great feel yet. I *highly* recommend wxDesigner. I've used it extensively. It's cheap and has a demo version you can download (the demo can't save your designs, but can generate code so you can try it out). -- Benji York From thatchmatic at yahoo.com Sat Oct 22 21:46:49 2005 From: thatchmatic at yahoo.com (thatchmatic) Date: Sun, 23 Oct 2005 01:46:49 -0000 Subject: New User Message-ID: I just downloaded and I think installed python. I am not sure if I did cause it does'nt respond to the commands that the read me file told me to use. Also can someone suggest a trial program I can maybe write for fun? Thanks. From grunar at gmail.com Wed Oct 19 22:18:50 2005 From: grunar at gmail.com (grunar at gmail.com) Date: 19 Oct 2005 19:18:50 -0700 Subject: sqlstring -- a library to build a SELECT statement Message-ID: <1129774730.887128.314960@z14g2000cwz.googlegroups.com> After some thought on what I need in a Python ORM (multiple primary keys, complex joins, case statements etc.), and after having built these libraries for other un-named languages, I decided to start at the bottom. What seems to plague many ORM systems is the syntactic confusion and string-manipulation required to build the SQL Statements. If you want to do a Left Outer Join, support nested functions, and a nested conditional clause, you'd be building more of a string library than an ORM. Let's not even mention syntactical differences between databases, data types, and such. My solution is sqlstring. A single-purpose library: to create SQL statement objects. These objects (such as sqlstring.Select), represent complex SQL Statements, but as Python objects. The benefit is that you can, at run-time, "build" the statement pythonically, without getting bogged down in String Manipulation. The theory is that once in use, things that were complex (string magic) become simpler, and allow the program to worry about higher-level issues. An Example: >>> import sqlstring >>> model = sqlstring.TableFactory() >>> print model.person SELECT person.* FROM [person] person >>> person_smith = model.person \ ** (model.person.first_name == "Smith") >>> print person_smith SELECT person.* FROM [person] person WHERE person.first_name = 'Smith' >>> print person_smith("party_id", "first_name") \ < < model.address ** (\ model.address.party_id == model.person.party_id) SELECT party_id party_id, first_name first_name, address.* FROM [person] person LEFT OUTER JOIN [address] address ON address.party_id = person.party_id WHERE person.first_name = 'Smith' Things can get much more interesting than this, including nested sub-selects (anywhere), conditional groups (and/or groups nested using & and |) and even CASE statements. Some of this stuff has been around for a while (using "magic" objects to build where clauses, etc.). But I'm trying to take it all the way--to a legit Select statement. While still in the early stages, it does work with a great many sql statements, as seen in the test suite. Currently supported are CASE statements, Nested conditional clauses, nested queries and most join types. At this point, I'm interested in getting feedback from the community on several fronts: 1. The Operator Overload model. I've chosen to overload Python's operators to give a short-hand syntax to most of the things you'd want to do with a select statement. The rest are accessable via methods. Currently ** is the "where" operator, // is the "in" operator, % the "like" operator and ^ aliases columns. Other overloads are as you'd expect- + / - * == all result in Expression Objects that dish out the right SQL string. The question is, is the "leap" in syntax to confusing? Is there a cleaner way to do this? (Functions for example) 2. How to best add further sql function support? Adding magic callable objects to columns came to mind, but this has it's own set of issues. I'm leaning towards a magic object in the sqlstring module. For example: sqlstring.F.substring(0, 4, person.first_name) would result in: substring(0, 4, person.first_name). the F object could be put in the local scope for short-hand. 3. I'm undecided on how best to handle database specific overwrites. I want this to be as easy as possible. I'm thinking about subclassing Expressions with a naming scheme on the Sub-Class (such as CaseExpression_oracle). Then the __init__ factory could dish out the right version of the object based on the the requestor. This brings up lots of questions, such as how to support multiple types of databases at the same time. Eventually the library should include all of the basic SQL Statements, including UPDATE, INSERT and CREATE statements. This is mostly for completeness, though. SELECT statements tend to be the most complex. The library can be downloaded at http://betur.net/download.php Any other thoughts or comments are very much appreciated From peter at engcorp.com Sun Oct 23 12:25:04 2005 From: peter at engcorp.com (Peter Hansen) Date: Sun, 23 Oct 2005 12:25:04 -0400 Subject: bsddb version? In-Reply-To: <1130083725.481400.323330@g14g2000cwa.googlegroups.com> References: <1130083725.481400.323330@g14g2000cwa.googlegroups.com> Message-ID: leasun wrote: > Anybody knows which version bsddb is released with py2.3 and py2.4? Is this what you wanted? Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 >>> import bsddb >>> bsddb.__version__ '4.3.0' I'll leave it up to you to do the work to find out what it is on Python2.3... I hope you can manage the effort. ;-) -Peter From my_email_is_posted_on_my_website at munged.invalid Mon Oct 24 09:19:27 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Mon, 24 Oct 2005 13:19:27 GMT Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <86k6g59ke6.fsf@bhuda.mired.org> <5y47f.174197$RW.59989@fe2.news.blueyonder.co.uk> Message-ID: <8qnpl11s9ie8s2pstqja5k5aeikn6tgtu7@4ax.com> On Mon, 24 Oct 2005 12:35:13 GMT, axel at white-eagle.invalid.uk wrote, quoted or indirectly quoted someone who said : >I see that you cannot make a reasoned argument against the fact that >property in the form of houses is taxed in America. And what has his inability to do that to your satisfaction got to do with the price of eggs? -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From beau at superiorss.com Tue Oct 25 13:43:52 2005 From: beau at superiorss.com (techdude27) Date: Tue, 25 Oct 2005 17:43:52 -0000 Subject: JOB: F/T Python Developer, San Francisco, CA Message-ID: JOB: F/T Python Developer, San Francisco, CA This is a full-time position. Contractors need not apply. Local candidates only. Responsibilities: - Implement client requirements in Python using our proprietary workflow and app server technology - Interact with clients to shepherd their projects to a successful conclusion - Enhance solutions with new or extended components in Python or Pyrex and C Experience Desired: - 3 years experience working in a professional software development organization - At least 3 years experience in web development Skills Desired: - Hard-working, motivated and self-reliant - Attention to detail and pride in one's work - Excellent analytical (including data analysis) and design skills - Open-minded and quick to learn new skills - In-depth knowledge of web development - Strong client-side scripting skills (JavaScript, DHTML and CSS) - Python programming skills, or at least some similar scripting language like Perl, Ruby or Tcl/Tk - The ability to write Python extension modules in C, SWIG or Pyrex would be a plus - Experience working in a professional software development organization with CVS Please send resume and salary requirement to beau at superiorss.com Thank you, Beau Gould www.superiorss.com From bulliver at badcomputer.org Mon Oct 24 22:04:47 2005 From: bulliver at badcomputer.org (darren kirby) Date: Mon, 24 Oct 2005 19:04:47 -0700 Subject: [OT] Re: output from external commands In-Reply-To: References: <435C6642.8020504@colannino.org> <200510241425.45538.hancock@anansispaceworks.com> Message-ID: <200510241904.52917.bulliver@badcomputer.org> quoth the Fredrik Lundh: > (using either on the output from glob.glob is just plain silly, of course) Silly? Sure. os.listdir() is more on point. Never said I was the smartest. However, I will defend my post by pointing out that at the time it was the only one that actually included code that did what the OP wanted. Recall I wrote: "If all you want is filenames this will work:" not: "This is how you should do it" And I invite you to prove me wrong ... it does work. As a novice, I do appreciate getting set strait when I code something dumb, but going off about the efficiency of "%s % foo" over "str(foo)" hardly helps the OP, and is not very pertinant to my glob faux pas either. An explanation of why glob is silly would perhaps teach me better than just stating it as fact. It is things like this that make me wary of posting to this list, either to help another, or with my own q's. All I usually want is help with a specific problem, not a critique involving how brain-dead my code is. I'm a beginner, of course my code is going to be brain-dead ;) I thought the idea was "make it work first, then optimize"? In any event, I will refrain from trying to help people here until I get over this silly stage I seem to be stuck in... it just doesn't seem worth it. I am not trying to sound like a whiner here, I just wish you experts would go easy on us novices... -d -- darren kirby :: Part of the problem since 1976 :: http://badcomputer.org "...the number of UNIX installations has grown to 10, with more expected..." - Dennis Ritchie and Ken Thompson, June 1972 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From no.offline.contact.please at nospam.com Sat Oct 15 09:50:44 2005 From: no.offline.contact.please at nospam.com (Rhino) Date: Sat, 15 Oct 2005 09:50:44 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: "Jeroen Wenting" wrote in message news:11l16dst501kjdd at corp.supernews.com... > > >> > >> Q: Microsoft's Operating System is used over 90% of PCs. If that's > >>not monopoly, i don't know what is. > > > > They got where they are by CHEATING. That is why they are evil, not > > because they have a large market share. > > no, they got their by clever marketing and generally having a product that > was easier to use for the average user than anything the competition made > and a lot more powerful than other products created for their main target > market. > > Microsoft isn't evil, they're not a monopoly either. > If they were a monopoly they'd have 100% of the market and there'd be no > other software manufacturers at all. > Prices would be far far higher than they are today, like they were back in > the days before Microsoft started competing with the likes of Ashton Tate > and WordPerfect corporation by offering similar products at 20% the price > (which is the real reason they got to be top dog, they delivered a working > product for a fraction of the price their competition did, and the > competition couldn't drop their prices that much and remain profitable). > > Without Microsoft 90% of us would never have seen a computer more powerful > than a ZX-81 and 90% of the rest of us would never have used only dumb > mainframe terminals. > IBM's prediction that there would be 5 computers (not counting game > computers like the Comodores and Spectrums) by 2000 would likely have come > true. > I'd be VERY surprised if IBM predicted that there would be only 5 COMPUTERS in *2000* - perhaps you mean 5 *manufacturers* of computers? - unless the prediction was made a VERY long time ago. I think you are giving a badly-mangled version of something I saw when I worked at IBM. About 10 years ago, when I was working at IBM, there was an employee newsletter circulated commemorating the death of Thomas J. Watson Jr., a former CEO of IBM. They cited an old interview with him in which he had predicted that the world wide market for computers would be 3 in the next year; in other words, he expected IBM to sell three of their computers in that year. However, he was not making this prediction in or for the year 2000; the interview had taken place just after World War II - 1946 perhaps - and was for the next year. I wasn't born then but, from what I recall about computer history, selling 3 Eniacs (or whatever model they were making that year) isn't too far out of line with what actually happened. Of course, we are talking about a time when computers were absolutely immense, ran on vacuum tubes (the transistor hadn't been invented yet) and filled very large rooms - and yet probably had less computing power than the average microwave oven you can buy today. Only very large companies or national governments would want or need a computer in those days. Everyone else was still using typewriters - which was IBM's bread and butter in those days - for their business needs. Rhino From nothingcanfulfill at gmail.com Tue Oct 4 20:22:36 2005 From: nothingcanfulfill at gmail.com (ncf) Date: 4 Oct 2005 17:22:36 -0700 Subject: wxPython equiv. to tag_configure In-Reply-To: References: <1128456689.100365.196050@g47g2000cwa.googlegroups.com> Message-ID: <1128471756.796040.126670@g14g2000cwa.googlegroups.com> Errm, can you slap me please? :X Either way, thank you soo much :) -Wes From jzgoda at o2.usun.pl Sun Oct 30 15:49:30 2005 From: jzgoda at o2.usun.pl (Jarek Zgoda) Date: Sun, 30 Oct 2005 21:49:30 +0100 Subject: Last.fm Python group Message-ID: I was missing miscellaneous Python group on last.fm, so here it is: http://www.last.fm/group/PythonCode. Enjoy. -- Jarek Zgoda http://jpa.berlios.de/ From mwm at mired.org Thu Oct 13 01:17:45 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 13 Oct 2005 01:17:45 -0400 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <868xx3m2ve.fsf@bhuda.mired.org> <86irw6l1mc.fsf@bhuda.mired.org> Message-ID: <86vf02uhae.fsf@bhuda.mired.org> Roedy Green writes: > On Wed, 12 Oct 2005 21:46:12 GMT, Tim Tyler wrote > or quoted : > >>Viruses can mail out change of address messages to everyone in the >>compromised machine's address book today. >> >>Of course, viruses don't bother doing that - since it's stupid and >>pointless. Except with Roedy's proposal, all the targets correspondents address books would get updated automatically. It's got much the same effect as filling a change of address at the locate post office for someone. It's a nasty practical joke. But much nicer than some of the things that viruses do today. > The key that makes that possible is Microsoft's features for running > self-executing code in emails. That is the problem. It has nothing to > do with formatting or pictures. No, that's what makes email a vector for infection. What makes using the address book - for whatever purpose - possible for viruses is having an API that allows arbitrary code to access it. But you have to have that API - your customers are going to insist that they be able to use their address book from third party applications. These days, viruses don't spread through a single vector; they use mutliple vectors, and will try them all once they've infected a machine. So you may cruse a web site that infects you, and the virus will then mail copies of itself to everyone in your address book, as well as infecting any web servers that may be running on the machine, and probing random IP addresses close to yours, and so on. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From appumail at gmail.com Thu Oct 6 04:48:01 2005 From: appumail at gmail.com (Murugesh) Date: Thu, 06 Oct 2005 14:18:01 +0530 Subject: Help-log in to a web page Message-ID: Hi all, I'm a newbie to python.I need to login to a webpage after supplying usename and password. import urllib sock = urllib.urlopen("http://xop-pc.main.com") htmlSource = sock.read() sock.close() print htmlSource In the above code how can i supply username and password to that URL. Thanks for you time. Thanks Amen. From allisfree at gmail.com Mon Oct 3 05:14:05 2005 From: allisfree at gmail.com (JackPhil) Date: 3 Oct 2005 02:14:05 -0700 Subject: windows service problem Message-ID: <1128330845.762679.66680@f14g2000cwb.googlegroups.com> i code a very simple web server with python, and i want it should run as service on WindowsXP. the problem is i can run the service in debug mode, and it seems works fine(i can connect the server with browser), but when i start the service in the services control panel, i can't connect the server, the server seems not start, and i can't stop the service. any advice? From sybrenUSE at YOURthirdtower.com.imagination Wed Oct 5 12:47:06 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Wed, 5 Oct 2005 18:47:06 +0200 Subject: updating local() References: <1128530014.323801.290360@g47g2000cwa.googlegroups.com> Message-ID: Flavio enlightened us with: > Can anyone tell me why, if the following code works, I should not do > this? > > def fun(a=1,b=2,**args): > > print 'locals:',locals() > locals().update(args) > print locals() Because it's very, very, very insecure. What would happen if someone found a way to call that function? It could replace any name in the locals dictionary, including functions from __builtins__. In other words: probably the whole program could be taken over by other code by just one call to that function. 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 nochiel at gmail.com Fri Oct 14 14:33:53 2005 From: nochiel at gmail.com (yoda) Date: 14 Oct 2005 11:33:53 -0700 Subject: setuptools, ez_setup over http proxy In-Reply-To: <1129276158.313427.325430@g43g2000cwa.googlegroups.com> References: <1129252549.899651.327160@g43g2000cwa.googlegroups.com> <1129262530.512786.169430@z14g2000cwz.googlegroups.com> <1129276158.313427.325430@g43g2000cwa.googlegroups.com> Message-ID: <1129314833.751372.243480@z14g2000cwz.googlegroups.com> It appears that it was my proxy config that was flakey. setup tools works like a charm. :$ From steve at REMOVEMEcyber.com.au Sun Oct 30 21:08:27 2005 From: steve at REMOVEMEcyber.com.au (Steven D'Aprano) Date: Mon, 31 Oct 2005 13:08:27 +1100 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <87ek65kbw5.fsf@lucien.dreaming> <1h57cu1.1jywbjibu87obN%aleaxit@yahoo.com> <1h58jkz.1byi9q5qwo1owN%aleaxit@yahoo.com> <1h598gf.y63d2z1ig1x93N%aleaxit@yahoo.com> Message-ID: <43657C9B.7060303@REMOVEMEcyber.com.au> Alex Martelli wrote: > Steven D'Aprano wrote: > ... > >>>No. But if you get a totally unexpected exception, >> >>I'm more concerned about getting an expected exception -- or more >>accurately, *missing* an expected exception. Matching on Exception is too >>high. EOFError will probably need to be handled separately, since it often >>isn't an error at all, just a change of state. IOError is the bad one. >>What else can go wrong? > > > Lots of things, but not ones you should WISH your application to > survive. [snip] > Sure, that's why you catch IOError, which covers these _expected_ cases > (or, if you want to be a bit wider, maybe OSError) AND check its errno > attribute to ensure you haven't mistakenly caught something you did NOT > in fact expect (and thus can't really handle), to use a bare raise > statement to re-raise the "accidentally caught" exception if needed. Ah, that's precisely the answer I was looking for: IOError and OSError, and then check the errno. Excellent: thanks for that. > But if something goes wrong that you had NOT anticipated, just log as > much info as you can for the postmortem, give nice diagnostics to the > user if you wish, and do NOT keep processing -- and for these > diagnostic-only purposes, use sys.excepthook, not a slew of try/except > all over your application making it crufty and unmaintainable. Agreed -- I never intended people to draw the conclusion that every line, or even every logical block of lines, should be wrapped in try/except. -- Steven. From davids at webmaster.com Tue Oct 25 14:55:17 2005 From: davids at webmaster.com (David Schwartz) Date: Tue, 25 Oct 2005 11:55:17 -0700 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> <435e786f$0$11061$e4fe514c@news.xs4all.nl> Message-ID: "Martin P. Hellwig" wrote in message news:435e786f$0$11061$e4fe514c at news.xs4all.nl... > Not Bill Gates wrote: >> steve at REMOVETHIScyber.com.au wrote... >>> On Tue, 25 Oct 2005 15:35:47 +0000, Not Bill Gates wrote: >>> >>>> Heck, I dunno. Like you, I don't even really care all that much. >>> You don't care that innovation in desktop software has been crippled by >>> the actions of the monopoly player Microsoft? >> You need to first prove innovation in desktop software has been crippled, >> don't you? > How about their "java" implementation between 1998 and 2004? > Sure killed the _easier_ write once run everywhere mantra, of course they > where not alone in the killing, SUN helped a great deal. It's easy to point to things you think are mistakes and claim that if you had been in charge of the world, those mistakes would not have been made. If you are trying to balance completely different possible paths the universe might have taken, you need to make sure to include everything on both sides, and that's really really hard to do. Perhaps the desktop software is good enough that how much better it would have been wouldn't make much difference. And perhaps the lack of competition steered the innovators into other fields where their innovations made huge differences. Perhaps not -- perhaps the desktop software we would have had in a more competitive market would have made other people's lives majorly better. Who knows? I don't think it's possible or sensible to try to have a reckoning of this type. There are so many variables and unpredictable possibilities. DS From nyamatongwe+thunder at gmail.com Fri Oct 28 05:30:36 2005 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Fri, 28 Oct 2005 09:30:36 GMT Subject: Spambayes modifications with web services In-Reply-To: <1130486425.402338.123720@g49g2000cwa.googlegroups.com> References: <1130486425.402338.123720@g49g2000cwa.googlegroups.com> Message-ID: <0dm8f.2917$Hj2.1592@news-server.bigpond.net.au> benmorganpowell: > So, as a web programmer and someone who specialises in getting good > results on Google, I realised that I could simply post every spammer > website on a Google optimized page, which if searched for on Google > would return something like: > > "WARNING: DO NOT BUY FROM THIS WEBSITE. THE SPAMMER IS A RUSSIAN MAFIA > CROOK WHO WILL STEAL YOUR MONEY." Spam may also contain the addresses of non-spamming businesses, sometimes in an effort to increase the apparent legitimacy of the spam. Attacking all of the web sites in spam will cost these businesses while having little effect on spammers who use temporary domains which may be cheaply abandoned. It also gives another attack vector for those criminals that attempt to extort money from web sites by threatening to damage them. If you want to take action against spammers, first think through all the potential consequences of your actions. Neil From news at NOwillmcguganSPAM.com Thu Oct 13 09:14:19 2005 From: news at NOwillmcguganSPAM.com (Will McGugan) Date: Thu, 13 Oct 2005 14:14:19 +0100 Subject: wxPython question In-Reply-To: <1129207833.953525.266880@f14g2000cwb.googlegroups.com> References: <1129207833.953525.266880@f14g2000cwb.googlegroups.com> Message-ID: <434e5dac$0$25428$db0fefd9@news.zen.co.uk> vpr wrote: > Hi > > Does anyone have some example code to create a wx dialog that apears > off screen on the bottom right hand corner and slides up into the > screen ? > Andrea Gavana does.. http://xoomer.virgilio.it/infinity77/eng/freeware.html#toasterbox Will McGugan -- http://www.willmcgugan.com "".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in "jvyy*jvyyzpthtna^pbz") From deets at nospam.web.de Tue Oct 11 04:47:31 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 11 Oct 2005 10:47:31 +0200 Subject: Question about StringIO In-Reply-To: <1129015844.347274.145840@g44g2000cwa.googlegroups.com> References: <1128849763.117104.34370@f14g2000cwb.googlegroups.com> <3qsacmFftrn5U1@uni-berlin.de> <1128940255.694551.318760@g14g2000cwa.googlegroups.com> <1129015844.347274.145840@g44g2000cwa.googlegroups.com> Message-ID: <3r1ch4FgbogbU1@uni-berlin.de> > Thanks for this pointer. I have read it, but I don't think it applies > to my situation, as it talks about 'reading' from the child's stdout > while the child is 'writing' to stderr. But that is exactly the point: the psql blocks because you don't read away the buffered data. Start a thread, read that stdout/stderr and see if things go smoothly. Diez From mhardas at cs.kent.edu Thu Oct 13 11:56:23 2005 From: mhardas at cs.kent.edu (mhardas at cs.kent.edu) Date: Thu, 13 Oct 2005 11:56:23 -0400 (EDT) Subject: ImportError: No module named dbm Message-ID: <2229.131.123.36.10.1129218983.squirrel@webmail.cs.kent.edu> Hi all, Iam trying to get 'cvs2svn' to get to work on a Trustix Linux machine. However is suspect that no dbm is installed because running cvs2svn gives the following error: ERROR: your installation of Python does not contain a suitable DBM module -- cvs2svn cannot continue. See http://python.org/doc/current/lib/module-anydbm.html to solve. So I ran test for the dbm installation and got the following, root at drbn /usr/local/lib/python2.3/test# python test_dbm.py Traceback (most recent call last): File "test_dbm.py", line 7, in ? import dbm ImportError: No module named dbm Can you tell me how do I go about getting the dbm module and install it.?? Thanks again. Manas. From grante at visi.com Tue Oct 4 14:22:15 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 04 Oct 2005 18:22:15 -0000 Subject: closing sockets References: Message-ID: <11k5i2ns09mg0f@corp.supernews.com> On 2005-10-04, Mohammed Smadi wrote: > hi; > > i am executing program whcih uses a tcp socket. At the end of the program > i do s.close() where s is my socket. > > when i try to run the program again right away i get the following error > Traceback (most recent call last): > File "asterisk_login.py", line 14, in ? > s.bind(("", hp_port)) # do some error checking > File "", line 1, in bind > socket.error: (98, 'Address already in use') > > how can i get around that http://www.google.com/search?hl=en&q=socket.error%3A+%2898%2C+%27Address+already+in+use%27%29&btnG=Google+Search The first hit has this link which explains it very well: http://hea-www.harvard.edu/~fine/Tech/addrinuse.html -- Grant Edwards grante Yow! I want to kill at everyone here with a cute visi.com colorful Hydrogen Bomb!! From codecraig at gmail.com Mon Oct 24 07:49:12 2005 From: codecraig at gmail.com (jas) Date: 24 Oct 2005 04:49:12 -0700 Subject: Redirect os.system output In-Reply-To: <43596c70$1_3@newspeer2.tds.net> References: <1129927486.854143.169670@g49g2000cwa.googlegroups.com> <43596c70$1_3@newspeer2.tds.net> Message-ID: <1130154552.795209.25830@g43g2000cwa.googlegroups.com> Any other ideas? or examples of using subprocess to do what I was asking? Kent Johnson wrote: > jas wrote: > > I would like to redirect the output from os.system to a variable, but > > am having trouble. I tried using os.popen(..).read() ...but that > > doesn't give me exactly what i want. > > Here is an example using subprocess: > http://groups.google.com/group/comp.lang.python/msg/9fa3a3c287e8e2a3?hl=en& > > Kent > > > > > ..this is windows by the way. > > > > For example: > > tmp = os.popen("hostname").read() > > > > ...works as expected. > > > > however, > > > > tmp = os.popen("cmd").read() > > ...i would like to have access to the cmd process...i.e. enter commands > > like a normal command line. os.system() allows this, but i dont want > > output to the screen..i wanna store it to a variable. then send > > content of variable elsewhere, receive more input and submit it. > > almost emulate the windows command prompt. > > > > any ideas? > > From steve at holdenweb.com Thu Oct 6 09:15:32 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 06 Oct 2005 14:15:32 +0100 Subject: updating local() In-Reply-To: References: <1128530014.323801.290360@g47g2000cwa.googlegroups.com> <1128603314.197733.119160@g47g2000cwa.googlegroups.com> Message-ID: Richard Brodie wrote: > "Flavio" wrote in message > news:1128603314.197733.119160 at g47g2000cwa.googlegroups.com... > > >>Now what would you do if you wanted to pass a lot of variables (like a >>thousand) to a function and did not wanted the declare them in the >>function header? > > > I'd lie down until I felt better. > > Or alternatively put them in a 1,000-element list. Just as a matter of interest, what on *earth* is the use case for a function with a thousand arguments? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From ronpro at cox.net Tue Oct 18 22:30:33 2005 From: ronpro at cox.net (Ron Provost) Date: Tue, 18 Oct 2005 22:30:33 -0400 Subject: Tkinter or Python issue? Message-ID: <98i5f.3686$vS1.1306@dukeread03> Hello, I'm using python 2.4.2 on Win XP Pro. I'm trying to understand a behavior I'm seeing in some Tkinter code I have. I've reduced my question to a small piece of code: #####BEGIN CODE ################# import Tkinter as Tk import tkFont sampleText = """Here is a test string. This is more text Here is a second line of text. How much more can I type. I can't think of anything else to type. """ root = Tk.Tk( ) t = Tk.Text( root ) t.pack( ) t.insert( Tk.END, sampleText ) t.tag_config( 'AB', font=tkFont.Font( family='ariel', size=24, weight=tkFont.BOLD ) ) t.tag_config( 'TBU', font=tkFont.Font( family='times', size=10, weight=tkFont.BOLD, underline=1 ) ) t.tag_add( 'AB', '1.8', '1.15' ) t.tag_add( 'TBU', '2.10', '2.30' ) root.mainloop( ) ################# #######END CODE Now when I run this I expect to see a small bit of the sampleText in ariel bold and another bit in times bold underline, instead I see both bits in the later style. Interestingly, if I create the Font objects before calling t.tag_config() (i.e. replace the two t.tag_config( ) lines with the following): f1 = font=tkFont.Font( family='ariel', size=24, weight=tkFont.BOLD ) f2 = font=tkFont.Font( family='times', size=10, weight=tkFont.BOLD, underline=1 ) t.tag_config( 'AB', font=f1 ) t.tag_config( 'TBU', font=f2 ) In rerunning the code, I see each bit of text now styled differently. This is the behavior that I both expect and want. Does anybody know why the two bits of code result in different behavior? Is it a Python thing or a Tkinter thing? Thanks for your feedback. Ron From jr2075 at columbia.edu Sat Oct 1 19:17:39 2005 From: jr2075 at columbia.edu (Jesse Rosenthal) Date: Sat, 01 Oct 2005 19:17:39 -0400 Subject: Background process for ssh port forwarding Message-ID: Hello all, I'm writing a script which will backup data from my machine to a server using rsync. It checks to see if I am on the local network. If I am, it runs rsync over ssh to 192.168.2.6 using the pexpect module to log in. That's the easy part. Now, when I'm not on the local network, I first want to open up an ssh connection to do port forwarding, so something like this: def hostforward(): #This is based on the assumption that the passfile is the gnus #authinfo file, or has a similar format... f = open(PASS_FILE, "r") f_list = f.read().split(' ') f.close() #Now, we get the entry after "password" (be slicker to make it a #dictionary, but maybe wouldn't work as well). pass_index = f_list.index('password') + 1 forwardpass = f_list[pass_index] #now we connect command = 'ssh -l %s -L 2022:%s:22 %s' % \ (login, my_server, forwarding_server) connection = pexpect.spawn(command) connection.expect('.*assword:') connection.sendline(forwardpass) If I end this with 'connection.interact()', I will end up logged in to the forwarding server. But what I really want is to go on and run rsync to localhost port 2022, which will forward to my_server port 22. So, how can I put the ssh connection I set up in hostforward() in the background? I need to make sure that connection is made before I can run the rsync command. I've looked at threading, but that seems excessive. There must be an easier way. Whatever I do, though, I'll need to use pexpect to spawn the processes, since I'll need to log in to ssh servers with a password. Thanks for any help. --Jesse From howardrh at westerncom.net Mon Oct 10 13:55:51 2005 From: howardrh at westerncom.net (hrh1818) Date: 10 Oct 2005 10:55:51 -0700 Subject: Learning Python References: <7e6dnQAA36FTBtfeRVn-rg@rogers.com> Message-ID: <1128966951.012055.315970@g49g2000cwa.googlegroups.com> A good introduction to Python is the recently published book "Beginning Python from Novice to Pro". It provides a quick introduction to Python, skips a lot of the details hard core programmers expect, and has very few samples of difficult to understand lines of code that can easily discourage the novice programmer. Paul DiRezze wrote: > I'm spending the next two weeks off and I'm looking to take a crack at > learning how to program in Python. Here's a list of the places I've > bookmarked: > > http://www.python.org/doc/ and more specifically > http://wiki.python.org/moin/ > http://wiki.python.org/moin/BeginnersGuide > http://www.python.org/doc/Intros.html > http://www.python.org/topics/ > > I'm looking for additional resources (links, names of books, > whatever...) that you think may help me out. > > I'm a hobby programmer using mostly BASIC(s) and some Java. I know > procedural programming and I know what encapsulation, inheritance and > polymorphism are but I have very little experience in using them as I've > written just a few Java programs (i.e., I guess I could use a primer in > OO programming). > > Any ideas? > > paul From alevinci at cheapnet.it Mon Oct 17 16:05:30 2005 From: alevinci at cheapnet.it (Vinci) Date: 17 Oct 2005 13:05:30 -0700 Subject: Xml document writing Message-ID: <1129579530.889814.290050@z14g2000cwz.googlegroups.com> Hi, I have to append a child under a node of a Xml document: I tried to create both a text and a node element, but the child doesn't figure in the Xml document. Can anyone help me? Thank you very much! :) -- Vinci From skip at pobox.com Thu Oct 13 13:08:04 2005 From: skip at pobox.com (skip at pobox.com) Date: Thu, 13 Oct 2005 12:08:04 -0500 Subject: Python's garbage collection was Re: Python reliability In-Reply-To: <3r6i0uFi3qb8U2@uni-berlin.de> References: <3r6i0uFi3qb8U2@uni-berlin.de> Message-ID: <17230.38004.290177.179818@montanaro.dyndns.org> Diez> AFAIK some LISPs do a similar trick to carry int values on Diez> cons-cells. And by this tehy reduce integer precision to 28 bit Diez> or something. Surely _not_ going to pass a regression test suite Diez> :) I'm pretty sure this was tried a few years ago w/ Python. I don't recall the results, but I'm pretty sure they weren't good enough. had they been we could just look at the source. Folks, most common GC schemes have been tried as experiments over the years. None have succeeeded, for various reasons. I think one of the main reasons is that Python has to "play nice" with external libraries, many of which weren't written with GC beyond malloc and free in mind. Here are some pointers interested readers might want to check out: Tagged integers: http://mail.python.org/pipermail/python-dev/2004-July/046139.html Boehm GC: http://mail.python.org/pipermail/python-dev/2005-January/051370.html http://www.python.org/doc/faq/general.html#how-does-python-manage-memory http://wiki.python.org/moin/CodingProjectIdeas/PythonGarbageCollected Miscellaneous: http://mail.python.org/pipermail/python-dev/2002-June/026032.html http://mail.python.org/pipermail/python-dev/2003-November/040299.html And lest anyone here think they were the first to suggest getting rid of reference counting in Python: http://www.python.org/search/hypermail/python-1993/0554.html I wouldn't be surprised if there were even earlier suggestions... Skip From davids at webmaster.com Thu Oct 20 06:28:00 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 20 Oct 2005 03:28:00 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <33sj23-6om.ln1@news.it.uc3m.es> Message-ID: "Peter T. Breuer" wrote in message news:33sj23-6om.ln1 at news.it.uc3m.es... > Not if they abuse a monopoly position in doing so, which is where we > started. In other words, what they did was wrong because it was them who did it. It is fine if anyone else does, just not fine if Microsoft does it. And what is it they have a monopoly in again? Operating systems? What about OSX? x86 operating systems? What about Linux? Oh yeah, they have a monopoly in "desktop operating systems for x86-based computers". Can you cite any rational reason whatsoever for defining the market so ridiculously narrowly? Of course not. There is no rational way Microsoft could have expected the irrational and nonsensical basis for this argument. DS From peter at commonlawgov.org Sat Oct 1 22:08:54 2005 From: peter at commonlawgov.org (Peter) Date: Sat, 01 Oct 2005 19:08:54 -0700 Subject: Class Help In-Reply-To: References: Message-ID: <433F4136.4060307@commonlawgov.org> Ivan Shevanski wrote: >To continue with my previous problems, now I'm trying out classes. But I >have a problem (which I bet is easily solveable) that I really don't get. >The numerous tutorials I've looked at just confsed me.For intance: > > > >>>>class Xyz: >>>> >>>> >... def y(self): >... q = 2 >... > > >>>>Xyz.y() >>>> >>>> >Traceback (most recent call last): > File "", line 1, in ? >TypeError: unbound method y() must be called with Xyz instance as first >argument >(got nothing instead) > > >So. . .What do I have to do? I know this is an extremley noob question but I >think maybe if a person explained it to me I would finally get it =/ > > > You have to create an instance of the class before it can be called. Ex: class foo: def bar(self): print "Hello, World!" foo().bar() This is because foo is a reference to a classobj, however, when you call the class, it becomes an instance. Ex: >>> type(foo) >>> type(foo()) When an instance is created it tells Python to pass the instance as the first argument (self). Otherwise it gives it None or something similer. (Note that im not 100% sure about why it does'nt work, im just guessing from the way it _seems_ to work. I have read no documentation on this. If you want it to work before you create an instance, then you can do that with class foo: @classmethod def bar(self): print "Hello, World!" or the older (but exactly the same): class foo: def bar(self): print "Hello, World!" bar = classmethod(bar) >thanks in advance, > >-Ivan > > > HTH, Peter From ron at vnetworx.net Fri Oct 14 14:33:46 2005 From: ron at vnetworx.net (Ron Guerin) Date: Fri, 14 Oct 2005 14:33:46 -0400 Subject: NYLUG meeting: The Python Object Model with Alex Martelli & Google(open bar and food!) In-Reply-To: <1129312792.c8c0370da34fd63e5cace1fe6133aff9@teranews> References: <1129312792.c8c0370da34fd63e5cace1fe6133aff9@teranews> Message-ID: <434FFA0A.4050400@vnetworx.net> George Sakkis wrote: > > > What date is it ? It isn't mentioned at the web site either. > Sorry about that, actually it is on the web site, right at the top in the blue band. October 26, 2005 6:00pm - 10:00pm Hope to see you there. - Ron From john at castleamber.com Sun Oct 16 23:30:01 2005 From: john at castleamber.com (John Bokma) Date: 17 Oct 2005 03:30:01 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: "Mike Schilling" wrote: > "John Bokma" wrote in message >> No, it's a recommendation, an advise, nothing else. Otherwise they >> would call it a standard. Why do you think W3C calls it >> recommendations? Because it are no standards. There is an ISO HTML >> standard though, but when people babble about HTML standards they >> talk about W3C *recommendations*. > > In that sense there are no standards in software. The ISO C++ > "standard" and the XML "recommendation" have the same amount of force > behind them. Yup, but ISO C++ is a standard, and XML is a recommendation. For some people that *does* matter. Hence there is ISO HTML and there is a HTML 4.01 recommendation. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From UrsusMaximus at gmail.com Thu Oct 20 18:06:59 2005 From: UrsusMaximus at gmail.com (UrsusMaximus at gmail.com) Date: 20 Oct 2005 15:06:59 -0700 Subject: Popularity of blogging tools used by python programmers In-Reply-To: References: Message-ID: <1129846019.329027.119980@o13g2000cwo.googlegroups.com> You might also consider Firedrop2, (see http://www.voidspace.org.uk/python/weblog/arch_d7_2005_10_15.shtml#e119 ) , a client side blog creation and content management system created by Hans Nowak and now being enhnaced and maintained by Michael Foord. Its very pythonic and extensable. Ron Stephens Python411 podcast sereis http://www.awaretek.com/python/index.html From peter at engcorp.com Tue Oct 11 07:16:24 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 11 Oct 2005 07:16:24 -0400 Subject: Send password over TCP connection In-Reply-To: References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> <1128979760.251637.316480@o13g2000cwo.googlegroups.com> Message-ID: Laszlo Zsolt Nagy wrote: > Peter Hansen wrote: >> Ignoring all the other issues, any solution which actually requires >> the password to be stored on the server is a bad solution. >> Administrators should not have access to user passwords, and in >> addition users should not be put in the position of having to trust >> your server-side security to keep their passwords (which they might >> have used on other systems) from being grabbed by hackers. >> > Users will always need to trust in the server. The authentication > process ensures that the > client is really talking with the desired server and vice versa. But > even if you know that you > are talking to the right server, you need to trust in the server. The > administrator of the server > has access to all data. Possibly other persons and softwares too. > Passwords are not different from this point of view. If you're saying that people have no choice but to trust that their passwords, stored in the clear on the server of some idiot who didn't know better, are safe from casual administrator observation and safe from hackers stealing the password file, then you shouldn't be allowed anywhere near a supposedly secure system... If you're just saying that one has to trust that the server you are talking to at this instant in time is really the one you thought it was, then that's an entirely different issue and I agree. But storing passwords in the clear, thus allowing administrators full access to users' passwords, is absolutely *not* necessary. That's my point, regardless of what other issues this thread spawns. If the OP implements strictly the sequence he mentioned in the posting to which I was replying, he'll be the aforementioned idiot... -Peter From gandalf at designaproduct.biz Mon Oct 17 03:28:46 2005 From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy) Date: Mon, 17 Oct 2005 09:28:46 +0200 Subject: Outdated documentation Message-ID: <435352AE.7030105@designaproduct.biz> Hi All, This is from the documentation of the dbhash module: Returns the key next key/value pair in a database traversal. The following code prints every key in the database |db|, without having to create a list in memory that contains them all: print db.first() for i in xrange(1, len(db)): print db.next() Apparently, it is different for gdbm: k = db.firstkey() while k != None: print k k = db.nextkey(k) I think both of them is outdated. This should be: for key,value in db.iteritems(): print key,value Is this the good place to post? Les From akbarhome at gmail.com Sun Oct 9 05:12:09 2005 From: akbarhome at gmail.com (akbarhome at gmail.com) Date: 9 Oct 2005 02:12:09 -0700 Subject: "import socket" error Message-ID: <1128849129.254683.155420@g43g2000cwa.googlegroups.com> Hi, I am following this tutorial https://www14.software.ibm.com/webapp/iwm/web/preLogin.do?source=dw-linux-pysocks&S_TACT=105AGX59&S_CMP=GR&ca=dgr-lnxw07PythonSockets ( free reg. req. ) The article told me to do this: [camus]$ python Python 2.4 (#1, Feb 20 2005, 11:25:45) [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import socket >>> socket.gethostbyname('www.ibm.com') '129.42.19.99' >>> When I try it, I get this error: >>> import socket Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.4/socket.py", line 1, in ? # Wrapper module for _socket, providing some additional facilities File "/usr/lib/python2.4/SocketServer.py", line 274, in ? class TCPServer(BaseServer): File "/usr/lib/python2.4/SocketServer.py", line 317, in TCPServer address_family = socket.AF_INET AttributeError: 'module' object has no attribute 'AF_INET' >>> Why? Thank you. From jepler at unpythonic.net Mon Oct 3 17:54:06 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Mon, 3 Oct 2005 16:54:06 -0500 Subject: Exception raising, and performance implications. In-Reply-To: <1128375280.034852.119910@o13g2000cwo.googlegroups.com> References: <1128375280.034852.119910@o13g2000cwo.googlegroups.com> Message-ID: <20051003215406.GA7081@unpythonic.net> As for performance, you'll need to benchmark it. However, I think the functionality you're asking for is available as inspect.currentframe(), and if the implementation is in "C" it may have a tiny performance advantage over the Python version. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From ptmcg at austin.rr._bogus_.com Sun Oct 30 23:41:34 2005 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 31 Oct 2005 04:41:34 GMT Subject: need start point for getting html info from web References: <1130724071.688187.59230@g47g2000cwa.googlegroups.com> Message-ID: <2gh9f.55954$GQ.22073@tornado.texas.rr.com> wrote in message news:1130724071.688187.59230 at g47g2000cwa.googlegroups.com... > hey there, > > i have a small app that i am going to need to get information from a > few tables on different websites. i have looked at urllib and httplib. > the sites i need to get data from mostly have this data in tables. So > that, i think would make it easier. Anyone suggest a good starting > point for me to find out how to do this, or know of a link to a good > how-to? > thanks, > sk > pyparsing comes with a simple HTML scraper example for extracting the NIST NTP servers from an HTML table. pyparsing is also fairly tolerant of "unclean" HTML. Download pyparsing at http://pyparsing.sourceforge.net. -- Paul From deets at nospam.web.de Thu Oct 13 05:54:00 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 13 Oct 2005 11:54:00 +0200 Subject: Setdefault bypasses __setitem__ In-Reply-To: References: <3r6hsnFi3qb8U1@uni-berlin.de> Message-ID: <3r6p5oFhvtg1U1@uni-berlin.de> > The implementation is certainly a design decision. setdefault() could be > implemented in terms of __set/getitem__() as > > def setdefault(self, key, value=None): > try: > return self[key] > except KeyError: > self[key] = value > return self[key] > > I guess it's not done for performance reasons. Nope. What if you changed your default value? Then you'd have to update the whole dictionary - but without keeping track of the keys you placed the default value under that isn't possible. Which strikes me as more-than-marginal overhead - without any advantage (as using __setitem__ for the default value isn't something I consider being a missing feature...) Diez From pas at despam Wed Oct 12 16:16:47 2005 From: pas at despam (gg) Date: Wed, 12 Oct 2005 22:16:47 +0200 Subject: crosswords helper program In-Reply-To: <6ugv13-h73.ln1@rogers.com> References: <434cd0b3$0$5378$8fcfb975@news.wanadoo.fr> <6ugv13-h73.ln1@rogers.com> Message-ID: <434d6f23$0$1733$8fcfb975@news.wanadoo.fr> Chris F.A. Johnson a ?crit : > On 2005-10-12, gg wrote: > >>I plan to write a program in Python in order to help me doing >>crosswords, I was wondering if such a program already existed. >> >>Basically it will get the number of letters of the word (5, 10, 12...) >>then the letters known (B in second letter, E in 5th letter...) and then >>search in a dictionary the words matching this criteria > > > import os > pattern = "B...E.." > wordfile = "/usr/share/dict/words" > cmd = "grep -i '\<" + pattern + "\>' " + wordfile > os.system( cmd ) > thanks to all, that should do the trick From grante at visi.com Tue Oct 4 16:29:13 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 04 Oct 2005 20:29:13 -0000 Subject: how to get any available port References: <1128456405.664869.170530@g47g2000cwa.googlegroups.com> Message-ID: <11k5pgpp19v0ec@corp.supernews.com> On 2005-10-04, ncf wrote: > Hmm...perhaps he is trying to do a transfer thing like many chat > programs do. Instead of sending large files across a server, you > "Direct Connect" and send the file directly. :shrugs: So how does that require binding the client end of a TCP connection? -- Grant Edwards grante Yow! I want you to at MEMORIZE the collected visi.com poems of EDNA ST VINCENT MILLAY... BACKWARDS!! From percivall at gmail.com Mon Oct 24 16:57:30 2005 From: percivall at gmail.com (Simon Percivall) Date: 24 Oct 2005 13:57:30 -0700 Subject: Simple server/client application In-Reply-To: <1130184666.541928.133350@z14g2000cwz.googlegroups.com> References: <1130184666.541928.133350@z14g2000cwz.googlegroups.com> Message-ID: <1130187450.794254.60660@z14g2000cwz.googlegroups.com> You're calling the grid() method on the Entry object you're instanciating. Are you sure that the grid() method returns the Entry object so that you're actually binding it to self.myAddress? From fredrik at pythonware.com Sun Oct 9 08:08:10 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 9 Oct 2005 14:08:10 +0200 Subject: assigning in nested functions References: <4349056D.1060805@vlakosim.com> Message-ID: "jena" wrote: > I have code > > # BEGIN CODE > def test(): > def x(): > print a > a=2 # *** > > a=1 > x() > print a > > test() > # END CODE > > This code fails (on statement print a in def x), if I omit line marked > ***, it works (it prints 1\n1\n). It look like when I assign variable in > nested function, I cannot access variable in container function. > I need to assign variable in container function, is any way to do this? no. see "Rebinding names in enclosing scopes" in the design document for a discussion (and a workaround): http://www.python.org/peps/pep-0227.html From timr at probo.com Sat Oct 1 21:38:22 2005 From: timr at probo.com (Tim Roberts) Date: Sun, 02 Oct 2005 01:38:22 GMT Subject: PyWin SendMessage References: <7jczvrb5.fsf@python.net> Message-ID: Gonzalo Monz?n wrote: > >Hi Gerd, > >I'm not really sure of, but I think you must use a message value in >range of WM_USER or WM_APP so this fact maybe let the receiver window >getting bad data... No. WM_COPYDATA is designed specifically for his use case -- interprocess communication. The WM_USER range is only if you are inventing a custom message for some new purpose. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From steve at REMOVETHIScyber.com.au Tue Oct 25 11:43:13 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Wed, 26 Oct 2005 01:43:13 +1000 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: On Tue, 25 Oct 2005 09:56:28 -0500, joe wrote: > Yes, I know, they can do whatever they want, it's not a crime, > etc. However when they use their market position to disallow > competition, it sounds to me like they're worried about something, and > trying to squelch it. But that's the whole point: they *can't* do whatever they want, and certain behaviours *are* crimes. Just because Microsoft executives wear business suits instead of torn jeans or dirty sweatshirts doesn't make them beyond the law. -- Steven. From grante at visi.com Thu Oct 20 10:36:16 2005 From: grante at visi.com (Grant Edwards) Date: Thu, 20 Oct 2005 14:36:16 -0000 Subject: Set an environment variable References: <43573022$0$155$edfadb0f@dread16.news.tele.dk> Message-ID: <11lfar07s5lbk4c@corp.supernews.com> On 2005-10-20, Christian wrote: > How do I export an environment variable in a .py script? http://www.python.org/doc/current/lib/os-procinfo.html#l2h-1548 -- Grant Edwards grante Yow! My BIOLOGICAL ALARM at CLOCK just went off... It visi.com has noiseless DOZE FUNCTION and full kitchen!! From timr at probo.com Sat Oct 29 14:34:49 2005 From: timr at probo.com (Tim Roberts) Date: Sat, 29 Oct 2005 18:34:49 GMT Subject: Microsoft Hatred FAQ References: <4ua533-60t.ln1@news.it.uc3m.es> <7xwtjz3jc9.fsf@ruckus.brouhaha.com> <7xwtjzcyxo.fsf@ruckus.brouhaha.com> <7xbr1b74rf.fsf@ruckus.brouhaha.com> <7xhdb35ghc.fsf@ruckus.brouhaha.com> Message-ID: "David Schwartz" wrote: >Paul Rubin wrote: > >> "David Schwartz" writes: > >>> To call it an "established legal fact" is to grossly distort the >>> circumstances under which it was determined and upheld. > >> Who is paying you to post such nonsense? > > That's basically slander. Slander is spoken. When it's written down like this, it's libel. Slander/spoken start with S, libel/literature start with L. Normally, I would never post such a trivial correction, but I thought it was quite appropriate to throw yet another completely useless fact into this completely useless thread, which was started by a completely useless troll. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From skip at pobox.com Thu Oct 27 16:42:11 2005 From: skip at pobox.com (skip at pobox.com) Date: Thu, 27 Oct 2005 15:42:11 -0500 Subject: How to replace all None values with the string "Null" in a dictionary In-Reply-To: <1130444785.353905.85380@g47g2000cwa.googlegroups.com> References: <1130444785.353905.85380@g47g2000cwa.googlegroups.com> Message-ID: <17249.15267.512151.986415@montanaro.dyndns.org> Daniel> How can I replace all None values with the string 'Null' in a Daniel> dictionary? a = {'item1': 45, 'item2': None} for key in a: if a[key] is None: a[key] = "Null" Skip From sybrenUSE at YOURthirdtower.com.imagination Thu Oct 6 02:23:18 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Thu, 6 Oct 2005 08:23:18 +0200 Subject: updating local() References: Message-ID: Jp Calderone enlightened us with: > If I can call functions in your process space, I've already taken > over your whole program. That's true for standalone programs, but not for things like web applications, RPC calls etc. 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 nephish at xit.net Tue Oct 4 10:25:51 2005 From: nephish at xit.net (nephish at xit.net) Date: 4 Oct 2005 07:25:51 -0700 Subject: question about smtplib In-Reply-To: References: <1128366567.887891.267520@g43g2000cwa.googlegroups.com> <1128380307.865252.289510@f14g2000cwb.googlegroups.com> <1494k1pvqvo9lg21q8bhi9qrgmc2ftl5kn@4ax.com> Message-ID: <1128435951.216282.276350@z14g2000cwz.googlegroups.com> thanks for all the help, got it working ok now, connecting once, sending many. thanks for the link too. cheers, sk From jabel at plus.net Tue Oct 25 05:04:52 2005 From: jabel at plus.net (John Abel) Date: Tue, 25 Oct 2005 10:04:52 +0100 Subject: Python/Apache Oddness On OSX In-Reply-To: <1130196040.005404.263530@g43g2000cwa.googlegroups.com> References: <1130196040.005404.263530@g43g2000cwa.googlegroups.com> Message-ID: <435DF534.3030906@plus.net> grahamd at dscpl.com.au wrote: >John Abel wrote: > > >>Hi, >> >>I'm running Python 2.3.5/2.4.2 on OSX 10.4.2, and am trying to run CGI >>scripts using the builtin Apache. For ease, I've symlinked my custom >>modules into the /Library/Python/2.3/site-packages directory, and they >>import OK via command line python. However, when I perform the import >>from a cgi script, python fails to find the module. It is definately >>something to do with the symlink, as the CGI works OK if I copy the >>directory into site-packages. Is there some oddness with Python/Apache >>and symlink imports? >> >>Any pointers would be most useful. >> >> > >If running OS supplied Apache, it runs as the user "www". Because this >isn't you or root, check that the directory your symlink points at is >accessible to others as well as any directories above it back up to the >root directory. If it isn't accessible, the user Apache runs as will >not >be able to find and use the files. When you are copying the directory >you are possibly giving it read access for others in the process and >that is why it works then. > >Graham > > > Yup, that's the problem. Just got to figure out OSX's permissions, now. Thank you! J From john at castleamber.com Sun Oct 16 23:27:21 2005 From: john at castleamber.com (John Bokma) Date: 17 Oct 2005 03:27:21 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: Roel Schroeven wrote: > John Bokma wrote: >> Roel Schroeven wrote: >> >>>John Bokma wrote: >> >>>>web based applications that work with any browser make OS irrelevant >>>>-> not true, since for OpenOffice it doesn't matter which Linux >>>>distribution one runs (or even if it's Linux), yet people seem to >>>>make a point of which distribution they use. >>> >>>You make the point yourself now: if web based applications work with >>>any browser, people can freely choose their distribution based on >>>their own preferences. >> >> >> Yup, and what will they pick? > > The one of their choice. Nobody knows which one that will be. Let me guess: Microsoft. > Maybe MS. I am quite sure about that one. > But that's not the point; the point is that they have the choice. > If MS had it its way, they wouldn't have that choice. I doubt that. But even if you're right, do you really think that MS is the only evil company on earth working like this? Do you really think that companies like Disney, Sony, Intel, AMD, Apple, etc work any different? >>>- An application works in IE, Firefox, Konqueror, Safari, Lynx, >>>Links, Opera, ... -> users can use it with any browser on any OS >> >> I think that we both understand that one browser will be more >> compatible then an other. It will only happen if all use exactly the >> same render engine, or all web recommendations are frozen. > > Thousands and thousands of website work perfectly in all of the > aforementioned websites right now. Maybe you define perfectly different then me, but have a look at the Acid tests for example. Even between minor versions of for example Firefox, or Opera there are differences in rendering. I won't call that perfectly, but maybe because I am a programmer. >> And if that happens, people selling stuff will find ways to make >> their version just a little better. > > It's very well possible to compete without breaking compatibility. > That's what Firefox, Opera, Konqueror etc. are already doing. Is that why people who design websites use both Firefox and Opera for testing? IIRC there are ambiguous parts in the CSS working drafts, and Opera thinks their interpretation is correct, which, (again IIRC) differs from other developers. Once the render engine is stable (my best guess, another 5-7 years), there will be (for quite some time) new things, that will worry developers of sites. >> Look at processors: which one would you buy at the moment? AMD? >> Intel? and if you pick a brand, which type? > > Depends on my needs, budget and the specs and price of the available > offers. Plus I always have a small, admittedly perhaps unjustified, > preference for the underdog; in the past that was AMD, in the future > that may very well be Intel. But I don't see the point of that > question. Others just pick Intel, because it's Intel. The same is happening for MS. People just buy MS, they don't care that it's cheaper (or maybe "cheaper") to install Linux + OpenOffice (for example). MS, so it's good. >> As soon as products can't evolve much more, the producers will find >> ways to make them even better compared to last week. > > As products can't evolve much more, the producers will find ways to > make them evolve?? Sorry, I don't understand what you're trying to say > here. As soon as the customer thinks the product is finished, the producer will create new things that should be there. How much more features do you want in an Office application? An instant message application? Do you need nudges, winks, voice samples? Wait until MSN Messenger 8 comes out, and then 9, maybe 10? >> Or wait until there comes a solution from a 3rd party. Force doesn't >> exists with software unless you can manipulate the law to enforce it. >> And I don't believe that everybody at Microsoft was/is that stupid to >> think they can make that something they don't controll only works >> with their software. Sure they can make it harder, like I said, you >> can always add things, especially if you are the major player, but >> Firefox is a nice proof that there is no such force, and I doubt that >> there are people working at Microsoft in major positions who didn't >> see this coming. > > Maybe they can force it, maybe not, but that's not the point (again). > The point is what their intentions are, and that is trying to lock > people into using their software. Can you name big companies that don't do this? -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From benji at benjiyork.com Tue Oct 4 09:16:27 2005 From: benji at benjiyork.com (Benji York) Date: Tue, 04 Oct 2005 09:16:27 -0400 Subject: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please! In-Reply-To: <1128428885.390019.304730@g43g2000cwa.googlegroups.com> References: <1128428885.390019.304730@g43g2000cwa.googlegroups.com> Message-ID: <434280AB.3030708@benjiyork.com> Luis M. Gonzalez wrote: > If not Ironpython, Boo (which could be considered almost an static > version of Python for .NET) would be a great choice. You could also use Python for .Net (http://www.zope.org/Members/Brian/PythonNet). -- Benji York From harddong at 21cn.net Mon Oct 24 09:07:04 2005 From: harddong at 21cn.net (Gonnasi) Date: Mon, 24 Oct 2005 21:07:04 +0800 Subject: How to separate directory list and file list? References: <0e9nl1tvvgqlhkahkmrrfc810b3ed1unb6@4ax.com> Message-ID: Lots of thanks for your help, My code can return the right result now. Thanks again! On Sun, 23 Oct 2005 17:27:49 +0200, "Fredrik Lundh" wrote: >"Gonnasi" wrote: > >> With >> >glob.glob("*") >> >> or >> >os.listdir(cwd) >> >> I can get a combined file list with directory list, but I just wanna a >> bare file list, no directory list. How to get it? > >use os.path.isfile on the result. > > for file in glob.glob("*"): > if not os.path.isfile(file): > continue > ... deal with file ... > > for file in os.listdir(cwd): > file = os.path.join(cwd, file) > if not os.path.isfile(file): > continue > ... deal with file ... > > files = map(os.path.isfile, glob.glob("*")) > > files = (file for file in os.listdir(cwd) if os.path.isfile(os.path.join(cwd, file))) > >etc. > > > > From mwm at mired.org Tue Oct 25 17:27:55 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 25 Oct 2005 17:27:55 -0400 Subject: Top-quoting defined [was: namespace dictionaries ok?] References: Message-ID: <86ll0h2so4.fsf@bhuda.mired.org> > On Tuesday 25 October 2005 00:31, Duncan Booth wrote: >> P.S. James, *please* could you avoid top-quoting > James Stroud writes: > I'm sorry if I can't find a dumb terminal for a "VAX" with which to read my > email. Perhaps, if i could, I would understand your frustration a little > better. You don't need a VAX. All it takes is trying to dethread a top-posted conversation. I've given up in frustration on more than one such venture. > The only reason I'm making a point of this is that many people come to python> from fields other than computer science or hacker-ology. Posting styles will > vary considerably among these people, so deal with the deviants carefully. I belive Duncan did so. He asked you to "please* avoid to top-posting". > Their differences in styles, like mine, probably arise from the culture of > their respective fields. Most, like me, may not even know what the heck you > are talking about. Also, here is a well written synopsis of the arguments in > favor of top-posting and they may even be strong enough to legitimize the > practice: > http://alpage.ath.cx/toppost/toppost.htm Well, if I could find a 300 baud modem, I might understand his objection to not top-posting (he really only has one). His comments about why people shouldn't complain about top-posting are full of suggestions that don't generally work on netnews and mail, though they may be valid elsewhere, and his suggestion about when to top-post leaves out the *very important* criteria that you don't expect to read any replies to your comment, and don't care if you make life difficult for those who have different expectations. He's right about inadequately-trimmed repklies, though. Not being on a 300 baud modem, I don't think they're as annoying as top-posting, but they are certainly something that we can do without. > In light of these arguments, I hereby reserve the right to revert to > top-posting if the compulsion overwhelms me. That's your right. Be aware that people will ignore, correct and/or complain about you doing so. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From pwatson at redlinepy.com Fri Oct 28 23:27:41 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Fri, 28 Oct 2005 22:27:41 -0500 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <3sf070Fo0klqU1@individual.net> Message-ID: <3sg8hiFmvbo7U1@individual.net> "Paul Watson" wrote in message news:3sf070Fo0klqU1 at individual.net... > wrote in message > news:1130497567.764104.125110 at g44g2000cwa.googlegroups.com... >>I want to scan a file byte for byte for occurences of the the four byte >> pattern 0x00000100. I've tried with this: >> >> # start >> import sys >> >> numChars = 0 >> startCode = 0 >> count = 0 >> >> inputFile = sys.stdin >> >> while True: >> ch = inputFile.read(1) >> numChars += 1 >> >> if len(ch) < 1: break >> >> startCode = ((startCode << 8) & 0xffffffff) | (ord(ch)) >> if numChars < 4: continue >> >> if startCode == 0x00000100: >> count = count + 1 >> >> print count >> # end >> >> But it is very slow. What is the fastest way to do this? Using some >> native call? Using a buffer? Using whatever? >> >> /David Here is a better one that counts, and not just detects, the substring. This is -much- faster than using mmap; especially for a large file that may cause paging to start. Using mmap can be -very- slow. #!/usr/bin/env python import sys fn = 't2.dat' ss = '\x00\x00\x01\x00' be = len(ss) - 1 # length of overlap to check blocksize = 64 * 1024 # need to ensure that blocksize > overlap fp = open(fn, 'rb') b = fp.read(blocksize) count = 0 while len(b) > be: count += b.count(ss) b = b[-be:] + fp.read(blocksize) fp.close() print count sys.exit(0) From mekstran at scl.ameslab.gov Fri Oct 21 08:53:44 2005 From: mekstran at scl.ameslab.gov (Michael Ekstrand) Date: Fri, 21 Oct 2005 07:53:44 -0500 Subject: Python vs Ruby In-Reply-To: <4358d9f6$0$19694$626a14ce@news.free.fr> References: <4358d9f6$0$19694$626a14ce@news.free.fr> Message-ID: <200510210753.45675.mekstran@scl.ameslab.gov> On Friday 21 October 2005 07:07, bruno modulix wrote: > >>Python is more like Java. > > > Err... Python is more like what Java would have been if Java was a > smart dynamic hi-level object oriented language !-) > +1. Python is easily applicable to most of the problem domain of Java, but solves problems much more elegantly. It just isn't shipped embedded in all leading browsers :-(. - Michael From jstroud at mbi.ucla.edu Tue Oct 25 01:08:14 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 24 Oct 2005 22:08:14 -0700 Subject: Importing at runtime In-Reply-To: <1130215994.502926.99190@g43g2000cwa.googlegroups.com> References: <1130215994.502926.99190@g43g2000cwa.googlegroups.com> Message-ID: <200510242208.14463.jstroud@mbi.ucla.edu> exec "import something" On Monday 24 October 2005 21:53, David Poundall wrote: > I have several .py files in a directory that I would like to import at > run time. Each file contains a state machine that requires to be run > in its own thread. > > The first problem I have is how can I import the code in all of the .py > files without knowing the file names in advance. > > Can this be done ?? > > TIA -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From fredrik at pythonware.com Fri Oct 7 13:15:59 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 7 Oct 2005 19:15:59 +0200 Subject: Why do I get an import error on this? References: <1128703953.497560.47620@z14g2000cwz.googlegroups.com> Message-ID: "Steve" wrote: > I'm trying to run a Python program on Unix and I'm encountering some > behavior I don't understand. I'm a Unix newbie, and I'm wondering if > someone can help. > If I run it through the Python interpreter, this way: > > >> python test.py > > it runs fine. > > But if I try to run it as an executable script, this way: > > >> test.py > > I get an import error that says it can't find cx_Oracle. > > Why does it behave differently when I run it in these two ways, and > what do I need to do to make it run successfully either way? in the first case, the shell uses the PATH variable to search for a python interpreter. in the second case, the shell uses the path specified in the script. what does "which python" say? From akiany at gmail.com Sat Oct 1 20:53:44 2005 From: akiany at gmail.com (Armin) Date: 1 Oct 2005 17:53:44 -0700 Subject: Soap Question (WSDL) In-Reply-To: References: <1128034565.390767.222310@g49g2000cwa.googlegroups.com> Message-ID: <1128214424.625734.281940@f14g2000cwb.googlegroups.com> Thanks for the comment everyone. I was considering to write my own soap interface to Flickr as apposed to use the ready to go libraries for Flickr as Fredrik pointed out. I got to get FlickrClient to work. Nonetheless, I am excited to use soap services for my needs. Thanks for your support, Armin From max at alcyone.com Mon Oct 24 15:47:46 2005 From: max at alcyone.com (Erik Max Francis) Date: Mon, 24 Oct 2005 12:47:46 -0700 Subject: XML Tree Discovery (script, tool, __?) In-Reply-To: <1130183060.195730.178330@g47g2000cwa.googlegroups.com> References: <1130183060.195730.178330@g47g2000cwa.googlegroups.com> Message-ID: eric.pederson at gmail.com wrote: > Finally diving into XML programmatically. Does anyone have a best > practice recommendation for programmatically discovering the structure > of an arbitrary XML document via Python? > > It seems like it is a common wheel I'd be re-inventing. It is. Look up XML DOM. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis An ounce of hypocrisy is worth a pound of ambition. -- Michael Korda From grig.gheorghiu at gmail.com Tue Oct 11 16:00:43 2005 From: grig.gheorghiu at gmail.com (Grig Gheorghiu) Date: 11 Oct 2005 13:00:43 -0700 Subject: What's the best SNMP interface? In-Reply-To: <1129050763.011814.92590@g14g2000cwa.googlegroups.com> References: <1129050763.011814.92590@g14g2000cwa.googlegroups.com> Message-ID: <1129060843.922067.265160@g44g2000cwa.googlegroups.com> I used pySNMP successfully. I think it's the most active SNMP-related Python project too. Grig From maksim.kasimov at gmail.com Wed Oct 26 06:02:38 2005 From: maksim.kasimov at gmail.com (Maksim Kasimov) Date: Wed, 26 Oct 2005 13:02:38 +0300 Subject: Pickle to source code In-Reply-To: <1130315056.793178.232760@g14g2000cwa.googlegroups.com> References: <1130315056.793178.232760@g14g2000cwa.googlegroups.com> Message-ID: As far i know, in pickle-file there are only attributes values of a pickled object, but not an object itself. It is possible to unpickle object only if you have the sourse of the class that object you have pickled. So, if you have class code and attribute values of the class instance, there is no problem to produce a textual representation of the object. Isn't it? (sorry for my English) Gabriel Genellina wrote: > Hello > > I want to convert from pickle format to python source code. That is, > given an existing pickle, I want to produce a textual representation > which, when evaluated, yields the original object (as if I had > unpickled the pickle). > I know of some transformations pickle/xml (Zope comes with one such > tool, gnosis xml is another) so I believe I could build something based > on them. > But I dont want to reinvent the wheel, I wonder if anyone knows of a > library which could do what I want? > > Thanks, > Gabriel Genellina > Softlab SRL > -- Best regards, Maksim Kasimov mailto: maksim.kasimov at gmail.com From smadim2 at grads.ece.mcmaster.ca Mon Oct 3 15:19:09 2005 From: smadim2 at grads.ece.mcmaster.ca (M.N.A.Smadi) Date: Mon, 03 Oct 2005 15:19:09 -0400 Subject: python getopt functionality In-Reply-To: References: <4341786B.1030901@grads.ece.mcmaster.ca> Message-ID: <4341842D.4060905@grads.ece.mcmaster.ca> It is not clear to me if i can define `mandatory' options? That sounds strange but let say that the command `requires ' a value for -z or --zoo (either or should be find but one and only one of them MUST be present). Can i do that with resorting to using if statements? thanks moe smadi Fredrik Lundh wrote: >"M.N.A.Smadi" wrote: > > > >>I have a perl script that I need to port to python. The script takes >>input from the command line. Is there a standard way of processing >>command line arguments based on the -flag preceeding the argument? >> >> > >http://docs.python.org/lib/module-getopt.html >http://docs.python.org/lib/module-optparse.html > > > > > > > From claudio.grondi at freenet.de Wed Oct 19 07:19:21 2005 From: claudio.grondi at freenet.de (Claudio Grondi) Date: Wed, 19 Oct 2005 11:19:21 -0000 Subject: How to organize Python files in a (relatively) big project References: Message-ID: <3rmhdhFk29hgU1@individual.net> Maybe looking at the todays thread ["dynamical" importing] can be helpful also here. Claudio P.S. Below a copy of one of the responses: : Joerg Schuster wrote: > I need to import modules from user defined paths. I.e. I want to do > something like: > > module_dir = sys.argv[1] > > my_path = os.path.join(module_dir, 'bin', 'my_module') > > from my_path import my_object > > Obviously, it doesn't work this way. How would it work? some alternatives: - if you want the modules to remain imported: try: sys.path.insert(0, os.path.join(module_dir, "bin")) module = __import__("my_module") finally: del sys.path[0] object = module.my_object - if you're only interested in the object: namespace = {} execfile(os.path.join(module_dir, "bin", "my_module" + ".py"), namespace) object = namespace["my_object"] "TokiDoki" schrieb im Newsbeitrag news:dj492l$3hf$1 at apollon.grec.isp.9tel.net... > Hello there, > > I have been programming python for a little while, now. But as I am > beginning to do more complex stuff, I am running into small organization > problems. > It is possible that what I want to obtain is not possible, but I would > like the advice of more experienced python programmers. > > I am writing a relatively complex program in python that has now around > 40 files. > At first, I had all of my files in one single directory, but now, with > the increasing number of files, it is becoming hard to browse my directory. > So, I would want to be able to divide the files between 8 directory, > according to their purpose. The problem is that it breaks the 'import's > between my files. And besides,AFAIK, there is no easy way to import a > file that is not in a subdirectory of the current file (I suppose I > could adjust the os.path in every file, but that seems not very elegant > to me). > I thought about turning the whole into a package. But I have to change > every 'import module_name' into > 'from package_name.sub_directory_name import module_name' > which is a little bit time consuming and not very flexible (if I change > my mind about the subdirectory a file belongs to, I will have to track > again every import to correct them) > > So, basically, here is the point: is there an 'elegant' way to keep my > files in separate directory and still be able to import between them > with simple 'import filename'? > > And if not, what would be the standard way to organize numerous python > files belonging to the same project? > > Thank you, > > TokiDoki From peter at commonlawgov.org Mon Oct 24 15:01:38 2005 From: peter at commonlawgov.org (Peter) Date: Mon, 24 Oct 2005 12:01:38 -0700 Subject: difference after remove In-Reply-To: <1d987df30510240602j4916a088s63f4fe34857943d1@mail.gmail.com> References: <1d987df30510240602j4916a088s63f4fe34857943d1@mail.gmail.com> Message-ID: <435D2F92.4020100@commonlawgov.org> Shi Mu wrote: >Is there any difference if I remove the '/' > > I will assume you mean "\", not "/". ;) >from the following statement? >intMatrix2 = [[1,1,2,4,1,7,1,7,6,9],\ > [1,2,5,3,9,1,1,1,9,1],\ > [0,0,5,1,1,1,9,7,7,7]] >print intMatrix2 > > >I removed one '\' and it still works. >So what is the use of '\'? > > Python normaly executes a statement as soon as a new line is given. A backslash is for "line continuation", it tells Python to ignore the new line (instead of executing the current line as it would normaly). If line-continuation is used in a string it will also ignore the new line (handy for when the theres to much on the line already but you don't want to break the string into two peices). In some situations (inside functions calls, tuples, lists) this is not needed. **** Some examples of using line-continuation**** # ------------------------------------------------- ## Example 1 # With line-continuation: >>> print "a"\ ... "b"\ ... "c" abc # Without line-continuation: >>> print "a" a >>> "b" 'b' >>> "c" 'c' # --------------------------------------------------- ## Example 2 # With line-continuation: >>> print "Hello, \ ... World!" Hello, World! # Without line-continuation: >>> print "Hello, File "", line 1 print "Hello, ^ SyntaxError: EOL while scanning single-quoted string >>> World!" File "", line 1 World!" ^ SyntaxError: invalid syntax # ----------------------------------------- ## Example 3 # With line-continuation: >>> print """Hello, \ ... World!""" Hello, World! # Without line-continuation: >>> print """Hello, ... World!""" Hello, World! # ----------------------------------------- ## Example 4 # With line-continuation: >>> [1,\ ... 2,\ ... 3] [1, 2, 3] # Without line-continuation: >>> [1, ... 2, ... 3] [1, 2, 3] >>> **** / End examples **** HTH, Peter From lameiro at gmail.com Sat Oct 15 03:22:31 2005 From: lameiro at gmail.com (Leandro Lameiro) Date: Sat, 15 Oct 2005 04:22:31 -0300 Subject: MD5 module Pythonicity In-Reply-To: References: <6815022a0510142223q3b6ae449ja0483f2f25ebb263@mail.gmail.com> Message-ID: <6815022a0510150022i11952397k16989e08206627a@mail.gmail.com> Hi Fredrik (and other too). First of all, thanks for taking your time to help me. On 10/15/05, Fredrik Lundh wrote: > Leandro Lameiro wrote: > > > What's wrong in having a function like the one I said, that would > > split files for you, feed md5.update and, when it is over, return the > > digest? > > Calculating the digest sum for a file on disk, without doing anything else > with that file, is a very small subset of everything you may want to use > digests for. Forcing every digest module to add code to cater for just > one of many use cases is most likely a waste of time. > Seems that we are disagreeing about frequency of use of file hashes compared to frequency of uses of all kind of digest. I don't have a way to support my point of view, as it was just a personal impression. Maybe I've got a distorted impression about the importance of this. As I'm not an experienced programmer, I'd probably trust more in your impressions than mine. :) > > "Although practicality beats purity." > > "Readability counts." > > "Beautiful is better than ugly." > > > > Have I got the wrong "Pythonic" definition? > > You're confusing the kitchensink approach with the modular approach. > Bloated API:s are not practical, readable, nor beautiful. Small flexible > components that can be easily combined are. Well, right. But for a very common thing (maybe not this one), is it OK to add some functionality to the Standard Library? I mean, if we all agreed that it is a common thing, a patch for this would probably be accepted, or even if it was an agreed common thing, it would still be a bad idea because it would bloat the API? Thanks and Regards Leandro Lameiro > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From davids at webmaster.com Tue Oct 25 00:06:36 2005 From: davids at webmaster.com (David Schwartz) Date: Mon, 24 Oct 2005 21:06:36 -0700 Subject: Microsoft Hatred FAQ References: <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: "Roedy Green" wrote in message news:5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9 at 4ax.com... > On Mon, 24 Oct 2005 12:59:33 -0700, "David Schwartz" > wrote, quoted or indirectly quoted someone who > said : >> I think you need to look up "extortion" in a dictionary. > In the days prior to Win95, Microsoft said "Co-operate with us is this > immoral scheme to screw OS/2 or go out of business. Your choice." > I call that extortion, even if their lawyers were careful enough to > skirt the letter of the law. Do you think it would be immoral if Microsoft said, "we will only sell Windows wholesale to dealers who don't sell other operating systems?" DS From kent37 at tds.net Fri Oct 21 13:28:46 2005 From: kent37 at tds.net (Kent Johnson) Date: Fri, 21 Oct 2005 13:28:46 -0400 Subject: Binding a variable? In-Reply-To: References: Message-ID: <43592348$1_2@newspeer2.tds.net> Paul Dale wrote: > > Hi everyone, > > Is it possible to bind a list member or variable to a variable such that No, Python variables don't work that way. > > temp = 5 The name 'temp' is now bound to the integer 5. Think of temp as a pointer to an integer object with value 5. > > list = [ temp ] the name 'list' is bound to a list whose only member is a reference to the integer 5 > > temp == 6 Ok now temp is bound to a new integer, but the list hasn't changed - it's member is still a reference to 5 > > list > > would show > > list = [ 6 ] You have to put a mutable object into the list - something whose state you can change. For example this works, because temp and lst[0] are references to the same mutable (changeable) list: >>> temp = [6] >>> lst = [temp] >>> lst [[6]] >>> temp[0] = 5 >>> lst [[5]] Kent From http Fri Oct 14 01:55:27 2005 From: http (Paul Rubin) Date: 13 Oct 2005 22:55:27 -0700 Subject: Python's garbage collection was Re: Python reliability References: <3r6i0uFi3qb8U2@uni-berlin.de> Message-ID: <7xr7aoskvk.fsf@ruckus.brouhaha.com> skip at pobox.com writes: > Folks, most common GC schemes have been tried as experiments over > the years. None have succeeeded, for various reasons. I think one > of the main reasons is that Python has to "play nice" with external > libraries, many of which weren't written with GC beyond malloc and > free in mind. Most GC'd language implementations I've seen actually have friendlier FFI's (foreign function interfaces) than Python does. I find it very easy to make errors with the reference counts in what little Python C extension hacking I've done. Maybe one gets better at it with experience. > Tagged integers: > http://mail.python.org/pipermail/python-dev/2004-July/046139.html That actually says there was a speedup from tagged ints with no obvious counterbalancing cost. However, it looks like there's no traditional GC, it stays with the same reference counts for heap objects. > Boehm GC: > http://mail.python.org/pipermail/python-dev/2005-January/051370.html This mentions use of Python idioms like txt = open(filename).read() expecting the file handle to get freed immediately. I think there's been some language extensions ("with" statement) discussed to replace that idiom. Note that the idiom is already not so safe in Jython. The Boehm GC doesn't seem like the right choice for an interpreter being built from scratch anyway, but who knows. Maybe I'm being premature but I'm already thinking of CPython as a legacy implementation and PyPy as the more likely testbed for stuff like this. I sorta wanted to go to the current sprint but oh well. > http://wiki.python.org/moin/CodingProjectIdeas/PythonGarbageCollected This correctly describes difficulties of using a copying GC in CPython. Note that the Boehm GC is mark-and-sweep. As Alex mentions, that usually means there's a pause every so often while the GC scans the entire heap, touching all data both live and dead (maybe the Boehm GC got around this somehow). I haven't been keeping up with this stuff in recent years so I have a worse concern. I don't know whether it's founded or not. Basically in the past decade or so, memory has gotten 100x larger and cpu's have gotten 100x faster, but memory is less than 10x faster once you're out of the cpu cache. The mark phase of mark/sweep tends to have a very random access pattern (at least for Lisp). In the old days that wasn't so bad, since a random memory access took maybe a couple of cpu cycles, but today it takes hundreds of cycles. So for applications that use a lot of memory, simple mark/sweep may be a much worse dog than it was in the Vax era, even if you don't mind the pauses. > Miscellaneous: > http://mail.python.org/pipermail/python-dev/2002-June/026032.html That looks potentially kind of neat, though it's not obvious what it does. > http://mail.python.org/pipermail/python-dev/2003-November/040299.html I'll try to read that sometime out of general interest. I'm too sleepy right now. > And lest anyone here think they were the first to suggest getting rid of > reference counting in Python: > > http://www.python.org/search/hypermail/python-1993/0554.html I think the language suggestions in that message are sound in principle, if not quite the right thing in every detail. Lisp went through about the same evolution in the 60's or 70's (before my time). With PyPy, it looks like Python implementation methodology is getting a lot more advanced, so hopefully some big performance gains are possible, and the language will likely evolve to help things along. From antonxx at gmx.de Wed Oct 12 02:57:58 2005 From: antonxx at gmx.de (anton) Date: 11 Oct 2005 23:57:58 -0700 Subject: HELP: Searching File Manager written in Python References: <1129037968.366932.144250@g44g2000cwa.googlegroups.com> Message-ID: <1129100278.841122.244650@g43g2000cwa.googlegroups.com> To answer to you both: The Norton Commander was a popular file manager for DOS, but the idea of the 2 window concept is still used by a lot of software. On Linux the one I use is Midnight Commander (mc). On Windows there are the 7-zip file manager see http://www.7-zip.org/ (7-zip is also a new compression format which is very good, there exist also a linux command line version) - Speed Commander is also a Windows filemanager. - Atol is based on GTK runs on Linux and Windows (http://atol.sourceforge.net/) but is not written in python or cannot run commands (I also get always error messages at startup that some drives are missing, perhaps my cdrom or my zip drive, but this happens with Gimp too -> so I believe GTK is the problem) But actually I work on Windows, thats why I am searching something which works on windows or better on Windows and Linux Perhaps some Python+wxWindows Application would be best. There exist a port of Atol to python+wxPython on: http://sourceforge.net/projects/wxpyatol But the project is stopped and abandonware ... Thanks a lot for now :-) I will have a look on your suggestions. Stephane From nil at dev.nul Mon Oct 10 08:34:35 2005 From: nil at dev.nul (Christian Stapfer) Date: Mon, 10 Oct 2005 14:34:35 +0200 Subject: Comparing lists References: <1128930699.799657.146210@g47g2000cwa.googlegroups.com> Message-ID: wrote in message news:1128930699.799657.146210 at g47g2000cwa.googlegroups.com... > try to use set. > L1 = [1,1,2,3,4] > L2 = [1,3, 99] > A = set(L1) > B = set(L2) > > X = A-B > print X > > Y = B-A > print Y > > Z = A | B > print Z But how "efficient" is this? Could you be a bit more explicit on that point? What is the order of complexity of set([...]) or of A-B, B-A, A | B, A ^ B and A & B? - The Python Documentation leaves me completely in the dark in this regard. Sorting the two lists and then extracting A-B, B-A, A|B, A & B and A ^ B in one single pass seems to me very likely to be much faster for large lists. Regards, Christian From my_email_is_posted_on_my_website at munged.invalid Wed Oct 12 18:10:58 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 12 Oct 2005 22:10:58 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> Message-ID: <5e2rk1luqjbhrajhlv5lvscrouns0fra3n@4ax.com> On Mon, 10 Oct 2005 01:33:43 +1000, Steven D'Aprano wrote or quoted : >> ...is pretty confusing - because "public key" is a term with a technical >> meaning in cryptography - and a public key really *is* public. > >The term you want is "wrong", not "confusing". In encryption the key you give others to encrypt messages to you is called the "public key". It is not public in the sense of everyone knows it. What term do you suggest? -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From pitonero at gmail.com Tue Oct 4 11:32:18 2005 From: pitonero at gmail.com (El Pitonero) Date: 4 Oct 2005 08:32:18 -0700 Subject: Will python never intend to support private, protected and public? References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xd5mstqab.fsf@ruckus.brouhaha.com> <7xzmpwuxd0.fsf@ruckus.brouhaha.com> <20050930075313.67b9b676.jk@ospaz.ru> <7xbr2a6dlz.fsf@ruckus.brouhaha.com> <7xk6gyoibc.fsf@ruckus.brouhaha.com> <433f56a3.2969039483@news.oz.net> <1128274267.064255.306980@f14g2000cwb.googlegroups.com> <7x8xxbgj4h.fsf@ruckus.brouhaha.com> Message-ID: <1128439938.509457.286790@o13g2000cwo.googlegroups.com> Paul Rubin wrote: > > Let's see, say I'm a bank manager, and I want to close my cash vault > at 5pm today and set its time lock so it can't be opened until 9am > tomorrow, including by me. Is that "handcuffs"? It's normal > procedure at any bank, for good reason. It's not necessarily some > distrustful policy that the bank CEO set to keep me from robbing the > bank. I might have set the policy myself. Java lets me do something > similar with instance variables. Why is it somehow an advantage for > Python to withhold such a capability? If so, you would probably be the type of person that also likes static typing, type safety and variable declaration, right? You like your language with extra baggages to improve some safety concerns, which most Python programmers don't seem to need. > def countdown(): > n = 3 > while n > 0: > yield n > g = countdown() > print g.next() # 3 > print g.next() # 2 > > where's the Python feature that lets me modify g's internal value of n > at this point? You missed the point. I have, for fun, built a GUI application in Python, while the program is running. I just kept on adding more and more code to it. This, while the Python program is running. I was able to change the GUI's look-and-feel, add more buttons, menus, all while the programming is running. I was able to change the class definition, preserve the previous object state variables. For that, you already have event-based program and can use module reload and some metaclass tricks to automatically relink your objects to new classes. Sure, Python is not as friendly as Lisp/Scheme for interactive programming, but you can still do a lot. > [Other stuff incomprehensible and snipped]. Sigh, I gave you the keywords: containment and aggregation. There are two ways of enhancing functionality from an existing object/class. One way is by inheritance, that's aggregation. Another way is by containment, that means that instead of inheriting, you add the additional features as an object contained in the new object. Vault encapsulation is one way to do OOP. But by no means it is the only way. The whole access level thing (the "private" keyword) is not an essential part of OOP. The concept of a "private" namespace is not necessary for OOP. Just because you learned OOP from one particular school of thought, does not mean that that's the only way. Let us call your OOP "school A". Another way of OOP is to accept by default that everything in the class hierarchy is inheritable. And Python is by no means the only language that does that. Now, obviously in this type of OOP you can run into name collision. But if you actually follow this other school of thought, you would organize your variables differently. Let us call this type of OOP "school B". Let me be more clear: when you have variables that are so, so, so private that no one else should touch, from school B's point of view, those variables do not belong to the object. They belong to another object. Let us say there is a financial instrument that pays some fixed coupon interest: class Bond: volatility = None interest = None def __init__(self): self.volatility = 0.3 # volatility from credit risk self.interest = 0.4 Now, you have another instrument that pays variable interest: class VariableInterestBond(Bond): volatility = None # this one collides with the base class def __init__(self): Bond.__init__(self) self.volatility = 0.2 # volatility for variable interest def calculate(self): interest = self.get_variable_interest() ... def get_variable_interest(self): return self.interest * (1 + random.random()*self.volatility) ... In this example, the subclass's "volatility" meant something else but collides with the base class's "volatility". It should have been a private variable, but now it accidentally overwrote an existing variable. We are trying to combine two "features" in the hierarchy tree: Bond | | +----- Variable Interest | | Variable-Interest Bond There are two ways to add the "variable interest" feature to the "bond" object. One way is by aggregation (inheritance), which is shown above. Another way is by containment. If the subsclass's "volatility" should be private and encapsulated from the main class hierarchy (i.e. Bond-like objects), then from school B's point of view, it does not belong to the bond object. It would be better to encapsulate it into another object. class VariableInterest: volatility = None def __init__(self, interest): self.interest = interest self.volatility = 0.2 def get_variable_interest(self): return self.interest * (1 + random.random()*self.volatility) class VariableInterestBond(Bond): variable_interest_calculator = None def __init__(self): Bond.__init__(self) self.variable_interest_calculator = VariableInterest(self.interest) def calculate(self): interest = self.variable_interest_calculator.get_variable_interest() ... That's one way of implementing it. Notice the name collision is gone. It is gone because you have properly organized your concepts and your objects. If you start to follow more along school B's way of thinking, you actually can eliminate the subclass, too. class Bond: ... def set_variable_rate(self): self.variable_interest_calculator = VariableInterest(self.interest) ... That is, by moving the features from aggregation into containment, often the depth of class inheritance tree can be shortened, too. -------------------------------- So, if you really think along the lines of school B, the chance of name collision reduces greatly. Because in your mind the state variables of the objects are more important/meaningful than in the case of school A. In school A you would often clutter the object's namespace with auxiliary variables. In school B you move the clutter to somewhere else. As for Python's double leading underscores, it's just a short-term "hardware" solution to name collision. In my opinion, a "software" code refactoring is the long-term solution. From carsten at uniqsys.com Thu Oct 27 14:16:24 2005 From: carsten at uniqsys.com (Carsten Haese) Date: Thu, 27 Oct 2005 14:16:24 -0400 Subject: syntax question - if 1:print 'a';else:print 'b' In-Reply-To: <312cfe2b0510271100y32f6163es8a27524ccc37747c@mail.gmail.com> References: <312cfe2b0510261507m2732e947p2be6fdae99a7c3d7@mail.gmail.com> <312cfe2b0510270757o51d3cfa7h2fccc775068b5549@mail.gmail.com> <8c7f10c60510270806y65510087t@mail.gmail.com> <312cfe2b0510270931r52a18d0em29168b9702d2c748@mail.gmail.com> <20051027174139.GC2575@kitchen.client.attbi.com> <312cfe2b0510271100y32f6163es8a27524ccc37747c@mail.gmail.com> Message-ID: <1130436984.22172.28.camel@dot.uniqsys.com> On Thu, 2005-10-27 at 14:00, Gregory Pi?ero wrote: > Not quite because if something(3) fails, I still want something(4) to > run. def something_ignore_exceptions(x): try: something(x) except: pass something_ignore_exceptions(1) something_ignore_exceptions(2) # etc... HTH, Carsten Haese From bretthoerner at gmail.com Thu Oct 13 14:02:31 2005 From: bretthoerner at gmail.com (Brett Hoerner) Date: 13 Oct 2005 11:02:31 -0700 Subject: installer for amd64 build of python? In-Reply-To: References: <1129162224.131305.269060@g49g2000cwa.googlegroups.com> <434E1674.5010201@v.loewis.de> <1129192705.632826.145210@z14g2000cwz.googlegroups.com> <1129225263.705977.181050@o13g2000cwo.googlegroups.com> Message-ID: <1129226551.255303.46270@g44g2000cwa.googlegroups.com> Trent Mick wrote: > Yes. The MS Platform SDK is free and includes a compiler that can target > x86, ia64 and x64 (the latter is what MS -- and Sun -- are calling > AMD64). Thanks, looking at their site I can't find a Platform SDK for XP... am I looking for the Windows 2003 Server SDK...? Seems counter-intuitive if so, but it does mention you can build 32 and 64-bit apps with it, I just assumed they would be uh, for Windows Server. Thanks again, Brett From xah at xahlee.org Sun Oct 16 22:00:58 2005 From: xah at xahlee.org (Xah Lee) Date: 16 Oct 2005 19:00:58 -0700 Subject: Perl-Python-a-Day: split a file full path Message-ID: <1129514458.420045.75670@g44g2000cwa.googlegroups.com> Split File Fullpath Into Parts Xah Lee, 20051016 Often, we are given a file fullpath and we need to split it into the directory name and file name. The file name is often split into a core part and a extension part. For example: '/Users/t/web/perl-python/I_Love_You.html' becomes '/Users/t/web/perl-python/' (directory name) 'I_Love_You' (file's base name) '.html' (file's ?extension?) Depending on the language, some language will remove the trailing slash after the dir name, and some will omit the dot before the suffix. In Python, to split a full path into parts is done with the os.path module. Example: # python import os.path myPath = '/Users/t/web/perl-python/I_Love_You.html' (dirName, fileName) = os.path.split(myPath) (fileBaseName, fileExtension)=os.path.splitext(fileName) print dirName # /Users/t/web/perl-python print fileName # I_Love_You.html print fileBaseName # I_Love_You print fileExtension # .html The official doc of the os.path module is at: http://www.python.org/doc/2.4.1/lib/module-os.path.html In Perl, spliting a full path into parts is done like this: # perl use File::Basename; $myPath = '/Users/t/web/perl-python/I_Love_You.html'; ($fileBaseName, $dirName, $fileExtension) = fileparse($myPath, ('\.html') ); print $fileBaseName, "\n"; # I_Love_You print $dirName, "\n"; # /Users/t/web/perl-python/ print $fileExtension, "\n"; # .html Note: the second argument to fileparse() is a list of regex. In particular, you need to escape the dot. For the official doc, type in command line: ?perldoc File::Path?. ------ This post is archived at http://xahlee.org/perl-python/split_fullpath.html Schemers, a scsh version will be appreciated. Xah xah at xahlee.org ? http://xahlee.org/ From NOSPAM.Blue27Jay at shaw.ca Sat Oct 8 18:55:42 2005 From: NOSPAM.Blue27Jay at shaw.ca (DaveInSidney) Date: Sat, 08 Oct 2005 22:55:42 GMT Subject: Book "Python and Tkinter Programming" References: <1128620086.240847.235490@g44g2000cwa.googlegroups.com> Message-ID: Check out BestBookBuys: http://www.bestwebbuys.com/Python_and_Tkinter_Programming-ISBN_1884777813.html?isrc=b-search -- ...................................................................... Remove NOSPAM. before replying Pursuant to U.S. code, title 47, Chapter 5, Subchapter II, Section 227 Any and all unsolicited commercial E-mail sent to this address is subject to a fee of US $500.00. E-Mailing denotes acceptance of these terms. Consult for details. "striker" wrote in message news:1128620086.240847.235490 at g44g2000cwa.googlegroups.com... > Does anyone who has this book willing to sell it. Please e-mail me the > condition and any other details if you are interested. > Thanks, > Kevin > From steve at REMOVETHIScyber.com.au Sun Oct 9 08:21:59 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 09 Oct 2005 22:21:59 +1000 Subject: Function decorator that caches function results References: <7x4q7rt3yl.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 09 Oct 2005 13:43:38 +0200, Fredrik Lundh wrote: > Steven D'Aprano wrote: > >> I notice that type(some_closure) and type(ordinary_function) both return >> the same result, . I also notice that both the closure >> and ordinary functions have an attribute "func_closure". Is there a way to >> tell which is a closure and which is not? In my tests, the ordinary >> function has func_closure == None, but I don't know if that will always be >> the case of just for my tests. > > closure != function. > > (did you read the wikipedia page? Yes I did. Did you read my post? If you create a closure, using a memoization technique as per the original post, and then call type() on that closure, Python reports . If you use dir() on that closure-that-Python-calls-a-function, it tells you that there is an attribute "func_closure". But ordinary functions that aren't closures also have that attribute. According to my tests, ordinary functions have None as the func_closure attribute, but I don't know if that will always be the case, or just the few examples I tested it. With a sample size of three, I have no confidence that I've found a bullet-proof test. Other that that, thank you for the links. -- Steven. From davids at webmaster.com Sun Oct 23 14:45:08 2005 From: davids at webmaster.com (David Schwartz) Date: Sun, 23 Oct 2005 11:45:08 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <86k6g59ke6.fsf@bhuda.mired.org> Message-ID: "Steven D'Aprano" wrote in message news:pan.2005.10.23.01.55.58.603513 at REMOVETHIScyber.com.au... > On Sat, 22 Oct 2005 18:02:44 -0700, David Schwartz wrote: >> I see you are a totalitarianist or perhaps a communist. If you want >> to >> live in America and discuss things that are relevent to America, let me >> know. > In other words, "why don't you go back to Russia, you commie pinko > fascist Jew Nazi". No. > Mike Meyer has got just as much right to live in America as David > Schwartz. Nice to see how quickly Americans' supposed love of freedom > disappears once they are exposed to views that contradict their own. This is about whether we're talking *ABOUT* America, you idiot. It's as if he said the press has no freedom, and I replied, "if you want to talk about some country where that's true, fine, but this discussion presumed America as the basis". Remember, he is the one who said the government owned the economy. That may be true in some countries, but it's simply *FALSE* in this country. Our government has limited powers and ownership of the economy is not one of them. DS From david at jotax.com Sat Oct 15 17:50:36 2005 From: david at jotax.com (spinner) Date: 15 Oct 2005 14:50:36 -0700 Subject: Queue question Message-ID: <1129413036.271162.279880@g43g2000cwa.googlegroups.com> --------------------------------------------- A two parter newbie question I am afraid. Am I right in thinking that using something like ... item = a_queue.get() print item will not print 'item' unless or until there is an item in the queue to retrieve. Effectively stalling the thread at the .get() instruction? I can see that this it may be tested for, using the .empty() function thereby allowing the code to progress if there was nothing in the queue, but how is .not_empty used ? Thanks in advance --------------------------------------------- From scott.daniels at acm.org Sat Oct 15 09:44:50 2005 From: scott.daniels at acm.org (Scott David Daniels) Date: Sat, 15 Oct 2005 06:44:50 -0700 Subject: Overloading & Overriden In-Reply-To: References: Message-ID: <43510755$1@nntp0.pdx.net> Fredrik Lundh wrote: > "Iyer, Prasad C" wrote: >>...This message contains information that may be privileged or confidential >>and is the property of the Capgemini Group. It is intended only for the >>person to whom it is addressed. If you are not the intended recipient, >>you are not authorized to read, print, retain, copy, disseminate, distribute, >>or use this message or any part thereof. If you receive this essage in error, >>please notify the sender immediately and delete all copies of this message. > > Oops. Ok. Done. Gotta love that reply to that biolerplate. --Scott David Daniels scott.daniels at acm.org From bokr at oz.net Mon Oct 3 01:38:48 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 03 Oct 2005 05:38:48 GMT Subject: Will python never intend to support private, protected and public? References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xd5mstqab.fsf@ruckus.brouhaha.com> <7xzmpwuxd0.fsf@ruckus.brouhaha.com> <20050930075313.67b9b676.jk@ospaz.ru> <7xbr2a6dlz.fsf@ruckus.brouhaha.com> <7xk6gyoibc.fsf@ruckus.brouhaha.com> <433f56a3.2969039483@news.oz.net> <7x1x34f85u.fsf@ruckus.brouhaha.com> <867jcvmz06.fsf@bhuda.mired.org> Message-ID: <4340b0e9.3057685589@news.oz.net> On Sun, 02 Oct 2005 16:42:49 -0400, Mike Meyer wrote: >Paul Rubin writes: >> Well, it's a discussion of why a certain feature might be useful, not >> that it's required. Mike Meyer points out some reasons it might be >> hard to do smoothly without changing Python semantics in a deep way >> (i.e. Python 3.0 or later). > >Actually, I think that the semantic changes required to make private >do what you want are deep enough that the resulting language wouldn't >be Python any longer. It has deep implications from the interpeter >implementation all the way out to the design of the standard library, >all of which would have to be reworked to make private do "the right >thing." > >Not that I think that private is a bad idea. If I'm not writing >python, then I'm probably writing Eiffel. Eiffel has facilities for >protecting features, though the design is more consistent than the >mishmash one gets in C++/Java. Nuts - in Eiffel, you can't write >"instance.attribute = value"; assignment to an attribute has to be >done in a method of the owning instance. Actually, ISTM that's true of python too, considering that instance.attribute = value is sort of syntactic sugar for instance.__setattr__('attribute', value) so it's a (normally inherited) "method of the owning instance" (taking that to mean a method of its class) that does the assignment. > >Which brings me to my point. Rather than trying to bandage Python to >do what you want - and what, based on this thread, a lot of other >people *don't* want - you should be building a system from the ground >up to support the kind of B&D environment you want. I agree, but I wouldn't agree if I thought you were saying it's useless to define exactly what it is we're talking about before deciding on what needs hw/os/gil/intepreter/convention level support, and how python would make use of such a capability, however implemented. Paul summarised three levels, of which at least fixing unintentional name-mangling collisions could be solved, IWT. > >Of course, you do realize that in practice you can *never* get what >you want. It assumes that the infrastructure is all bug-free, which >may not be the case. Yeah, but IRL how close to *never* do you in practice demand to bet your life on it? ;-) > >For example, I once had a system that took a kernel panic trying to >boot an OS upgrade. It had been running the previous versionn of the >OS for most of a year with no problems. Other basically identical >systems ran the upgraded OS just fine. I finally wound up stepping >through the code one instruction at a time, to find that the >subroutine invocation instruction on this machine was setting a bit in >a register that it wasn't supposed to touch, but only in kernel >mode. An internal OS API change meant it only showed up in the >upgraded OS. > >The infamous Pentium floating point bug shows that this case isn't >restricted to failing hardware. > Was that software? I've forgotten the details and am too lazy to google ;-/ Regards, Bengt Richter From rune.strand at gmail.com Wed Oct 12 18:05:38 2005 From: rune.strand at gmail.com (Rune Strand) Date: 12 Oct 2005 15:05:38 -0700 Subject: Adding a __filename__ predefined attribute to 2.5? In-Reply-To: <1h4ce9x.v65tbpm7xivfN%aleax@mail.comcast.net> References: <1129098667.336115.303060@g47g2000cwa.googlegroups.com> <1129103007.870187.101790@g44g2000cwa.googlegroups.com> <1129150883.303899.259570@g43g2000cwa.googlegroups.com> <1h4ce9x.v65tbpm7xivfN%aleax@mail.comcast.net> Message-ID: <1129154738.455062.140750@f14g2000cwb.googlegroups.com> Ok, Alex. I know a good explanation when I see one. Thanks! From my_email_is_posted_on_my_website at munged.invalid Fri Oct 14 22:31:33 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sat, 15 Oct 2005 02:31:33 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> Message-ID: On 14 Oct 2005 19:01:42 -0700, "Xah Lee" wrote or quoted : > > Q: Microsoft's Operating System is used over 90% of PCs. If that's >not monopoly, i don't know what is. They got where they are by CHEATING. That is why they are evil, not because they have a large market share. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From fairwinds at eastlink.ca Mon Oct 17 11:21:14 2005 From: fairwinds at eastlink.ca (David Pratt) Date: Mon, 17 Oct 2005 12:21:14 -0300 Subject: Stripping ASCII codes when parsing In-Reply-To: Message-ID: Many thanks Steve. This is good information. I think this should work fine. I was doing a string.replace in a cleanData() method with the following characters but don't know if that would have done it. This contains all the control characters that I really know about in normal use. ord(c) < 32 sounds like a much better way to go and comprehensive. So I guess instead of string.replace, I should do a ... for char in ... and check evaluate each character, correct? - or is there a better way of eliminating these other that reading a string in character by character. '\a','\b','\e','\f','\n','\r','\t','\v','|' Regards, David On Monday, October 17, 2005, at 06:04 AM, Steve Holden wrote: > David Pratt wrote: >> I am working with a text format that advises to strip any ascii >> control >> characters (0 - 30) as part of parsing data and also the ascii pipe >> character (124) from the data. I think many of these characters are >> from a different time. Since I have never seen most of these >> characters >> in text I am not sure how these first 30 control characters are all >> represented (other than say tab (\t), newline(\n), line return(\r) ) >> so >> what should I do to remove these characters if they are ever >> encountered. Many thanks. > > You will find the ord() function useful: control characters all have > ord(c) < 32. > > You can also use the chr() function to return a character whose ord() > is > a specific value, and you can use hex escapes to include arbitrary > control characters in string literals: > > myString = "\x00\x01\x02" > > regards > Steve > -- > Steve Holden +44 150 684 7255 +1 800 494 3119 > Holden Web LLC www.holdenweb.com > PyCon TX 2006 www.python.org/pycon/ > > -- > http://mail.python.org/mailman/listinfo/python-list > From ptmcg at austin.rr.com Wed Oct 26 15:26:39 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 26 Oct 2005 12:26:39 -0700 Subject: replace words References: <1130310159.632687.295020@g44g2000cwa.googlegroups.com> Message-ID: <1130354799.182900.268070@z14g2000cwz.googlegroups.com> hagai26 at gmail.com wrote: > What is the way for replacing in a string from . to . the sentence? > for example: > "been .taken. it may be .left. there, > even if the .live coals were not. cleared" > I want to do this-> replace(\.(.*)\.,\.start (1) end\.) > result: > "been .start taken end. it may be .start left end. there, > even if the .start live coals were not end. cleared" Here is a pyparsing version. Yes, it is more verbose, and, being pure Python, is not as fast as regexp. But the syntax is very easy to follow and maintain, and the parse actions can add quite a bit of additional logic during the parsing process (for example, rejecting dot pairs that span line breaks). -- Paul from pyparsing import Literal,SkipTo data = """been .taken. it may be .left. there, even if the .live coals were not. cleared""" DOT = Literal(".") # expression to match, comparable to regexp r"\.(.*?)\." dottedText = DOT + SkipTo(DOT).setResultsName("body") + DOT # action to run when match is found - return modified text def enhanceDots( st, loc, tokens): return ".start " + tokens.body + " end." dottedText.setParseAction( enhanceDots ) # transform the string print dottedText.transformString( data ) Gives: been .start taken end. it may be .start left end. there, even if the .start live coals were not end. cleared From samrobertsmith at gmail.com Sun Oct 9 21:17:46 2005 From: samrobertsmith at gmail.com (Shi Mu) Date: Sun, 9 Oct 2005 18:17:46 -0700 Subject: is there any Python code for spatial tessellation? In-Reply-To: <1d987df30510080440x5ae758eard7ccfbd829f88264@mail.gmail.com> References: <1d987df30510080440x5ae758eard7ccfbd829f88264@mail.gmail.com> Message-ID: <1d987df30510091817i3852ea41v1b0b592bf2551c3c@mail.gmail.com> is there any course website about teaching python? for instance, some computer science courses website? On 10/8/05, Shi Mu wrote: > is there any Python code for spatial tessellation? > thanks a lot! From mwm at mired.org Sat Oct 29 18:29:52 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 29 Oct 2005 18:29:52 -0400 Subject: Automatic binding of **kwargs to variables References: <1130539752.667045.183460@g14g2000cwa.googlegroups.com> <86d5lpdwg3.fsf@bhuda.mired.org> <1130608862.858527.124330@g14g2000cwa.googlegroups.com> Message-ID: <86r7a4c5y7.fsf@bhuda.mired.org> "chris.atlee at gmail.com" writes: > Mike Meyer wrote: > [snip] >> for name, value in kwargs.items(): >> if name in ('a', 'list', 'of', 'valid', 'keywords'): >> exec "%s = %s" % (name, value) >> else: >> raise ValueError, "Unrecognized keyword " + name >> >> Others will probably tell you that you really shouldn't be using exec. > > What about using setattr? > > for name, value in kwargs.items(): > if name in ('a', 'list', 'of', 'valid', 'keywords'): > setattr(self, name, value) > else: > raise ValueError, "Unrecognized keyword " + name You clipped my description of what's wrong with setattr: it doesn't bind the names in the local namespace, it binds them to an object. This may be acceptable, but wasn't what the OP asked for. > I'd probably turn the list of valid keywords into another dictionary to > make it easy to specify default values for all the parameters as well. If you're going to do that, why not just specify them explicitly in the function definition instead of using **kwargs? That takes care of everything - binding, checking, and providing a default value - in one swoop. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From my_email_is_posted_on_my_website at munged.invalid Sun Oct 9 15:24:31 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sun, 09 Oct 2005 19:24: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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> Message-ID: <5hrik11q3p5ugcjm4hmmgqgq20o8fdrhr9@4ax.com> On Sun, 09 Oct 2005 16:14:32 GMT, Roel Schroeven wrote or quoted : >His reply wasn't exactly clear, but I that he means that wen you use HTM >mail, you don't have to attach the photo with the email. You can also >use the HTML to refer to an image somewhere on a webserver. There is that and also the use of HTML formatting, embedded images, captioning, rows, borders to make the message look more like a page from a photo album. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From david at jotax.com Tue Oct 25 01:33:37 2005 From: david at jotax.com (David Poundall) Date: 24 Oct 2005 22:33:37 -0700 Subject: Importing at runtime References: <1130215994.502926.99190@g43g2000cwa.googlegroups.com> <1130217675.420469.155930@z14g2000cwz.googlegroups.com> Message-ID: <1130218417.383625.110660@g47g2000cwa.googlegroups.com> Devan, would ... __import__(name) for name in module_names have worked just as well - without the equate to modules? or is the modules list required as a hook for the imports ? From http Mon Oct 10 19:54:49 2005 From: http (Paul Rubin) Date: 10 Oct 2005 16:54:49 -0700 Subject: Send password over TCP connection References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> <1128979760.251637.316480@o13g2000cwo.googlegroups.com> <7xk6glhvgl.fsf@ruckus.brouhaha.com> Message-ID: <7x1x2t6i7q.fsf@ruckus.brouhaha.com> Dan Stromberg writes: > > No. It's vulnerable to dictionary search. Use SRP if you can. > Where can I learn more about this? http://srp.stanford.edu as already mentioned. Also, RFC 2945 describes an older version (still ok). From rajarshi at presidency.com Mon Oct 3 18:29:11 2005 From: rajarshi at presidency.com (Rajarshi Guha) Date: Mon, 03 Oct 2005 18:29:11 -0400 Subject: packaging a python project and associated graphics files Message-ID: Hi, I've been trying to package a python project and I'm a little confused about how I distribute some PNG's that the program uses as icons. Using distutils I can set the data_files argument of setup() and get my data files located in, say, /usr/local/mydata. However when I write my code, it would seem that I have to hardcode the above path. But this would mean that while working on the code I would need to have it 'installed' on my system (or else actually make the above directory). This seems a little unwieldy. How do people handle this situation? Thanks, From pinard at iro.umontreal.ca Wed Oct 19 19:54:49 2005 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Wed, 19 Oct 2005 19:54:49 -0400 Subject: Vim IS a capable IDE [was Re: Vim capable IDE?] In-Reply-To: <1129721976.745281.64800@z14g2000cwz.googlegroups.com> References: <1129603486.291175.167860@f14g2000cwb.googlegroups.com> <4354b229$0$21286$626a54ce@news.free.fr> <1129644971.811765.105900@g49g2000cwa.googlegroups.com> <22a5f.20376$ae.2646@tornado.tampabay.rr.com> <1129663697.620665.99040@g44g2000cwa.googlegroups.com> <1129675547.108377.246320@o13g2000cwo.googlegroups.com> <1129721976.745281.64800@z14g2000cwz.googlegroups.com> Message-ID: <20051019235449.GA6572@phenix.progiciels-bpi.ca> [Chris Lasher] > Thanks for the replies, guys! I had no idea Vim was capable of doing > some of those things. One detail which should be more widely known, in my opinion, is the capability of Vim (if compiled properly) to use Python has an extension language. That is, you may add new Vim commands to your liking (presuming you know how to program), writing them in Python. -- Fran?ois Pinard http://pinard.progiciels-bpi.ca From fredrik at pythonware.com Sun Oct 9 12:00:13 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 9 Oct 2005 18:00:13 +0200 Subject: Function decorator that caches function results References: <7x4q7rt3yl.fsf@ruckus.brouhaha.com> Message-ID: Steven D'Aprano wrote: > "Each def or lambda expression that is executed will create a closure if > the body of the function or any contained function has free variables." > > Presumably that means that if there are no free variables, no closure > is created. you're quoting selectively; the word "closure" isn't used anywhere in the design document except for a section that talks about "flat closures", which is an implementation approach used in CPython (as the sentence before the one you quoted explains). I don't think it's necessarily a good idea to treat a reference to an algorithm and an attribute on an object in a specific implementation as the definition of an computer term... From david.murmann at rwth-aachen.de Tue Oct 4 05:10:18 2005 From: david.murmann at rwth-aachen.de (David Murmann) Date: Tue, 04 Oct 2005 11:10:18 +0200 Subject: semi-newbie module namespace confusion In-Reply-To: References: <1128404572.837225.41870@g47g2000cwa.googlegroups.com> <3qer81FeldcmU1@news.dfncis.de> Message-ID: <3qev4iFash6dU1@news.dfncis.de> Fredrik Lundh wrote: > David Murmann wrote: > >> I ran into the same problem some time ago and even wanted to post here >> about it, but found out that it had been reported as a bug three times >> at sourceforge (if i remember correctly). The comments there explained >> it of course, but I still think that this behavior is somehow "wrong". >> >> I like to think of the import statement as a way to provide the names >> defined in a module to the current namespace, so there is no "this gets >> evaluated twice". > > are you sure you understand the problem? import does exactly what you > say; it creates a module object and populates it by running the code in the > module. maybe i don't... but i'm not convinced yet, see below. > the problem is that when you hand Python a chunk of code (a script), it > doesn't necessarily know where it came from. and even if you know the > filename it came from, there's no way to know if that chunk actually corre- > sponds to a module somewhere out there (the import system can map a > module name to a file, but it cannot map a file to a module name). well, in my opinion python is not trying hard enough. to me it is immediately obvious that the main module gets evaluated twice and i am rather sure that one could introduce some magic of the kind "oh, i reevaluate the main script here, the module does not get filled the usual way but uses the existing objects instead". this would have to happen on a very low level (when the file i just read from is known) but i think it would be possible. whether the effort to do so is worth it, is a different question... >> Now i wonder how difficult it would be to "correct" the behavior? > > there's no way to "fix" it without introducing a huge number of inconsistencies. > >> And would such a change break any code? > > any code that uses the "if __name__ == "__main__" pydiom, for a start. i wouldn't lose that, the main module should still be named "__main__", it should just get more names (somehow) :) i see, it's difficult at the moment hoping i'm not completely wrong here, David. From timr at probo.com Fri Oct 21 02:16:06 2005 From: timr at probo.com (Tim Roberts) Date: Fri, 21 Oct 2005 06:16:06 GMT Subject: Accessing a dll from Python References: <1129814361.130127.255990@f14g2000cwb.googlegroups.com> Message-ID: "dcrespo" wrote: > >Can someone give me lights on how can I deal with dlls from python? > >My main purpose is to get access to a Unitech PT600 Bar Code system. I >have the dll that works fine through Visual Basic. But I'm migrating to >Python, so I need a way to use the same dll, or a C library. > >I tried to access a dll created by myself on Visual Basic. The dll just >have one function. It works perfect when using it on a VB project just >including it in the references configuration. But I can't access it >from python. I tried the ctypes module. Are you talking about VB6 or VB.NET? If you had to add a reference, then it is either a COM interface or a managed code class. DLLs don't get in through references -- they use the Declare statement. COM interfaces are pretty easy to call in Python. Calling managed code is almost impossible right now. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From peter at engcorp.com Sun Oct 23 08:26:48 2005 From: peter at engcorp.com (Peter Hansen) Date: Sun, 23 Oct 2005 08:26:48 -0400 Subject: Listening for keypress in the background In-Reply-To: References: Message-ID: Mathias Dahl wrote: > Peter Hansen writes: >>>How can I make it listen for a certain keypress (say, Windows-key + >>>space) in a controlled fashion even when it is not the program having >>>focus? >>> >>>I need to do this running under GNOME in Mandrake GN/Linux 10. >> >>Search Google for "python keylogger". > > Thanks, good idea! The relevant pages I found only link to > Windows-specific keyloggers though. Oops, you're quite right. Sorry! I didn't even read the second sentence in your post. Stupid me... -Peter From aleaxit at yahoo.com Mon Oct 17 04:35:33 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 17 Oct 2005 10:35:33 +0200 Subject: Comparing lists References: <1128930699.799657.146210@g47g2000cwa.googlegroups.com> <1128952417.0544cc73190bbbd4e683448c137969c8@teranews> <434ba977@nntp0.pdx.net> <1129216693.445956.155490@g47g2000cwa.googlegroups.com> Message-ID: <1h4knvy.41r7fw1k4bge7N%aleaxit@yahoo.com> Christian Stapfer wrote: > This is why we would like to have a way of (roughly) > estimating the reasonableness of the outlines of a > program's design in "armchair fashion" - i.e. without > having to write any code and/or test harness. And we would also like to consume vast amounts of chocolate, while similarly reclining in comfortable armchairs, without getting all fat and flabby. Unfortunately, what we would like and what reality affords are often pretty uncorrelated. No matter how much theoreticians may love big-O because it's (relatively) easy to compute, it still has two failings which are often sufficient to rule out its sufficiency for any "estimate [of] the reasonableness" of anything: [a] as we operate on finite machines with finite wordsize, we may never be able reach anywhere even remotely close to the "asymptotic" region where big-O has some relationship to reality; [b] in many important cases, the theoretical worst-case is almost impossible to characterize and hardly ever reached in real life, so big-O is of no earthly use (and much harder to compute measures such as big-Theta should be used for just about any practical purpose). Consider, for example, point [b]. Quicksort's big-O is N squared, suggesting that quicksort's no better than bubblesort or the like. But such a characterization is absurd. A very naive Quicksort, picking its pivot very systematically (e.g., always the first item), may hit its worst case just as systematically and in cases of practical importance (e.g., already-sorted data); but it takes just a little extra care (in the pivot picking and a few side issues) to make the worst-case occurrences into ones that will not occur in practice except when the input data has been deliberately designed to damage by a clever and determined adversary. Designing based on worst-case occurrences hardly ever makes sense in any field of engineering, and blind adherence to worst-case assessments can be an unmitigated disaster, promoting inferior technology just because, in the WORST imaginable case, the best available technology would fare no better than the inferior one (even though in 99.99999% of cases the best technology would perform better, if you're designing based on worst-case analyses you may not even NOTICE that -- and NEVER, *NEVER* forget that big-O is nothing BUT "extreme-worst-case" analysis!). Why bother using prestressed concrete, when, should a large asteroid score a direct hit, the costly concrete will stand up no better than cheap bricks, or, for that matter, slightly-damp straw? Why bother doing (e.g.) random pivot selection in quicksort, when its big-O (i.e., worst-case) behavior will remain N-squared, just like naive quicksort, or, for that matter, bubblesort? Alex From jepler at unpythonic.net Mon Oct 31 20:26:34 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Mon, 31 Oct 2005 19:26:34 -0600 Subject: Tkinter problem In-Reply-To: <1130800625.796277.222980@g14g2000cwa.googlegroups.com> References: <1130761580.552145.167340@z14g2000cwz.googlegroups.com> <1130800625.796277.222980@g14g2000cwa.googlegroups.com> Message-ID: <20051101012633.GA7132@unpythonic.net> On Mon, Oct 31, 2005 at 03:17:05PM -0800, dale cooper wrote: > Thanks, but I've got another question: > > can't find Tcl configuration script "tclConfig.sh" This file comes from the following package: $ rpm -qf /usr/lib*/tclConfig.sh tcl-devel-8.4.9-3 Fedora generally splits packages which are libraries into "foo" and "foo-devel" (and maybe others). Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From spe.stani.be at gmail.com Thu Oct 27 10:05:38 2005 From: spe.stani.be at gmail.com (SPE - Stani's Python Editor) Date: 27 Oct 2005 07:05:38 -0700 Subject: ANN: SPE 0.7.5.d released! Message-ID: <1130421938.507881.207330@z14g2000cwz.googlegroups.com> I'm currently packaging the new SPE. The release is a matter of minutes. Next releases (0.8.*) will focus on the Mac in honour of the fund raising for the purchase of a Mac. Read more on the homepage. New features: * UML export to bitmap (bmp, gif, jpg, pcx, png, pnm, tif, xbm, xpm), to vector drawing (eps) or to printer (pdf). * Dialog box for passing arguments and options to debugger. * Unicode support (specify encoding in source file) You can read more on the SPE news blog. It would be nice if some (experienced) Mac users would subscribe to the developers mailing list to speed up the Mac port for SPE. I expect my new Mac any moment. Stani -- http://pythonide.stani.be http://pythonide.stani.be/manual/html/manual.html From donn at u.washington.edu Mon Oct 10 14:21:18 2005 From: donn at u.washington.edu (Donn Cave) Date: Mon, 10 Oct 2005 11:21:18 -0700 Subject: Python's Performance References: <20051008040614.47429.qmail@web30607.mail.mud.yahoo.com> <178B879D-FDB6-458C-BE00-A03820D98703@advfn.com> <1128888628.643764@yasure> Message-ID: In article , "Fredrik Lundh" wrote: > Donn Cave wrote: > > > | > Except it is interpreted. > > | > > | except that it isn't. Python source code is compiled to byte code, which > > | is then executed by a virtual machine. if the byte code for a module is > > | up > > | to date, the Python runtime doesn't even look at the source code. > > > > Fair to say that byte code is interpreted? Seems to require an > > application we commonly call an interpreter. > > well, the bytecode isn't Python (the transformation isn't exactly straight- > forward, as we've seen in other posts I've made today). > > and even if the bytecode engine used in CPython can be viewed as an inter- > preter, does that make Python an interpreted language? what about Python > code that uses a runtime that converts it to machine code? (e.g. Psycho, > Iron- > Python). is it still an interpreter if it generates machine code? Is what an interpreter? I am not very well acquainted with these technologies, but it sounds like variations on the implementation of an interpreter, with no really compelling distinction between them. When a program is deployed as instructions in some form other than native code executable, and therefore those instructions need to be evaluated by something other than the hardware, then that would be some kind of interpretation. I agree that there are many shades of grey here, but there's also a real black that's sharply distinct and easy to find -- real native code binaries are not interpreted. Donn Cave, donn at u.washington.edu From andreas.lobinger at netsurf.de Thu Oct 13 16:05:06 2005 From: andreas.lobinger at netsurf.de (Andreas Lobinger) Date: Thu, 13 Oct 2005 22:05:06 +0200 Subject: extract PDF pages References: Message-ID: <434EBDF2.B7ACD69B@netsurf.de> Aloha, David Isaac wrote: > I am looking for a Python solution. > Just for PDF page extraction. > Any hope? With python, there's always hope. http://sourceforge.net/projects/pdfplayground In the CVS (sorry no distribution at the time) you'll find an example page-extract. http://cvs.sourceforge.net/viewcvs.py/pdfplayground/ppg/Exp/page-extract.py?rev=1.1&view=markup pdfplayground is limited at the moment to PDF <= 1.4. If you want to do more with .pdfs you'll probably need at least a basic understanding of the PDF specification. pdfplayground is focused at low-level .pdf (by implementation resources...). Thomas Lotze is also preparing a pdf reader/writer project: http://svn.thomas-lotze.de/PDFSpec/ So is David Boddie: http://www.boddie.org.uk/david/Projects/Python/pdftools Wishing a happy day LOBI From iainking at gmail.com Wed Oct 26 06:21:13 2005 From: iainking at gmail.com (Iain King) Date: 26 Oct 2005 03:21:13 -0700 Subject: Double replace or single re.sub? Message-ID: <1130322073.666179.49350@g44g2000cwa.googlegroups.com> I have some code that converts html into xhtml. For example, convert all tags into . Right now I need to do to string.replace calls for every tag: html = html.replace('','') html = html.replace('','') I can change this to a single call to re.sub: html = re.sub('<([/]*)i>', r'<\1em>', html) Would this be a quicker/better way of doing it? Iain From gregpinero at gmail.com Tue Oct 25 14:59:35 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Tue, 25 Oct 2005 14:59:35 -0400 Subject: xml.dom.minidom - parseString - How to avoid ExpatError? Message-ID: <312cfe2b0510251159p5e2501cbxf21e4f62f3d70b1c@mail.gmail.com> Hi guys, I was hoping some XML expert could help me make this code work. Below is sample code with sample XML similar to what I'm dealing with. How can I make the weird characters in the XML not break the parser? I'll do anything to make this work! (Note: the   broke my parser yesterday but doesn't seem to in this sample code) But really I'm looking for solutions that will handles lots of unusual characters. Much thanks, Greg from xml.dom.minidom import parseString data=""" This is sample problem text.   ?500.00 """ myDOM=parseString(data) Traceback (most recent call last): File "C:\Python23\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 307, in RunScript debugger.run(codeObject, __main__.__dict__, start_stepping=0) File "C:\Python23\Lib\site-packages\pythonwin\pywin\debugger\__init__.py", line 60, in run _GetCurrentDebugger().run(cmd, globals,locals, start_stepping) File "C:\Python23\Lib\site-packages\pythonwin\pywin\debugger\debugger.py", line 631, in run exec cmd in globals, locals File "C:\Documents and Settings\Gregory\My Documents\Python\xml help\xmlproc.py", line 9, in ? myDOM=parseString(data) File "C:\Python23\lib\xml\dom\minidom.py", line 1929, in parseString return expatbuilder.parseString(string) File "C:\Python23\lib\xml\dom\expatbuilder.py", line 940, in parseString return builder.parseString(string) File "C:\Python23\lib\xml\dom\expatbuilder.py", line 223, in parseString parser.Parse(string, True) ExpatError: undefined entity: line 4, column 29 -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com ) -------------- next part -------------- An HTML attachment was scrubbed... URL: From programmer.py at gmail.com Wed Oct 26 14:21:24 2005 From: programmer.py at gmail.com (Jaime Wyant) Date: Wed, 26 Oct 2005 13:21:24 -0500 Subject: Raw string fu In-Reply-To: <1130350167.20384.7.camel@localhost.localdomain> References: <1130350167.20384.7.camel@localhost.localdomain> Message-ID: This URL has a good section on raw strings. http://www.ferg.org/projects/python_gotchas.html r'\' is wrong because raw strings were originally added to make regular expressions easier to write. And you can't have a regexp that ends with \. Also, you can use the \ to escape your original quote character. >>> r'I can\'t end strings with a \'' "I can\\'t end strings with a \\'" hth jw On 10/26/05, Joshua Ginsberg wrote: > >>> r'\' > File "", line 1 > r'\' > ^ > SyntaxError: EOL while scanning single-quoted string > >>> r'\\' > '\\\\' > > Does that seem wrong to anybody else? Shouldn't the first one be > syntactically correct? > > -jag > > -- > http://mail.python.org/mailman/listinfo/python-list > From dudufigueiredo at gmail.com Mon Oct 31 11:33:10 2005 From: dudufigueiredo at gmail.com (dudufigueiredo at gmail.com) Date: 31 Oct 2005 08:33:10 -0800 Subject: Rename files with numbers Message-ID: <1130776390.085587.116270@g43g2000cwa.googlegroups.com> I have one folder containing mp3 files, the folder is: C:\My Shared Folder\Rubber Soul And the files are: 01 drive my car.mp3 02 norwegian wood.mp3 03 you won't see me.mp3 04 nowhere man.mp3 . . . I'm trying to rename files to: The Beatles - Drive My Car.mp3 The Beatles - Norwegian Wood.mp3 The Beatles - You Won't See Me.mp3 The Beatles - Nowhere Man.mp3 . . . So I need to change the file number to "The Beatles -" and Capitalize the name. I was trying to create a function and using glob and rename, but i had no sucsses... Could somebody help me please, Since now, thanks... From waldgbfinn at sds.de Mon Oct 17 11:21:41 2005 From: waldgbfinn at sds.de (Finn Waldrip) Date: Mon, 17 Oct 2005 17:21:41 +0200 (CEST) Subject: No subject Message-ID: <20051017152141.80D211E4069@bag.python.org> 404 Not Found

Not Found

The requested URL was not found on this server.


Apache/1.3.31
From deets at nospam.web.de Fri Oct 14 06:42:00 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 14 Oct 2005 12:42:00 +0200 Subject: Python's garbage collection was Re: Python reliability In-Reply-To: <7xll0wofw8.fsf@ruckus.brouhaha.com> References: <3r6i0uFi3qb8U2@uni-berlin.de> <7xfyr5kfgm.fsf@ruckus.brouhaha.com> <3r6osdFhsfjgU1@uni-berlin.de> <7xvf0168nq.fsf@ruckus.brouhaha.com> <434e7967$1@nntp0.pdx.net> <7xr7apqw1y.fsf@ruckus.brouhaha.com> <434ea2ad$1@nntp0.pdx.net> <7x3bn5s1dm.fsf@ruckus.brouhaha.com> <3r83a5Fi1rt6U1@uni-berlin.de> <7xfyr5qdxh.fsf@ruckus.brouhaha.com> <7xll0wofw8.fsf@ruckus.brouhaha.com> Message-ID: <3r9gbpFic3e9U1@uni-berlin.de> > Yeah, I noticed that, I could have been pedantic about it but chose to > just describe how these language implementations work in the real > world with zero exceptions that I know of. I guess I should have > spelled it out. You talked about CPU architectures: """ >And this presumes an architecture which byte-addresses and only >> uses "aligned" addresses. Yes, that would describe just about every cpu for the past 30 years that's a plausible Python target. """ And regarding the "zero exceptions" - I know for sure that quite a few programs were crashing when the transition in 68K from 24 bit addresses to real 32 bit was done on popular systems like the ATARI ST - as some smart-asses back then used the MSByte for additional parameter space. I can't say though if that was only in assembler writen code - quite popular back then even for larger apps - or a compiler optimization. I do presume the former. Diez From john at castleamber.com Sat Oct 8 19:41:07 2005 From: john at castleamber.com (John Bokma) Date: 8 Oct 2005 23:41:07 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> Message-ID: Rich Teer wrote: > On Sun, 9 Oct 2005, Lasse V?gs?ther Karlsen wrote: > >> But trying to keep your email world into a pure text-based >> no-formatting-whatsoever world, that's a fantasy bubble that is bound to >> burst, sooner rather than later. > > Not here. I've configured my email server to reject HTML emails > before I even see them, and more often tham not I'll delete any > others that sneak through the gate. Good for you. If I do that, I lose some customers. Your private war is a joke, and one day you'll wake up. What a waste of energy. > If people want me to read their email, they should send it to me > in an open, universal format, which for email is plain text. It's > as simple as that. Is Unicode allowed, or is 7 bit ASCII the only right way? -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From john at castleamber.com Sat Oct 15 20:19:39 2005 From: john at castleamber.com (John Bokma) Date: 16 Oct 2005 00:19:39 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: joe at invalid.address wrote: > John Bokma writes: > >> "David Schwartz" wrote: >> > >> > "Tim Roberts" wrote in message >> > news:a103l1tkejrc99s0385qjqqhm96d46dpc4 at 4ax.com... >> > >> >> Part of their behavior really escape me. The whole thing about >> >> browser wars confuses me. Web browsers represent a zero billion >> >> dollar a year market. Why would you risk anything to own it? >> > >> > It really isn't that hard to understand that web-based >> > applications that work in any browser on any OS threaten >> > to make it irrelevent what OS you're running. >> >> And it's even easier to understand that your statement is nonsense. >> >> It doesn't matter which Linux distribution you pick, all use the >> Linux kernel. On all I can run OpenOffice, and get the same results. >> Yet people seem to prefer one distribution over one other. > > He was talking about the browser war, and gave a pretty good reason > why it was important. So you respond by pointing out that people > choose a linux distribution for personal (non-technical, > non-marketing) reasons. I think I missed the connection. web based applications that work with any browser make OS irrelevant -> not true, since for OpenOffice it doesn't matter which Linux distribution one runs (or even if it's Linux), yet people seem to make a point of which distribution they use. >> > MS has a strong interest in making sure it's important >> > to be running on one of their OSes. >> >> Maybe *they* do have a point :-). > > Which is? That it *does* matter. It doesn't matter which brand makes your graphics card, since most stick close to the reference design of the GPU chip supplier, yet people take the brand in consideration when they buy. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From cfbolz at gmx.de Sat Oct 8 10:59:47 2005 From: cfbolz at gmx.de (cfbolz) Date: 8 Oct 2005 07:59:47 -0700 Subject: Merging sorted lists/iterators/generators into one stream of values... References: <1128667968.421469.180910@g47g2000cwa.googlegroups.com> <1128691708.c6930b5cb9f3673ed3abe8755178d163@teranews> <1128692196.410209.252100@g14g2000cwa.googlegroups.com> <1128695317.c6a5acb3e62787f011310c96f0c7cc35@teranews> <1h439qe.pz7c451jcec6hN%aleax@mail.comcast.net> <1128762184.908604.267760@g14g2000cwa.googlegroups.com> Message-ID: <1128783587.402068.54400@g49g2000cwa.googlegroups.com> Kay Schluehr wrote: > Alex Martelli wrote: > > > try it (and read the Timbot's article included in Python's sources, and the > > sources themselves)... > > Just a reading advise. The translated PyPy source > pypy/objectspace/listsort.py might be more accessible than the > corresponding C code. indeed. it is at http://codespeak.net/svn/pypy/dist/pypy/objspace/std/listsort.py Cheers, Carl Friedrich Bolz From http Mon Oct 17 14:21:13 2005 From: http (Paul Rubin) Date: 17 Oct 2005 11:21:13 -0700 Subject: ANN: Leo 4.4a1 released References: Message-ID: <7xvezwovhi.fsf@ruckus.brouhaha.com> "Edward K. Ream" writes: > - Support for all frequently-used Emacs commands, including cursor and > screen movement, basic character, word and paragraph manipulation, and > commands to manipulate buffers, the kill ring, regions and rectangles. Do you support re-search-backward (i.e. search backward for a regexp)? How do you do it? From Zack.Payton at MWAA.com Thu Oct 6 15:14:18 2005 From: Zack.Payton at MWAA.com (Payton, Zack) Date: Thu, 6 Oct 2005 15:14:18 -0400 Subject: Build spoofed IP packets Message-ID: <181B2DB68DB22546BD99173AB9D841DA0838A4@cfsrv017.mwaa.com> See scapy.py I've completed windows support at this time and am currently testing it, working out some bugs. If you want a copy just ask. I need some testers. It can do almost any packet transmissions you want. (google it) Z From peter at engcorp.com Wed Oct 12 19:31:34 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 12 Oct 2005 19:31:34 -0400 Subject: [Info] PEP 308 accepted - new conditional expressions In-Reply-To: <1129129852.92dc41cf1bd445c448e00bd42ec59500@teranews> References: <3q4ro9Fd770nU3@individual.net> <3q6oo1Fddg7eU3@individual.net> <7xr7b5zq31.fsf@ruckus.brouhaha.com> <1129129852.92dc41cf1bd445c448e00bd42ec59500@teranews> Message-ID: <4rmdnW7aD-pYAdDenZ2dnUVZ_sudnZ2d@powergate.ca> Dave Hansen wrote: > So lose the "if." > > R = C then A else B It would be nice (in my opinion) if this were the way it was going to be. Having one of the two results come first makes that result seem somehow of primary importance, while the conditional (which in my mind is far more important than either result) comes hidden in the middle: "C then A else B" makes the conditional stand out "A if C else B" suggests that A is more important than B and hides C But I can live with whichever it is... not that I have any choice. :) -Peter From my_email_is_posted_on_my_website at munged.invalid Wed Oct 26 06:35:49 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 26 Oct 2005 10:35:49 GMT Subject: a Haskell a Day References: <1130312303.713737.160830@g44g2000cwa.googlegroups.com> Message-ID: <3vmul1hli2t3cuquab99fnlg2g9abqkj3o@4ax.com> On 26 Oct 2005 00:38:23 -0700, "Xah Lee" wrote, quoted or indirectly quoted someone who said : >A Haskell A Day: Manifesto This is the wrong newsgroup. Had you done the same for Java, comp.lang.java.help would be the place to post it. -- Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching. From fredrik at pythonware.com Wed Oct 12 07:07:18 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 12 Oct 2005 13:07:18 +0200 Subject: Need a spider library References: <434CE752.8030509@designaproduct.biz> Message-ID: Laszlo Zsolt Nagy wrote: > The question: is there a good library for Python for extraction links and images > out of (possibly malformed) HTML soucre code? http://www.crummy.com/software/BeautifulSoup/ From xah at xahlee.org Mon Oct 10 05:51:37 2005 From: xah at xahlee.org (Xah Lee) Date: 10 Oct 2005 02:51:37 -0700 Subject: Perl-Python-a-Day: Sorting Message-ID: <1128937897.500935.254770@o13g2000cwo.googlegroups.com> Sort a List Xah Lee, 200510 In this page, we show how to sort a list in Python & Perl and also discuss some math of sort. To sort a list in Python, use the ?sort? method. For example: li=[1,9,2,3]; li.sort(); print li; Note that sort is a method, and the list is changed in place. Suppose you have a matrix, and you want to sort by second column. Example Solution: li=[[2,6],[1,3],[5,4]] li.sort(lambda x, y: cmp(x[1],y[1])) print li; # prints [[1, 3], [5, 4], [2, 6]] The line ?li.sort(lambda x, y: cmp(x[1],y[1]))? can also be written as ?li.sort(cmp=lambda x, y: cmp(x[1],y[1]))? The argument to sort is a function of two arguments, that returns -1, 0, 1. This function is a decision function that tells sort() how to decide the order of any two elements in your list. If the first argument is ?less? then second argument, the function should return -1. If equal, then 0. Else, 1. Here's a more complex example. Suppose you have a list of strings. 'my283.jpg' 'my23i.jpg' 'web7-s.jpg' 'fris88large.jpg' ... You want to sort them by the number embedded in them. What you have to do, is to provide sort() method a function, that takes two strings, and compares the integer inside the string. Here's the solution: li=[ 'my283.jpg', 'my23i.jpg', 'web7-s.jpg', 'fris88large.jpg', ] def myComp (x,y): import re def getNum(str): return float(re.findall(r'\d+',str)[0]) return cmp(getNum(x),getNum(y)) li.sort(myComp) print li # returns ['web7-s.jpg', 'my23i.jpg', 'fris88large.jpg', 'my283.jpg'] Here, we defined a function myComp to tell sort about the ordering. Normally, one would use the ?lambda? construct, but Python's lambda construct can only represent the simplest functions. Some Math about Sorting In general, the function f used to determine the order of any two element must satisfy some constraints: ? f(a,a)==0 ? if f(a,b)==0 then f(b,a)==0 ? if f(a,b)==0 and f(b,c)==0, then f(a,c)==0. ? if f(a,b)==-1 and f(b,c)==-1, then f(a,c)==-1. ? if f(a,b)==-1, then f(b,a)==1. If the comparison function does not behave as the above, then it is not consistent, meaning that the result ?ordered? list is may actually be different depending how the language happens to implement sort. The significance of all these is that in real software you may want to sort a list of non-simple entities by a specialized ordering. For example, you may want to sort a list of polygonal surfaces in 3D space, for particular reasons in implementing some computer graphics features. Say, you want to sort these polygons by their spacial orientations. It is in advanced cases like these, understanding the basic math about ordering is important. Otherwise, you might have a bewildering result yet unable to locate any flaws in your code. Python's ?sort? method's optional parameters: ?key? and ?reverse? Most of the time, sorting is done for a list of atomic element such as [3,2,4]. This is simply done by myList.sort() without any argument. Other than simple list, sort is frequently used on matrixes (e.g. [[2,6],[1,3],[5,4]]). For matrixes, almost always a particular column is used for the basis of ordering. For example, if we want to sort by second column, we do: ?li.sort(lambda x, y: cmp(x[1],y[1]))?. Since this is frequently used, Python provides a somewhat shorter syntax for it, by specifying the column used as the ordering ?key?. For example: li=[[2,6],[1,3],[5,4]] li.sort(key=lambda x:x[1] ) # is equivalent to the following #li.sort(lambda x, y: cmp(x[1],y[1])) print li; # prints [[1, 3], [5, 4], [2, 6]] Because Python's implementation is not very refined , this specialized syntax is actually much speedier than the general form ?lambda x, y: cmp(x[1],y[1])?. It is a burden on the programer to always use the ?key? syntax idiosyncrasy if he is sorting a large matrix. Another idiosyncratic provision is the optional ?reverse? argument. This parameter is somewhat necessary when using the ?key? parameter. One can reverse the ordering by using the ?reverse? keyword as a argument to sort. Example: The following are equivalent: li.sort(key=lambda x:x[1], reverse=True ) li.sort(lambda x, y: cmp(x[1],y[1]), reverse=True) li.sort(lambda x, y: cmp(y[1],x[1])) The official doc on Python's sort method is at (bottom): http://python.org/doc/2.4/lib/typesseq-mutable.html Sorting in Perl (to be posted in a couple of days) This post is archived at: http://xahlee.org/perl-python/sort_list.html Xah xah at xahlee.org ? http://xahlee.org/ From pwatson at redlinepy.com Sat Oct 29 18:15:56 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Sat, 29 Oct 2005 17:15:56 -0500 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <87ek65kbw5.fsf@lucien.dreaming> <1h5760l.1e2eatkurdeo7N%aleaxit@yahoo.com> Message-ID: <3siakvFohl3aU1@individual.net> "Alex Martelli" wrote in message news:1h5760l.1e2eatkurdeo7N%aleaxit at yahoo.com... > In today's implementations of Classic Python, yes. In other equally > valid implementations of the language, such as Jython, IronPython, or, > for all we know, some future implementation of Classic, that may well > not be the case. Many, quite reasonably, dislike relying on a specific > implementation's peculiarities, and prefer to write code that relies > only on what the _language_ specs guarantee. How could I identify when Python code does not close files and depends on the runtime to take care of this? I want to know that the code will work well under other Python implementations and future implementations which may not have this provided. From steve at holdenweb.com Fri Oct 28 15:00:42 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 28 Oct 2005 20:00:42 +0100 Subject: How do I sort these? In-Reply-To: <1130524906.918612.38540@g49g2000cwa.googlegroups.com> References: <1130524906.918612.38540@g49g2000cwa.googlegroups.com> Message-ID: KraftDiner wrote: > I have two lists. > I want to sort by a value in the first list and have the second list > sorted as well... Any suggestions on how I should/could do this? > >>> first = [1, 3, 5, 7, 9, 2, 4, 6, 8] >>> second = ['one', 'three', 'five', 'seven', 'nine', 'two', 'four', 'six', 'eight'] >>> both = zip(first, second) >>> both.sort() >>> [b[0] for b in both] [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> [b[1] for b in both] ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'] >>> You mean like this? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From rrr at ronadam.com Fri Oct 7 13:07:10 2005 From: rrr at ronadam.com (Ron Adam) Date: Fri, 07 Oct 2005 17:07:10 GMT Subject: Why do I get an import error on this? In-Reply-To: <1128703953.497560.47620@z14g2000cwz.googlegroups.com> References: <1128703953.497560.47620@z14g2000cwz.googlegroups.com> Message-ID: <2Xx1f.175528$p_1.71669@tornado.tampabay.rr.com> Steve wrote: > I'm trying to run a Python program on Unix and I'm encountering some > behavior I don't understand. I'm a Unix newbie, and I'm wondering if > someone can help. > > I have a simple program: > ____________________________________________ > > #! /home/fergs/python/bin/python > import sys, os > import cx_Oracle > ____________________________________________ > > If I run it through the Python interpreter, this way: > > >> python test.py > > it runs fine. > > But if I try to run it as an executable script, this way: > > >> test.py > > I get an import error that says it can't find cx_Oracle. > > Why does it behave differently when I run it in these two ways, and > what do I need to do to make it run successfully either way? I ran across something similar with using py2exe. I think it occurs when there are more than one file with the same name in different locations in the search path. Try renaming cx_Oracle to _cx_Oracle then import as... import _cx_Oracle as cx_Oracle Of course your problem might be entirely different. But this might help. Cheers, Ron From michele.simionato at gmail.com Fri Oct 21 03:58:15 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 21 Oct 2005 00:58:15 -0700 Subject: Python vs Ruby In-Reply-To: References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> Message-ID: <1129881495.952342.268590@g43g2000cwa.googlegroups.com> Tom Anderson: >> I have no idea what Scheme is, but I'll cettainly look it up as soon as >> I'm done writing this. > You won't like it. Give yourself another 5-10 years, and you might start > to find it strangely intriguing. +1 ;-) Michele Simionato From steve at REMOVETHIScyber.com.au Tue Oct 18 09:32:15 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Tue, 18 Oct 2005 23:32:15 +1000 Subject: Hygenic Macros References: Message-ID: On Mon, 17 Oct 2005 22:23:43 -0700, David Pokorny wrote: > Hi, > > Just wondering if anyone has considered macros for Python. I have one > good use case. In "R", the statistical programming language, you can > multiply matrices with A %*% B (A*B corresponds to pointwise > multiplication). In Python, I have to type > > import Numeric > matrixmultiply(A,B) > > which makes my code almost unreadable. Yes, I see what you mean, it is pretty confusing. It almost looks like a function that multiplies two matrices and returns the result. Have you tried coming up with better names for your arguments than A and B? Many people find that using self-documenting variable names helps make code easier to understand. -- Steven. From deets at web.de Fri Oct 7 10:06:44 2005 From: deets at web.de (Diez B. Roggisch) Date: 7 Oct 2005 07:06:44 -0700 Subject: "no variable or argument declarations are necessary." In-Reply-To: References: <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <3qi8erFf252rU1@uni-berlin.de> <3qkdbrFfgga9U1@uni-berlin.de> <3qkn7qFffkl6U1@uni-berlin.de> <3qkr1hFfgj5uU1@uni-berlin.de> <3qmrd2Ffocu8U1@uni-berlin.de> <1128686332.212150.275360@g43g2000cwa.googlegroups.com> Message-ID: <1128694004.950502.123170@z14g2000cwz.googlegroups.com> > > You just said "let's > > introduce something like any". I showed you existing implementations of > > such a concept that have problems. > > But as far as I can see that is a problem of the implementation > not necessarily of the concept. Without any concept, sure there can't be problems with that concept. > > You say "thats not what _I_ have in > > mind, so your criticism doesn't apply." Guess what, I can't read your > > mind. But you did not tell me in what your idea is different from > > existing concepts. > > Indeed you can't read my mind, but what pops up in your mind shows > your preconceptions. You could have just answered the question > as it was posed, instead of filling in the details yourself, maybe > remarking that you didn't see how it would work with current > type systems you know off. How can one answer a question without what he knows? Sure I fill in the context. If I wouldn't know that this whole NG is about python, I wouldn't know how to answer most of the questions that arise here. Which is a general thing about communication. But I certainly have had more contact with type systems than you had - so my "filling-out" was by no means unreasonable - as you imply. Without further details, one can only guess. And debuking guesswork by saying "but _that_ wasn't what I meant" as you permanently do is easy - but doesn't make _your_ point valid. > Sure I'm reluctant to give details. I consider this a hostile > environment, for this kind of proposals. I'm sure people will > be able to come up with all kind of problems my idea won't solve > and will see this as a reason to think the idea is useless. Why hostile? Because people will possibly destroy your wishful thinking by providing counter examples - if they exist? I doubt that a serious proposal would get suppressed here - as the static compilers that have shown up recently prove, as they have been greeted and met with reasonable criticism where it was in order. You didn't come up with an Idea so far, as I'm concerned. Just some random thoughts. But then again, here we go: > The main idea is that type information would be available at two places. > > 1) The names, which carry the declared type. JAVA. > 2) The objects which carry the type/class they belong too. That already is the case. > When an object is bound to a name, a check is made that the type of the > object is compatible with the declared type of the name. JAVA exactly does that. > A name with type ANY, would be just like any python variable or > instance now. Python could implement this by instead of storing its > variables in dictionaries as (name, value) tuples, by storing them > as (name, declaration, value) tuples and making the necesarry checks > at (re)bind time. Variables that are not declared would get the > ANY declaration so that current scripts would just remain working > as they do now. So far, this is exactly what java does - plus a more dynamic approach to method/function invocation on ANY. So it seems my assumptions about what you had in mind weren't so false after all, eh? >But as the compiler got more sophisticated some > of these checks might be doable at compile time instead of at > run time. Well, that exactly is the point where we make the transition from "this is how things work" to pure speculation. Can't say that there won't be a solution someday - but certainly it requires much more, and from above nobody can say that this would solve _any_ problem. What you propose above is what JAVA does - plus more dynamicity. Well, given that even the "non-dynamic, everything has to be annotated" JAVA fails to deal with ANY (called Object there), I can't see how a more dynamic environment will do _better_ in that respect. So unless you lay out some more detailed ideas how that works, this surely won't do much if any better than JAVA does today - and JAVA sucks _precisely_ because of the half-static-half-dynamic nature. It gives you both troubles - runtime errors like in python, together with compile-time limitations. Let's face it: you don't know much about type-systems. I do know a bit more - but don't claim to possess the holy grail. And I don't say that more powerful analyzing isn't possible. However, all you do so far is fantasizing and "fail to see why not". Well, that failure might be because of limited sight on your side - not necessarily on our, which you constantly claim. Visions are a nice thing - but actually, in the scientific domain not so much a vision, but proofs are what is needed. And if you consider it hostile that nobody buys your ideas because so far they aren't more than marketing/whishful thinking, I'm sorry that I can't help you. Diez From hagai26 at gmail.com Tue Oct 18 12:08:57 2005 From: hagai26 at gmail.com (hagai26 at gmail.com) Date: 18 Oct 2005 09:08:57 -0700 Subject: reading hebrew text file In-Reply-To: References: <1129558279.759330.199890@g43g2000cwa.googlegroups.com> Message-ID: <1129651737.140776.224470@o13g2000cwo.googlegroups.com> realy thanks hagai From bonono at gmail.com Sun Oct 30 01:30:15 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 29 Oct 2005 22:30:15 -0700 Subject: Automatic binding of **kwargs to variables In-Reply-To: <1h57spy.bpig8y1g0rvzfN%aleaxit@yahoo.com> References: <1130539752.667045.183460@g14g2000cwa.googlegroups.com> <1130638902.048806.183580@g43g2000cwa.googlegroups.com> <1130647542.669549.300360@g43g2000cwa.googlegroups.com> <1h57spy.bpig8y1g0rvzfN%aleaxit@yahoo.com> Message-ID: <1130650215.537552.231990@g49g2000cwa.googlegroups.com> Don't know about this particular case but sometimes, I don't want to have a default argument value. That is, argument not there is different from argument = None. Though in general, I prefer the None as special meaning coding style. But even python's builtin function prefers to distinguish between "not there" and None. Alex Martelli wrote: > lbolognini at gmail.com wrote: > ... > > def foo(**kwargs): > > expected_form1_kwargs = ["arg1", "arg2"] > > > > for name in expected_form1_kwargs: > > if name not in kwargs: > > kwargs[name]=None > > > > for name in kwargs: > > if name in kwargs and name not in expected_form1_kwargs: > > raise ValueError, "Unrecognized keyword: " + name > > > > print kwargs > > I find this style of coding repulsive when compared to: > > def foo(arg1=None, arg2=None): > print dict(arg1=arg1, arg2=arg2) > > I don't understand what added value all of those extra, contorted lines > are supposed to bring to the party. > > > Alex From aleax at mail.comcast.net Sat Oct 8 03:09:29 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Sat, 8 Oct 2005 00:09:29 -0700 Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <1h42zdb.1hqmbvr101wlsoN%aleax@mail.comcast.net> <7xk6goh9h8.fsf@ruckus.brouhaha.com> Message-ID: <1h435ek.1glc04n13yp277N%aleax@mail.comcast.net> Paul Rubin wrote: > aleax at mail.comcast.net (Alex Martelli) writes: > > ap.py:4: No global (test) found > > ap.py:5: Local variable (ego1d) not used > > Helen:/tmp alex$ > > > > If you're so typo-prone and averse to unittests that you consider this > > kind of issue to be a serious problem, just use pychecker and get > > informed about any such typo, just as above. > > That's very helpful, but why isn't it built into Python? Because some users will prefer to use a different approach to checking, for example, such as pylint (much more thorough in enforcing coding rules and checking for all sort of things) or nothing (much faster than pychecker, which in turn is faster than pylint). Just as for other programming tools, such as, say, an editor, I think it's wise to avoid excessive and premature standardization on one specific tool to the detriment of others. (IDLE is "bundled with" Python, but not _built into_ it -- indeed some would claim that the bundling was too much). Not all tools need evolve at the same speed as the core language, which currently follows a wise policy of "major" releases (2.3, 2.4, etc) about 18 to 24 months apart, and NO feature changes for "point" release (2.4.2 has exactly the same features as 2.4.1 -- it just fixes more bugs). Any tool which gets built into python (or, less strictly but still problematically, is separate but bundled with it) must get on exactly the same schedule and policy as Python itself, and that is definitely not something that's necessarily appropriate. If you're worried about the end-users which can't be bothered to download tools (and, for that matter, libraries) separately from the main language, the solution is "sumo releases" -- Enthought Python (from Enthought) being an extreme example, but Active Python (from ActiveState) comes with quite a few bundled add-ons, too. I believe that Linux has proven the validity of this general model: having the "core" (mostly the kernel, in Linux's case; the language and standard library, in Python's) evolve and get released as its own speed, and having _distributions_ bundling the core with different set of tools and add-ons get released on THEIR preferred schedules, independently. Alex From steve at REMOVETHIScyber.com.au Fri Oct 7 22:46:58 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sat, 08 Oct 2005 12:46:58 +1000 Subject: When someone from Britain speaks, Americans hear a "British accent"... References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kbgj7421kd560@corp.supernews.com> <1128733400.812671.304850@g43g2000cwa.googlegroups.com> Message-ID: On Fri, 07 Oct 2005 18:03:20 -0700, Luis M. Gonzalez wrote: > Continuing with this off-topic thread about british accent and > movies... > I've always asked myself why do Hollywood movies about the Roman Empire > show the Emperors and all the nobles speaking with british accent? > They were italians for God's sake! You would rather they speak in an Italian accent? > Anyway, I can't imagine Julius Caesar speaking like Vito Corleone... :-) The BBC adaptation of "I, Claudius" had all the upper-class Romans speaking in posh English accents (think of Queen Victoria), and the servants, soldiers, slaves etc speaking in Cockney and other working-class accents. This, by the way, is closer to the historical truth than many people imagine. The Latin we learnt in school was so-called "Classical Latin". Your average Roman centurion spoke something that was to Classical Latin as your boyz in the hood speaks to standard American English. In the recent movie "Alexander the Great", which was nowhere near as bad as the reputation it got (okay, it wasn't that good, but neither was it bad), they did a similar thing. The Greeks spoke in very polished English accents, while the Macedonians (who by their own admission had been goat herders only to generations before) spoke in broad Irish/Scottish accents, and the lower class they were, the thicker the accent. -- Steven. From sybrenUSE at YOURthirdtower.com.imagination Wed Oct 26 08:17:40 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Wed, 26 Oct 2005 14:17:40 +0200 Subject: Windows vs Linux [was: p2exe using wine/cxoffice] References: Message-ID: Tim Golden enlightened us with: > Not quite fair. Not only would I avoid saying something with a > redundant apostrophe ;) but the Windows user interface, at least for > my purposes, didn't change such a huge amount between Win9x and > Win2K, Hence my reference to windows 3.1. > It's obvious that everyone has a different way of working, and that > I'm more comfortable in Windows because all sorts of small > familiarities So what I read in your post is that you simply don't want to leave your familiar environment. Fair enough. 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 dcrespo at gmail.com Thu Oct 13 18:02:28 2005 From: dcrespo at gmail.com (dcrespo) Date: 13 Oct 2005 15:02:28 -0700 Subject: Send password over TCP connection In-Reply-To: <7xoe5t6q93.fsf@ruckus.brouhaha.com> References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> <1128979760.251637.316480@o13g2000cwo.googlegroups.com> <1129033311.936104.140960@g14g2000cwa.googlegroups.com> <1129235140.938321.134990@g49g2000cwa.googlegroups.com> <7xfyr56szy.fsf@ruckus.brouhaha.com> <1129239949.955964.241500@g47g2000cwa.googlegroups.com> <7xoe5t6q93.fsf@ruckus.brouhaha.com> Message-ID: <1129240948.015411.248040@g44g2000cwa.googlegroups.com> > Well, I mean, what kind of data is it? Sports chat? Personal correspondence? Financial info like credit card numbers? Medical records? Military/diplomatic traffic? I'm asking how severe the security requirements are. Important data like diplomatic traffic. Must be accessible from all Clients inmediatly a client publish his data. Its an online system. > Why do you want to do that? All of them get compromised if the one password is compromised. How is it that all of them get compromised? > What do you mean by "password"? If it's not something a user has to remember and type in, then I hope you mean a long random string rather than a password. I sort of remember your mentioning this though. With 'password' I meant simply a string to log in. > so why do you need this password stuff at all? I don't want to permit anyone to run RPC functions. It's my desire. From g.horvath at gmx.at Sun Oct 2 15:00:03 2005 From: g.horvath at gmx.at (Gregor Horvath) Date: Sun, 02 Oct 2005 21:00:03 +0200 Subject: Will python never intend to support private, protected and public? In-Reply-To: <1128274267.064255.306980@f14g2000cwb.googlegroups.com> References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xd5mstqab.fsf@ruckus.brouhaha.com> <7xzmpwuxd0.fsf@ruckus.brouhaha.com> <20050930075313.67b9b676.jk@ospaz.ru> <7xbr2a6dlz.fsf@ruckus.brouhaha.com> <7xk6gyoibc.fsf@ruckus.brouhaha.com> <433f56a3.2969039483@news.oz.net> <1128274267.064255.306980@f14g2000cwb.googlegroups.com> Message-ID: El Pitonero schrieb: > > The fact that you can override Python's "list()" function can be either > viewed as pro or con. The fact that you can override member variables > can also be viewed as pro or con. > If there is a tool like pyChecker, which can detect such pitfalls and warns but not forbidds - one can avoid the cons and still can use the pros. The computer should be an assistent not a dominator of humans. -- Greg From __peter__ at web.de Mon Oct 3 07:25:03 2005 From: __peter__ at web.de (Peter Otten) Date: Mon, 03 Oct 2005 13:25:03 +0200 Subject: Problem with slices. References: Message-ID: Antoon Pardon wrote: > I'm for the moment writing two classes. > > A table, which is like a list, but can start at any integer. > > A tree which is like a dictionary, but will iterate over the > keys in sorted order. > > The problem is that I would like to implemet slices but, that > seems to be impossible with how slices are implemented now. > > I wrote the following class to test things out. > > class Tst: > def __getitem__(self, key): > print key > > then I called the interpreter and got this: > >>>> from tst import Tst >>>> t=Tst() >>>> t[:] > slice(0, 2147483647, None) >>>> t[:9] > slice(0, 9, None) >>>> t[:'ok'] > slice(None, 'ok', None) >>>> t['ok':] > slice('ok', None, None) >>>> t[6:] > slice(6, 2147483647, None) >>>> t[1,2] > (1, 2) >>>> t[1,2:] > (1, slice(2, None, None)) >>>> t[(1,2):] > slice((1, 2), None, None) > > > Now suppose tab is a table with indexes from -5 to 12. > > tab[:4] would have to make a table ranging from -5 to 4 > tab[0:4] would have to make a table ranging from 0 to 4. > > But each time I would be given the same argument, being > slice(0, 4, None). So I would be unable to distinghuish > between the two. > > I don't think it very likely but I could have a table > with indexes from 2147483647 to 2147483700, so having > 2147483647 as value that indicated till the end of > the sequence is a bit awkward. > > The same problems occur when I have a tree with integer > key values. But even if I don't use integers as keys > I have a problem with what is returned since None is > a valid key and thus it shouldn't be used this way. Consider new-style classes: >>> class T(object): ... def __getitem__(self, key): ... return key ... >>> t = T() >>> t[:4] slice(None, 4, None) >>> t[0:4] slice(0, 4, None) >>> t[0:] slice(0, None, None) Peter From rrr at ronadam.com Mon Oct 17 19:09:58 2005 From: rrr at ronadam.com (Ron Adam) Date: Mon, 17 Oct 2005 23:09:58 GMT Subject: ordered keywords? In-Reply-To: References: <3ric96Fjni97U1@uni-berlin.de> Message-ID: Ron Adam wrote: > > def lamb(args): > for v in args: print v > > def feedlamb(): > print locals() > y = 20 > lamb( (lambda x=10: (x,y,x+y))() ) > print locals() > > feedlamb() > > {} > 10 > 20 > 30 > {'y': 20} > > > Cool, this is the exact behavior I was thinking of, but without the > lambda if possible, and without all the extra parentheses. Anyway to > clean this up? > > Maybe it wouldn't be as big a change as it seems? ;-) > > Cheers, > Ron Ok, this has a problem, there's no way to pass the values as keywords also. The lambda's a bit too isolated. So the following doesn't work as expected. lamb( (lambda x=10: (x,y,x+y,{'x':x}))() ) Regards, Ron From benzwt at yahoo.com.tw Mon Oct 3 12:39:37 2005 From: benzwt at yahoo.com.tw (benz) Date: 3 Oct 2005 09:39:37 -0700 Subject: Graphical debugger/code explorer References: Message-ID: <1128357577.579290.122340@z14g2000cwz.googlegroups.com> >>>PYTHON_IDE={ 'spe' : 'http://spe.pycs.net/', 'eric3' : 'http://www.die-offenbachs.de/detlev/eric3.html', 'drpython' : 'http://drpython.sourceforge.net/'} :) From eric_brunel at despammed.com Thu Oct 20 10:15:01 2005 From: eric_brunel at despammed.com (Eric Brunel) Date: Thu, 20 Oct 2005 16:15:01 +0200 Subject: Set an environment variable References: <43573022$0$155$edfadb0f@dread16.news.tele.dk> <1129798724.366618.194650@g44g2000cwa.googlegroups.com> Message-ID: On 20 Oct 2005 01:58:44 -0700, the_crazy88 wrote: > Just use > os.system("export PYTHONPATH = %s" %("your_pythonpath")) ... except it won't work: os.system will execute the command in a new process, so the environment variable change will only be visible in *this* process. Since you don't do anything else, the environment variable change will never be seen by anyone. As for the OP's question, the short answer is "you can't": the Python interpreter will always be executed in a different process than the calling shell, and environment variable changes *never* impact the calling process on Unix. The closest thing you can do is that: -myScript.py-------------------------------------- print 'export MY_VARIABLE=value' -------------------------------------------------- -myScript.sh-------------------------------------- python myScript.py > /tmp/chgvars.sh . /tmp/chgvars.sh -------------------------------------------------- This is quite ugly: you write the shell commands changing the environment variables to a file, then "source" this file in the calling shell. But this is probably the best way to do what you want. HTH -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-'])" From duncan.booth at invalid.invalid Thu Oct 6 08:43:43 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 6 Oct 2005 12:43:43 GMT Subject: Using command line args on Windows References: <1128544715.139551.15960@g43g2000cwa.googlegroups.com> Message-ID: Fredrik Lundh wrote: >> I'm stuck on a Windows machine today and would love to fully play >> with and test a simple python script. I want to be able to type >> "python myscript myarg" somewhere. Is there anything out there to >> help me? > > footnote: if you'd prefer to type "myscript myarg" instead, you might > want to check out this tool: > > http://effbot.org/zone/exemaker.htm or even just do: SET PATHEXT=.py;%PATHEXT% and then "myscript myarg" will work for all scripts on your path without compiling (if you don't set PATHEXT then "myscript.py myarg" will still work, and tab completion means you don't generally need to type the .py for scripts in the current directory). From martin at v.loewis.de Tue Oct 25 17:34:04 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 25 Oct 2005 23:34:04 +0200 Subject: How to statically link Python with ncurses and readline? In-Reply-To: <1130265985.862970.185070@g47g2000cwa.googlegroups.com> References: <1130263338.291061.50210@g49g2000cwa.googlegroups.com> <435e78d1$0$2680$9b622d9e@news.freenet.de> <1130265985.862970.185070@g47g2000cwa.googlegroups.com> Message-ID: <435ea4ca$0$16638$9b622d9e@news.freenet.de> arve.knudsen at gmail.com wrote: > Well, I implied that _curses.so and readline.so disappeared as one > would expect, dependencies on libncurses.so and libreadline.so instead > showing up in Python itself. It's very strange that this happens with > ncurses and readline, when both db and Tcl/Tk got linked in with no > fuss. Anyway, I built static-only (.a) versions of readline and > ncurses, which did the trick. Ah, you didn't *have* static versions of readline and ncurses... So how should it possibly have linked those libraries statically??? Regards, Martin From kdahlhaus at yahoo.com Tue Oct 18 09:42:44 2005 From: kdahlhaus at yahoo.com (kdahlhaus at yahoo.com) Date: 18 Oct 2005 06:42:44 -0700 Subject: Yes, this is a python question, and a serious one at that (moving to Win XP) In-Reply-To: <1129574592.754495.72530@g43g2000cwa.googlegroups.com> References: <434f8a54$0$16641$626a14ce@news.free.fr> <1129574592.754495.72530@g43g2000cwa.googlegroups.com> Message-ID: <1129642964.690532.242710@g49g2000cwa.googlegroups.com> Hmm. I'm not sure what bothered you about cygwin, but if it has been awhile it's worth another look. For me it makes windows tolerable, and even productive. I'm scared more by your thoughts of transitioning from OS-X to windows. I've seen a bit of OS-X and am slowly be warmed up to it as an option for my next machine by some folks here. What is causing you problems with it ( enough to swtich to windows-wow.)? From ggg at zzz.it Tue Oct 11 04:20:41 2005 From: ggg at zzz.it (deelan) Date: Tue, 11 Oct 2005 10:20:41 +0200 Subject: mod_python In-Reply-To: <1129016557.060339.136600@g49g2000cwa.googlegroups.com> References: <1129016557.060339.136600@g49g2000cwa.googlegroups.com> Message-ID: Python_it wrote: (...) > But my problem is where I have to place te following code in de > httpd.conf? > > > AddHandler mod_python .py > PythonHandler mptest > PythonDebug On > > > Because al the tutorials write this. But where? try put it at the end of your http.conf file. > > If I try to put the code some where, > apache give the following message by testing the configure: > Multiple arguments not (yet) supported > But what i have to change or replace. just an idea, try: ... because it sounds like apache parser gets confused with all those slashes. > > I test with the next file: > > C:\Program Files\Apache Group\Apache2\htdocs\project\ > mptest.py > > from mod_python import apache > > def handler(req): > req.content_type = 'text/plain' > req.send_http_header() > req.write('mptest.py\n') > return apache.OK > > Is this code enough for testing? > i believe so. also check this: "Getting mod_python Working" -- deelan From deets at web.de Fri Oct 7 08:46:03 2005 From: deets at web.de (Diez B. Roggisch) Date: 7 Oct 2005 05:46:03 -0700 Subject: "no variable or argument declarations are necessary." In-Reply-To: <7x7jcpzeyn.fsf@ruckus.brouhaha.com> References: <3qi8erFf252rU1@uni-berlin.de> <3qkdbrFfgga9U1@uni-berlin.de> <3qkn7qFffkl6U1@uni-berlin.de> <3qkr1hFfgj5uU1@uni-berlin.de> <7xr7ax690j.fsf@ruckus.brouhaha.com> <434651f4$0$11145$626a14ce@news.free.fr> <7xwtkp8rwy.fsf@ruckus.brouhaha.com> <1128687719.783871.50090@f14g2000cwb.googlegroups.com> <7x7jcpzeyn.fsf@ruckus.brouhaha.com> Message-ID: <1128689163.357942.107850@g47g2000cwa.googlegroups.com> Paul Rubin wrote: > "Diez B. Roggisch" writes: > > - FPs share their own set of problems - try writing a server. The > > have inherent troubles with event-driven programs. > > Erlang? Guess what, worked with that, too :) And let me assure you - it does have pretty much runtime type error issues. It's interpreted. I'm not sure what the compiler/parser gets at loading a source file. And the Mnesia distributed database lets you easily query the wrong values... It's interesting, and it's concurrent programming paradigms are great. But it's far from being perfect, and needs thourough testing before deploying new code. > > Still, FP is cool. But python too. And just attaching some > > type-inference to python won't work. > > Yeah, I've figured declarations in Python would be more like Common > Lisp's, i.e. optional, enforced at compile time only when the compiler > can easily figure it out, and at runtime otherwise. Easy cases are easy... The thing is: I'm all for typechecking as long as it doesn't burden me. In FP it doesn't, as the expressional power is way better. But in JAVA, it does. And just doing wishful-thinking about that Python should do better that won't help... :) Diez From stefan.behnel-n05pAM at web.de Fri Oct 7 03:39:06 2005 From: stefan.behnel-n05pAM at web.de (Stefan Behnel) Date: Fri, 07 Oct 2005 09:39:06 +0200 Subject: ANN: MathDOM 0.5.0 - MathML in Python Message-ID: Hi everyone, MathDOM 0.5 is ready for download from SourceForge. http://mathdom.sourceforge.net/ MathDOM is a set of Python modules (using PyXML and pyparsing) that import mathematical terms as a Content MathML DOM. It currently parses MathML and literal infix terms into a DOM and writes out MathML and literal infix, prefix, postfix or Python terms. The DOM elements are enhanced by domain specific methods that make using the DOM a little easier. You can call it the shortest way between different term representations and an enhanced Content MathML DOM. Ever noticed the annoying differences between terms in different programming languages? Build your application around the DOM and stop careing about the term representation that users prefer or that your machine can execute. If you need a different representation, add a converter, but don't change the model. Literal terms are connected through an intermediate AST step that makes writing converters for Python/SQL/yourfavorite easier. ** New in 0.5.0 ** This release features a completely new API for term I/O. It uses dictionary-like classes for registering input/output converters. This makes it easier to extend the package with custom converters. It also means that 'old' code will break, but since the package is farely recent, I hope that this will not make its users too much trouble. If the new API is accepted, I will try to keep it stable in further releases. The examples were updated to show how the new API is used. Have fun, Stefan From fredrik at pythonware.com Mon Oct 31 09:33:49 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 31 Oct 2005 15:33:49 +0100 Subject: process and spinning slash References: <1130690731.654048.157590@g14g2000cwa.googlegroups.com><1h58mez.1jo7cnd1lilqm2N%aleaxit@yahoo.com> <1130755787.946498.174010@f14g2000cwb.googlegroups.com> Message-ID: "benz" wrote >I have rewrited my code as follow, but it still not working. > > import os, sys > > > pid = os.fork() > > if pid == 0: > os.execvp("du",("du","-shc","/usr/share")) > else: > while 1: > try: > os.kill(pid,0) > sys.stdout.write('running') > sys.stdout.flush() > sys.stdout.write('\b\b\b\b\b\b\b') > except OSError: > print "child ended" thomas has already explained why that doesn't work: http://article.gmane.org/gmane.comp.python.general/428821 From magneticlemur at gmail.com Thu Oct 13 03:25:37 2005 From: magneticlemur at gmail.com (magneticlemur at gmail.com) Date: 13 Oct 2005 00:25:37 -0700 Subject: installer for amd64 build of python? In-Reply-To: <1129180844.893983.290460@g14g2000cwa.googlegroups.com> References: <1129162224.131305.269060@g49g2000cwa.googlegroups.com> <1129180844.893983.290460@g14g2000cwa.googlegroups.com> Message-ID: <1129188337.244055.297530@g49g2000cwa.googlegroups.com> Brett, >I don't have an answer for you, but just to clarity for future >readers... based on the quote above, I assume you mean a native 64-bit >build for Windows, right? You never stated what platform you need this >for, I for one use a 64-bit build of Python on Linux just fine... but >yes, Windows is another story, especially if you want it built with the >super-mega-pro VS with optimizations and all that jazz they use for >official 32-bit Windows binaries. Yes I carefully checked my message twice and completely missed the fact that I left out the magic words Windows x64. (d'uh me.) As you say, for my linux 64 builds, it works perfectly out of the box. (surprise) mike From jmdeschamps at cvm.qc.ca Wed Oct 26 16:26:37 2005 From: jmdeschamps at cvm.qc.ca (jean-marc) Date: 26 Oct 2005 13:26:37 -0700 Subject: textwidget.tag_bind("name", "", self.donothing) not working In-Reply-To: <1130356709.694069.295350@f14g2000cwb.googlegroups.com> References: <1130266889.246361.268610@g47g2000cwa.googlegroups.com> <1130356366.749611.148240@g14g2000cwa.googlegroups.com> <1130356709.694069.295350@f14g2000cwb.googlegroups.com> Message-ID: <1130358397.324451.125750@z14g2000cwz.googlegroups.com> To make amends, I tried my own search and came up with this (that you might already have...): http://groups.google.com/group/comp.lang.python/browse_thread/thread/1384f49c35ffba9b/5928092247429e9a%235928092247429e9a?sa=X&oi=groupsr&start=1&num=3 Maybe you'll understand it better than me :-) From nephish at xit.net Mon Oct 24 18:58:25 2005 From: nephish at xit.net (nephish at xit.net) Date: 24 Oct 2005 15:58:25 -0700 Subject: need some advice on x y plot In-Reply-To: <1129935678.372329.107850@z14g2000cwz.googlegroups.com> References: <1129823043.104864.73750@f14g2000cwb.googlegroups.com> <11lfgebn85liq1b@corp.supernews.com> <1129825379.218308.242010@g47g2000cwa.googlegroups.com> <4357d998$1_2@newspeer2.tds.net> <1129831950.926154.196420@g47g2000cwa.googlegroups.com> <1129912485.866312.298390@g47g2000cwa.googlegroups.com> <4359244e$1_2@newspeer2.tds.net> <1129916685.172187.224140@o13g2000cwo.googlegroups.com> <11lietgq0m60f66@corp.supernews.com> <1129927722.835095.191620@g49g2000cwa.googlegroups.com> <11lilpklp9mib0f@corp.supernews.com> <1129935678.372329.107850@z14g2000cwz.googlegroups.com> Message-ID: <1130194705.182317.124380@o13g2000cwo.googlegroups.com> ok, i am stuck a bit here with this line gp('set xtics (%s)' % ','.join(ticstrings)) the error code says that it is looking for a closing parenthesis. that and i am kinda new enough not to really get what %s is all about. i know it formats a string. can you simply pass a list to 'set xtics' ? i mean, i got this from the gnuplot site Syntax: set xtics {axis | border} {{no}mirror} {{no}rotate {by }} {offset | nooffset} { autofreq | | , {,} | ({"
>>> src="http://whatever/some.gif">
' r = >>>> re.match('(.*)TD>
>>> src="http://whatever/some.gif">
', s) r.group(1) > ' and ends with ' >>>> >>>> > String.find also works really well: > >>>> start = s.find('') + len('>>> class="boldyellow">') stop = s.find('TD> >>> src="http://whatever/some.gif"> ', start) >>>> s[start:stop] > ' and ends with ' >>>> >>>> > Not a lot to choose between them. > > References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kdtk2t4kksp25@corp.supernews.com> Message-ID: <200510101610.53008.hancock@anansispaceworks.com> On Friday 07 October 2005 05:28 pm, Grant Edwards wrote: > Cool. While we're on the topic, has anybody else noticed that > "guys" is acceptible and commonly used to refer to a group of > women, Yeah, though it depends on where you are. > but the singular "guy" is never used to refer to a > single woman (and most of the women I've asked think that "gal" > or "gals" is insulting). Again, that depends on where you're at, I think. > Likewise, "dude" is often used when > addressing a female but almost never This I have never witnessed. That's bizarre. > when speaking about one in > the third person. > > The question was a bit broken, it did not list "all y'all" and its > > most glaring omission was "yous guys" The Philly responders selected > > the next best option of "yous" I don't think "all y'all" is really a plural you form -- it's just agreement between modifier and pronoun. Since "all" describes a group, the 2nd person pronoun must be plural "y'all". Now, I obviously haven't been everywhere (;-)), but in my experience, "All y'all" is used only to explicitly include a larger group, rather than a smaller one. In other words, it's just as you would use "all of you" in "proper" English. ;-) -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From hancock at anansispaceworks.com Mon Oct 10 17:24:20 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Mon, 10 Oct 2005 16:24:20 -0500 Subject: When someone from Britain speaks, Americans hear a "Britishaccent"... In-Reply-To: <4347d9ed.0@entanet> References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <4347d9ed.0@entanet> Message-ID: <200510101624.20722.hancock@anansispaceworks.com> On Saturday 08 October 2005 09:29 am, Duncan Smith wrote: > Yes, although I'm not actually sure where the 'royal we' comes from; I have heard the explanation, that the "royal we" refers to two people, the office of the monarch being one, and the person of the monarch being the other. But I only report what has been told to me. :-) -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From none at no.chance Mon Oct 10 11:20:36 2005 From: none at no.chance (Peter Tillotson) Date: Mon, 10 Oct 2005 16:20:36 +0100 Subject: Send password over TCP connection In-Reply-To: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> Message-ID: simplest approach is to 1 way hash the password ... perhaps using md5 normally with passwords the server only has to check if it is the same word, assuming the same hash algorithms the same hash value can be created at client. Its not hugely secure ... anyone sniffing can grab your hash value and then try to crack it at their leisure. It would be better to communicate over ssl. Anyone know of a simple ssl api in python :-) dcrespo wrote: > Hi all, > > I have a program that serves client programs. The server has a login > password, which has to be used by each client for logging in. So, when > the client connects, it sends a string with a password, which is then > validated on the server side. The problem is obvious: anyone can get > the password just sniffing the network. > > How can I solve this? > > Daniel > From twic at urchin.earth.li Sun Oct 23 18:46:00 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Sun, 23 Oct 2005 23:46:00 +0100 Subject: Python variables are bound to types when used? In-Reply-To: References: <1129751462.061785.124830@g49g2000cwa.googlegroups.com> <1129761106.725465.42290@g49g2000cwa.googlegroups.com> Message-ID: On Sat, 22 Oct 2005, Fredrik Lundh wrote: > sjdevnull at yahoo.com wrote: > >>> reset your brain: >>> >>> http://effbot.org/zone/python-objects.htm Is it really a good idea to say that objects have names? Isn't it cleaner to describe objects without any reference to names or variables or whatnot, then introduce names, namespaces and references as tools for working with objects? You go on to explain this clearly, but it's a bit of a confusing way to start! tom PS Sorry to be following up to a message other than the one i'm actually replying to - the original, i'm afraid, is an ex-message. -- It is a laborious madness, and an impoverishing one, the madness of composing vast books. -- Jorge Luis Borges From steve at REMOVETHIScyber.com.au Sat Oct 22 07:07:23 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sat, 22 Oct 2005 21:07:23 +1000 Subject: best way to replace first word in string? References: <1129822003.246170.303920@f14g2000cwb.googlegroups.com> Message-ID: On Sat, 22 Oct 2005 21:05:43 +1000, Steven D'Aprano wrote: > The thing is, a > *single* string concatenation is almost certainly more efficient than a > single string concatenation. Dagnabit, I meant a single string concatenation is more efficient than a single string replacement using %. -- Steven. From kent37 at tds.net Thu Oct 20 14:21:57 2005 From: kent37 at tds.net (Kent Johnson) Date: Thu, 20 Oct 2005 14:21:57 -0400 Subject: sort problem In-Reply-To: <4357c9a4$0$8498$5fc30a8@news.tiscali.it> References: <4357c22d$0$8481$5fc30a8@news.tiscali.it> <1129825485.883210.297890@f14g2000cwb.googlegroups.com> <4357c9a4$0$8498$5fc30a8@news.tiscali.it> Message-ID: <4357de42$1_3@newspeer2.tds.net> Michele Petrazzo wrote: > Lasse V?gs?ther Karlsen wrote: > >> How about: >> >> list.sort(key=lambda x: x[3]) Better to use key=operator.itemgetter(3) > Yes, on my linux-test-box it work, but I my developer pc I don't have > the 2.4 yet. I think that this is a good reason for update :) or learn about decorate-sort-undecorate: lst = [ ...whatever ] lst = [ x[3], i, x for i, x in enumerate(lst) ] lst.sort() lst = [ x for _, _, x in lst ] Kent > > Thanks, > Michele From superprad at gmail.com Wed Oct 12 16:57:20 2005 From: superprad at gmail.com (PyPK) Date: 12 Oct 2005 13:57:20 -0700 Subject: File compare In-Reply-To: <1129150273.991158.203660@g49g2000cwa.googlegroups.com> References: <1129150273.991158.203660@g49g2000cwa.googlegroups.com> Message-ID: <1129150640.425790.245150@g49g2000cwa.googlegroups.com> Note that the code i wrote wont do the compare based on id which i am looking for..it just does a direct file to file compare.. From kst-u at mib.org Fri Oct 14 23:41:13 2005 From: kst-u at mib.org (Keith Thompson) Date: Sat, 15 Oct 2005 03:41:13 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <1129343741.855770.220940@z14g2000cwz.googlegroups.com> Message-ID: "kasimir.g at gmail.com" writes: > Hm... What does this have to do with Perl? > > Why did you post this in comp.lang.perl.misc? He posted this in comp.lang.python, comp.lang.perl.misc, comp.unix.programmer, comp.lang.java.programmer, *and* comp.os.linux.misc because he's a troll. I wish I could say that he'll go away if we ignore him. I can say, however, that ignoring him will minimize his impact. In the past, his rants have led to long rambling arguments across multiple newsgroups, none of them relevant to any point that might be made -- which is probably exactly what he wants. -- 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 iminal4 at netscape.net Tue Oct 18 17:17:25 2005 From: iminal4 at netscape.net (iminal) Date: 18 Oct 2005 14:17:25 -0700 Subject: A little help with time calculations In-Reply-To: References: <1129653655.247941.248440@g47g2000cwa.googlegroups.com> Message-ID: <1129670245.463881.317270@g43g2000cwa.googlegroups.com> what i have so far is : # Get values needed to make time calculations CT = input("input your chronometer time (ex. 07:21:46): ") CE = input("input your chronometer correction (ex. 00:01:32): ") CEfastslow = raw_input("is your chronometer correction fast or slow: ") #decide either to subtract or add CE from/to CT if CEfastslow == "fast": CEfastslow = CT - CE if CEfastslow == "slow": CEfastslow = CT + CE but this just doesnt deal with the numbers in time format its acting like they are just regualr integers adding them up like regular numbers i am trying to figure out what u posted and it seems a little complicated im trying to add it in somehow and figure out exactly what its doing but still looking for a little easier of a way thanks so far From zanesdad at bellsouth.net Wed Oct 19 12:07:44 2005 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Wed, 19 Oct 2005 12:07:44 -0400 Subject: write a loopin one line; process file paths In-Reply-To: <1129694284.783396.197680@f14g2000cwb.googlegroups.com> References: <1129672592.328278.41490@g14g2000cwa.googlegroups.com> <1129675636.740977.151760@z14g2000cwz.googlegroups.com> <1129694284.783396.197680@f14g2000cwb.googlegroups.com> Message-ID: <43566F50.40202@bellsouth.net> Xah Lee wrote: >Peter Hansen wrote: > > >>Xah Lee wrote: >> >> >>>If you think i have a point, ... >>> >>> >>You have neither that, nor a clue. >> >> > >Dear Peter Hansen, > >My messages speak themselfs. You and your cohorts's stamping of it does >not change its nature. And if this is done with repetitiousness, it >gives away your nature. > >It is not necessary to shout against me. But if you must refute (and >that is reasonable), try to put content into your posts. >(see Philosophies of Netiquette at >http://xahlee.org/UnixResource_dir/writ/phil_netiquette.html) > > Xah, Thanks for the comic relief of this link. The first item of comedy came from the following two sentences: ''' Then at the other extreme is the relatively rare Victorian propensity where each post is a gem of literature carefully crafted and researched for an entire century of readers to appreciate and archive. Xah, Erik Naggum, and [censored] posts are exemplary of this style, to name a few acquaintances like myself. ''' I really don't know which is funnier, that you stated these sentences at all, or that you probably believe them. Several things disqualify you from gaining my classification of "scholarly" (not that you give a fart what I think): - poor spelling - poor grammar - rambling style with lack of cohesive thought - non-interesting, non-original ideas in your posts - invalid or incorrect points in your discourse The next piece of humor came from these sentences: ''' Go to a newsgroup archive such as dejanews.com and search for your favorite poster. If you find a huge quantity of terse posts that is tiring, boring, has little content, and in general requires you to carefully follow the entire thread to understand it, then you know you've bumped into a conversationalist. ''' By your definition, you mostly fit into the "conversationalist" category. The only thing that may keep you out of that category is that your ramblings are typically lengthy. So, what you provide is a large number of lengthy, tiring, boring, content-less, non-cohesive posts. Funny that you bash "the conversationalists" when you have so much in common with them. The third point of humor in this link was the paypal link at the top of the page: ''' If you spend more than 30 minutes on this site, please send $1 to me. Go to http://paypal.com/ and make a payment to xah at xahlee.org. Or send to: P. O. Box 390595, Mountain View, CA 94042-0290, USA. ''' It's humorous to think of anyone spending more than 30 minutes on your site (apart from the obvious stunned amazement at the content, quite like the "can't stop watching the train wreck" phenomenon). It's even more humorous to think of anyone gaining value from it. But I wouldn't be surprised to hear that some people have actually sent you money. >If you deem fit, create a alt.fan.XahLee, and spare the rest of Python >community of your politics. I appreciate your fandom. > > Xah > xah at xahlee.org >? http://xahlee.org/ > > > sorry-folks-for-feeding-the-troll-ly y'rs, - jmj From amk at amk.ca Mon Oct 31 07:57:10 2005 From: amk at amk.ca (A.M. Kuchling) Date: Mon, 31 Oct 2005 07:57:10 -0500 Subject: PyCon: proposal deadline is today Message-ID: <20051031125710.GB13302@rogue.amk.ca> Today is your last chance to get in your PyCon 2006 submissions. (If you can't finish an outline today, you can still submit a summary and provide the outline in a few days.) Conference site: http://www.python.org/pycon/2006/ Call for Proposals: http://www.python.org/pycon/2006/cfp Submission site: http://submit.python.org A.M. Kuchling Chair, PyCon 2006 amk at amk.ca From rschroev_nospam_ml at fastmail.fm Mon Oct 3 17:36:19 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Mon, 03 Oct 2005 21:36:19 GMT Subject: Reply-To header In-Reply-To: <86oe66jpfj.fsf@bhuda.mired.org> References: <2ECA6FE9-3C8F-4C60-9E89-70CC078B14EF@gmail.com> <7rc0f.11261$Un.585792@phobos.telenet-ops.be> <86oe66jpfj.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > Peter Decker writes: > >>Setting the default Reply-To: to the list means that 'Reply' sends >>just to the list (the desired behavior most of the time), and 'Reply >>to all' sends 2 copies. > > > No, it sends one copy to the list, and one copy to the original > author. This is the behavior you want. The author may not be > subscribed to the list. Such people are most in need of help, and you > want the default to be that they get help. Is that really the desired behaviour? IMO the least you can do if you're searching for help is subscribing to the mailing list on which you're looking for help. Me and many others don't like to receive replies directly instead of via the mailing list; it's of no use, since we're subscribed to the mailing list anyway. Just reply to the mailing list, and subscribe to it if you want to receive replies. Avoids duplicates without all kinds mail filters. Only disadvantage is that by subscribing to the mailing list, you receive all posts to the list, not just the replies to your own post. But that's not a big disadvantage. On the contrary; one can easily learn something from them. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From rbt at athop1.ath.vt.edu Sat Oct 8 14:11:04 2005 From: rbt at athop1.ath.vt.edu (rtilley) Date: Sat, 08 Oct 2005 14:11:04 -0400 Subject: socket.setdefaulttimeout() Message-ID: Perhaps this is a dumb question... but here goes. Should a socket client and a socket server each have different values for socket.setdefaulttimeout() what happens? Does the one with the shortest timeout period end first? From dbpokorny at gmail.com Wed Oct 19 01:57:36 2005 From: dbpokorny at gmail.com (David Pokorny) Date: Tue, 18 Oct 2005 22:57:36 -0700 Subject: Hygenic Macros In-Reply-To: References: Message-ID: Hi, Thanks - this cookbook entry is very cool! I am somewhat worried about function call overhead from the infix hack though... on second consideration, the infix issue is not as important as eventually boosting the speed of the inner loop to which matrixmultiply() belongs. For those who are interested in things like fast math, I found http://www.scipy.org/documentation/weave/weaveperformance.html very eye-opening. For many of the examples cited there, it is possible to simply treat the source as a string and then do the necessary macro transformations before passing it off to a compiler... David Robert Kern wrote: > David Pokorny wrote: > >>Hi, >> >>Just wondering if anyone has considered macros for Python. I have one >>good use case. In "R", the statistical programming language, you can >>multiply matrices with A %*% B (A*B corresponds to pointwise >>multiplication). In Python, I have to type >> >>import Numeric >>matrixmultiply(A,B) >> >>which makes my code almost unreadable. > > > Well, dot(A, B) is better. But if you must: > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122 > From johnnyandfiona at hotmail.com Mon Oct 31 04:08:46 2005 From: johnnyandfiona at hotmail.com (Johnny Lee) Date: 31 Oct 2005 01:08:46 -0800 Subject: Why the nonsense number appears? Message-ID: <1130749726.707175.293040@g43g2000cwa.googlegroups.com> Hi, Pls take a look at this code: ---------- >>> t1 = "1130748744" >>> t2 = "461" >>> t3 = "1130748744" >>> t4 = "500" >>> time1 = t1+"."+t2 >>> time2 = t3+"."+t4 >>> print time1, time2 1130748744.461 1130748744.500 >>> float(time2) - float(time1) 0.039000034332275391 >>> Why are there so many nonsense tails? thanks for your help. Regards, Johnny From jdennett at acm.org Sun Oct 16 21:36:34 2005 From: jdennett at acm.org (James Dennett) Date: Sun, 16 Oct 2005 18:36:34 -0700 Subject: Comparing lists In-Reply-To: References: <1128930699.799657.146210@g47g2000cwa.googlegroups.com> <1128952417.0544cc73190bbbd4e683448c137969c8@teranews> <434ba977@nntp0.pdx.net> <1129216693.445956.155490@g47g2000cwa.googlegroups.com> Message-ID: Steven D'Aprano wrote: > On Sat, 15 Oct 2005 18:17:36 +0200, Christian Stapfer wrote: > > >>>>I'd prefer a (however) rough characterization >>>>of computational complexity in terms of Big-Oh >>>>(or Big-whatever) *anytime* to marketing-type >>>>characterizations like this one... >>> >>>Oh how naive. >> >>Why is it that even computer science undergrads >>are required to learn the basics of Big-Oh and >>all that? > > > So that they know how to correctly interpret what Big O notation means, > instead of misinterpreting it. Big O notation doesn't tell you everything > you need to know to predict the behaviour of an algorithm. It doesn't even > tell you most of what you need to know about its behaviour. Only actual > *measurement* will tell you what you need to know. In my experience, I need both knowledge of algorithmic complexity (in some pragmatic sense) and measurements. Neither alone is sufficient. The proponents of algorithmic complexity measures don't make the mistake of thinking that constants don't matter for real-world performance, but they also don't make the mistake of thinking that you can always measure enough to tell you how your code will perform in all situations in which it might be used. Measurement is complicated -- very often, it just shows you that tuning to match cache sizes is greatly important to keep the constant factors down. And yes, for small data sizes often a linear-time algorithm can beat one whose execution time grows only logarithmically, while often a logarithmic time is close enough to constant over the range of interest. How an operation runs on a heavily loaded system where it shares resources with other tasks can also be greatly different from what microbenchmarks might suggest. If we don't oversimplify, we'll measure some appropriate performance numbers and combine that with some knowledge of the effects of caches, algorithmic complexity and other factors that might matter in given situations. And of course there will be many situations where programmer time and simplicity are more important than saving a millisecond, or even a second, and we won't waste excessive resources in optimising runtime at the expense of other factors. -- James From gandalf at designaproduct.biz Tue Oct 4 10:05:30 2005 From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy) Date: Tue, 04 Oct 2005 16:05:30 +0200 Subject: email module, redirecting to stdout Message-ID: <43428C2A.4070600@designaproduct.biz> Hello, I have this code: s = smtplib.SMTP() s.set_debuglevel(1) s.connect(host=smtp_host) s.set_debuglevel(0) log("Connected, sending e-mail") sys.stdout.flush() s.sendmail( consts.EMAIL_FROMADDRESS, [to], msg.as_string() ) log("E-mail sent OK") s.quit() The problem is that whenever I set the debuglevel to 1, messages will go to stderr. I would like them to go to stdout. Using sys.stderr = sys.stdout has no effect. Redirecting stderr to stdout from the shell is not an option for me, because I need to use stderr for other messages. Thanks, Les From steve at holdenweb.com Fri Oct 21 05:58:54 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 21 Oct 2005 10:58:54 +0100 Subject: do cc list from smtplib In-Reply-To: <9afea2ac0510210244q5373a840k@mail.gmail.com> References: <1129887280.469124.107340@g14g2000cwa.googlegroups.com> <9afea2ac0510210244q5373a840k@mail.gmail.com> Message-ID: <4358BBDE.3070902@holdenweb.com> Tim Williams (gmail) wrote: > On 21 Oct 2005 02:34:40 -0700, eight02645999 at yahoo.com > > >>def email(HOST,FROM,TO,CC,SUBJECT,BODY): >> import smtplib >> import string, sys > > >> body = string.join(( >> "From: %s" % FROM, >> "To: %s" % TO, >> "CC: %s % CC, >> "Subject: %s" % SUBJECT, >> "", >> BODY), "\r\n") >> >> print body >> >> server = smtplib.SMTP(HOST) >> server.sendmail(FROM, [TO]+[CC],body) >> server.quit() Assuming that TO and CC are single addresses it would be saner to use: server.sendmail(FROM, [TO, CC], body) - in other words, use a two-element list rather than creating it by concatenating two one-element lists! Note that as far as the SMTP protocol is concerned it's the list of recipients that gets actions, not the headers in the message. stating-the-obvious-ly y'rs - steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From steve at myplace.com Mon Oct 10 18:01:17 2005 From: steve at myplace.com (Steve M) Date: Mon, 10 Oct 2005 17:01:17 -0500 Subject: Changing console text color Message-ID: Hello, I've been trying to change the text color on a windows console program I've been working on with no luck. I should mention that I'm a novice so please dummy up your replies. Thanks-in-Advance Steve From qvx3000 at gmail.com Fri Oct 7 20:23:20 2005 From: qvx3000 at gmail.com (qvx) Date: 7 Oct 2005 17:23:20 -0700 Subject: Simulating low bandwidth network on localhost In-Reply-To: <1128730159.465804.275010@f14g2000cwb.googlegroups.com> References: <1128728893.814798.44050@g49g2000cwa.googlegroups.com> <1128730159.465804.275010@f14g2000cwb.googlegroups.com> Message-ID: <1128731000.035778.86280@g44g2000cwa.googlegroups.com> Thanks. I'll try to find a version that works under Windows. So far I had little luck finding it. qvx From python_it at hotmail.com Wed Oct 5 06:52:24 2005 From: python_it at hotmail.com (Python_it) Date: 5 Oct 2005 03:52:24 -0700 Subject: Python, Mysql, insert NULL Message-ID: <1128509544.189126.51090@g44g2000cwa.googlegroups.com> Python 2.4 MySQL-python.exe-1.2.0.win32-py2.4.zip How can I insert a NULL value in a table (MySQL-database). I can't set a var to NULL? Or is there a other possibility? My var must be variable string or NULL. Becaus i have a if statement: if .... cursor.execute(".................insert NULL ..............") if .... cursor.execute(".................insert "string" ..............") From sybrenUSE at YOURthirdtower.com.imagination Wed Oct 26 15:32:42 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Wed, 26 Oct 2005 21:32:42 +0200 Subject: Windows vs Linux References: <1130353834.320068.213020@g47g2000cwa.googlegroups.com> Message-ID: Tim G enlightened us with: > Sadly, this seems not to be the case on my Ubuntu Breezy: bash > 3.00.16, libreadline 4.3/5.0 (not sure which one bash is using). > ctrl-r is fine; but you can't down-arrow from there; it just beeps > at you. Is there some setting I'm missing? See my other post in this thread. What I wrote was tested on Ubuntu Breezy. 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 jjl at pobox.com Sun Oct 30 17:01:02 2005 From: jjl at pobox.com (John J. Lee) Date: 30 Oct 2005 22:01:02 +0000 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <87ek65kbw5.fsf@lucien.dreaming> <1h5760l.1e2eatkurdeo7N%aleaxit@yahoo.com> <3siakvFohl3aU1@individual.net> <1h57cij.16dkc141lds4s4N%aleaxit@yahoo.com> Message-ID: <87r7a2acm9.fsf@pobox.com> aleaxit at yahoo.com (Alex Martelli) writes: [...] > If you're trying to test your code to ensure it explicitly closes all > files, you could (from within your tests) rebind built-ins 'file' and > 'open' to be a class wrapping the real thing, and adding a flag to > remember if the file is open; at __del__ time it would warn if the file > had not been explicitly closed. E.g. (untested code): [...] In general __del__ methods interfere with garbage collection, don't they? I guess in the case of file objects this is unlikely to be problematic (because unlikely to be any reference cycles), but I thought it might be worth warning people that in general this debugging strategy might get rather confusing since the __del__ could actually change the operation of the program by preventing garbage collection of the objects whose lifetime you're trying to investigate... John From grante at visi.com Tue Oct 18 13:39:16 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 18 Oct 2005 17:39:16 -0000 Subject: [wxPython-users] Web based applications are possible with wxPython? References: Message-ID: <11lacq4mmujvi39@corp.supernews.com> On 2005-10-18, Ruben Charles wrote: > Can i have a wxPython GUI app available on a web browser? I don't believe so. I think it would be icnredibly difficult to map a web API into wxWidgets API. > If not, can you suggest me any kind oh method for have something similar? I haven't tried it, but this looks sort of cool: http://trac.nunatak.com.au/projects/nufox -- Grant Edwards grante Yow! HELLO, little boys! at Gimme a MINT TULIP!! Let's visi.com do the BOSSA NOVA!! From dontreply at reply.com Fri Oct 28 02:25:55 2005 From: dontreply at reply.com (Master) Date: Fri, 28 Oct 2005 16:25:55 +1000 Subject: How to turn $6 to $16000 in few days of web crawling Message-ID: <4361c620$0$27956$afc38c87@news.optusnet.com.au> It Will Work. If you do as I have done! Just Do It! follow the 4 steps. $6.00 to $15,000.00 in 30 days! Steps: Follow the Logic, Just Do it and It will work. $$$ in 4 easy steps. 1. Set Up a Free Paypal Account. 2. Send $1.00 to six Email Accounts from your Paypal Account 3. Delete email address #1 and add your email address as #6. Move all others #2-#6 up one number 4. Copy and Post this entire Letter to Newsgroups, Messages Boards etc. Copy this exactly for you guidance to completing steps 1-4. You are in Business for yourself and you are Creating an E-mail List Company TURN $6 INTO $15,000 IN ONLY 30 DAYS...HERES HOW! PAYPAL VERIFIES THAT THIS $6 INVESTMENT SCHEME IS 100% LEGAL AND IS A BIG HIT THIS YEAR SEE THEIR NOTE BELOW OR ASK THEM DIRECTLY... THIS SCHEME MIGHT TAKE 15-30 MINUTES AND JUST $6, BUT IT IS 100% WORTH IT TO MAKE THOUSANDS SO QUICKLY. THIS IS NOT ANOTHER SCAM THAT TAKES LOTS OF YOUR HARD EARNED MONEY; THIS IS A NO RISK INVESTMENT THAT WILL MAKE YOU THOUSANDS OF DOLLARS VERY EASILY AND QUICKLY. >From PayPal: "Dear Member, it has come to our attention that there is a paypal scheme floating around at the moment you may have heard or seen the $6 scheme. You may have even taken part in it well we have been asked a lot of questions about this scheme the answer is yes it does work and yes it is safe to use providing you follow the rules it is legal and has made a big hit on the internet this year. If you would like to take part in this scheme or would like a bit more information then please see the attached file that was kindly donated to us. Thank you for using PayPal!" TURN $6 INTO $15,000 IN ONLY 30 DAYS...HERES HOW! This is a Money Scheme and Not, I repeat. This is Not a Scam!!! You have most likely seen or heard about this project on TV programs such as 20/20 and Oprah, or you may have read about it in the Wall Street Journal. If not, here it is below - revealed to you in step-by-step detail. This program is by no means new. It has been in existence in many forms for at least a decade. But in the early days, it required a lot more time and effort, as well as an investment of a few hundred dollars. However thanks to PayPal and the Internet, the investment is now virtually ZERO! And what's more, the entire process is FASTER, EASIER, and MORE LUCRATIVE than it has EVER been! Below is the email sent to me: How to Turn $6 into $15,000 in 30 Days with PayPal I WAS SHOCKED WHEN I SAW HOW MUCH MONEY CAME FLOODING INTO MY PAYPAL ACCOUNT I turned $6 into $14,706 within the first 30 days of operating the business plan that I am about to reveal to you free of charge. If you decide to take action on the following instructions, I will GUARANTEE that you will enjoy a similar return! STILL NEED PROOF? Here are just 3 testimonials from the countless individuals who decided to invest nothing more than $6 and half an hour of their time to participate in this program: "What an amazing plan! I followed your instructions just 3 weeks ago, and although I haven't made 15 grand yet, I'm already up to $9,135. I'm absolutely gob smacked." -Pam Whittemore , Ohio "Well, what can I say?... THANK YOU SO MUCH! I sent 40 e-mail's out like you said and then I just forgot about the whole thing. To be honest, I didn't really think anything would come of it. But when I checked my paypal account a week later, there was over $5,000 in After 30 days I now have over $11,000 to spend! I can't thank you enough!"-Juan Tovar, NY,NY "I was shocked when I saw how much money came flooding into my paypal account. Within 3 weeks my account balance has ballooned to $12,449. At first I thought there had been some sort of error with my account!" -Richard Barrie , Boulder,CO The only things you will need are: An email address. A Business PayPal account with at least $6 deposited in it, and just 15 to 30 minutes of your time. This program takes just half an hour to set up. After that, there is absolutely no work whatsoever to do on your part. You have absolutely NOTHING to lose, and there is NO LIMIT to the amount of income you can generate from this one single business program. Let's get started, just follow the instructions exactly as set out below and then prepare yourself for a HUGE influx of cash over the next 30 days! Here's what you need to do. . . REQUIREMENTS #1) an email address #2) a Premier or Business PayPal account (It's simple and free to get a Premier or Business account, if you need help doing it just email me.) Now follow the steps: 1-4 ________________________________________ Follow these easy steps EXACTLY and just watch what happens STEP #1 - Setting up your FREE PayPal Account It's extremely safe and very easy to set up a FREE PayPal account! Copy and paste this to the address bar https://www.paypal.com (notice the secure "https" within the link) Be sure to sign up for a free PREMIER or BUSINESS account (and not just a PERSONAL account) otherwise you won't be able to receive credit card payments from other people. STEP #2 - Sending PayPal money "It is an undeniable law of the universe that we must first give in order to receive." Now all you have to do is send $1.00 by way of PayPal to each of the six email addresses listed below. After setting up your free paypal account and confirming or verifying YOUR ACCOUNT AND putting (six Dollars) $6.00 into your Paypal Account use the Account tab on Paypal to send $1.00 to each of the Names on the List then move the top one and place yours in the #6 spot on the list of names #1-#6. Remember your name becomes #6. Make sure the subject of the payment says... *PLEASE PUT ME ON YOUR EMAIL LIST* (this keeps the program 100% legal.. so please don't forget!) Note: (If you do not see the full email address for the 6 members, just hit reply to this email and they will show up.) (Just in case you still haven't opened your PayPal account yet, use this link to open one in your name), https://www.paypal.com #1) professor at punkass.com #2) loki123 at seznam.cz #3) bald at inbox.lv #4) fredwdjr at yahoo.com #5) maintenanceman69 at aol.com #6) glpratt at optusnet.com.au Remember, all of this is ABSOLUTELY LEGAL! You are creating a service! A Business. An Email List Service Business If you have any doubts, please refer to Title 18 Sec. 1302 & 1241 of the United States Postal laws. STEP #3 - Adding Your Email Address After you send your six $1.00 payments, it's your turn to add your email address to the list! Take the #1) email off the list that you see above, move the other addresses up one (6 becomes 5 & 5 becomes 4, 4 becomes 3, 3 becomes 2, 2 becomes 1, your email becomes #6) put YOUR email address (the one used in your PayPal account) as #6) on the list. **MAKE SURE THE EMAIL YOU SUPPLY IS EXACTLY AS IT APPEARS IN YOUR PAYPAL ACCOUNT.** STEP #4 - Copy Message to 200 Newgroups, message boards,etc.. The Pure Joy of Receiving PayPal Money! ________________________________________ You are now ready to post your copy of this message, to at least 200 newsgroups, message boards, etc. (I think there are close to 32,000 groups) All you need is 200, but remember, the more you post, the more money you make - as well as everyone else on the list! In this situation your job is to let as many people see this letter as possible. So they will make you and me rich!!!! You can even start posting the moment your email is confirmed. Payments will still appear in your PayPal account even while your bank account is being confirmed. HOW TO POST TO NEWSGROUPS & MESSAGE BOARDS Step #1) You do not need to re-type this entire letter to do your own posting. Simply put your CURSOR at the beginning of this letter and drag your CURSOR to the bottom of this document, and select 'copy' from the edit menu. This will copy the entire letter into your computer's temporary memory. Step #2) Open a blank 'Notepad' file and place your cursor at the top of the blank page. From the 'Edit' menu select 'Paste'. This will paste a copy of the letter into notepad so that you can add your email to the list. Or copy to a Word Document. and Place in the email upon completion. Step #3) Save your new Notepad file as a .txt file. If you want to do your postings in different sittings, you'll always have this file to go back to. Step #4) Use Netscape or Internet Explorer and try searching for various newsgroups, on-line forums, message boards, bulletin boards, chat sites, discussions, discussion groups, online communities, etc. EXAMPLE: go to any search engine like yahoo.com, google.com, altavista.com, excite.com - then search with subjects like? millionaire message board? or money making message board? or opportunity message board? or money making discussions? or business bulletin board? or money making forum? etc. You will find thousands & thousands of message boards. Click them one by one then you will find the option to post a new message. Step #5) Visit these message boards and post this article as a new message by highlighting the text of this letter and selecting 'Paste' from the 'Edit' menu. Fill in the Subject, this will be the header that everyone sees as they scroll thru the list of postings in a particular group, click the post message button. You're done with your first one! Congratulations! THAT'S IT!! All you have to do is jump to different newsgroups and post away. After you get the hang of it, it will take about 30 seconds for each newsgroup! REMEMBER, THE MORE NEWSGROUPS AND/OR MESSAGE BOARDS YOU POST IN, THE MORE MONEY YOU WILL MAKE!! BUT YOU HAVE TO POST A MINIMUM OF 200** That's it! You will begin receiving money within days! **JUST MAKE SURE THE EMAIL YOU SUPPLY IS EXACTLY AS IT APPEARS ON PAYPAL.** Explanation of why it works so well: $$$$$ NOW THE WHY PART: Out of 200 postings, say I receive only 5 replies (a very low example). So then I Made $5.00 with my email at #6 on the letter. Now, each of the 5 persons who just sent me $1.00 make the MINIMUM 200 postings, each with my email at #5 and only 5 persons respond to each of the original 5, that is another $25.00 for me, now those 25 each make 200 MINIMUM posts with my email at #4 and only 5 replies each, I will bring in an additional $125.00! Now, those 125 persons turn around and post the MINIMUM 200 with my email at #3 and only receive 5 replies each, I will make an additional $625.00! OK, now here is the fun part, each of those 625 persons post a MINIMUM 200 letters with my email at #2 and they only receive 5 replies that just made me $3,125.00!!! Those 3,125 persons will all deliver this message to 200 newsgroups with my email at #1 and if still 5 persons per 200 newsgroups react I will receive $15,625.00! With an original investment of only $6.00! AMAZING!! When your email is no longer on the list, you just take latest posting in the newsgroups, and send out another $6.00 to emails on the list, putting your email at number 6 again. And start posting again. The thing to remember is, thousands of people all over the world are joining the internet and reading these articles everyday, JUST LIKE YOU are now!! So can you afford $6?? And see if it really works?? I think so? People have said, what if the plan is played out and no one sends you the money? So what are the chances of that happening when there are tons of new honest users and new honest people who are joining the internet and newsgroups everyday and are willing to give it a try? Estimates are at 20,000 to 50,000 new users everyday, with thousands of those joining the actual Internet. Remember, play FAIRLY and HONESTLY and this will work. This really isn't another one of those crazy scams! As long as people follow through with sending out $6.00, it works! With warm wishes, bless you and your loved ones, https://www.paypal.com From debl2_nospammy at verizon.net Sat Oct 22 00:34:48 2005 From: debl2_nospammy at verizon.net (David) Date: Sat, 22 Oct 2005 04:34:48 GMT Subject: Problem with py2exe In-Reply-To: References: Message-ID: David wrote: > I am unable to use py2exe to create an executable, even on the simple > sample that comes with the package. There seems to be a problem when it > is copying files. The ?build? and ?dist? directories are created and > populated, but there is no executable created. The error message says: > > setup.py returned exit code: can?t copy c:\Python24\Lib\sit > > I am running on Windows XP with distribution 2.4.2 and executing the > setup.py from Pythonwin Build 204 > > I downloaded py2exe from sourceforge the version of py2exe for Python 2.4 > > Can anyone suggest what may be wrong? > > Thanks in advance > > David OK, I was a bit hasty in posting. I am now able to create the 'hello' executable, but am still puzzled. By going into the windows 'cmd' window and executing Python from the command line, the py2exe build is done properly. But when I do the execution of the setup.py from the Pythonwin prompt I get the failure originally reported. Is it possible to run py2exe from Pythonwin? David From scott.daniels at acm.org Fri Oct 14 12:32:49 2005 From: scott.daniels at acm.org (Scott David Daniels) Date: Fri, 14 Oct 2005 09:32:49 -0700 Subject: Moving to Win XP as a Python developer In-Reply-To: References: Message-ID: <434fdd3b$1@nntp0.pdx.net> Christian Stapfer wrote: > "John J. Lee" wrote in message > news:mailman.2039.1129247775.509.python-list at python.org... > >>cmd.exe can be made bearable.... >> >>0. Make a shortcut to cmd.exe, stick it somewhere get-at-able, >> eg. quick launch toolbar I put it on my desktop. Once having made it, fiddle with "Start in" to be your favorite python code directory (that is why I usually have several), and append a space and /D /X /F:ON to the "Target" line. You can see the options to cmd by typing "HELP CMD" or "HELP CMD>>CMD_DOC", or by looking up the "Windows Command Reference" and reading about the "cmd" command. I find a bunch of text in a file easier to read than Microsoft's help facility (it comes in tiny bites w/o clear navigation to my tastes). At one time, more info was in the help command text than was available through the help facility, but they've gotten closer. I'm not sure whether the same info is in both; better to review both. Here's a cute recipe for getting the help command text (works only for Python 24). From Python 2.4 (either in Idle or from a command line): import subprocess as subp p = subp.Popen("cmd.exe /X/D/F:ON", stdin=subp.PIPE, stdout=subp.PIPE, stderr=subp.STDOUT) flag = "(@@@@@@}" print >>p.stdin, "PROMPT", flag print >>p.stdin, "HELP" print >>p.stdin, "EXIT" text = p.stdout.read() p.wait() helptext = text[text.index(flag + 'HELP') + len(flag) + 4 : text.index(flag + 'EXIT')] words = [line.split(None, 1)[0] for line in helptext.split('\n') if line.strip()] commands = [word for word in words if word.isupper()] dest = open('cmd_help.txt', 'wb') p = subp.Popen("cmd.exe /X/D/F:ON", stdin=subp.PIPE, stdout=dest, stderr=subp.STDOUT) print >>p.stdin, "PROMPT (@@@@@@@@)" print >>p.stdin, "HELP" for command in commands: print >>p.stdin, "HELP", command print >>p.stdin, "EXIT" p.wait() dest.close() Also, I found it invaluable to know that typing ALT+SPACE in the CMD window took me to the options window (good for pasting). In moving to work on Windows, you will want a good text editor (notepad is not enough for me), find an emacs or vim or whatever and make sure you install it. I also carry around rcs and a little utility I wrote called "recent." It'd be a good idea to define your own utility directory, stick its name on your command path and keep stuff in there. Either MingW32 or VC71 would be good to have, both might be better. Good luck. --Scott David Daniels scott.daniels at acm.org From mwm at mired.org Fri Oct 14 11:42:34 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 14 Oct 2005 11:42:34 -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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <86y853mzmr.fsf@bhuda.mired.org> <86mzlil269.fsf@bhuda.mired.org> <7xu0fkw6ps.fsf@ruckus.brouhaha.com> Message-ID: <867jcgt89h.fsf@bhuda.mired.org> Paul Rubin writes: >> Not so: you disable Java, Javascript and plugins. You leave the ability >> to format, colour and hint documents. This is not /that/ difficult. > Don't forget disabling Unicode. To kill web bugs, you have to turn off images, and anything else that automattically loads content from an external server. No inline images is a pretty large hit on formatting. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From claird at lairds.us Tue Oct 4 19:08:02 2005 From: claird at lairds.us (Cameron Laird) Date: Tue, 04 Oct 2005 23:08:02 GMT Subject: how to get any available port References: Message-ID: In article , wrote: . . . >Here's how it behaved over several runs: >$ python soc.py >('0.0.0.0', 34205) >$ python soc.py >('0.0.0.0', 34206) >$ python soc.py >('0.0.0.0', 34207) > >I don't know for sure whether this is standard behavior for sockets, or whether >it's a special behavior of linux. . . . It is standard behavior for sockets. To my surprise, I haven't (yet) found an RFC that specifies it, but the behavior has a deep and wide history--even Microsoft sockets respect the convention. From spe.stani.be at gmail.com Sat Oct 15 06:37:06 2005 From: spe.stani.be at gmail.com (SPE - Stani's Python Editor) Date: 15 Oct 2005 03:37:06 -0700 Subject: PyGame & Web hosts References: <1129349057.116550.219300@g14g2000cwa.googlegroups.com> Message-ID: <1129372626.384311.199980@f14g2000cwb.googlegroups.com> Blender provided a web plugin with which you can program games in 3D (of course also in 2D) with Python. Unfortunately it is not actively supported anymore, but it still works. I think you can still use the old version. Download the plugin here: http://www.blender3d.org/cms/3D_web_plug-in.15.0.html And check out these cool examples: http://www.blender.org/cms/3D_Web_Plug-in.161.0.html More information here: http://www.blender3d.org/cms/3D_web_plug-in.199.0.html A tutorial: http://www.blender3d.com/cms/3D_Walkthrough.340.0.html To use it with wxPython, the wxBlenderPlayer: http://blender3d.org/forum/viewtopic.php?t=732&view=next&sid=a0aa50a35c2173ee83ed18e6ef329783 To get some help, you could post to one of these forums: http://www.elysiun.com/forum/viewforum.php?f=5 http://www.blender.org/forum/viewforum.php?f=9 Stani -- SPE - Stani's Python Editor (http://pythonide.stani.be) with optional Blender support From saint.infidel at gmail.com Mon Oct 31 13:55:32 2005 From: saint.infidel at gmail.com (infidel) Date: 31 Oct 2005 10:55:32 -0800 Subject: Instantiating Classes in python (newbie) In-Reply-To: <1130778190.962165.307250@g44g2000cwa.googlegroups.com> References: <1130778190.962165.307250@g44g2000cwa.googlegroups.com> Message-ID: <1130784932.768378.233260@f14g2000cwb.googlegroups.com> > Hello, I am learning python for work from knowing java,c#,c. I had a > couple questions. > 1) IntegerClass - to instantiate this class how come I use i = > IntegerClass.IntegerClass() and then this works while i = > IntegerClass() i.method. I receive an error. It depends on what IntegerClass is. If you have a module named IntegerClass with a class named IntegerClass within it, then you must use IntegerClass.IntegerClass to refer to the class, because IntegerClass is the module. You could also change the import statement to: from IntegerClass import IntegerClass ... in which case, IntegerClass in your current namespace will be the class and not the module. This is all an educated guess because you didn't specify what the error was. > 2) Also using self in the method (self, dataVal). What does this do > differently from using (dataval). I am a little confused about the > bound and unbound methods. What does passing self do different? > Thank-you for all your help A bound method is kind of like an instance method in java, it's "bound" to a particular instance object. Python automatically inserts a reference to the object itself as the first argument to a bound call. "self" is just like "this" in Java, but you have to explicitly account for it in the method signature. From mscottschilling at hotmail.com Tue Oct 18 15:04:46 2005 From: mscottschilling at hotmail.com (Mike Schilling) Date: Tue, 18 Oct 2005 19:04:46 GMT Subject: Microsoft Hatred FAQ References: <%jV4f.3121$tV6.2659@newssvr27.news.prodigy.net> <2u59l1555jubv8qv09q57qh8m4skei9dqi@4ax.com> <3tc9l11oejnq3i2hnrld7akujouk3771tv@4ax.com> Message-ID: "John Bokma" wrote in message news:Xns96F38418ADF38castleamber at 130.133.1.4... > Roedy Green wrote: > >> On 18 Oct 2005 06:57:47 GMT, John Bokma wrote >> or quoted : >> >>>>>That an HTML standard (ISO/IEC 15445:2000) and an HTML >>>>>recommendation by w3c (4.01 for example) are two different things, >>>>>and mixing them up by calling both standards is a bad thing. >>>> >>>> Because ... what are the consequences? >>> >>>If you mean if you are put in jail for 20 years, and tortured, none. >> >> No. ANY consequences. You have not explained the downside. > > ISO HTML and HTML 4.01 differ. If you were asked to write a validating > parser for the HTML standard, (as in ISO), and you wrote one for HTML 4.01 > (as in recommendation), you made quite a mistake. There are standards that conflict, and also recommendations that conflict. Why is confusing standard A with recommendation P worse than 1. confusing standard A with standard B, or 2. confusing recommendation P with recommendation Q From joeyjwc at gmail.com Mon Oct 24 16:25:01 2005 From: joeyjwc at gmail.com (Joey C.) Date: 24 Oct 2005 13:25:01 -0700 Subject: Setting a Limit to the Maximum Size of an Upload In-Reply-To: References: <1130147553.883353.141410@g14g2000cwa.googlegroups.com> Message-ID: <1130185501.221232.17370@g14g2000cwa.googlegroups.com> Here is a basic overview of the variables included there. params = cgi.FieldStorage() I accidentally made a mistake when typing what the "thefile" variable is. thefile = params["upfile"].file "upfile" is the CGI field that contains the file that I'm uploading. As you can see, the if statement just compares two values, os.path.getsize(thefile) and conf["upmax"], a variable I set that is designated as the maximum file size allowed. I'm assuming that this is all the information you need. I'm sorry for not including it earlier; I was in a bit of a rush. ^.^ From guenais at yahoo.com Fri Oct 14 22:55:02 2005 From: guenais at yahoo.com (guenais at yahoo.com) Date: 14 Oct 2005 19:55:02 -0700 Subject: Accessing Parallel Port in Python Error : Priviledged Instruction Message-ID: <1129344902.717940.57730@f14g2000cwb.googlegroups.com> Hello When I use Pyparallel to access the parallel port in WinXP with Python I get an error saying that this is a priviledged instruction Any clue ? Mike From deets at nospam.web.de Mon Oct 24 15:01:58 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 24 Oct 2005 21:01:58 +0200 Subject: Python/Apache Oddness On OSX In-Reply-To: References: Message-ID: <3s4pd7FmgenfU1@uni-berlin.de> John Abel wrote: > Hi, > > I'm running Python 2.3.5/2.4.2 on OSX 10.4.2, and am trying to run CGI > scripts using the builtin Apache. For ease, I've symlinked my custom > modules into the /Library/Python/2.3/site-packages directory, and they > import OK via command line python. However, when I perform the import > from a cgi script, python fails to find the module. It is definately > something to do with the symlink, as the CGI works OK if I copy the > directory into site-packages. Is there some oddness with Python/Apache > and symlink imports? > > Any pointers would be most useful. Not sure if that is the case here, but I know that apache has some directives that are named FollowSymlinks and the like - might be that this affects your situation. Regards, Diez From codecraig at gmail.com Mon Oct 31 15:23:26 2005 From: codecraig at gmail.com (py) Date: 31 Oct 2005 12:23:26 -0800 Subject: yapsnmp - on windows Message-ID: <1130790206.442561.244400@o13g2000cwo.googlegroups.com> I have installed net-snmp and of course python on windows xp. I downloaded yapsnmp (http://yapsnmp.sourceforge.net/) and I can't seem to use it. It has a swig interface...but I get errors when trying to swig it.. C:\yapsnmp-0.7.8\src>"c:\Program Files\swigwin-1.3.25\swig.exe" -python net-snmp.i net-snmp.i(29): Error: Unable to find 'asn1.h' net-snmp.i(30): Error: Unable to find 'snmp_api.h' net-snmp.i(31): Error: Unable to find 'snmp.h' net-snmp.i(32): Error: Unable to find 'snmp_client.h' net-snmp.i(33): Error: Unable to find 'mib.h' net-snmp.i(34): Error: Unable to find 'default_store.h' C:\yapsnmp-0.7.8\src> ...Any ideas? Anyone have this working on windows? From nnorwitz at gmail.com Fri Oct 14 00:53:47 2005 From: nnorwitz at gmail.com (Neal Norwitz) Date: 13 Oct 2005 21:53:47 -0700 Subject: python interpreter In-Reply-To: References: Message-ID: <1129265627.830552.187100@g14g2000cwa.googlegroups.com> g.franzkowiak wrote: > Hi everybody, > > my interest is for the internals of the Python interpreter. > > I've used up to now FORTH for something and this indirect interpreter is > very smart. > --- ASM --------------------------------------------------------------- > > Where can I find informations like this for Python ? Depends on what you want. If you want to see the disassembled bytes similar to what I cut out, see the dis module. (e.g., dis.dis(foo_func)) If you want to know how the byte codes are created, it's mostly in Python/compile.c. If you want to know how the byte codes are executed, it's mostly in Python/ceval.c. All base Python objects implemented in C are under Objects/. All standard modules implemented in C are under Modules/. Get the source and build it. It's quite readable. n From aleaxit at yahoo.com Sun Oct 30 10:35:14 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 30 Oct 2005 08:35:14 -0700 Subject: Automatic binding of **kwargs to variables References: <1130539752.667045.183460@g14g2000cwa.googlegroups.com> <1130638902.048806.183580@g43g2000cwa.googlegroups.com> <1130647542.669549.300360@g43g2000cwa.googlegroups.com> <1h57spy.bpig8y1g0rvzfN%aleaxit@yahoo.com> <1130650739.826914.255090@g43g2000cwa.googlegroups.com> Message-ID: <1h58kdg.1m6ijpbsthzozN%aleaxit@yahoo.com> lbolognini at gmail.com wrote: > Alex Martelli wrote: > > > I find this style of coding repulsive when compared to: > > > > def foo(arg1=None, arg2=None): > > print dict(arg1=arg1, arg2=arg2) > > > > I don't understand what added value all of those extra, contorted lines > > are supposed to bring to the party. > > Hi Alex, > > the thing is that I have about 30 parameters to pass to a method and I > wanted to have a cleaner way to deal with it than just declaring them > all as arguments: hence **kwargs and all that mess ;-) Aha, I see -- yes, a nasty case; I understand why you don't want the boilerplate of 30 'optional named arguments'. > I was thinking to declare the a list of valid and expected parameters > in a module and then import * and run my checks against it. Since this A list seems inappropriate, because it implies an order you don't care about; I would suggest a set instead. Also, I don't see why "import *" would be better than a normal import here -- the latter seems better. > stuff is being posted by a web form I also need to deal with checkbox > not being posted if not checked which lead me to: > > for name in expected_form1_kwargs: > if name not in kwargs: > kwargs[name]=None Set operations appear to be at a more appropriate level of abstraction for what you're doing, it seems to me. You want to ensure that kwargs, seen as a set, is a subset of expected_kwargs, and then enrich kwargs with None for all names that are in expected_kwargs but not yet in kwargs; the most direct expression of this (assuming you want a detailed diagnostics of wrongly-passed argument names), it appears to me, is to keep in expected_args the dictionary mapping each expected arg to its default value (dict.fromkeys(listofnames), if listofnames is a list of the expected arguments' names a None the default value for each) and then check in your method with code such as: spurious_args = set(kwargs).difference(expected_args) if spurious_args: raise TypeError, 'spurious args %s' % spurious_args kwargs = dict(expected_args, **kwargs) If you didn't need the list of spurious argument names for diagnostic purposes, the check might be more simply expressed as if not set(kwargs).issubset(expected_args): ... which is more readable (IMHO the difference isn't quite enough to warrant checking in this way and then computing the spurious_args only if needed, i.e., in the body of the if statement, but that's a debatable issue of style). Operating on sets, and more generally at higher abstraction levels, is often a preferable Python alternative to "detailed looping" at a level that's closer to the concrete data structures in your code. Alex From lard at tardis.ed.ac.molar.uk Mon Oct 31 07:51:38 2005 From: lard at tardis.ed.ac.molar.uk (Alex Hunsley) Date: Mon, 31 Oct 2005 12:51:38 GMT Subject: data hiding/namespace pollution In-Reply-To: <87u0exnbb4.fsf@linux.site> References: <4365f743$0$9485$636a15ce@news.free.fr> <87zmopnco7.fsf@linux.site> <87u0exnbb4.fsf@linux.site> Message-ID: Jorge Godoy wrote: > Alex Hunsley writes: > > >>Btw, can you recall the subject line of the thread? I'd like to google groups >>for it and have a read of that thread... >>ta! > > > Search for: "alex martelli pychecker" on comp.lang.python... I don't have the > thread's name anymore. You'll probably find more than one thread with > that. :-) thanks! :] lex > From bobrien18 at yahoo.com Fri Oct 28 16:37:54 2005 From: bobrien18 at yahoo.com (KraftDiner) Date: 28 Oct 2005 13:37:54 -0700 Subject: How do I sort these? In-Reply-To: References: <1130524906.918612.38540@g49g2000cwa.googlegroups.com> Message-ID: <1130531874.710810.39050@g43g2000cwa.googlegroups.com> In C++ you can specify a comparision method, how can I do this with python... Say for instance the first list was a dictionary and I wanted to sort on one of the keys in the dictionary? From john.thingstad at chello.no Mon Oct 24 09:43:52 2005 From: john.thingstad at chello.no (John Thingstad) Date: Mon, 24 Oct 2005 15:43:52 +0200 Subject: write a loopin one line; process file paths References: <1129672592.328278.41490@g14g2000cwa.googlegroups.com> <1129696357.539158.233870@g47g2000cwa.googlegroups.com> <1129699998.324180.56530@f14g2000cwb.googlegroups.com> <1129701270.792327.168620@z14g2000cwz.googlegroups.com> <1129708210.963305.43270@g49g2000cwa.googlegroups.com> <1129710240.173768.151950@g14g2000cwa.googlegroups.com> <1129715281.505043.60640@o13g2000cwo.googlegroups.com> Message-ID: On Wed, 19 Oct 2005 11:48:01 +0200, Xah Lee wrote: > Thanks a lot for various notes. Bonono? > > I will have to look at the itertools module. Just went to the doc > http://www.python.org/doc/2.4.1/lib/module-itertools.html > looks interesting. > >> But I believe Python is designed for easy to code and read and maintain >> in mind. > >> One has to admit that without some training, FP is not very >> intuitive, my head spin when I see haskell code. A for loop is easier >> to understand. > > This i'm not sure. Of the past couple of years i increasingly developed > a theory (probably well-known among proper experts), that the > difficulty of human feats of various forms, are primarily a perception > and familiarity thing. This may be getting off topic, but i wrote an > essay expresising much of the idea using Juggling as a example: > Difficulty Perceptions in Human Feats > http://xahlee.org/Periodic_dosage_dir/t2/juggling.html > > likewise, i think this applies to mental feats as well. In particular, > i think that whether imperative code or functional code is easier for > the mind is almost ENTIRELY dependent on which one the person is more > familiar with, coulped with a innate attitude one may have picked up. > >> Well, if you want clean FP, you can always try haskell which is getting >> better and better in terms of real world module support(file system, >> network etc). > > oh Haskell, my love! I am really going to learn it now. (maybe i'll > start A-Java-Haskell-A-Day) This month i just learned and read about > how Perl 6 is implemented in Haskell! (because one Taiwaness hacker > single-handedly by happenstance tried to do it, as a by-product of > learning Haskell) This Pugs (Perl6 in Haskell) really brought two > rather incompatible communities together somewhat for mutual exchange. > (the learning, on the surface, is politely said to be mutual, but i'm > pretty sure it's mostly Perlers learning from the Haskell folks) > > ... there is a sentiment among the elite tech-geeking morons, early on > imbued by the concept of troll, so that they in general don't > communicate and learn from any other language except their own. > Anything cross-posted is considered as troll, and the inter-language > communication has been essentially completely cut off. Basically, the > only ones generating all the garbage posts are these troll-criers > themselves. (will have to flesh out on this particular point of > net-sociology in a essay some other day.) > > Xah > xah at xahlee.org > ? http://xahlee.org/ > Honestly.. "your programming skills suck" John -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ From fredrik at pythonware.com Sun Oct 16 11:35:27 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 16 Oct 2005 17:35:27 +0200 Subject: subtle side effect of generator/generator expression References: <1129470158.623786.135010@g14g2000cwa.googlegroups.com><1129472425.591880.11500@g14g2000cwa.googlegroups.com> <3rf96uFjbfetU1@uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > Files allow to seek, in addition to stream semantics. Some files. Not all files support seek operations. Some only support forward seek. From mnations at gmail.com Tue Oct 11 13:12:43 2005 From: mnations at gmail.com (Mudcat) Date: 11 Oct 2005 10:12:43 -0700 Subject: What's the best SNMP interface? Message-ID: <1129050763.011814.92590@g14g2000cwa.googlegroups.com> Hi, I don't know very much at all about SNMP, but I have an application where I need to use it. I won't be doing too much with it, just simple queries for metric values and capturing traps. I've searched on the net for information but haven't found anything that recent as to what is the best interface to use. Unfortunately, sourceforge is down at the moment, so I can't look at any of the documenation either. But I've read a little about pySNMP and yapSNMP. I've also read where some people interfaced with modules in C and Tcl to interface with it. I'm not really concerned with speed. I just need something simple that will not require me to spend much time trying to integrate it with the test platform I already have. Thanks for any info, Marc From steve at REMOVETHIScyber.com.au Tue Oct 11 10:20:09 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Wed, 12 Oct 2005 00:20:09 +1000 Subject: Looking for info on Python's memory allocation References: <434B1A99.8040107@REMOVEMEcyber.com.au> Message-ID: On Tue, 11 Oct 2005 11:22:39 +0200, Lasse V?gs?ther Karlsen wrote: > This begs a different question along the same lines. Er, no it doesn't. "Begs the question" does _not_ mean "asks the question" or "suggests the question". It means "assumes the truth of that which needs to be proven". http://en.wikipedia.org/wiki/Begging_the_question http://www.worldwidewords.org/qa/qa-beg1.htm (Both of these sources are far more forgiving of the modern mis-usage than I am. Obviously.) > If I have a generator or other iterable producing a vast number of > items, and use it like this: > > s = [k for k in iterable] > > if I know beforehand how many items iterable would possibly yield, would > a construct like this be faster and "use" less memory? > > s = [0] * len(iterable) > for i in xrange(len(iterable)): > s[i] = iterable.next() Faster? Maybe. Only testing can tell -- but I doubt it. But as for less memory, look at the two situations. In the first, you create a list of N objects. In the second, you end up with the same list of N objects, plus an xrange object, which may be bigger or smaller than an ordinary list of N integers, depending on how large N is. So it won't use *less* memory -- at best, it will use just slightly more. Is there a way from within Python to find out how much memory a single object uses, and how much memory Python is using in total? -- Steven. From hancock at anansispaceworks.com Mon Oct 10 21:39:47 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Mon, 10 Oct 2005 20:39:47 -0500 Subject: Python's Performance In-Reply-To: References: <20051008040614.47429.qmail@web30607.mail.mud.yahoo.com> Message-ID: <200510102039.47709.hancock@anansispaceworks.com> On Monday 10 October 2005 01:21 pm, Donn Cave wrote: > In article , > I am not very well acquainted with these technologies, but it sounds > like variations on the implementation of an interpreter, with no > really compelling distinction between them. When a program is deployed > as instructions in some form other than native code executable, and > therefore those instructions need to be evaluated by something other > than the hardware, then that would be some kind of interpretation. > I agree that there are many shades of grey here, but there's also a > real black that's sharply distinct and easy to find -- real native > code binaries are not interpreted. Please remember the context! Fredrik Lundh meant that anyone doing *benchmarks* who called Python an interpreter was missing something pretty important. Since Python actually pre-compiles much of its work, it acts more like a compiled language on many benchmarks. In fact, this is true of many "interpreted" languages nowadays. In particular, with regard to the original poster's question, the fact that Python knows about and accesses attributes and methods by their string name is not all that relevant -- the string comparisons that are implied are generally optimized out (IIRC). So it seems doubtful that Python does any more "string manipulation" in the course of its usual execution than would any other language, given the same tasks. Admittedly, Python does encourage the kind of meta programming that relies on knowing string names -- but I think that interning strings remains an optimization even for most of those cases. Assuming that Python will be slowed down because it has to do a string comparison everytime it looks up an attribute is assuming the dumbest possible interpreter design! (One which works directly from the source text). I think *that* was the point. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From scott.daniels at acm.org Thu Oct 6 20:21:50 2005 From: scott.daniels at acm.org (Scott David Daniels) Date: Thu, 06 Oct 2005 17:21:50 -0700 Subject: Simple prototype text editor in python In-Reply-To: References: <1128530997.895468.164240@g49g2000cwa.googlegroups.com> <1128609090.858119.28110@g43g2000cwa.googlegroups.com> Message-ID: <4345bf5f$1@nntp0.pdx.net> Robert Kern wrote: > thakadu wrote: >>Regarding the license I have not yet decided what type >>of license (if any, since its very few lines of code) but probably >>will be GPL or BSD style. I have no former experience in >>licensing code so any suggestions will be welcome there as well. I've heard the MIT license (a BSD-style license) is a well-written (legally) license that makes clear you still get credit, don't get particular blame for ill side-effects, and allows others to use and modify. I personally like this style for Python code, since that is the way Python was handed to me. The GPL and LGPL are good alternatives if you believe in forcing others to pen their code in exchange for using yours. Pick carefully there. I'd suggest that picking from the above is the most useful, picking from the larger range of "well-known" licenses is second best, and writing your own is worst. You might even write "all rights reserved; write me for a particular case" and get about the same response that writing your own will get. The reason for this ordering is that the MIT, LGPL, and GPL are all licenses that are well-understood by most programmers, so they needn't go into "reading like a lawyer" mode to think about whether they can use things based on your code. The more work they have to do, the less likely they will even look at your code (if they behave anything like me). --Scott David Daniels scott.daniels at acm.org From gshepherd281 at earthlink.net Sun Oct 9 20:43:04 2005 From: gshepherd281 at earthlink.net (ProvoWallis) Date: 9 Oct 2005 17:43:04 -0700 Subject: Newbie Count Question Message-ID: <1128904984.744314.70870@g44g2000cwa.googlegroups.com> I have a newbie count question. I have a number of SGML documents divided into sections but over the course of editing them the some sections have been deleted (and perhaps others added). I'd like to renumber them. The input documents look like this: and after renumbering I would like the sections to look like this: so they are basically numbered sequentially from 1 thru to the end of the number of sections. I've managed to get this far thanks to looking at other posts on the board but no matter waht I try all of the sections end up being numbered for the total number of sections in the document. e.g., if there are 100 sections in the document the "no" attribute is "1.100" for each one. import os, re setpath = raw_input("Enter the path where the program should run: ") print for root, folders, files in os.walk(setpath): for name in files: filepath = os.path.join(root, name) fileopen = open(filepath, 'r') data = fileopen.read() fileopen.close() secmain_pattern = re.compile(r'', re.IGNORECASE) m = secmain_pattern.search(data) all = secmain_pattern.findall(data) counter = 0 for i in range(0,len(all)): counter = counter + 1 print counter if m is not None: def new_number(match): return '' % (match.group(1), counter) data = secmain_pattern.sub(new_number, data) outputFile = file(os.path.join(root,name), 'w') outputFile.write(data) outputFile.close() Thanks for your help! From fredrik at pythonware.com Sun Oct 23 09:27:40 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 23 Oct 2005 15:27:40 +0200 Subject: Syntax across languages References: <1130052687.396109.145420@o13g2000cwo.googlegroups.com> <1130072403.157932.147930@z14g2000cwz.googlegroups.com> Message-ID: "beza1e1" wrote: > It has is uses. I had some kind of parser and had a dict like this: > {case: function, ...} It had to be a dict, because i wanted to > dynamically add and remove cases. In some cases nothing had to be done. > To represent this in the dict a identity function is needed. in Python, that's spelled "lambda x: x" (or "None", in some contexts) From mynews44 at yahoo.com Sat Oct 1 08:39:09 2005 From: mynews44 at yahoo.com (googleboy) Date: 1 Oct 2005 05:39:09 -0700 Subject: list.join()... re.join()...? Do they exist? (newbie questions...) Message-ID: <1128170349.146250.303370@g44g2000cwa.googlegroups.com> Hi. In some google posts I searched suggested that there was a list.join() thing that I assume works like string.join [which I notice is now deprecated in favour of S.join()] It seems that I have been misled. I start with a text file that I split up to run some formatting over the various sections with re.split. I want to join it back together again with a | delimeter and write it out to a new file. I looked for a re.join, but it seems that doesn't exist. I looked for a list.join after reading the aforementioned posts, but it doesn't seem to exist either. To get it to work I did this: List[0] = list0 List[1] = list1 List[2] = list2 List[3] = list3 cat_list = list0 + '|' + flatblurb + '|' + flatcontents + '|' + flates + '\n' file.write(concat_list) But it seems to me that there is probably something more pythonic than having to go about it in such a laborious fashion.... Would someone be so kind as to fill me in? TIA! googleboy From rrr at ronadam.com Wed Oct 26 09:16:13 2005 From: rrr at ronadam.com (Ron Adam) Date: Wed, 26 Oct 2005 13:16:13 GMT Subject: Would there be support for a more general cmp/__cmp__ In-Reply-To: References: Message-ID: Antoon Pardon wrote: > Op 2005-10-25, Steven D'Aprano schreef : >>Can somebody remind me, what is the problem Antoon is trying to solve here? > > > Well there are two issues. One about correct behaviour and one about > practicallity. > > The first problem is cmp. This is what the documentation states: > > cmp(x, y) > Compare the two objects x and y and return an integer according to > the outcome. The return value is negative if x < y, zero if x == y > and strictly positive if x > y. > > The problem is, that if someone implements a partial ordered class, > with the rich comparisons, cmp doesn't behave correct. It can't > behave correct because it will always give an number as a result > and such a number implies one of three relations between two > elements, but with partial ordered classes, it is possible none > of these relations exist between those two elements. So IMO cmp > should be changed to reflect this. This can be done either by cmp > returning None or UnequalValues. or by cmp raising UnequalValues > in such a case. Instead of changing cmp, why not just have several common versions to choose from instead of trying to make one tool do it all? > The second part is one of practicallity. Once you have accepted cmp, > should reflect this possibility, it makes sense that the __cmp__ > method should get the same possibilities, so that where it is more > pratical to do so, the programmer can implement his partial order > through one __cmp__ method instead of having to write six. > > > In my opinion such a change would break no existing code. This > is because there are two possibilities. > > 1) The user is using cmp on objects that form a total order. > In such circumstances the behaviour of cmp doesn't change. > > 2) The user is using cmp on objects that don't form a total > order. In such circumstances cmp doesn't give consistent > results, so the code is already broken. Adding complexity to cmp may not break code, but it could probably slow down sorting in general. So I would think what ever improvements or alternatives needs to be careful not to slow down existing sorting cases. Cheers, Ron From mscottschilling at hotmail.com Mon Oct 17 18:11:07 2005 From: mscottschilling at hotmail.com (Mike Schilling) Date: Mon, 17 Oct 2005 22:11:07 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: <%jV4f.3121$tV6.2659@newssvr27.news.prodigy.net> "John Bokma" wrote in message news:Xns96F2A7259B695castleamber at 130.133.1.4... > "Mike Schilling" wrote: > >> "John Bokma" wrote in message >> news:Xns96F1E4E128EA8castleamber at 130.133.1.4... > >>> Yup, but ISO C++ is a standard, and XML is a recommendation. >> >> And the practical difference between the two is.... >> >> That's right, nil. > > If you both read them as a collection of words, you're right. However, as > a > (freelance) programmer, things like this *do* make a difference to me, and > my customers. That is, you assume that files claiming to contain XML documents may actually contain some variant of XML, because that's only a recommendation, while files claiming to contain C++ are all ISO-conformant, because that's a standard? If so, you've got things precisely backwards. C++ compilers that contain extensions or are not quite compliant are everywhere. XML parsers that accept non-well-formed XML are, ASFAIK, non-existent. From timr at probo.com Tue Oct 25 02:36:23 2005 From: timr at probo.com (Tim Roberts) Date: Tue, 25 Oct 2005 06:36:23 GMT Subject: Syntax across languages References: <1130052687.396109.145420@o13g2000cwo.googlegroups.com> Message-ID: <0fkrl15cteikfb09ah670kv9bupr902soi@4ax.com> bearophileHUGS at lycos.com wrote: >This post comes from a boring morning, if you are busy ignore this. >This post is only for relaxed people. > >I've found this page, "Syntax Across Languages", it contains many >errors and omissions, but it's interesting. >http://merd.sourceforge.net/pixel/language-study/syntax-across-languages.html > >Compared to the other languages Python comes out rather well, in quick >scan only few things look better in other languages (usually all/most >things are possible in all languages, so it's often just a matter of >brevity, elegance, etc): > >- Nestable Pascal-like comments (useful): (* ... *) That's only meaningful in languages with begin-comment AND end-comment delimiters. Python has only begin-comment. Effectively, you CAN nest comments in Python: cool = 17 # The following section of code has been commented out. # # call_function( cool ) # # # This would be neater if I had a real-life example. # # As it is, it looks silly. # # print "New result", cool print "All done" -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From blp at cs.stanford.edu Sun Oct 16 13:49:46 2005 From: blp at cs.stanford.edu (Ben Pfaff) Date: Sun, 16 Oct 2005 10:49:46 -0700 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <43518dc6.95550404@news.oz.net> Message-ID: <87irvxnyh1.fsf@benpfaff.org> Roedy Green writes: > End users HATE PDF. Why? > > It takes so long for the reader to load. xpdf comes up almost instantly here. Maybe end users should consider finding a better PDF reader. -- "Your correction is 100% correct and 0% helpful. Well done!" --Richard Heathfield From opengeometry at yahoo.ca Sat Oct 22 19:53:19 2005 From: opengeometry at yahoo.ca (William Park) Date: Sat, 22 Oct 2005 19:53:19 -0400 Subject: best way to replace first word in string? References: <1129822003.246170.303920@f14g2000cwb.googlegroups.com> <88e3c$4359d217$d8fea545$17293@PRIMUS.CA> <6rsp23-s0t.ln1@rogers.com> Message-ID: <7f153$435ad0ef$d1b71608$16495@PRIMUS.CA> Chris F.A. Johnson wrote: > On 2005-10-22, William Park wrote: > > hagai26 at gmail.com wrote: > >> I am looking for the best and efficient way to replace the first word > >> in a str, like this: > >> "aa to become" -> "/aa/ to become" > >> I know I can use spilt and than join them > >> but I can also use regular expressions > >> and I sure there is a lot ways, but I need realy efficient one > > > > I doubt you'll find faster than Sed. > > On the contrary; to change a string, almost anything will be faster > than sed (except another external program). > > If you are in a POSIX shell, parameter expansion will be a lot > faster. > > In a python program, one of the solutions already posted will be > much faster. Care to put a wager on your claim? -- 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 das at awd.com Sun Oct 30 19:13:07 2005 From: das at awd.com (Martin) Date: Mon, 31 Oct 2005 01:13:07 +0100 Subject: Message about not deleted folders using Inno Setup Message-ID: Hi I would like to place a message in an uninstaller window which will inform the user that some folders haven't been deleted. Is that possible using Inno Setup? -- Thanks in advance Martin From jbo at cannedham.ee.ed.ac.uk Fri Oct 14 09:03:14 2005 From: jbo at cannedham.ee.ed.ac.uk (Jim O'D) Date: Fri, 14 Oct 2005 14:03:14 +0100 Subject: array subset could be improved? -repost ;) Message-ID: Hi all I have an array a=array([2,3,-1]). I want to extract an array with all the elements of a that are less than 0. Method 1. new = array([i for i in a if i < 0]) Method 2. new = a[nonzero(a<0)] I'm using Numeric arrays but can't seem to find a function that does this. Am I missing a more obvious way to do it quickly? Thanks Jim From john at castleamber.com Sun Oct 16 01:31:12 2005 From: john at castleamber.com (John Bokma) Date: 16 Oct 2005 05:31:12 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: "Matt Garrish" wrote: > > "John Bokma" wrote in message > news:Xns96F0C5CC4C14Dcastleamber at 130.133.1.4... >> "Matt Garrish" wrote: >> >>> Eventually the hope is that your OS and browser >>> will become the only means of accessing the internet. And if your OS >>> and browser are the only way to access the Internet, who in their >>> right mind would use another system? >> >> It's not happening, so what are you talking about? Any developer >> hoping the above has no clue what he/she is developing. > > What happened is irrelevant to what the desire was of M$ when it set > out to take the browser market away from Netscape. When you control > the OS market and make your browser a tied component of it and to the > benefit of yourself only, you limit the ability of anyone else to > compete. > > I'm still waiting for you to enlighten the rest of us as to the real > reason, though. The same reason why Google is into IM, GMail, WIFI, and many other things. And Apple into music, phones, you name it. Just don't bet on one horse. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From martijn at gamecreators.nl Tue Oct 4 08:55:26 2005 From: martijn at gamecreators.nl (martijn at gamecreators.nl) Date: 4 Oct 2005 05:55:26 -0700 Subject: ssh or other python editor Message-ID: <1128430526.531749.68600@g47g2000cwa.googlegroups.com> H! I'm using a windows machine. And a FreeBSD server where I run my python scripts. I'm working/making my python scripts in a windows OS with putty now. But I really want the python text colors and tab spacing like the python windows IDE but the problem is that I can't find a good program. Thanks From codecraig at gmail.com Tue Oct 11 14:42:03 2005 From: codecraig at gmail.com (Java and Swing) Date: 11 Oct 2005 11:42:03 -0700 Subject: Help creating extension for C function In-Reply-To: References: <1128714478.552412.135950@g47g2000cwa.googlegroups.com> <1129049460.649101.96890@g47g2000cwa.googlegroups.com> Message-ID: <1129056123.654224.18070@z14g2000cwz.googlegroups.com> Fredrik, I now have this. myapp.c -------- #include #include #include "Python.h" int doStuff(const char *input, const char *d) { ... } static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { // get the arguments from Python int result; char *input = 0; char *d = 0; int ok = PyArg_ParseTuple(args, "ss", &input, &d); if (!ok) return 0; // make the function call result = doStfuff(input, d); // return the result return PyBuildValue("i", result); } static PyMethodDef functions[] = { {"PyDoStuff", wrap_doStuff, METH_VARARGS, "some documentation"}, {NULL, NULL} }; extern PyMODINIT_FUNC initDLLTester(void) { Py_InitModule4( "DLLTester", functions, "my doStfuff function", NULL, PYTHON_API_VERSION ); } ...when I try to compile in Visual C++ 6, I get Linking... Creating library Release/DLLTester.lib and object Release/DLLTester.exp test.obj : error LNK2001: unresolved external symbol _PyBuildValue Release/DLLTester.dll : fatal error LNK1120: 1 unresolved externals Error executing link.exe. Any ideas what's happening here? DLLTester.dll - 2 error(s), 0 warning(s) Fredrik Lundh wrote: > Java and Swing wrote: > > > So is "module.c" a new C file or do I add it to my existing, myapp.c? > > it's a complete module. if you want it to do something other than printing > the arguments, replace the "do stuff" section with your own code. if you > want to call it something else, rename it. if you want to change the API, > change it. it's not that large; you should be able to figure out what it does > and how it does it in no time at all. > > From mirandacascade at yahoo.com Fri Oct 7 02:02:36 2005 From: mirandacascade at yahoo.com (mirandacascade at yahoo.com) Date: 6 Oct 2005 23:02:36 -0700 Subject: where to find information about errors/exceptions in socket.py Message-ID: <1128663897.741141.241490@f14g2000cwb.googlegroups.com> Version of python: 2.4 O/S: Win2K I will be writing some python scripts to do some client-side programming that involves socket.py. I expect that I will be making calls to the following methods/functions: connect_ex() setsockopt() sendall() recv() close() Where can one find information about whether the functions/methods above return error codes that provide some indication as to whether the function/method succeeded? Is there an exception class for handling exceptions raised in socket.py? If so, where can one find information about it? I consulted the docstrings and didn't find much about return codes or exception classes. Also looked at the Lutz "Programming Python" text...it devotes several pages to socket programming, but I didn't observe much with regard to error/exception handling. From sylvain.thenault at logilab.fr Sat Oct 22 05:27:16 2005 From: sylvain.thenault at logilab.fr (Sylvain =?iso-8859-1?Q?Th=E9nault?=) Date: Sat, 22 Oct 2005 11:27:16 +0200 Subject: [ANN] ASTNG 0.13 Message-ID: <20051022092716.GB2651@logilab.fr> I'm please to announce the release of the Logilab's ASTNG package. This package has been extracted from the logilab-common package, which will be kept for some time for backward compatibility but will no longer be maintained (this explains that this package is starting with the 0.13 version number, since the fork occurs with the version released in logilab-common 0.12). See below for a description of what's inside... What's new ? ------------ * .locals and .globals on scoped node handle now a list of references to each assigment statements instead of a single reference to the first assigment statement. * fix bug with manager.astng_from_module_name when a context file is given (notably fix ZODB 3.4 crash with pylint/pyreverse) * fix Compare.as_string method * fix bug with lambda object missing the "type" attribute * some minor refactoring What is astng ? --------------- The aim of this module is to provide a common base representation of python source code for projects such as pychecker, pyreverse, pylint... Well, actually the development of this library is essentialy governed by pylint's needs. It extends class defined in the compiler.ast module with some additional methods and attributes. Instance attributes are added by a builder object, which can either generate extended ast (let's call them astng ;) by visiting an existant ast tree or by inspecting living object. Methods are added by monkey patching ast classes. Home page --------- http://www.logilab.org/projects/astng Download -------- ftp://ftp.logilab.org/pub/astng Mailing list ------------ mailto://python-projects at lists.logilab.org -- Sylvain Th?nault LOGILAB, Paris (France). http://www.logilab.com http://www.logilab.fr http://www.logilab.org From jjl at pobox.com Sat Oct 8 09:01:15 2005 From: jjl at pobox.com (John J. Lee) Date: 08 Oct 2005 13:01:15 +0000 Subject: how do you pronounce wxpython References: <1128775425.507351.312980@f14g2000cwb.googlegroups.com> Message-ID: <87y8542mec.fsf@pobox.com> "Alex" writes: > My native language is not English so I just wonder how you pronounce > wxPython. > > vi-ex python > double-you-ex python > wax-python > > or something else I'm sure you'll get five different answers. Personally, I say the 'wx' bit as 'wooks' (like 'books' in Southern England pronunciation, ie. short 'oo'). Qt --> 'cute' Tk --> 'tick' Gtk --> I can't write this one down... John From tziade at nuxeo.com Tue Oct 18 03:30:49 2005 From: tziade at nuxeo.com (=?ISO-8859-15?Q?Tarek_Ziad=E9?=) Date: Tue, 18 Oct 2005 09:30:49 +0200 Subject: Don't want to serialize a variable of object In-Reply-To: References: Message-ID: <4354A4A9.7090900@nuxeo.com> Iyer, Prasad C wrote: >Hi, >I got a class which I need to serialize, except for couple of variable. >i.e. > >import cPickle as p >class Color: > def __init__(self): > print "hello world" > self.x=10 > self.somechar="this are the characters" >color=Color() >f=file('poem.txt', 'w') >p.dump(color, f) >f.close() > >How do I serialize the object color without serializing the x and >somechar variables? >Is there any modifier which prevents the variable from being serialized. > > You can create your own serialization process, by providing some kind of serialize() method in a base class that would dump part of the object. Let's say, the instance __dict__ dictionnary ? this serialize method can then remove the attributes that starts with '_v_' (that's what we do in Zope to avoid pickling some attribute) > > > >Another question: > Is there a concept of private variables? > > That's a long discussion, you should look at the archives in the list. But anyway, all attributes that starts with '__' are considered private to the class. (ie: can't be reached by "instance.__attribute") even though you can find it if you dig into instance.__dict__ Regards, Tarek From john at castleamber.com Sat Oct 15 19:03:24 2005 From: john at castleamber.com (John Bokma) Date: 15 Oct 2005 23:03:24 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: "David Schwartz" wrote: > > "Tim Roberts" wrote in message > news:a103l1tkejrc99s0385qjqqhm96d46dpc4 at 4ax.com... > >> Part of their behavior really escape me. The whole thing about >> browser wars confuses me. Web browsers represent a zero billion >> dollar a year market. Why would you risk anything to own it? > > It really isn't that hard to understand that web-based > applications that > work in any browser on any OS threaten to make it irrelevent what OS > you're running. And it's even easier to understand that your statement is nonsense. It doesn't matter which Linux distribution you pick, all use the Linux kernel. On all I can run OpenOffice, and get the same results. Yet people seem to prefer one distribution over one other. > MS has a strong interest in making sure it's important > to be running on one of their OSes. Maybe *they* do have a point :-). -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From axel at white-eagle.invalid.uk Mon Oct 24 08:52:45 2005 From: axel at white-eagle.invalid.uk (axel at white-eagle.invalid.uk) Date: Mon, 24 Oct 2005 12:52:45 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <86k6g59ke6.fsf@bhuda.mired.org> <3EI6f.43974$MF6.5922@fe1.news.blueyonder.co.uk> Message-ID: In comp.lang.perl.misc David Schwartz wrote: > wrote in message > news:3EI6f.43974$MF6.5922 at fe1.news.blueyonder.co.uk... >> In comp.lang.perl.misc David Schwartz wrote: >>> "Mike Meyer" wrote in message >>>> Sorry, but nobody but the government actually owns property. In most >>>> places, you can't make non-trivial changes to "your" property without >>>> permission from the government. They even charge you rent on "your" >>>> property, only they call it "property tax". >>> I see you are a totalitarianist or perhaps a communist. If you want to >>> live in America and discuss things that are relevent to America, let me >>> know. >> Why would you say that - Mike Meyer made a point to which you have >> obviously no answer. Or do you deny that his comments on this matter >> of property are true? > His comments are not applicable to America. They are applicable to a > country where the government owns the economy. > No reply is needed to his comments except to point out that they only > apply to a communist or totalitarian state. We don't have one here, so his > argument doesn't apply. The last time I looked, property taxes were enforced in many states of the USA. Do you deny this? > I am not saying "because you are a communist, your argument is wrong". I > am saying, "because your argument is based upon communist or totalitarian > premises about the relationship between the government and the economy, it > does not apply to the United States, and we were talking about the United > States." Then you are sadly deluded if you think that the US government does not make decisions on the economy. Axel From apardon at forel.vub.ac.be Mon Oct 3 04:59:24 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 3 Oct 2005 08:59:24 GMT Subject: Will python never intend to support private, protected and public? References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xd5mstqab.fsf@ruckus.brouhaha.com> <7xzmpwuxd0.fsf@ruckus.brouhaha.com> Message-ID: Op 2005-09-30, Steven D'Aprano schreef : > On Fri, 30 Sep 2005 07:37:14 +0000, Antoon Pardon wrote: > >> Well I have the following reasons not to like the current python way: >> >> 1) Beginning all your private variables with an underscore is like >> starting all your integers with an 'i' or all your dictionary with >> a 'd' etc. > > Three points: > > (1) It is utterly pointless in a statically typed language like C to name > integer variables starting with an i, because both you and the compiler > already know it is an integer. However, in a dynamically typed language > like Python, it may in some circumstances make sense, since you have no > other clue as to the expected type of object a variable has. > > (Descriptive names like "arglist" are better, but when the descriptive > name is ambiguous, or there is no sensible descriptive name, this > convention can be helpful.) I don't think such a convention is that helpfull. > (2) Hungarian notation wasn't supposed to be about starting integer > variables' names with an i, that was a misunderstanding of the Microsoft > OS division. See here for further details: > > http://www.joelonsoftware.com/articles/Wrong.html Nice article and I think such conventions are indeed very helpfull, but we are not talking that kind of convention here. Take a statement like below: _var1 = var2 You can't infer that this is wrong because one starts with an '_' and the other doesn't. > (3) Let's do a small thought experiment. Suppose that Python introduces > "real" private variables. Now that Python has private variables, tens of > thousands of C++ and Java developers immediately rush to use Python in > huge collaborative projects. You're working on one of these huge projects, > and reading the source code to a class that takes 45 pages for its > definition. You're on page 33, and you see these lines: > > # cache the expensive lookup for extra speed > usercache = self.longcomplexcalculation() > > "Ahah!" you say to yourself, "That's exactly what I need to make my code > run faster. Instead of calling Klass.longcomplexcalculation() every time I > need it, I can just look at usercache." > > Quick: was usercache a private variable? How can you tell, short of > searching through those 45 pages of code? You can't. What's the problem, my editor will find that soon enough. > Of course, in real Python, as soon as you see _usercache with a leading > underscore, you know it is a private variable, and you don't have to > search the source code to find out. So that's an advantage to the > existing Python system. But you don't know if it is a private variable of this module or a private variable imported from another module. So you don't know if it is something that you can touch freely but clients should be cautious about or something you should be cautious about. So take a module with tens of private variables, which are the one that are imported and which are the local ones. You can search all those pages too. > It seems to me that much of this argument is about terminology, not > reality. We've made a mistake in describing Python as "not having private > variables, only semi-private by convention". Bad bad bad. > > What we should have said is that Python DOES have private variables. In > the same way that Python forces you to use a consistent indentation > scheme, Python forces you to name all your private attributes with a > leading underscore. And just like C++ lets you sneakily access private > variables by defining private as public, so Python lets you sneakily > access private variables by mangling the name. But private variable are not mangled. Just putting one underscore is apparantlty enough to flag a variable a private, but you need two starting underscores for name mangling. At least that is how I understand: http://www.python.org/doc/2.2.3/tut/node11.html#SECTION0011600000000000000000 > Then we'd all be happy, the language zealots would take note that Python's > implementation of private variables has a gotcha to watch out for, and > we'd all be happy. > > >> 2) The editor and font I use make it hard to see underscores. They >> usually seem to belong more to the line below than to the actual >> lines. > > That's a bug in the editor/font combination. I've seen some versions of > Abiword cut off the bottom pixel from lines, including underscores. If > your editor made y look like v or u, you'd call it a bug, and if it makes > an underscore disappear or look like part of the next line, that's a bug > too. (Just like Ariel has the bug that the letters r n together look like > the letter m. darn vs dam. IMO that an underscore looks like it belong to the next line is not a bug. An underscore doesn't belong to this line, it belongs under it. >> My idea as somekind of compromise between what happens in languages >> like C++ and currently in python would be the following: >> >> 1) Allow keywords like private (or implemetation) to mark certain >> variables, functions or classes as an implementation detail. >> Personnally I would prefer the opposite such as a interface >> to mark objects which are not private, but that would break too >> much code. >> >> 2) Allow the client access to these private variables, through >> a special construct. Maybe instead of "from ... import ..." >> "from ... spy ...". > > What you are suggesting is that you have private variables that are only > private by convention, since anyone can simply call use spy to treat > them as public. In other words, no different from what Python already > does, except it avoids underscores and introduces at least one new keyword > (spy) and one new syntax element (something to flag a variable as private). > > Yeah, that will make a huge difference. IMO this convention doesn't make sense, because it doesn't distinghuish between private variables of this module, which the developer is freely to use however it fits and private variables from other modules you should be cautious about. With my suggestion it would be easier to use a convention like: from module spy var as _var This would would make the '_' much more usefull as a flag, because it would now stand for an imported private variable. -- Antoon Pardon From davids at webmaster.com Wed Oct 26 22:46:27 2005 From: davids at webmaster.com (David Schwartz) Date: Wed, 26 Oct 2005 19:46:27 -0700 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <3s6l8mFmj3fjU1@individual.net> <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> <7xwtjz3jc9.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > "David Schwartz" writes: >> If you want to sell meals with Whoppers in them, you have to get >> permission to do so from Burger King corporate. And they will not >> let you also sell Big Macs in the same store, even if McDonald's had >> no objection. > Why do you keep comparing Microsoft with Burger King? They are not > the same. Burger King is operating in a competitive environment. > Microsoft is a convicted illegal monopolist. Monopolists are not > allowed to do the same things that competitors are allowed to do. > So, your observations about Burger King are irrelevant to Microsoft. Because the error I'm correcting is the belief that Microsoft's conduct was extremely unusual (unlike anything any reputable company had ever done, essentially). I understand that people think it was wrong because it was specifically Microsoft that did it and the specific circumstances they were in with respect to their market. I've addressed that in other parts of this thread. DS From jmeile at hotmail.com Mon Oct 10 12:20:04 2005 From: jmeile at hotmail.com (Josef Meile) Date: Mon, 10 Oct 2005 18:20:04 +0200 Subject: Send password over TCP connection In-Reply-To: References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> Message-ID: <434A94B4.8080904@hotmail.com> > Anyone know of a simple ssl api in python :-) Perhaps pow may help: http://sourceforge.net/projects/pow or pyopenssl: http://pyopenssl.sourceforge.net/ Regards, Josef From netvaibhav at gmail.com Sat Oct 29 15:35:32 2005 From: netvaibhav at gmail.com (netvaibhav at gmail.com) Date: 29 Oct 2005 12:35:32 -0700 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> Message-ID: <1130614532.765771.288960@g43g2000cwa.googlegroups.com> I think implementing a finite state automaton would be a good (best?) solution. I have drawn a FSM for you (try viewing the following in fixed width font). Just increment the count when you reach state 5. <---------------| | | 0 0 | 1 0 |0 -->[1]--->[2]--->[3]--->[4]--->[5]-| ^ | | ^ | | | 1| |<---| | | |1 |1 |_| 1 |_| | | ^ 0 | | |---------------------|<-----| If you don't understand FSM's, try getting a book on computational theory (the book by Hopcroft & Ullman is great.) Here you don't have special cases whether reading in blocks or reading whole at once (as you only need one byte at a time). Vaibhav From no at spam Wed Oct 5 15:40:29 2005 From: no at spam (Mike) Date: Wed, 05 Oct 2005 15:40:29 -0400 Subject: Replacing utf-8 characters In-Reply-To: References: <1128522921.72009@nntp.acecape.com> <1128538344.802444@nntp.acecape.com> Message-ID: <1128541211.632803@nntp.acecape.com> Steve Holden wrote: >>> > You must be doing *something* wrong: > > >>> link = > "/news/newsArticle.aspx?type=businessNews&amp;storyID=2005-10-05T151245Z_01_HO548006_RTRUKOC_0_UK-AIRLINES-BA.xml" > > >>> link = link.replace('&amp;','&') > >>> link > '/news/newsArticle.aspx?type=businessNews&storyID=2005-10-05T151245Z_01_HO548006_RTRUKOC_0_UK-AIRLINES-BA.xml' > > >>> > > regards > Steve What you and I typed was ascii. The value of link came from importing that utf-8 web page into that variable. That is why I think it is not working. But not sure what the solution is. From p at ulmcnett.com Fri Oct 21 15:30:47 2005 From: p at ulmcnett.com (Paul McNett) Date: Fri, 21 Oct 2005 12:30:47 -0700 Subject: how to modify text in html form from python In-Reply-To: References: <0Ra6f.5050$q%.616@newssvr12.news.prodigy.com> Message-ID: <435941E7.6070806@ulmcnett.com> Philippe C. Martin wrote: > PS: If my question is not clear, I am trying to "share" the form between the > client and server. > > just as many sites out there allow you to modify existing data: > 1) the server pops up a form with your data in it. > 2) the client can modify it and submit. > > I know this is a _basic_ question, sorry. When debugging Python cgi scripts, it is helpful to run the scripts from a command line just to make sure there aren't any compiler errors. Depending on how the server is set up, you'll get a server error or just a blank page if your script won't compile. When I run your script directly as I suggest, here's what I get: pmcnett at sol:~$ python test.py File "test.py", line 23 ^ SyntaxError: invalid syntax D'oh! You needed to surround the html with quotes to make it a string, as in: print """ ... """ I don't really understand your original problem, but perhaps this will help get you rolling again. -- Paul McNett http://paulmcnett.com http://dabodev.com From sjdevnull at yahoo.com Mon Oct 24 12:41:54 2005 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: 24 Oct 2005 09:41:54 -0700 Subject: Python variables are bound to types when used? In-Reply-To: References: <1129751462.061785.124830@g49g2000cwa.googlegroups.com> <1129761106.725465.42290@g49g2000cwa.googlegroups.com> Message-ID: <1130172114.746051.242780@f14g2000cwb.googlegroups.com> Fredrik Lundh wrote: > the page was written before the "type/class unification" in Python 2.2, > at a time where the word "type" had a stricter meaning (referring to C- > level types, not user-level classes). Gotcha. Thanks. That writeup is definitely on my required reading list for new Python programmers. From salvatore.didio at wanadoo.fr Thu Oct 13 17:19:00 2005 From: salvatore.didio at wanadoo.fr (Salvatore) Date: 13 Oct 2005 14:19:00 -0700 Subject: Nufox examples hosted :-) Message-ID: <1129238340.814966.326060@z14g2000cwz.googlegroups.com> Hello, I've been kindly authorized to host Nufox examples for free on : http://bsd.miki.eu.org:9090/ Regards From aleaxit at yahoo.com Sat Oct 29 19:36:22 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 29 Oct 2005 16:36:22 -0700 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <87ek65kbw5.fsf@lucien.dreaming> <1h5760l.1e2eatkurdeo7N%aleaxit@yahoo.com> <3siakvFohl3aU1@individual.net> Message-ID: <1h57cij.16dkc141lds4s4N%aleaxit@yahoo.com> Paul Watson wrote: > "Alex Martelli" wrote in message > news:1h5760l.1e2eatkurdeo7N%aleaxit at yahoo.com... > > > In today's implementations of Classic Python, yes. In other equally > > valid implementations of the language, such as Jython, IronPython, or, > > for all we know, some future implementation of Classic, that may well > > not be the case. Many, quite reasonably, dislike relying on a specific > > implementation's peculiarities, and prefer to write code that relies > > only on what the _language_ specs guarantee. > > How could I identify when Python code does not close files and depends on > the runtime to take care of this? I want to know that the code will work > well under other Python implementations and future implementations which may > not have this provided. Then you should use try/finally (to have your code run correctly in all of today's implementations; Python 2.5 will have a 'with' statement to offer nicer syntax sugar for that, but it will be a while before all the implementations get around to adding it). If you're trying to test your code to ensure it explicitly closes all files, you could (from within your tests) rebind built-ins 'file' and 'open' to be a class wrapping the real thing, and adding a flag to remember if the file is open; at __del__ time it would warn if the file had not been explicitly closed. E.g. (untested code): import __builtin__ import warnings _f = __builtin__.file class testing_file(_f): def __init__(self, *a, **k): _f.__init__(self, *a, **k) self._opened = True def close(self): _f.close(self) self._opened = False def __del__(self): if self._opened: warnings.warn(...) self.close() __builtin__.file = __builtin__.open = testing_file Alex From al at none.fr Sun Oct 9 09:50:40 2005 From: al at none.fr (al) Date: Sun, 09 Oct 2005 15:50:40 +0200 Subject: What about letting x.( ... ? ... ) be equivalent to ( ... x ... ) In-Reply-To: References: <4348e72f$0$11133$626a14ce@news.free.fr> Message-ID: <43491faf$0$11131$626a14ce@news.free.fr> > It seems to me that what you proposed was a "solution", that seems > obvious only to you, to a problem perceived only by you. > > I am afraid you would have to work rather harder to persuade me that > there is a problem, let alone that you have found the solution to it. Hello, I never said there is a problem, since you can do whithout it. I just said that in some cases, it's better and cleaner to do it in another way, and also that this solution is a complement : it does not replace or break nothing. Regards, Al From tengo at DELETEMEecc.lu Sun Oct 9 18:42:18 2005 From: tengo at DELETEMEecc.lu (Stefaan A Eeckels) Date: Mon, 10 Oct 2005 00:42:18 +0200 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <41hhk195gcipfarnqu85ggs606aqi89ea1@4ax.com> Message-ID: <20051010004218.03171fb6.tengo@DELETEMEecc.lu> On Mon, 10 Oct 2005 08:49:32 +1000 Steven D'Aprano wrote: > On Sun, 09 Oct 2005 19:28:31 +0000, Roedy Green wrote: > > > What if I am sending diagrams to help someone repair > > their computer? It is ridiculous to tie people's arms behind their > > backs. What you do instead is work to prevent abuse. Captions in > > and of themselves are not dangerous things. > > I didn't say they were. Obviously you haven't been reading my emails, > just reacting against them mindlessly. I use a mail client that gives > me the choice of displaying or not displaying HTML emails. If there > is no alternative to HTML, then I may _choose_ to render the HTML. Norm Reitzel said it all a while ago: "I don't understand that attitude. Don't we want email that has dancing bears, cute little videos, musical tunes, animated waving hands, sixty fonts, and looks like it's been done with crayolas? Good grief, man, think like a three year old!" -- Stefaan -- As complexity rises, precise statements lose meaning, and meaningful statements lose precision. -- Lotfi Zadeh From gandalf at designaproduct.biz Mon Oct 10 03:45:40 2005 From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy) Date: Mon, 10 Oct 2005 09:45:40 +0200 Subject: Comparing lists In-Reply-To: References: Message-ID: <434A1C24.4000100@designaproduct.biz> Odd-R. wrote: >I have to lists, A and B, that may, or may not be equal. If they are not >identical, I want the output to be three new lists, X,Y and Z where X has >all the elements that are in A, but not in B, and Y contains all the >elements that are B but not in A. Z will then have the elements that are >in both A and B. > > These are set operations. >One way of doing this is of course to iterate throug the lists and compare >each of the element, but is there a more efficient way? > > Maybe, using sets? L1 = [1,2,3,4] L2=[3,4,5,6] diff1 = list(set(L1)-set(L2)) # [1,2] diff2 = list(set(L2)-set(L1)) # [5,6] symdiff = diff1+diff2 # Symmetric difference [1,2,5,6] intersect = set(L1+L2) - set(symdiff) # Intersect [3,4] Best, Les From joerg.schuster at gmail.com Tue Oct 25 06:55:17 2005 From: joerg.schuster at gmail.com (Joerg Schuster) Date: 25 Oct 2005 03:55:17 -0700 Subject: more than 100 capturing groups in a regex In-Reply-To: References: <1130160675.270886.208420@z14g2000cwz.googlegroups.com> <1130225565.592108.197670@z14g2000cwz.googlegroups.com> Message-ID: <1130237717.557334.277910@g44g2000cwa.googlegroups.com> No limitation at all would be best. If a limitation is necessary, then the more capturing groups, the better. At the time being, I would be really happy about having the possibility to use 10000 capturing groups. J?rg From robert.kern at gmail.com Tue Oct 11 13:20:50 2005 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 11 Oct 2005 10:20:50 -0700 Subject: scipy.plt legend? In-Reply-To: <1129046539.630460.326290@g49g2000cwa.googlegroups.com> References: <1129046539.630460.326290@g49g2000cwa.googlegroups.com> Message-ID: gurkesaft wrote: > Hello, > > Does anyone know how to use scipy.plt? The documentation is wrong or > out of date at the scipy website, and I can't join their mailing lists > for some reason. > > Most importantly, I need to be able to make and manipulate a legend. > The scipy.plt.legend('whatever') command doesn't seem to exist. I > can't even get started! scipy.plt is incredibly obsolete, unmaintained, and deprecated. Don't use it. Please use matplotlib instead: 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 Wed Oct 5 09:51:25 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Wed, 5 Oct 2005 08:51:25 -0500 Subject: how to debug when "Segmentation fault" In-Reply-To: <4343D5AE.2000601@gmail.com> References: <200510041122.25067.mekstran@scl.ameslab.gov> <20051004190827.3914.1498135555.divmod.quotient.23977@ohm> <4343D5AE.2000601@gmail.com> Message-ID: <20051005135125.GC13147@unpythonic.net> Interesting. I'd noticed that the metaclass one didn't crash my 2.2, but I didn't check the marshal one. This one core dumps in 'Python 2.2.2 (#1, Feb 24 2003, 19:13:11) ... linux2' but inexplicably prints 'keys' when I ran it on the 2.4.1 I used in my last post. >>> import marshal >>> f = lambda: None >>> d = marshal.dumps(f.func_code).replace('\0\0S', '~~S') >>> f.func_code = marshal.loads(d) >>> f() This crashes both my 2.2.2 and 2.4.1: >>> import marshal >>> f = lambda: None >>> d = marshal.dumps(f.func_code).replace('\0\0S', '\xff\xffS') >>> f.func_code = marshal.loads(d) >>> f() Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From jadedgamer at hotmail.com Sun Oct 16 03:50:50 2005 From: jadedgamer at hotmail.com (Tor Iver Wilhelmsen) Date: 16 Oct 2005 09:50:50 +0200 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <11l29j29rq4jh18@corp.supernews.com> <8qs723-dr7.ln1@news.it.uc3m.es> <11l3kmgggj66800@corp.supernews.com> Message-ID: John Wingate writes: > In 1986? That would be version 3. I have MS-DOS 3.10 (Victor/Sirius > version corresponding to 3.1 for x86) dated 1986. Yes, a better example of existing platforms (when PC-DOS 1.0 was shipped with IBM's PCs) is CP/M, which QDOS -> PCDOS -> MSDOS was a bastardized clone of. From steve at holdenweb.com Wed Oct 12 15:42:15 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 12 Oct 2005 20:42:15 +0100 Subject: Threads and socket.setdefaulttimeout In-Reply-To: <1129142005.610543.212180@o13g2000cwo.googlegroups.com> References: <1128030031.130958.185620@z14g2000cwz.googlegroups.com> <1129142005.610543.212180@o13g2000cwo.googlegroups.com> Message-ID: Russell Warren wrote: > It appears that the timeout setting is contained within a process > (thanks for the confirmation), but I've realized that the function > doesn't play friendly with threads. If I have multiple threads using > sockets and one (or more) is using timeouts, one thread affects the > other and you get unpredictable behavior sometimes. I included a short > script at the end of this that demonstrates the threading problem. > When you say "one thread affects another", I see that your example uses the same function for both threads. IMHO it's much better to override the thread's run() method than to provide a callable at thread creating time. That way you can be sure each thread's execution is firmly in the context of the particular thread instance's namespace. having said all this, I don't think that's your issue. > I'm trying to get around this by forcing all locations that want to set > a timeout to use a 'safe' call immediately prior to socket creation > that locks out setting the timeout again until the lock is released. > Something like this: > > try: > SafeSetSocketTimeout(Timeout_s) > #lock currently acquired to prevent other threads sneaking in here > CreateSocket() > finally: > ReleaseSocketTimeoutSettingLock() > UseSocket() > This seems extremely contorted, and I'm pretty sure we can find a better way. > However - this is getting increasingly painful because I don't have > easy access to all of the socket creations where I'd like to do this. > The biggest pain right now is that I'm using xmlrpclib which has some > seriously/frustratingly heavy use of __ prefixes that makes getting > inside to do this at socket creation near impossible (at least I think > so). Right now the best I can do is surround the xmlrpclib calls with > this (effectively putting the lock release after the UseSocket), but > then other threads get hung up for the duration of the call or timeout, > rather than just the simple socket creation. > The threads' network calls should be yielding process control during their timeout period to allow other runnable threads to proceed. That's how it's always worked for me, anyway, and I've written an email sender with 200 parallel threads. > It would be nice if the timeout were implemented as an argument in the > socket constructor rather than having this global method. Is there a > reason for this? I tried sifting through the cvs source and got lost - > couldn't even find the call definition for socket(family, type, proto) > and gave up... > You are aware, I presume, that you can set a timeout on each socket individually using its settimeout() method? > Does anybody have any idea of another way to do what I need (indpendent > socket timeouts per thread), or have suggestions on how to break into > xmlrpclib (actually down into httplib) to do the methdo I was trying? > See above. However, this *does* require you to have access to the sockets, which is tricky if they are buried deep in some opaque object's methods. > Related question: Is there some global way that I'm unaware of to make > it so that some few lines of code are atomic/uninterruptable and no > other thread can sneak in between? > There are locks! I suspect what you need is a threading.Rlock object, that a thread has to hold to be able to modify the (global) default timeout. This isn't a full solution to your problem, though, as you have correctly deduced. The problem arises when a single method call creates a socket and then tries to do something with it (like connect to a remote server), which *is* problematic. I have to say that I haven't ever used different timeout values for the sockets in different parallel threads, so this is a new problem to me. > All suggestions appreciated! Hopefully I'm just missing something > obvious. > > Russ > > #--- This script confirms that settimeout's affect is across threads > import threading, xmlrpclib, socket > > def st(): > socket.setdefaulttimeout(0.1) > > try: > proxy = xmlrpclib.ServerProxy("http://localhost:10000") > print proxy.NonExistentCallThatShouldTimeout() > except Exception, E: print "Exception caught: %s" % (E,) > > cbThread = threading.Thread(target = st) > cbThread.start() > > try: > print proxy.NonExistentCallThatShouldTimeout() > except Exception, E: print "Exception caught: %s" % (E,) > > #Output is: > #Exception caught: (10061, 'Connection refused') > #Exception caught: timed out > Here (unless I'm missing something obvious) it seems that your worker thread terminates immediately after setting the default timeout, and both of the proxy calls are made from the main thread, so I'm not particularly surprised at the results, given the global nature of the default socket timeout. Maybe someone else can think of something that will help. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From robert.kern at gmail.com Mon Oct 17 22:35:47 2005 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 17 Oct 2005 19:35:47 -0700 Subject: A Logging System for Python In-Reply-To: References: Message-ID: Philippe C. Martin wrote: > Dear all, > > I have been looking for a logging system and have come across > http://www.red-dove.com/python_logging.html. > > As the site refers to PEP 282, I assume this package is a potential > contender for integration in the Python distribution. > > Am I correct and if so is there any trend to include it in Python 2.5 ? http://docs.python.org/lib/module-logging.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 steven.bethard at gmail.com Tue Oct 18 14:27:14 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Tue, 18 Oct 2005 12:27:14 -0600 Subject: override a property In-Reply-To: References: <43542065$0$21621$636a15ce@news.free.fr> <4354ABB3.1030203@jessikat.fsnet.co.uk> <4354b324$0$21023$636a55ce@news.free.fr> Message-ID: Robin Becker wrote: > ## my silly example > class ObserverProperty(property): > def __init__(self,name,observers=None,validator=None): > self._name = name > self._observers = observers or [] > self._validator = validator or (lambda x: x) > self._pName = '_' + name > property.__init__(self, > fset=lambda inst, value: self.__notify_fset(inst,value), > ) > > def __notify_fset(self,inst,value): > value = self._validator(value) > for obs in self._observers: > obs(inst,self._pName,value) > inst.__dict__[self._pName] = value > > def add(self,obs): > self._observers.append(obs) > > def obs0(inst,pName,value): > print 'obs0', inst, pName, value > > def obs1(inst,pName,value): > print 'obs1', inst, pName, value > > class A(object): > x = ObserverProperty('x') > > a=A() > A.x.add(obs0) > > a.x = 3 > > b = A() > b.x = 4 > > #I wish I could get b to use obs1 instead of obs0 > #without doing the following > class B(A): > x = ObserverProperty('x',observers=[obs1]) > > b.__class__ = B > > b.x = 7 Can you add the object to be observed as another parameter to the add method? py> class ObservableProperty(property): ... def __init__(self, *args, **kwargs): ... super(ObservableProperty, self).__init__(*args, **kwargs) ... self._observers = {} ... def __set__(self, obj, value): ... super(ObservableProperty, self).__set__(obj, value) ... for observer in self._observers.get(obj, []): ... observer(obj) ... def add(self, obj, observer): ... self._observers.setdefault(obj, []).append(observer) ... py> class A(object): ... def _getx(self): ... return self._x ... def _setx(self, value): ... self._x = value ... x = ObservableProperty(_getx, _setx) ... py> def obs1(obj): ... print 'obs1:', obj.x ... py> def obs2(obj): ... print 'obs2:', obj.x ... py> a = A() py> a.x = 3 py> A.x.add(a, obs1) py> a.x = 4 obs1: 4 py> A.x.add(a, obs2) py> a.x = 5 obs1: 5 obs2: 5 py> b = A() py> b.x = 6 py> A.x.add(b, obs2) py> b.x = 7 obs2: 7 Probably "self._observers" should use some sort of weakref dict instead of a regular dict, but hopefully the idea is clear. STeVe From lbolognini at gmail.com Sun Oct 30 01:38:59 2005 From: lbolognini at gmail.com (lbolognini at gmail.com) Date: 29 Oct 2005 22:38:59 -0700 Subject: Automatic binding of **kwargs to variables In-Reply-To: <1h57spy.bpig8y1g0rvzfN%aleaxit@yahoo.com> References: <1130539752.667045.183460@g14g2000cwa.googlegroups.com> <1130638902.048806.183580@g43g2000cwa.googlegroups.com> <1130647542.669549.300360@g43g2000cwa.googlegroups.com> <1h57spy.bpig8y1g0rvzfN%aleaxit@yahoo.com> Message-ID: <1130650739.826914.255090@g43g2000cwa.googlegroups.com> Alex Martelli wrote: > I find this style of coding repulsive when compared to: > > def foo(arg1=None, arg2=None): > print dict(arg1=arg1, arg2=arg2) > > I don't understand what added value all of those extra, contorted lines > are supposed to bring to the party. Hi Alex, the thing is that I have about 30 parameters to pass to a method and I wanted to have a cleaner way to deal with it than just declaring them all as arguments: hence **kwargs and all that mess ;-) I was thinking to declare the a list of valid and expected parameters in a module and then import * and run my checks against it. Since this stuff is being posted by a web form I also need to deal with checkbox not being posted if not checked which lead me to: for name in expected_form1_kwargs: if name not in kwargs: kwargs[name]=None Lorenzo From http Mon Oct 17 15:41:32 2005 From: http (Paul Rubin) Date: 17 Oct 2005 12:41:32 -0700 Subject: UI toolkits for Python References: <863bn12k6i.fsf@bhuda.mired.org> Message-ID: <7xslv02aoj.fsf@ruckus.brouhaha.com> Michael Ekstrand writes: > > 2) Keybindings in a web application > > Not sure here, but JavaScript may be able to do something to accomplish > some of this. A web-delivered XUL app can definitely do this. But > that's pushing the limits of what can be considered a web application. All this extreme use of JS misses the point, it's client side programming all over again, not really what most of us think of as a web interface which puts all the hair on the server side. If you want to program on the client, why not use a reasonable language like Python instead of a monstrosity like JS? From __peter__ at web.de Fri Oct 14 12:04:01 2005 From: __peter__ at web.de (Peter Otten) Date: Fri, 14 Oct 2005 18:04:01 +0200 Subject: Problems with properties References: Message-ID: Michael Schneider wrote: > Rather then dispatching the property assignment to setNothing, the > property object is being replaced with a string. properties are for newstyle classes only (i. e. classes that inherit from object). from unittest import TestCase import unittest class Task(object): def __init__(self,command): self._command = command def setNothing(self, value): raise AttributeError def getCommand(self): return self._command command=property(getCommand, setNothing) # or just # command=property(getCommand) class taskTest(TestCase): def testTask(self): t = Task("dir c:") c = t.command self.assertEquals("dir c:", c) def set(): t.command = "foo Bar" self.assertRaises(AttributeError, set) self.assertEquals("dir c:", t.command) if __name__ == "__main__": unittest.main() Peter From tim.golden at viacom-outdoor.co.uk Wed Oct 26 08:52:30 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Wed, 26 Oct 2005 13:52:30 +0100 Subject: Windows vs Linux [was: p2exe using wine/cxoffice] Message-ID: <9A28C052FF32734DACB0A288A3533991044D22A3@vogbs009.gb.vo.local> [Sybren Stuvel] [Tim Golden] > > It's obvious that everyone has a different way of working, and that > > I'm more comfortable in Windows because all sorts of small > > familiarities > So what I read in your post is that you simply don't want to leave > your familiar environment. Fair enough. Well yes. I think the (only slightly) wider point I was making was that -- despite goodwill and several attempts on my part -- Linux still has not overpowered me with its usefulness. Extending from this, where I am someone who's a competent computer user (indeed, a professional software developer of some years' standing) and who has honestly tried, it seems that switching to Linux is not quite such a no-brainer as people sometimes make out. Just occasionally you read posts from people who say (synthesised) "The Windows command line is rubbish", "Windows crashes all the time", "All Windows machines are overrun with adware and generate spam willy-nilly". And you just wonder whether such people have actually *used* a properly set up Windows machine recently. 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 donn at drizzle.com Sat Oct 29 12:20:38 2005 From: donn at drizzle.com (Donn Cave) Date: Sat, 29 Oct 2005 16:20:38 -0000 Subject: popen2 References: <1130524659.070912.256550@o13g2000cwo.googlegroups.com> <11m6tj5q9rskma1@corp.supernews.com> <4363887f$0$459$7a628cd7@news.club-internet.fr> Message-ID: <1130602837.837709@yasure> Quoth Pierre Hanser : | Grant Edwards a ?crit : |> On 2005-10-29, Piet van Oostrum wrote: |>>>>>>>"g.franzkowiak" (gf) wrote: |>> |>>>gf> If starts a process with popen2.popen3('myprogram') and myprogram.exe is |>>>gf> running before, I've a connection to the second process, not to the first. |>>>gf> I can find the process by name before I start a process with popen2..., |>>>gf> but how bcan I connect t this process with a pipe ? |>> |>>You have to use a named pipe. |> |> |> That would require that the application know about the named |> pipe and open it. I don't think there is any way to swap a |> pipe in for stdin/stdout once a process is running. |> | in C: freopen Hello, it seems fairly clear that the stdin/stdout in question belongs to another process, which cannot be instructed at this point to execute freopen(). If there's a way to do this, it will be peculiar to the platform and almost certainly not worth the effort. Donn Cave, donn at drizzle.com From my_email_is_posted_on_my_website at munged.invalid Sat Oct 22 23:24:21 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sun, 23 Oct 2005 03:24:21 GMT Subject: Microsoft Hatred FAQ References: <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> Message-ID: On Sun, 23 Oct 2005 11:46:53 +1000, Steven D'Aprano wrote or quoted : > >Or would you like to suggest that Microsoft's board of directors should be >allowed carte blache to break any law, commit any deed, so long as it >makes Microsoft money? Why should the standards of acceptable conduct be any lower for groups of people (namely corporations) than individuals? It would be like excusing bad behaviour based on other group memberships such as churches or gangs. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From apgwoz at gmail.com Fri Oct 7 07:51:14 2005 From: apgwoz at gmail.com (Andrew Gwozdziewycz) Date: Fri, 7 Oct 2005 07:51:14 -0400 Subject: divide In-Reply-To: <1d987df30510061933t58bffe8ai5f32b0e08ff9037d@mail.gmail.com> References: <1d987df30510061933t58bffe8ai5f32b0e08ff9037d@mail.gmail.com> Message-ID: <163A9425-B814-425F-8DE8-00021C68024B@gmail.com> Do the divisions have to be themselves rectangles? xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x____________B_____C_______x x_____A____________________x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx would be a representation of the problem? However, though, I think that what you mean with your Points being smaller and things, is that the points are centered in the middle of their peice of the rectangle, whichs makes the problem really easy. If that is the case, notice that: width of Rectangle A = 2 * the_x_coordinate_ofA Subsequent widths can be found by subtracting the left side of the rectangle from the equation above. This is modified as follows width of Rectangle X = 2 * the_x_coordinate_ofX - width_so_far The height of your rectangles will all be the same (if i read the question right), so translating this to python is simple. On Oct 6, 2005, at 10:33 PM, Shi Mu wrote: > I have three points in a rectangle and i wonder how to use PYTHON > to divide the rectangle into three > parts with each point located in the different part. > For instance, Point A > goes to Part I, Point B goes to Part II and Point C goes to Part III. > And the distance between any point within Part I and Point A is > smaller than to Point B and Point C. And the similar rule applies > to Part II and Part III. > Thanks for any idea. > -- > http://mail.python.org/mailman/listinfo/python-list --- Andrew Gwozdziewycz apgwoz at gmail.com http://ihadagreatview.org http://plasticandroid.org From steve at holdenweb.com Wed Oct 5 09:15:18 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 05 Oct 2005 14:15:18 +0100 Subject: bug or feature? In-Reply-To: <1128515482.807324.265000@f14g2000cwb.googlegroups.com> References: <1128508770.727391.313300@f14g2000cwb.googlegroups.com> <1128515482.807324.265000@f14g2000cwb.googlegroups.com> Message-ID: Ben Sizer wrote: > Fredrik Lundh wrote: > > >>it's also mentioned in chapter 4 of the tutorial: >> >> http://docs.python.org/tut/node6.html#SECTION006710000000000000000 >> >> "*Important warning*: The default value is evaluated only once. This >> makes a difference when the default is a mutable object such as a list, >> dictionary, or instances of most classes. " > > > Perhaps it would be a good idea if Python actually raised a warning > (SyntaxWarning?) if you use an unnamed list or dict as a default > argument. This would doubtless help quite a few beginners. And for > people who really do want that behaviour, working around the warning > should involve minimal extra code, with extra clarity thrown in for > free. > This would have to be extended to any mutable object. How does the compiler know which objects are mutable? This would not be a good change. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From hmcy2002 at yahoo.co.uk Tue Oct 25 12:22:12 2005 From: hmcy2002 at yahoo.co.uk (Geirr) Date: 25 Oct 2005 09:22:12 -0700 Subject: Newbie question Message-ID: <1130257332.726811.135510@o13g2000cwo.googlegroups.com> Hi, ive just started playing around with python and wondered if someone could poing me in the right way here. I have a xmlrpc server simple script: Server script: import SimpleXMLRPCServer class tpo: def retTPOXML(): theFile=open('tpo.xml') try: self.strXML = theFile.read() return self.strXML finally: theFile.close() tpo_object = tpo() server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost",8888)) server.register_instance(tpo_object) print "Listening on port 8888" server.serve_forever() and im trying to print the return value with any luck Client Code: import xmlrpclib server = xmlrpclib.ServerProxy("http://localhost:8888") current = server.retTPOXML print current Any comment would be appriciated From david at jotax.com Wed Oct 26 19:42:38 2005 From: david at jotax.com (David Poundall) Date: 26 Oct 2005 16:42:38 -0700 Subject: How best to reference parameters. In-Reply-To: References: <1130274796.584531.229340@g43g2000cwa.googlegroups.com> <4SM7f.4313$Zd.1145@tornado.tampabay.rr.com> <1130342595.533405.191920@g43g2000cwa.googlegroups.com> Message-ID: <1130370158.610870.297960@f14g2000cwb.googlegroups.com> Sorry Ron, my earlier reply was too brief I wasn't thinking straight (so what else is new ;-) my apologies. The main reason for going down the route I am looking at (thread 2) is that intellisense runs OK in my IDE using that aproach. In my application this will be important as I will be using the IDE (Wing) as a high level user editor in a limited code area. The user will need to see (hence the use of intellisense) which properties are available for him to work with. The second example you gave runs similar to the first, and unfortunately the intellisense does not pick up available properties as you go walk the dots. Not suprisingly really as the class is dynamic in the way it operates. It only see's the index property and the showall function. The code as you wrote it works fine though, and it is already salted away in my meager (but growing) codebank. Many thanks for your reply. From mwm at mired.org Mon Oct 3 00:31:33 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 03 Oct 2005 00:31:33 -0400 Subject: Will python never intend to support private, protected and public? References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <86y85hp5y7.fsf@bhuda.mired.org> <7xfyrozxf0.fsf@ruckus.brouhaha.com> <86psqsq0jd.fsf@bhuda.mired.org> <7xhdc4vk23.fsf@ruckus.brouhaha.com> <86ll1gpj7j.fsf@bhuda.mired.org> <7x4q7zi8i9.fsf@ruckus.brouhaha.com> Message-ID: <86ek73kyqi.fsf@bhuda.mired.org> Paul Rubin writes: > Mike Meyer writes: >> >> Compile-time restrictions don't matter for squat - you need >> >> serious restrictions on what the program can do at runtime. >> > You need both. >> Yup. Any language besides Java even *try* to provide both for a >> production environment? > Yes. Python tried. It had a module called rexec for that purpose. > I keep mentioning that, and you keep ignoring it. Rexec was around > for a long time, and was removed for technical reasons with some > reluctance. There is nothing un-Pythonic about the idea. If you've mentioned it before, it wasn't to me. Or maybe my news server dropped it. Rexec was removed because it didn't work. Just like bastion and every other attempt to create a "safe" environment in Python. Any security wonk worth his pay will tell you that you don't add security to something after the fact if you want good security. You design it in from the beginning. Of course, what rexec tried to do and what "private" do are orthogonal issues. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From steve at holdenweb.com Mon Oct 31 21:59:05 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 01 Nov 2005 02:59:05 +0000 Subject: Does Asyncore Send require newline? In-Reply-To: References: Message-ID: <4366D9F9.8050608@holdenweb.com> John W wrote: > Hello, > > I have a test environment that consists of a server and an application that > opens an asyncore socket and communicates with it. > > In my application, on the handle_write call, if I do not append a "\n" to my > message the server never gets the message. If I do append it, the server can > read the message and act accordingly. > > So my call looks like this: > self.send( message] + "\n") > > Is this how it was designed? Do you have to send a '\n' to have the data > read? I can't find a whole lot of documentation on the send method. > > If you could offer some help, I would appreciate it. > The short answer to your question is "no, send() does not require newline". But much depends on your protocol design and on explicit details of your client and server software. You'd probably have to post a bit more code before we could say why you are seeing what you are seeing. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From my_email_is_posted_on_my_website at munged.invalid Thu Oct 27 03:57:35 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Thu, 27 Oct 2005 07:57:35 GMT Subject: Microsoft Hatred FAQ References: <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> Message-ID: On Thu, 27 Oct 2005 00:48:25 -0700, "David Schwartz" wrote, quoted or indirectly quoted someone who said : >> We are not talking about legal agreements. We are talking junior Mafia >> style enforcement. > > Can you cite any evidence of Microsoft actually using or threatening >force? YES . Have you not read a word I said. -- Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching. From news at NOwillmcguganSPAM.com Thu Oct 13 13:45:46 2005 From: news at NOwillmcguganSPAM.com (Will McGugan) Date: Thu, 13 Oct 2005 18:45:46 +0100 Subject: 1-liner to iterate over infinite sequence of integers? In-Reply-To: References: Message-ID: <434e9d4b$0$32652$da0feed9@news.zen.co.uk> Neal Becker wrote: > I can do this with a generator: > > def integers(): > x = 1 > while (True): > yield x > x += 1 > > for i in integers(): > > Is there a more elegant/concise way? > import itertools for i in itertools.count(): print i Will McGugan -- http://www.willmcgugan.com "".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in "jvyy*jvyyzpthtna^pbz") From skip at pobox.com Sat Oct 15 22:24:52 2005 From: skip at pobox.com (skip at pobox.com) Date: Sat, 15 Oct 2005 21:24:52 -0500 Subject: dis.dis question In-Reply-To: <4351affc.104308027@news.oz.net> References: <4351affc.104308027@news.oz.net> Message-ID: <17233.47604.113773.78543@montanaro.dyndns.org> >> I'm still looking for info on how to use disassemble_string(). How about this? >>> import dis >>> def f(): ... print "hello world" ... >>> f.func_code.co_code 'd\x01\x00GHd\x00\x00S' >>> dis.disassemble_string(f.func_code.co_code) 0 LOAD_CONST 1 (1) 3 PRINT_ITEM 4 PRINT_NEWLINE 5 LOAD_CONST 0 (0) 8 RETURN_VALUE Skip From jon_usenet at capisco.com Fri Oct 14 12:11:04 2005 From: jon_usenet at capisco.com (jon) Date: 14 Oct 2005 09:11:04 -0700 Subject: array subset could be improved? -repost ;) In-Reply-To: References: Message-ID: <1129306264.568089.197320@o13g2000cwo.googlegroups.com> Jim O'D wrote: > Hi all > > I have an array a=array([2,3,-1]). > > I want to extract an array with all the elements of a that are less than 0. > > Method 1. > new = array([i for i in a if i < 0]) > > Method 2. > new = a[nonzero(a<0)] > > I'm using Numeric arrays but can't seem to find a function that does this. > > Am I missing a more obvious way to do it quickly? > > Thanks > > Jim From saint.infidel at gmail.com Wed Oct 19 15:44:41 2005 From: saint.infidel at gmail.com (infidel) Date: 19 Oct 2005 12:44:41 -0700 Subject: infinite cherrypy autoreloader loop Message-ID: <1129751081.407613.289710@g14g2000cwa.googlegroups.com> I did an "svn update" of cherrypy this morning, and now when I try running a server, the log window just keeps reporting the autoreloader restarting over and over: 2005/10/19 12:42:33 HTTP INFO SystemExit raised: shutting down autoreloader 2005/10/19 12:42:33 HTTP INFO CherryPy shut down 2005/10/19 12:42:34 CONFIG INFO Server parameters: 2005/10/19 12:42:34 HTTP INFO SystemExit raised: shutting down autoreloader 2005/10/19 12:42:34 HTTP INFO CherryPy shut down 2005/10/19 12:42:34 CONFIG INFO Server parameters: 2005/10/19 12:42:34 HTTP INFO SystemExit raised: shutting down autoreloader 2005/10/19 12:42:34 HTTP INFO CherryPy shut down It seemed to be working fine this morning. Any ideas what I may have done to cause this? From paul at boddie.org.uk Wed Oct 19 11:33:24 2005 From: paul at boddie.org.uk (Paul Boddie) Date: 19 Oct 2005 08:33:24 -0700 Subject: UI toolkits for Python References: <7xslv56ud1.fsf@ruckus.brouhaha.com> <3ras6oFit2djU1@individual.net> <4350dd34$0$6774$9b4e6d93@newsread4.arcor-online.net> <863bn12k6i.fsf@bhuda.mired.org> <7xslv02aoj.fsf@ruckus.brouhaha.com> <87psq39aur.fsf@wilson.rwth-aachen.de> <7xwtkbud5q.fsf@ruckus.brouhaha.com> <1h4mhm2.1rmv4fh1czi843N%aleaxit@yahoo.com> <86r7aiyg4g.fsf@bhuda.mired.org> <1h4n6ag.5uhq7a7xe1v4N%aleaxit@yahoo.com> <86ach6y6ta.fsf@bhuda.mired.org> <1h4o6eo.4gi3s6xgesmzN%aleaxit@yahoo.com> Message-ID: <1129736004.876031.44040@z14g2000cwz.googlegroups.com> Steve Holden wrote: [80/20 rule] > This is as much an economic decision as a marketing one, but a good engineer > knows instinctively that there is a desirable cut-off point beyond which > adding further functionality is a waste of engineering effort. But Mike Meyer's point was that the Web standards are designed to allow fancy functionality where it's available but for the experience to degrade gracefully where such functionality isn't available. For example, you have all the "events module" attributes in XHTML, but take away the events capability in the browser and there's a decent chance for the semantics of the application to remain the same: no, you don't get instant updates of the page when you select some menu item, but the user can still have a similar experience which involves slightly more inconvenience - they have to submit the page and get back an updated version from the server. It's misleading to claim that designing in such a way requires huge additional development, especially since the standards are constructed in such a way to facilitate such designs. It goes without saying that implementing advanced functionality on Netscape 3.x and NCSA Mosaic would be a costly and ultimately non-viable burden, but that isn't the issue for many Web applications and wasn't the point being made. Paul From kent37 at tds.net Tue Oct 18 10:41:48 2005 From: kent37 at tds.net (Kent Johnson) Date: Tue, 18 Oct 2005 10:41:48 -0400 Subject: unittest of file-reading function In-Reply-To: References: Message-ID: <435507b9$1_3@newspeer2.tds.net> Helge Stenstroem wrote: > Say I have a function > > def f(filename): > result = openFileAndProcessContents(filename) > return result > > Can that function be unit tested without having a real file as input? If you can refactor openFileAndProcessContents() so it looks like this: def openFileAndProcessContents(filename): data = open(filename).read() processContents(data) then you can write your tests against processContents() and just pass it a string with the test data. I usually have a set of test files as part of my project that I can pass to functions like this. Kent From noreply at gunnar.cc Sat Oct 15 22:49:30 2005 From: noreply at gunnar.cc (Gunnar Hjalmarsson) Date: Sun, 16 Oct 2005 04:49:30 +0200 Subject: Microsoft Hatred FAQ In-Reply-To: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> Message-ID: <3rdthnFj0uchU1@individual.net> [ Followup-To set to the less inappropriate alt.religion ] Xah Lee wrote: > Microsoft Hatred, FAQ Once again you fools have been tricked by the XL troll to hold an endless off-topic discussion in several groups. -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl From __peter__ at web.de Wed Oct 12 10:28:57 2005 From: __peter__ at web.de (Peter Otten) Date: Wed, 12 Oct 2005 16:28:57 +0200 Subject: Very dumb question References: Message-ID: Laszlo Zsolt Nagy wrote: > I have a program with this code fragment: > > print?len(data) > print?data[:50] > raise?SystemExit > > This prints: > > 20381 > > But if I change 50 to 51 > > print?len(data) > print?data[:51] > raise?SystemExit > > then it prints > > 20381 > !DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.1//EN" The closest I can get to your situation is [on linux] >>> print "abc\rx"[:4] abc >>> print "abc\rx"[:5] xbc i. e. a character after a 'carriage return' ('\r') overwrites part of the string which therefore doesn't seem to grow. Try print repr(data[:51]) to see what's really in your data string. Peter From __peter__ at web.de Sat Oct 1 12:47:54 2005 From: __peter__ at web.de (Peter Otten) Date: Sat, 01 Oct 2005 18:47:54 +0200 Subject: Help with syntax warnings References: Message-ID: Ivan Shevanski wrote: > Well I've been experimenting with the warning filter and it doesn't seem > to be working. . .I think it has something to do with the fact that > warnings are issued during the compiling and not during the excecution. . > .So the filter would come in to late to block them? Any ideas? $ cat syntaxwarning.py def f(): x = 42 global x $ python2.4 syntaxwarning.py syntaxwarning.py:1: SyntaxWarning: name 'x' is assigned to before global declaration def f(): Method 1: precompile the py-file and then invoke the compiled variant: $ python2.4 -c 'import syntaxwarning' syntaxwarning.py:1: SyntaxWarning: name 'x' is assigned to before global declaration def f(): $ python2.4 syntaxwarning.pyc Method 2: switch off the warning: $ python2.4 -Wignore::SyntaxWarning syntaxwarning.py Peter From amk at amk.ca Tue Oct 25 06:04:23 2005 From: amk at amk.ca (A.M. Kuchling) Date: Tue, 25 Oct 2005 06:04:23 -0400 Subject: Reminder: PyCon proposals due in a week Message-ID: <20051025100423.GB4930@rogue.amk.ca> The deadline for PyCon 2006 submissions is now only a week away. If you've been procrastinating about putting your outline together, now's the time to get going... Call for Proposals: http://www.python.org/pycon/2006/cfp Proposal submission site: http://submit.python.org/ --amk From mrosenstihl at macnews.de Wed Oct 12 05:09:43 2005 From: mrosenstihl at macnews.de (Markus Rosenstihl) Date: Wed, 12 Oct 2005 11:09:43 +0200 Subject: Nicer way of strip and replace? References: <7xslv7d44n.fsf@ruckus.brouhaha.com> Message-ID: On 2005-10-12 01:29:28 +0200, Paul Rubin said: > > Oh cool. I think you could even say: > > rechnung = list(read_file) > > instead of the for loop. Yes, that is working too. From bokr at oz.net Tue Oct 25 01:16:40 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 25 Oct 2005 05:16:40 GMT Subject: namespace dictionaries ok? References: <1130207021.408597.322950@g14g2000cwa.googlegroups.com> Message-ID: <435dbd8e.894214442@news.oz.net> On Tue, 25 Oct 2005 03:10:17 GMT, Ron Adam wrote: >Simon Burton wrote: > >> Yes! >> >> I do this a lot when i have deeply nested function calls >> a->b->c->d->e >> and need to pass args to the deep function without changing the >> middle functions. > >Yes, :-) Which is something like what I'm doing also. Get the >dictionary, modify it or validate it somehow, then pass it on. I also >find that when I'm passing variables as keywords, > > foo(name=name, address=address, city=city) > >I really don't want (or like) to have to access the names with >dictionary key as *strings* in the function that is called and collects >them in a single object. > > >> In this situation I think i would prefer this variation: >> >> class Context(dict): >> def __init__(self,**kwds): >> dict.__init__(self,kwds) >> def __getattr__(self, name): >> return self.__getitem__(name) >> def __setattr__(self, name, value): >> self.__setitem__(name, value) >> def __delattr__(self, name): >> self.__delitem__(name) > > >> def foo(ctx): >> print ctx.color, ctx.size, ctx.shape >> >> foo( Context(color='red', size='large', shape='ball') ) >> >> >> This is looking like foo should be a method of Context now, >> but in my situation foo is already a method of another class. >> Or maybe just add a __repr__ method, if you want to see a readable representation (e.g., see below). >> Simon. > >I didn't see what you were referring to at first. But yes, I see the >similarity. > >>> class Context(dict): ... def __init__(self,**kwds): ... dict.__init__(self,kwds) ... def __getattr__(self, name): ... return self.__getitem__(name) ... def __setattr__(self, name, value): ... self.__setitem__(name, value) ... def __delattr__(self, name): ... self.__delitem__(name) ... def __repr__(self): ... return 'Context(%s)' % ', '.join('%s=%r'% t for t in sorted(self.items())) ... >>> print Context(color='red', size='large', shape='ball') Context(color='red', shape='ball', size='large') >>> ctx = Context(color='red', size='large', shape='ball') >>> print ctx Context(color='red', shape='ball', size='large') >>> ctx Context(color='red', shape='ball', size='large') >>> ctx.color 'red' Regards, Bengt Richter From http Sun Oct 16 17:19:07 2005 From: http (Paul Rubin) Date: 16 Oct 2005 14:19:07 -0700 Subject: A Tree class, my $0.02 contribution to the python community. References: Message-ID: <7xfyr1yxbo.fsf@ruckus.brouhaha.com> Antoon Pardon writes: > The underlying implementation is an AVL balanced binary tree with > inorder threading. Dan Bernstein argues for switching from hash tables to crit-bit trees (a/k/a Patricia trees), because of their guaranteed worst case performance. He also claims: "Crit-bit trees are faster than comparison-based structures such as AVL trees and B-trees. They're also simpler, especially for variable-length strings." See: http://cr.yp.to/critbit.html See: http://www.cs.rice.edu/~scrosby/hash/ for some stuff about the dangers of hash tables. From lasse at vkarlsen.no Sun Oct 30 06:23:45 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Sun, 30 Oct 2005 12:23:45 +0100 Subject: dreaming in Python In-Reply-To: <1130625997.428653.28080@g49g2000cwa.googlegroups.com> References: <1130625997.428653.28080@g49g2000cwa.googlegroups.com> Message-ID: The Eternal Squire wrote: > All, > > I have to tell all of you this, at least for some laughs. Honestly, I > had the silliest dream involving the language last night. I dreamt > that it was a decade into the future and that Grand Central Station in > NYC was installing a cement and steel "computer core" for directing its > trains and station elevators... and for some reason I was supervising a > technician on the project. I asked the technician, what version of > Python was being used, and he said 2.1... I said better install 2.4! > So he loaded a chip into the 15 ton cylindrical core, then the core was > lowered by winch into a manhole cover. The lights in the station lit, > and I shouted: One Python to Rule Them All And In The Darkness Bind > Them! Then I took an elevator downstairs to log into the terminal. > Who did I meet on a neighboring terminal other than the BDFL? He was > doing something esoteric and strange on the terminal but I was just > having trouble logging in. End of dream. > > Anyone ever have a wierd engineering dream sometime in thier career? > > The Eternal Squire > Just sit still while the men in white come to pick you up :) -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From buzzard at urubu.freeserve.co.uk Fri Oct 7 14:51:18 2005 From: buzzard at urubu.freeserve.co.uk (Duncan Smith) Date: Fri, 07 Oct 2005 19:51:18 +0100 Subject: When someone from Britain speaks, Americans hear a "Britishaccent"... In-Reply-To: References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kbgj7421kd560@corp.supernews.com> <4h5ck1hkqq0ls83pq0lodkb51tsda4053k@4ax.com> Message-ID: <4346c5a8.0@entanet> Rocco Moretti wrote: > Steve Holden wrote: > >>> On Fri, 07 Oct 2005 00:33:43 -0000, Grant Edwards >>> wrote: > > >>>> For example: In British English one uses a plural verb when the >>>> subject consists of more than one person. Sports teams, >>>> government departments, states, corporations etc. are grammatically >>>> plural. In American, the verb agrees with the >>>> word that is the subject, not how many people are denoted by >>>> that word. >> >> >> There aren't any universal rules, except possibly "British people >> speak English while Americans don't". > > > I believe you overgeneralize. :) > > A Welshman would likely be offended if you implied he spoke English, and > the Scots are notorious for only speaking English when they have too. (I > remember a news story some years back about a Scottish "lad" who was > fined/imprisoned for replying to an official court representative with > "Aye" rather than "Yes".) For that matter there are plenty of people in > Cornwall and even in London (Cockney) who speak something that is only > called "English" for lack of a better term. > So English is spoken only in the South East of England, except London? I think you should also disbar the queen (unless she's already classified as a Londoner), due to her apparent confusion between the 1st person singular and 1st person plural :-). Duncan From deets at nospam.web.de Sun Oct 16 10:29:56 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 16 Oct 2005 16:29:56 +0200 Subject: wxPython & Cygwin In-Reply-To: References: <434e8dbf$0$452$7a628cd7@news.club-internet.fr> <3r8bo1Fi9etjU1@uni-berlin.de> Message-ID: <3rf6f4Fj4tqhU1@uni-berlin.de> >> Why? Use windows python, wxPython for it - and put it in your path to >> use it inside cygwin. >> > Don't think that'll work for an extension module. Sure it will. You can call whatever program you want from cygwin, as long as it is in the path. No difference to double-clicking an icon or something similar. > >> But maybe you _can_ compile it yourself - I didn't try, though. >> >> Diez > > > Probably a daunting task. Yes, and probably not working unless you use MinGW, as you need windows-headers instead of Posix-style GCC. But I've compiled Python, Qt and some other libs using MinGW, and cygwin. So I think it should be doable. Diez From bosteen at maysubdivide.org Mon Oct 31 05:40:47 2005 From: bosteen at maysubdivide.org (Ben O'Steen) Date: Mon, 31 Oct 2005 10:40:47 -0000 (GMT) Subject: Why the nonsense number appears? In-Reply-To: References: <1130749726.707175.293040@g43g2000cwa.googlegroups.com> Message-ID: <40782.213.235.52.66.1130755247.squirrel@www.maysubdivide.org> On Mon, October 31, 2005 10:23, Sybren Stuvel said: > Ben O'Steen enlightened us with: >> Using decimal as opposed to float sorts out this error as floats are >> not built to handle the size of number used here. > > They can handle the size just fine. What they can't handle is 1/1000th > precision when using numbers in the order of 1e10. > I used the word 'size' here incorrectly, I intended to mean 'length' rather than numerical value. Sorry for the confusion :) > 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 > From peter at engcorp.com Mon Oct 24 12:24:18 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 24 Oct 2005 12:24:18 -0400 Subject: output from external commands In-Reply-To: <868xwj6mgv.fsf@bhuda.mired.org> References: <435C6642.8020504@colannino.org> <868xwj6mgv.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > darren kirby writes: > >>If all you want is filenames this will work: >> >>>>>import glob >>>>>files = ["%s" % f for f in glob.glob("*")] > > > What's the point of doing "%s" % f? How is this different from just > file = [f for f in glob.glob("*")]? Answering narrowly, the difference is that using "%s" calls str() on the items in the result list, while your suggestion does not. ("Why not just use str(f) instead of the less clear '%s' % f?" would be a valid question too though.) -Peter From steve at holdenweb.com Sun Oct 16 11:09:25 2005 From: steve at holdenweb.com (Steve Holden) Date: Sun, 16 Oct 2005 16:09:25 +0100 Subject: wxPython & Cygwin In-Reply-To: <3rf6f4Fj4tqhU1@uni-berlin.de> References: <434e8dbf$0$452$7a628cd7@news.club-internet.fr> <3r8bo1Fi9etjU1@uni-berlin.de> <3rf6f4Fj4tqhU1@uni-berlin.de> Message-ID: Diez B. Roggisch wrote: >>>Why? Use windows python, wxPython for it - and put it in your path to >>>use it inside cygwin. >>> >> >>Don't think that'll work for an extension module. > > > Sure it will. You can call whatever program you want from cygwin, as > long as it is in the path. No difference to double-clicking an icon or > something similar. > Aah, right - I misunderstood you to be saying "use the Windows wxPython module under Cygwin Python". > >>>But maybe you _can_ compile it yourself - I didn't try, though. >>> >>>Diez >> >> >>Probably a daunting task. > > > Yes, and probably not working unless you use MinGW, as you need > windows-headers instead of Posix-style GCC. But I've compiled Python, Qt > and some other libs using MinGW, and cygwin. So I think it should be doable. > I'm sure the Cygwin world would be grateful if you or someone else were to establish the correct build procedure. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From fredrik at pythonware.com Wed Oct 5 04:57:26 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 5 Oct 2005 10:57:26 +0200 Subject: Confused with module and .py files References: Message-ID: "Iyer, Prasad C" wrote: > How would I use it if I declare it as given below in my 3rd class > > from import1.py import * > from import2.py import * thats a syntax error; I assume you meant from import1 import * from import2 import * which simply doesn't work if you need to access things that happens to have the same name in both modules. it's like typing a = 1 a = 2 and then asking how you can access the original 1 via the "a" variable. so unless you know *exactly* what you're doing, you should *never* use "from import *" -- unless you're using a module that someone else wrote, and the documentation for that module tells you do use it. see http://effbot.org/zone/import-confusion.htm for more on this. (see other replies for how to do what you want in a way that actually works). From mwm at mired.org Sun Oct 9 19:07:42 2005 From: mwm at mired.org (Mike Meyer) Date: Sun, 09 Oct 2005 19:07:42 -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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <86y853mzmr.fsf@bhuda.mired.org> Message-ID: <86mzlil269.fsf@bhuda.mired.org> Tim Tyler writes: > In comp.lang.java.programmer Mike Meyer wrote or quoted: >> The technial problems have been solved for over a decade. NeXT shipped >> systems that used text/richtext, which has none of the problems that >> HTML has. The problems are *social* - you've got to arrange for >> people to use mail/news readers that understand a rich text format >> that isn't a vector for viruses. > It's not HTML that has problems, it's Microsoft's crappy software. HTML is a problem on *other* peoples crappy software as well. It wasn't designed to carry code content, but has been hacked up to do that. > Writing virus-free HTML renderers is not hard - but of course > Microsoft can still screw it up. Sure - just disable all the features that make people want to use HTML instead of something else. > Don't blame HTML for viruses - *every* document format Microsoft has > anything to do with becomes a vector for viruses. Which would mean that every open format that MS has had anything to do with comes a vector for viruses. Somehow, I'm not buying it. And HTML has more problems than just viruses - web bugs, for one. But MIME's support for external bodies gives you that anyway. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From renting at astron.nl Tue Oct 18 08:17:43 2005 From: renting at astron.nl (Adriaan Renting) Date: Tue, 18 Oct 2005 14:17:43 +0200 Subject: Hygenic Macros Message-ID: Using numarray/pylab there's also dot: >>> from pylab import * >>> A = array(range(10)) >>> B = array(range(10)) >>> A * B [ 0, 1, 4, 9,16,25,36,49,64,81,] >>> dot(A, B) 285 It might also make your code more readable. I would like "A dot B", but even using ipython I can only get as close as "dot A, B" >>>Dan Farina 10/18/05 1:33 pm >>> David Pokorny wrote: >Hi, > >Just wondering if anyone has considered macros for Python. I have one >good use case. In "R", the statistical programming language, you can >multiply matrices with A %*% B (A*B corresponds to pointwise >multiplication). In Python, I have to type > >import Numeric >matrixmultiply(A,B) > >which makes my code almost unreadable. > >Thanks, >David The problem here is that Python's parse trees are of non-trivial ugliness. A page on the compiler.ast module: http://docs.python.org/lib/node792.html it is, in fact, perfectly possible to write yourself a pre-processor for your particular application. You may have to fiddle with the token you want for notation depending on how the AST fleshes out (% is used by at least a couple of things, after all). My cursory familiarity with python grammar suggests to me that this particular choice of token could be a problem. I would say try it and see. Keep in mind though that since Python's AST is not a trivial matter like it is in Lisp and the like that doing metaprogramming of this sort probably falls into the category of black magic unless it turns out to be very trivial. Another option is to define your own tiny class that will override the __mult__ method so that you can simply do: A * B Which may not be what you want. df -- http://mail.python.org/mailman/listinfo/python-list From aleaxit at yahoo.com Sun Oct 30 19:25:25 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 30 Oct 2005 17:25:25 -0700 Subject: Pickling and unpickling inherited attributes References: <1130713951.953157.270130@g14g2000cwa.googlegroups.com> Message-ID: <1h599ak.9lq5cmarleceN%aleaxit@yahoo.com> Alex wrote: > I have a serious problem and I hope there is some solution. It is > easier to illustrate with a simple code: > > >>> class Parent(object): > __slots__=['A', 'B'] > def __init__(self, a, b): > self.A=a; self.B=b > def __getstate__(self): > return self.A, self.B > def __setstate__(self, tup): > self.A, self.B=tup > > > >>> class Child(Parent): > __slots__=['C',] > def __init__(self, c): > self.C=c > def __getstate__(self): > return self.C, > def __setstate__(self, tup): > self.C, =tup Child.__getstate__ and __setstate__ need to cooperate with those of Parent, not just override them as yours do. __getstate__ is easy: in Child: def __getstate__(self): return super(Child, self).__getstate__ + (self.C,) i.e., each class will successively append its parts of state to the resulting overall tuple. It's harder to do for __setstate__ without building into it a strong dependency on how many items of the tuple the Parent is taking for its own use; you need to establish some protocol of your own for that purpose, such as: in Parent: def __setstate__(self, tup): self.A, self.B = tup[:2] self._tup = tup[2:] in Child: def __setstate__(self, tup): super(Child, self).__setstate__(tup) self.C, = self._tup[:1] self._tup = self._tup[1:] (the last statement is needed in case Child was further subclassed by a Grandchild class following the same set-state protocol). Working with lists rather than tuples might in fact be simpler. But simplest might be if __setstate__ was allowed to return something different than None, so it could return "whatever's left of the tuple" rather than relying on that nasty self._tup thingy (which is going to be left there, empty, in the end -- though, each class could conditionally delete it if it was empty). However, while I believe it is not currently enforced that __setstate__ might return a non-None value to be ignored, I'm not sure it's _allowed_, either, so I wouldn't try (lest this application should break in strange ways in future Python versions). Alex From shannonlayland at gmail.com Wed Oct 26 15:43:37 2005 From: shannonlayland at gmail.com (shannonl) Date: 26 Oct 2005 12:43:37 -0700 Subject: textwidget.tag_bind("name", "", self.donothing) not working In-Reply-To: References: <1130266889.246361.268610@g47g2000cwa.googlegroups.com> Message-ID: <1130355817.708385.119790@g14g2000cwa.googlegroups.com> No I haven't, but I will give it a try. Thanks for your reply! From http Mon Oct 3 03:22:22 2005 From: http (Paul Rubin) Date: 03 Oct 2005 00:22:22 -0700 Subject: Will python never intend to support private, protected and public? References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xd5mstqab.fsf@ruckus.brouhaha.com> <7xzmpwuxd0.fsf@ruckus.brouhaha.com> <20050930075313.67b9b676.jk@ospaz.ru> <7xbr2a6dlz.fsf@ruckus.brouhaha.com> <7xk6gyoibc.fsf@ruckus.brouhaha.com> <433f56a3.2969039483@news.oz.net> <1128274267.064255.306980@f14g2000cwb.googlegroups.com> Message-ID: <7x8xxbgj4h.fsf@ruckus.brouhaha.com> "El Pitonero" writes: > The thing is, there are two sides to every coin. Features surely can > be viewed as "goodies", or they can be viewed as "handcuffs". Let's see, say I'm a bank manager, and I want to close my cash vault at 5pm today and set its time lock so it can't be opened until 9am tomorrow, including by me. Is that "handcuffs"? It's normal procedure at any bank, for good reason. It's not necessarily some distrustful policy that the bank CEO set to keep me from robbing the bank. I might have set the policy myself. Java lets me do something similar with instance variables. Why is it somehow an advantage for Python to withhold such a capability? > Sure, in these very dynamic languages you can ACCIDENTALLY override > the default system behavior. How many Python programmers have once > upon a time done stupid things like: > list = 3 That's just a peculiarity, not any deep aspect of Python. Try it for 'None' instead of 'list': >>> None = 3 SyntaxError: assignment to None Why is 'list' somehow different from 'None'? I'd say there's a case to be made for having the compiler protect 'list' and other builtins the same way it protects 'None'. Python won't be any less dynamic because of it. > The upside is exactly the same as the fact that you can override the > "list()" function in Python. Python is dynamic language. That's not exactly an upside, and it has nothing to do with Python being dynamic. C is static but you can override 'printf'. Overriding 'list' in Python is pretty much the same thing. > In Python, if you have a private variable: > > self._x = 3 > > and you, for curiosity reasons and DURING runtime (after the program is > already up and running) want to know the exact moment the self._x > variable is accessed (say, print out the local time), or print out the > calling stack frames, you can do it. And I mean the program is running. So let's see: def countdown(): n = 3 while n > 0: yield n g = countdown() print g.next() # 3 print g.next() # 2 where's the Python feature that lets me modify g's internal value of n at this point? How is that different from modifying a private instance variable? "Python feature" means something in the language definition, not an artifact of some particular implementation. Is Python somehow deficient because it doesn't give a way to do that? Do you want to write a PEP to add a way? Do you think anyone will take it seriously? [Other stuff incomprehensible and snipped]. From mlist at fastwebnet.it Wed Oct 12 05:42:40 2005 From: mlist at fastwebnet.it (billie) Date: Wed, 12 Oct 2005 11:42:40 +0200 Subject: how to(can we ?) pass argument to .py script ? References: <1129039664.425406.265670@f14g2000cwb.googlegroups.com> <1129042115.926410.71880@g47g2000cwa.googlegroups.com> <1129042655.097833.307550@o13g2000cwo.googlegroups.com> Message-ID: It's quite simple. If this usage example can helps you... ### parser try: opts, args = getopt.getopt(sys.argv[1:], "h, e, p:", ["help"]) mode = 'reply' # default mode pwd = ' ' # default pass (blank) for o, a in opts: if o == '--help' or o == '-h': print helper() os._exit(0) if o == '-h': print helper() os._exit(0) if o == '-e': mode = 'echo/reply' if o == '-p': pwd = a if len(args) < 3 : print " ERR: Too much few arguments.\n Type %s -h for help." \ %(sys.argv[0]) os._exit(0) if len(args) > 3: print \ " ERR: Too much arguments.\n Type -h and \ look example to send argumented commands." os._exit(0) except: print " ERR: Invalid Option.\n Type %s -h for help." \ %(sys.argv[0]) os._exit(0) ### /parser From mde at micah.elliott.name Wed Oct 19 11:32:15 2005 From: mde at micah.elliott.name (Micah Elliott) Date: Wed, 19 Oct 2005 08:32:15 -0700 Subject: [newbie]Is there a module for print object in a readable format? In-Reply-To: References: Message-ID: <20051019153215.GB20480@kitchen.client.attbi.com> On Oct 20, Steven D'Aprano wrote: > That's not what I get. What are you using? > > py> pprint.pprint([1,2,3,4,[0,1,2], 5], width=1, indent=4) > Traceback (most recent call last): > File "", line 1, in ? > TypeError: pprint() got an unexpected keyword argument 'width' I find it useful to have all relevant python versions (as listed on http://www.python.org/download/) installed on my primary test machines. It really helps me with portability testing: $ ls /usr/local/bin/python* /usr/local/bin/python /usr/local/bin/python2.0 /usr/local/bin/python2.1 /usr/local/bin/python2.2 /usr/local/bin/python2.3 /usr/local/bin/python2.4 Then I see that v2.3 didn't have 'width': $ python2.3 -c 'import pprint; pprint.pprint([1,2,3,4,[0,1,2], 5], width=1, indent=4)' Traceback (most recent call last): File "", line 1, in ? TypeError: pprint() got an unexpected keyword argument 'width' But v2.4 does: $ python2.4 -c 'import pprint; pprint.pprint([1,2,3,4,[0,1,2], 5], width=1, indent=4)' [ 1, 2, 3, 4, [ 0, 1, 2], 5] -- _ _ ___ |\/|icah |- lliott http://micah.elliott.name mde at micah.elliott.name " " """ From fredrik at pythonware.com Tue Oct 4 09:27:20 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 4 Oct 2005 15:27:20 +0200 Subject: ssh or other python editor References: <1128430526.531749.68600@g47g2000cwa.googlegroups.com> <1128431721.153846.236930@g43g2000cwa.googlegroups.com> Message-ID: "projecktzero" wrote: > If samba isn't available/set-up, you can try using FTP. You can then > use Crimson Editor which does the syntax coloring and can ftp to/from a > server. are you guys for real? is there any major text editor for Unix that doesn't support Python syntax coloring and indentation these days? From python_it at hotmail.com Tue Oct 11 04:59:53 2005 From: python_it at hotmail.com (Python_it) Date: 11 Oct 2005 01:59:53 -0700 Subject: mod_python In-Reply-To: References: <1129016557.060339.136600@g49g2000cwa.googlegroups.com> Message-ID: <1129021193.741523.252320@f14g2000cwb.googlegroups.com> Thanks for your replay. I put the handler code at the end of the file. No error! But if I go to my localhost\project\mptest.py The code of my function appears. I solve this by put the following code in the confige file: AllowOverride FileInfo From vasialisa-petrova at ryandex.ru Wed Oct 5 13:46:24 2005 From: vasialisa-petrova at ryandex.ru (Vasilisa) Date: Wed, 5 Oct 2005 19:46:24 +0200 Subject: Antsoft Best domain software Message-ID: <1128534544_54013@spool6-east.superfeed.net> Find expired domains with the best software: http://www.antssoft.com The best domain names are already taken. But with expired domain software you can find the best domain names like: -------------------------------- http://www.beyx.com http://www.c6d.de http://www.fyq.us http://www.gv0.net http://www.j1o.de http://www.aj0.net http://www.3tt.de http://www.3ss.de http://www.aryh.com http://www.qym.us http://www.f6x.de http://www.60n.de http://www.7ix.de http://www.k9m.de http://www.4bx.de http://www.9kk.de http://www.bx0.net http://www.0ol.de http://www.w6x.de http://www.xub.us ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= East/West-Coast Server Farms - Total Privacy via Encryption =--- From vincent.gulinao at gmail.com Tue Oct 25 05:39:43 2005 From: vincent.gulinao at gmail.com (Vincent Gulinao) Date: Tue, 25 Oct 2005 17:39:43 +0800 Subject: Upgrading 2.4.1 to 2.4.2 In-Reply-To: <1129712636.124150.248200@g44g2000cwa.googlegroups.com> References: <20051017192011.28785.qmail@web50206.mail.yahoo.com> <1129690538.026623.28230@o13g2000cwo.googlegroups.com> <1129712636.124150.248200@g44g2000cwa.googlegroups.com> Message-ID: Hi, I'm new to python and just upgraded python on my system from 2.3 to 2.4. My platform is Linux-2.6.9-1.667smp-i686-with-redhat-3-Heidelberg. Is there any way to inherit (share?) all extensions and additional modules the my 2.3 have? (of course, beside re-installing everything) On 19 Oct 2005 02:03:56 -0700, Ben Sizer wrote: > > > brusstoc at gmail.com wrote: > > Not sure that is a good idea on a linux system. MS should be fine, but > > I actually tried that on linux. Didn't realize how much on a linux > > system depends on Python. > > I had that problem once, although to be fair it really does depend on > which distribution you use as to how many problems you're going to > have. > > Perhaps the way to do it is to install the new Python version in > /usr/local/ (alongside the distro's version is in /usr/ ), then when > you're sure your new version is installed and working, change the > references over - perhaps it's possible to do this with just 1 symbolic > link somewhere. > > -- > Ben Sizer > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From graham.fawcett at gmail.com Mon Oct 24 09:59:52 2005 From: graham.fawcett at gmail.com (Graham Fawcett) Date: 24 Oct 2005 06:59:52 -0700 Subject: write a loopin one line; process file paths In-Reply-To: <1129694284.783396.197680@f14g2000cwb.googlegroups.com> References: <1129672592.328278.41490@g14g2000cwa.googlegroups.com> <1129675636.740977.151760@z14g2000cwz.googlegroups.com> <1129694284.783396.197680@f14g2000cwb.googlegroups.com> Message-ID: <1130162392.932790.31430@g44g2000cwa.googlegroups.com> Xah Lee wrote: > Dear Peter Hansen, > My messages speak themselfs. You and your cohorts's stamping of it does > not change its nature. And if this is done with repetitiousness, it > gives away your nature. Taunt not the cohorts of Peter Hansen! Graham From Ido.Yehieli at gmail.com Thu Oct 6 07:40:50 2005 From: Ido.Yehieli at gmail.com (Ido.Yehieli at gmail.com) Date: 6 Oct 2005 04:40:50 -0700 Subject: replacments for stdio? In-Reply-To: <1128597932.529665.51810@g14g2000cwa.googlegroups.com> References: <1127477278.036977.189230@g44g2000cwa.googlegroups.com> <1127670588.872596.117560@o13g2000cwo.googlegroups.com> <1128079278.563621.8310@g47g2000cwa.googlegroups.com> <1128548582.759883.326290@g47g2000cwa.googlegroups.com> <1128597932.529665.51810@g14g2000cwa.googlegroups.com> Message-ID: <1128598850.769891.327140@g49g2000cwa.googlegroups.com> the source (and Bryan) doesn't say anything about further distribution - and he did not provide a real email address. Can I safely modify it and include it in the source distribution of my program (it is open source licensed)? Would that be the polite thing to do, i have no idea how to contact this guy? From samrobertsmith at gmail.com Sun Oct 30 16:21:39 2005 From: samrobertsmith at gmail.com (Shi Mu) Date: Sun, 30 Oct 2005 13:21:39 -0800 Subject: Tk In-Reply-To: <1d987df30510280144k1a2a2565h77fa28dc58a22ac4@mail.gmail.com> References: <1d987df30510280144k1a2a2565h77fa28dc58a22ac4@mail.gmail.com> Message-ID: <1d987df30510301321o23ba3ab3o3e3c84d5acad5fd@mail.gmail.com> How can I make the main menu come first, and after clicking test/just try, "how are you" interface shows. Thanks a lot! from Tkinter import * from Tkinter import _cnfmerge class Dialog(Widget): def __init__(self, master=None, cnf={}, **kw): cnf = _cnfmerge((cnf, kw)) self.widgetName = '__dialog__' Widget._setup(self, master, cnf) self.num = self.tk.getint( apply(self.tk.call, ('tk_dialog', self._w, cnf['title'], cnf['text'], cnf['bitmap'], cnf['default']) + cnf['strings'])) try: Widget.destroy(self) except TclError: pass def destroy(self): pass if __name__ == '__main__': q = Button(None, {'text': 'How are you', Pack: {}}) b1 = Listbox() b1.pack() c1 = Checkbutton(text="Check") c1.pack() q.mainloop() from Tkinter import * root =Tk() menu=Menu(root) root.config(menu=menu) filemenu=Menu(menu) menu.add_cascade(label="Test", menu=filemenu) filemenu.add_command(label="Just Try") filemenu.add_separator() mainloop() From qwweeeit at yahoo.it Mon Oct 10 17:15:17 2005 From: qwweeeit at yahoo.it (qwweeeit at yahoo.it) Date: 10 Oct 2005 14:15:17 -0700 Subject: Works only in interactive mode Message-ID: <1128978917.143125.68230@g43g2000cwa.googlegroups.com> Hi all, using Python 2.4 under Linux (SUSE 9.3) I was developping a script to get various lists related with DCOP. In interactive Python all is working correctly: import pcop # application's registration with DCOP x=pcop.register_as('kate') print x kate-7497 # list of DCOP registered applications print pcop.app_list('kate') ['kwin', 'kicker', 'konqueror-7203', 'kate', 'kded', 'kmix', 'kate-7497', 'knotify', 'susewatcher', 'suseplugger', 'kio_uiserver', 'kcookiejar', 'klauncher', 'khotkeys', 'kdesktop', 'konsole-7340', 'klipper', 'ksmserver', 'kaccess', 'kpowersave'] Instead as a script: 1 import pcop 2 3 # application's registration with DCOP 4 x=pcop.register_as('kate') 5 print x 6 7 # list of DCOP registered applications (emula dcop) 8 print pcop.app_list('kate') you get: 0 Traceback (most recent call last): File "/home/bf/python/pippo.py", line 4, in ? x=pcop.register_as('kate') AttributeError: 'module' object has no attribute 'register_as' How is it possible? Bye. From mail at eikepreuss.de Fri Oct 14 04:20:30 2005 From: mail at eikepreuss.de (Eike Preuss) Date: Fri, 14 Oct 2005 10:20:30 +0200 Subject: Jargons of Info Tech industry In-Reply-To: References: <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <86y853mzmr.fsf@bhuda.mired.org> <86mzlil269.fsf@bhuda.mired.org> <86slv8xdkw.fsf@bhuda.mired.org> Message-ID: <3r97uiFi7bsaU1@individual.net> >> >>1. flipping to a digital id based email system so that the sender of >>any piece of mail can be legally identified and prosecuted. >>If every piece of anonymous email disappeared that would go a long >>way to clearing up spam. Let those sending ransom notes, death >>threats and hate mail use snail mail. As a second best, >>correspondents are identified by permission/identity/encryption keys >>given to them by their recipients. > > > The first part seems rather expensive and I'm not sure it would help. > Is spam illegal? I don't see how it can be. I mean, those messages are > annoying, but not that annoying. I get unsolicited email that I > actually want often enough to want to avoid gumming it up in legal > issues. > Just think about 'protecting the youth'. Everybody can send highly sexual (to the abnormal) content to everybody. If you would do this personally on the streets you would surely be prosecuted in most countries. So, if it isn't illegal, it should be. [snip] ++ Eike From bonono at gmail.com Sun Oct 16 09:42:38 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 16 Oct 2005 06:42:38 -0700 Subject: subtle side effect of generator/generator expression Message-ID: <1129470158.623786.135010@g14g2000cwa.googlegroups.com> Hi, I initially thought that generator/generator expression is cool(sort of like the lazy evaluation in Haskell) until I notice this side effect. >>>a=(x for x in range(2)) >>>list(a) [1,2] >>>list(a) [] Would this make generator/generator expression's usage pretty limited ? As when the program/system goes beyond a single module, this behaviour can cause subtle bugs ? From jepler at unpythonic.net Mon Oct 31 07:50:17 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Mon, 31 Oct 2005 06:50:17 -0600 Subject: taking x-window screen shot In-Reply-To: <43660C33.5080603@gmail.com> References: <43660C33.5080603@gmail.com> Message-ID: <20051031125017.GB11789@unpythonic.net> I recommend using 'xwd' to actually get the screenshot, because xwd is installed nearly everwhere X is. xwd-format images are "documented" by the header file X11/XWDFile.h. This program works in a pipeline to convert certain xwd-format images to postscript. You can use it something like this: $ xwd | python xwdtops.py | lpr .. it should print a greyscale rendition of the clicked window to the default printer, if it accepts postscript. It's been quite awhile since I wrote this program (and later re-wrote it in C because it's a bit slow), so I'm not really familiar with this code anymore. However, I do believe that it works on common 16 and 32-bit X displays. One more thing --- if you have imagemagick installed, you may want to consider using its command "import" instead. Instead of the xwd format, it can write the image in many formats, instead of just xwd. Jeff #----------------------------------------------------------------------- import struct, sys print "%!PS-Adobe-1.0" def get_shift(n): for i in range(32): if n & (1<> rs) gsc = .587*256/(green_mask >> gs) bsc = .114*256/(blue_mask >> bs) print "%", red_mask, green_mask, blue_mask print "%", rs, gs, bs print "%", rsc, gsc, bsc print "%", bits_per_pixel wscale = 558./window_width hscale = 720./window_height scale = min(1, wscale, hscale) rwscale = 558./window_height rhscale = 720./window_width rscale = min(1, rwscale, rhscale) print "% scale -", scale, rscale print "/Helvetica findfont 16 scalefont setfont" print "18 756 moveto" print "(%s) show" % " ".join(sys.argv[1:]) or window_name if scale < rscale: scale = rscale #print "%d %d translate" % (window_height*scale+18, 36) print "%d %d translate" % (8.5*72, 0) print "90 rotate" print "18 %d translate" % (594-window_height*scale) # 8.25" sz = 8.5*72 else: print "18 %d translate" % (750-window_height*scale) # 10.5" sz = 11*72 print "%d %d scale" % (window_width*scale, window_height*scale) print "/picstr %d string def" % window_width bytes_per_pixel = (bits_per_pixel+7)/8 row_format = "%c%d%c" % ("<>"[byte_order], window_width, "HI"[bits_per_pixel > 16]) print "%", row_format, bytes_per_line, bytes_per_pixel*window_width print "%", len(rest) print "%d %d 8 [%d 0 0 %d 0 0] {currentfile picstr readhexstring pop } image" % (window_width, window_height, window_width, window_height) if 0: print "00"* window_width for row in range(window_height-2): print "00" + "c0" * (window_width-2) + "00" print "00"* window_width else: for row in range(window_height-1, -1, -1): a = row * bytes_per_line b = a + bytes_per_pixel*window_width for pixel in struct.unpack(row_format, rest[a:b]): r = (pixel & red_mask) >> rs g = (pixel & green_mask) >> gs b = (pixel & blue_mask) >> bs gray = int(rsc*r+gsc*g+bsc*b) sys.stdout.write("%02x" % gray) sys.stdout.write("\n") print print "showpage" #----------------------------------------------------------------------- -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From steve at ferg.org Fri Oct 7 12:52:33 2005 From: steve at ferg.org (Steve) Date: 7 Oct 2005 09:52:33 -0700 Subject: Why do I get an import error on this? Message-ID: <1128703953.497560.47620@z14g2000cwz.googlegroups.com> I'm trying to run a Python program on Unix and I'm encountering some behavior I don't understand. I'm a Unix newbie, and I'm wondering if someone can help. I have a simple program: ____________________________________________ #! /home/fergs/python/bin/python import sys, os import cx_Oracle ____________________________________________ If I run it through the Python interpreter, this way: >> python test.py it runs fine. But if I try to run it as an executable script, this way: >> test.py I get an import error that says it can't find cx_Oracle. Why does it behave differently when I run it in these two ways, and what do I need to do to make it run successfully either way? From darkpaladin79 at hotmail.com Fri Oct 7 22:29:32 2005 From: darkpaladin79 at hotmail.com (Ivan Shevanski) Date: Fri, 07 Oct 2005 22:29:32 -0400 Subject: noob question Letters in words? In-Reply-To: Message-ID: >Is it *really* a good idea if the user types "STOP!!!" and it has the >same effect as if they typed "Start please"? > >I've heard of "Do what I mean, not what I said" systems, which are usually >a really bad idea, but this is the first time I've seen a "Do what I don't >mean, not what I said" system. =D Alright, I'm going to stop trying to defend my idea since it's obviously a bad one. What do you recommend? -Ivan _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ From my_email_is_posted_on_my_website at munged.invalid Sat Oct 8 18:39:38 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sat, 08 Oct 2005 22:39:38 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> Message-ID: On Sun, 09 Oct 2005 00:03:05 +0200, Lasse V?gs?ther Karlsen wrote or quoted : >On one side you got control freaks who condemn everyone who dares send >an email with something other than what you've got your own email set up >to use. "You dare specify the font sized when I finally figured out that >10 is just right? Infidel!" This is one of the marvels of CSS once you get the hang of it. If you don't like bright red letters on green backgrounds, you can CHANGE that. You can change the fonts, sizes etc etc. You can if you want get something very like plain ASCII text. So from an aesthetic point of view, once people learn how it works, CSS lets sender and receiver compromise on what the message looks like. No other medium gives ANY control to the receiver about how a message is formatted. One of the most important changes in the ability to select special fonts for the those without prefect vision and larger fonts. There is also the philosophical question. When my nephew sends me a message, do I have a right to warp his intent even if I don't like the aesthetics? That is part of his message. Should my email reader fix the spelling mistakes in the emails sent me by angry US soldiers? Or is that part of the message? There are three different issues getting muddled together: 1. avoiding spam 2. making mail from well meaning but inept friends more readable. 3. what constitutes a good general style for general correspondence. How should you use rich text appropriately. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From hancock at anansispaceworks.com Fri Oct 7 02:05:12 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Fri, 7 Oct 2005 01:05:12 -0500 Subject: [Info] PEP 308 accepted - new conditional expressions In-Reply-To: References: <3q4ro9Fd770nU3@individual.net> Message-ID: <200510070105.12846.hancock@anansispaceworks.com> On Monday 03 October 2005 03:48 am, Volker Grabsch wrote: > Fredrik Lundh wrote: > > /... snip comment that the natural order is C, X, Y and that programmers that > > care about readable code will probably want to be extremely careful with this > > new feature .../ > > That's also my opinion, but OTOH, Guido's syntax is more close to the syntax > of list comprehensions. GvR's syntax has the advantage of making grammatical sense in English (i.e. reading it as written pretty much makes sense). -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From mwm at mired.org Tue Oct 4 14:25:04 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 04 Oct 2005 14:25:04 -0400 Subject: ssh or other python editor References: <1128430526.531749.68600@g47g2000cwa.googlegroups.com> <1128431721.153846.236930@g43g2000cwa.googlegroups.com> <1128433683.342113.32060@g47g2000cwa.googlegroups.com> Message-ID: <86ek71i1hb.fsf@bhuda.mired.org> "Fredrik Lundh" writes: > martijn at gamecreators.nl wrote: >>- I'm a newbie at freeBSD so I think there is , but I don't know where. > Putty isn't doing any syntax coloring; it just draws things in the color specified > by your editor. If you don't get any colors, it's probably because your editor > isn't properly configured. Explicitly setting the TERM variable to "xterm" might > help: > > http://www.chiark.greenend.org.uk/~sgtatham/putty/faq.html#faq-term According to the FAQ, putty sets it to xterm. I use xter-color on FreeBSD. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From bignose+hates-spam at benfinney.id.au Mon Oct 31 02:10:30 2005 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Mon, 31 Oct 2005 18:10:30 +1100 (EST) Subject: Rich __repr__ Message-ID: Howdy all, The builtin types have __repr__ attributes that return something nice, that looks like the syntax one would use to create that particular instance. The default __repr__ for custom classes show the fully-qualified class name, and the memory address of the instance. If I want to implement a __repr__ that's reasonably "nice" to the programmer, what's the Right Way? Are there recipes I should look at? -- \ "For certain people, after fifty, litigation takes the place of | `\ sex." -- Gore Vidal | _o__) | Ben Finney From klaus at seistrup.dk Tue Oct 4 09:01:06 2005 From: klaus at seistrup.dk (Klaus Alexander Seistrup) Date: Tue, 4 Oct 2005 13:01:06 +0000 (UTC) Subject: NNTP module capable of "MODE STREAM" Message-ID: Hi, I need a Python NNTP module that is capable of doing "MODE STREAM" as client and as server. Does anyone here know of such a module except the twisted.protocols.nntp module? Cheers, -- Klaus Alexander Seistrup Copenhagen, Denmark http://streetkids.dk/ From kibleur.christophe at gmail.com Thu Oct 6 16:33:10 2005 From: kibleur.christophe at gmail.com (Tool69) Date: 6 Oct 2005 13:33:10 -0700 Subject: SetBackgroundColor doesn't work for me Message-ID: <1128630790.642555.143090@g49g2000cwa.googlegroups.com> Hi, I'm on Linux Ubuntu Breezy with wxPython 2.6.1 and Python 2.4.1 installed. I've made an app, but the BackgroundColors won't work on any of my ListBoxes, they only work with Windows XP. Does someone had this problem before ? Any suggestion ? thanks. From hungryblank at gmail.com Fri Oct 14 06:37:01 2005 From: hungryblank at gmail.com (hungryblank at gmail.com) Date: 14 Oct 2005 03:37:01 -0700 Subject: get_payload problem with large mail attachments Message-ID: <1129286221.172200.217160@o13g2000cwo.googlegroups.com> I'm having troubles with a script that uses the get_payload function. My script just works perfectly if I use it with attachment up to 8 Mb. If the attachment are more than 8 Mb large, the script exits with a TypeError exception. IMHO when get_payload try to convert the attachment in a single string it occours in some size limit. How can I fix it? I'm using python-2.3.3 on a SuSE 9.1 distro The error raised is Traceback (most recent call last): File "/usr/local/sbin/mailbox2home.py", line 44, in ? fp.write(part.get_payload(decode=1)) TypeError: argument 1 must be string or read-only buffer, not None and this is the slice of code where the error occours. for message in messages: for part in message.walk(): # multipart/* are just containers if part.get_content_maintype() == 'multipart': continue # Applications should really sanitize the given filename so that an # email message can't be used to overwrite important files filename = part.get_filename() if not filename: ext = mimetypes.guess_extension(part.get_type()) if not ext: # Use a generic bag-of-bits extension ext = '.bin' filename = 'part-%03d%s' % (counter, ext) counter += 1 fp = open(os.path.join(dir, filename), 'wb') fp.write(part.get_payload(decode=1)) fp.close() From timr at probo.com Fri Oct 21 02:13:06 2005 From: timr at probo.com (Tim Roberts) Date: Fri, 21 Oct 2005 06:13:06 GMT Subject: sqlstring -- a library to build a SELECT statement References: <1129774730.887128.314960@z14g2000cwz.googlegroups.com> Message-ID: "grunar at gmail.com" wrote: > >An Example: > >>>> import sqlstring >>>> model = sqlstring.TableFactory() >>>> print model.person >SELECT >person.* >FROM >[person] person The [bracket] syntax is unique to Microsoft. Everyone else, including Microsoft SQL Server, uses "double quotes" to protect special characters in identifiers. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From renting at astron.nl Tue Oct 25 03:17:32 2005 From: renting at astron.nl (Adriaan Renting) Date: Tue, 25 Oct 2005 09:17:32 +0200 Subject: Redirect os.system output Message-ID: Maybe Pexpect can help you, I think it does what you want, I'm just not sure it works on windows, as I think it uses pty's. Please read it's FAQ about stdio buffer behaviour, I think it's also valid on Windows. pexpect.sourceforge.net Adriaan Renting. >>>"jas" 10/24/05 2:33 pm >>> #I see that, although I don't totall grasp the code. However, I am #looking to basically emulate a command prompt. i.e. everything u see #in the windows command prompt should be displayed back in python. # #How can I do it without files? # #Kent Johnson wrote: #>jas wrote: #>>Any other ideas? or examples of using subprocess to do what I was #>>asking? #> #>Actually I thought I was giving an example of what you were asking: #>- on windows #>- send a series of commands to a command process #>- capture the result to a variable #> #>The example I referenced sends a series of HELP commands to cmd.exe, captures the output of the commands and saves it to a #file. #> #>What did I miss? #> #>Kent #> #>> #>> #>>Kent Johnson wrote: #>> #>>>jas wrote: #>>> #>>>>I would like to redirect the output from os.system to a variable, but 3>>>>am having trouble. I tried using os.popen(..).read() ...but that #>>>>doesn't give me exactly what i want. #>>> #>>>Here is an example using subprocess: #>>>http://groups.google.com/group/comp.lang.python/msg/9fa3a3c287e8e2a3?hl=en& 3>>> #>>>Kent #>>> #>>> From fredrik at pythonware.com Wed Oct 26 18:24:01 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 27 Oct 2005 00:24:01 +0200 Subject: syntax question - if 1:print 'a';else:print 'b' References: <312cfe2b0510261507m2732e947p2be6fdae99a7c3d7@mail.gmail.com> Message-ID: Gregory Pi?ero wrote: > Any idea why I can't say: > > if 1:print 'a';else:print 'b' > > all in one line like that? because ";" can only be used to separate simple statements, not the different parts in a compound statement. see the grammar for details: http://docs.python.org/ref/grammar.txt (look for "compound_stmt", "suite", "statement", etc) From mwm at mired.org Mon Oct 3 17:17:15 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 03 Oct 2005 17:17:15 -0400 Subject: Reply-To header References: <2ECA6FE9-3C8F-4C60-9E89-70CC078B14EF@gmail.com> <7rc0f.11261$Un.585792@phobos.telenet-ops.be> Message-ID: <86k6gujo6c.fsf@bhuda.mired.org> Roel Schroeven writes: > Peter Decker wrote: >> Setting the default Reply-To: to the list means that 'Reply' sends >> just to the list (the desired behavior most of the time), and 'Reply >> to all' sends 2 copies. > The thing is: Reply-to has legitimate uses. I don't really understand > the use cases (AFAICS all of them could be done with Form: instead) Yes, they can all be done with From:. But From: has uses other than just listing the reply address, and if you hijack From: to replace reply-to (because other people have hijacked Reply-To: for purposes for which it wasn't intended :-), then you can't use From: for what *it* was intended for. I send out mail - well, mail gets sent out for me - every day that uses both the From: and Reply-To: fields. The mail is *from* me, and that's what the from header says. The reply needs to go to a magic maildrop that takes action based on the reply address. The recipient doesn't need to see the reply address, and would only be confused by it if they did. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From dave at pythonapocrypha.com Wed Oct 19 23:04:45 2005 From: dave at pythonapocrypha.com (Dave Brueck) Date: Wed, 19 Oct 2005 21:04:45 -0600 Subject: destroy your self???? In-Reply-To: <1129776816.148308.210460@g44g2000cwa.googlegroups.com> References: <1129776816.148308.210460@g44g2000cwa.googlegroups.com> Message-ID: <4357094D.2050407@pythonapocrypha.com> KraftDiner wrote: > if I create an object like... > > obj = None > ... > obj = anObject() > > can obj set itself to none in some method of the class? No - Python doesn't work that way. What are you trying to accomplish? There's probably a way to do what you need to do, but this isn't it. -Dave From dcrespo at gmail.com Fri Oct 14 17:45:20 2005 From: dcrespo at gmail.com (dcrespo) Date: 14 Oct 2005 14:45:20 -0700 Subject: How to get a raised exception from other thread Message-ID: <1129326320.914350.171460@o13g2000cwo.googlegroups.com> Hi all, How can I get a raised exception from other thread that is in an imported module? For example: --------------- programA.py --------------- import programB thread = programB.MakeThread() thread.start() --------------- programB.py --------------- import threading, time class SomeException(Exception): pass class MakeThread(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self): i = 0 while 1: print i i += 1 time.sleep(1) #wait a second to continue if i>10: raise SomeException() Thanks Daniel From gregpinero at gmail.com Thu Oct 27 10:49:02 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Thu, 27 Oct 2005 10:49:02 -0400 Subject: xml.dom.minidom - parseString - How to avoid ExpatError? In-Reply-To: <43608B8F.1000506@plus.net> References: <312cfe2b0510251159p5e2501cbxf21e4f62f3d70b1c@mail.gmail.com> <312cfe2b0510260738j460b075ch998371a460c39df8@mail.gmail.com> <435F9C6C.50707@plus.net> <312cfe2b0510261020w1d485c98m526e325d6ada1082@mail.gmail.com> <43608B8F.1000506@plus.net> Message-ID: <312cfe2b0510270749x2685c686w3f033a5f151a903a@mail.gmail.com> Thanks, John. That was all very helpful. It looks like one option for me would be to put cdata[ around my text with all the weird characters. Otherwise running it through on of the SAX utilities before parsing might work. I wonder if the sax utilities would give me a performance hit. I have 6000 xml files to parse at 100KB each. -Greg -------------- next part -------------- An HTML attachment was scrubbed... URL: From borell at nytimes.com Thu Oct 13 19:25:42 2005 From: borell at nytimes.com (Frank Borell) Date: 13 Oct 2005 16:25:42 -0700 Subject: win32api.FindFiles Win2003, problem with Short Name Message-ID: <1129245942.185252.171220@o13g2000cwo.googlegroups.com> I'm having a problem retrieving the ShortName from a file that was written by a MAC and only from a Windows 2003 server. I realize the file has a space after it, but I can retrieve the short name from Windows XP and 2000; >>>print win32api.FindFiles(process_source_dir + "*") Excluding the results from "." and "..", it returns: (32, , , , 0, 44118, 29741111, 0, '10^2f16 Hardcover a ', '10^2F167.5AC') - All OK!! When using the same command on Win2003, it returns: , , 0, 44118, 29741111, 0, '10^2f16 Hardcover a ', '') The versions of Python / Win32 are the same on all servers. Does anyone have any ideas? Frank From davids at webmaster.com Thu Oct 27 18:29:22 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 15:29:22 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <66u633-etj.ln1@news.it.uc3m.es> <7xbr1aewtq.fsf@ruckus.brouhaha.com> <86acgulv5z.fsf@localhost.localdomain> <7xvezi8ypy.fsf@ruckus.brouhaha.com> <86y84ehd3j.fsf@bhuda.mired.org> Message-ID: "Mike Meyer" wrote in message news:86y84ehd3j.fsf at bhuda.mired.org... > I've noticed something strange that makes me wonder the same > thing. Everytime someone compares MS's behavior with that of any other > criminals, he responds about MS's activity being "equated to that of > criminals with guns", and refuses to discuss the issue. Ironically, > while no one else has so much as compared MS to criminals with guns - > after all, they're white collar criminals - David Schwartz called the > DOJ official who were investigating MS "criminals with guns pointed > out [MS officers] heads". I can't understand why you would post an outright lie like this. "Ironically, while no one else has so much as compared MS to criminals with guns". I defy you to find *one* place where I complain that MS behavior is equated to the actual use of force where that is not in fact done in precisely the thread I'm replying to. In the present thread, for example, I was responding to: "We are talking junior Mafia style enforcement." and "Try the same thing to deal with a Mafia extortion racket." and his response to my question if he was specifically saying that Microsoft ever used or threatened force was: "YES . Have you not read a word I said." and "It will be very hard to prosecute MS for their crimes because they commit them much the way the Mafia does. ... Everyone was terrified of MS and would never dream of going public. I have talked about this publicly many times because it always looked as if I were going to die in a few years anyway." DS From avnit7 at gmail.com Mon Oct 31 14:02:07 2005 From: avnit7 at gmail.com (avnit) Date: 31 Oct 2005 11:02:07 -0800 Subject: Print to printer In-Reply-To: <1130552901.655182.203330@g44g2000cwa.googlegroups.com> References: <1130528702.908172.189990@g47g2000cwa.googlegroups.com> <1130552901.655182.203330@g44g2000cwa.googlegroups.com> Message-ID: <1130783807.396650.268660@g47g2000cwa.googlegroups.com> I just want to print text. I'll try macpython. Thanks for the help. From my_email_is_posted_on_my_website at munged.invalid Thu Oct 20 07:08:20 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Thu, 20 Oct 2005 11:08:20 GMT Subject: Microsoft Hatred FAQ References: <867jcbzdw9.fsf@bhuda.mired.org> <4vcbl1dkek9kr86embmgrj70vk945t99ho@4ax.com> <35jbl1dprs4v1o87i0tapc2husjqiqm6fi@4ax.com> <4355ea72$1_3@news.melbourne.pipenetworks.com> Message-ID: On Wed, 19 Oct 2005 03:15:03 -0700, "David Schwartz" wrote or quoted : > Did I say their obligation was to secure their shareholders as much >profit as possible? I said their obligation was to their shareholders. You are literally saying people work for a company have an obligation to the shareholders. That is too obvious to be bothered with announcing. The employees take the shareholder's money, so obviously they have an obligation to produce something in return. When I read your words, I think you really mean this is the prime or sole obligation of an employee. I disagree with that. There are many loyalties that compete. Personally, the loyalty to the preservation of my planet is far above loyalty to any company. For example, I would feel a moral obligation to be a whistleblower of actions of a company that was destroying the environment. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From mwm at mired.org Mon Oct 31 11:45:02 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 31 Oct 2005 11:45:02 -0500 Subject: Arguments for button command via Tkinter? References: <1130768146.414955.106780@g47g2000cwa.googlegroups.com> Message-ID: <864q6xbppt.fsf@bhuda.mired.org> "dakman at gmail.com" writes: > Recently, I have been needing to do this alot and I can never find a > way around it, the main reason I want to do this is because for example > in the application I am making right now, it creates a grid of buttons > in a loop and they all have the same purpose so they need to call the > same method, within this method they need to change the background > color of the button clicked, I've tried stuff like... > > button['command'] = lambda: self.fill(button) > > def fill(self, wid): > button['bg'] = '#ff0000' > > But that's no good, everytime it I do click a button the lambda method > I have setup keeps getting recreated so all of the button commands > point to the same lambda method, I have also tried appending them to an > array, and calling them from that. > > Anyone have any clue as of what to do? Thanks. People have pointed out how to do this with a class, but you can do it with lambdas as well. I suspect the problem you're having is that python is binding values at call time instead of at definition time, but it's hard to tell without more of your source code. If I'm right, one solution is to make the values you want bound at definition time optional arguments to the lambda, bound to the correct value then. So you'd do: button['command'] = lambda b = button: self.fill(b) The version you used will look up the name button when the lambda is invoked. My version will look it up when the lambda is defined. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From thomasbartkus at comcast.net Mon Oct 10 16:43:21 2005 From: thomasbartkus at comcast.net (Thomas Bartkus) Date: Mon, 10 Oct 2005 15:43:21 -0500 Subject: Python reliability References: <7xr7au1hr5.fsf@ruckus.brouhaha.com> Message-ID: "Ville Voipio" wrote in message news:slrndkka7r.62en.vvoipio at kosh.hut.fi... > In article <7xr7au1hr5.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > I would need to make some high-reliability software > running on Linux in an embedded system. Performance > (or lack of it) is not an issue, reliability is. > The software should be running continously for > practically forever (at least a year without a reboot). > is the Python interpreter (on Linux) stable and > leak-free enough to achieve this? > > Adding the Python interpreter adds one layer on uncertainty. > On the other hand, I am after the simplicity of programming > offered by Python. > I would need to make some high-reliability software > running on Linux in an embedded system. Performance > (or lack of it) is not an issue, reliability is. > The software should be running continously for > practically forever (at least a year without a reboot). > is the Python interpreter (on Linux) stable and > leak-free enough to achieve this? All in all, it would seem that the reliability of the Python run time is the least of your worries. The best multi-tasking operating systems do a good job of segragating different processes BUT what multitasking operating system meets the standard you request in that last paragraph? Assuming that the Python interpreter itself is robust enough to meet that standard, what about that other 99% of everything else that is competing with your Python script for cpu, memory, and other critical resources? Under ordinary Linux, your Python script will be interrupted frequently and regularly by processes entirely outside of Python's control. You may not want a multitasking OS at all but rather a single tasking OS where nothing happens that isn't 100% under your program control. Or if you do need a multitasking system, you probably want something designed for the type of rugged use you are demanding. I would google "embedded systems". If you want to use Python/Linux, I might suggest you search "Embedded Linux". And I wouldn't be surprised if some dedicated microcontrollers aren't showing up with Python capability. In any case, it would seem you need more control than a Python interpreter would receive when running under Linux. Good Luck. Thomas Bartkus From davids at webmaster.com Thu Oct 27 07:07:50 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 04:07:50 -0700 Subject: Microsoft Hatred FAQ References: <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> Message-ID: Roedy Green wrote: > The tactic Univac/Burroughs/Prime used, at least for big sales, was > for example invite the potential customer to view some installation to > talk to a satisfied client about how they were using their gear. There > might be a convenient client in say ... Las Vegas. Yep, that's a classic. Notice that no force, fraud, or threats are involved. > The game then became to get the client to get drunk and laid and do > crazy things to help very uptight people cut loose. > > On one of these trips, we ran through fields chasing fireflies. That is a bit questionable, I admit. It is questionable because the intent is pretty obviously to get the individuals more interested in being nice to you than looking out for the interests of their employers when they make their purchasing decisions. On the other hand, it's a far cry from force, fraud, blacklisting, threats of false accusations, and so on. DS From apardon at forel.vub.ac.be Thu Oct 6 02:47:58 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 6 Oct 2005 06:47:58 GMT Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> <434245F5.6060500@REMOVEMEcyber.com.au> <7xr7b14lk0.fsf@ruckus.brouhaha.com> <7xu0fx9l7y.fsf@ruckus.brouhaha.com> Message-ID: Op 2005-10-05, Brian Quinlan schreef : > Paul Rubin wrote: >> Brian Quinlan writes: >> >>>Have those of you who think that the lack of required declarations in >>>Python is a huge weakness given any thought to the impact that adding >>>them would have on the rest of the language? I can't imagine how any >>>language with required declarations could even remotely resemble >>>Python. >> >> >> Python already has a "global" declaration; > > Which is evaluated at runtime, does not require that the actual global > variable be pre-existing, and does not create the global variable if not > actually assigned. I think that is pretty different than your proposal > semantics. > >> how does it de-Pythonize the language if there's also a "local" >> declaration and an option to flag any variable that's not declared as >> one or the other? > > Your making this feature "optional" contradicts the subject of this > thread i.e. declarations being necessary. But, continuing with your > declaration thought experiment, how are you planning on actually adding > optional useful type declarations to Python e.g. could you please > rewrite this (trivial) snippet using your proposed syntax/semantics? > > from xml.dom import * > > def do_add(x, y): > return '%s://%s' % (x, y) > > def do_something(node): > if node.namespace == XML_NAMESPACE: > return do_add('http://', node.namespace) > elif node.namespace == ... > ... > IMO your variable are already mostly declared. The x and y in the do_add is kind of a declarartion for the parameters x and y. -- Antoon Pardon From juho.schultz at helsinki.fi Thu Oct 13 02:43:48 2005 From: juho.schultz at helsinki.fi (Juho Schultz) Date: Thu, 13 Oct 2005 09:43:48 +0300 Subject: how to make this code faster In-Reply-To: <1129183717.183243.100540@g49g2000cwa.googlegroups.com> References: <1129183717.183243.100540@g49g2000cwa.googlegroups.com> Message-ID: ajikoe at gmail.com wrote: > def f(x,y): > return math.sin(x*y) + 8 * x > I have code like this: > > def main(): > n = 2000 > a = zeros((n,n), Float) > xcoor = arange(0,1,1/float(n)) > ycoor = arange(0,1,1/float(n)) > > > for i in range(n): > for j in range(n): > a[i,j] = f(xcoor[i], ycoor[j]) # f(x,y) = sin(x*y) + 8*x > > print a[1000,1000] > pass > > if __name__ == '__main__': > main() > > > I try to make this run faster even using psyco, but I found this still > slow, I tried using java and found it around 8x faster... > I guess the double loop (4E6 rounds) makes your program so slow. I assume you are using numarray or numeric for this. The built-in array operations are a lot faster. Try using them instead. And function calls are not free either. Xcoor and ycoor are equal, so there is no need to generate them both. I guess the following would be a lot faster: def func(): n = 2000 a = numarray.zeros((n,n), "Float") coor = numarray.arange(0,1,1/float(n)) for i in range(n): a[:,i] = numarray.sin(coor*coor[i]) + 8*coor print a[1000,1000] pass From who at me.com Mon Oct 10 00:54:54 2005 From: who at me.com (Free Music) Date: Mon, 10 Oct 2005 04:54:54 GMT Subject: Unlimited Free Music Downloads WOW! 100% Legal Message-ID: ALL COOL MUSIC -------------- next part -------------- An HTML attachment was scrubbed... URL: From gandalf at designaproduct.biz Thu Oct 6 07:44:30 2005 From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy) Date: Thu, 06 Oct 2005 13:44:30 +0200 Subject: /usr/bin/env python, force a version In-Reply-To: <1128597929.636452.223890@o13g2000cwo.googlegroups.com> References: <1128597929.636452.223890@o13g2000cwo.googlegroups.com> Message-ID: <43450E1E.6010903@designaproduct.biz> manatlan at gmail.com wrote: >I've got a trouble, and i think that anybody there can help me > >I've got a python script which i distribute in somes packages for *nix. >This script is full of python and need python 2.4 ! And i'd like to >display a message when the user doesn't have a python2.4 version. > > >>> import sys >>> sys.version '2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]' >>> There is also sys.hexversion sys.api_version sys.version_info* Read this: *http://docs.python.org/lib/module-sys.html Les ** From ms at cerenity.org Sat Oct 1 07:53:33 2005 From: ms at cerenity.org (Michael) Date: Sat, 01 Oct 2005 12:53:33 +0100 Subject: Where to find python c-sources References: Message-ID: <433e7898$0$49766$ed2e19e4@ptn-nntp-reader04.plus.net> John J. Lee wrote: > "Tor Erik S??nvisen" writes: >> "Erik Max Francis" wrote in message >> > Tor Erik S?nvisen wrote: >> >> I need to browse the socket-module source-code. I believe it's >> >> contained in the file socketmodule.c, but I can't locate this file... >> >> Where should I look? >> > The source tarball, available on python.org. Are people really too >> > lazy to do elementary research on Google? >> Thanks for the answers... And yes, I have searched google! ... > Does google vary in its results across the globe? Aside from Paul Boddie's comment to the effect of "yes", there is a very important thing that people forget - *no everyone is as good at using a search engine as others*. People are not simply as good at finding the same information using the same tools as others. You liken the problem to a library. If you understand how a library is laid out, you can find the information alot quicker. If however you're looking in a library for a book on "how to create those odd things for computers" and you've been told it involves "python" you're as likely to end up in the fiction section as you are zoology. If you can't figure out the right search terms you need, google can be useless. (That said when that happens to me, I tend to either use kartoo.com or ask a friend) The search terms might be obvious to you, but it simply means your google-fu is strong, and the strong should help the weak. (or not attack them at least...) Michael. From robin at SPAMREMOVEjessikat.fsnet.co.uk Fri Oct 21 03:56:15 2005 From: robin at SPAMREMOVEjessikat.fsnet.co.uk (Robin Becker) Date: Fri, 21 Oct 2005 07:56:15 +0000 Subject: override a property In-Reply-To: <1129795405.446874.294130@g43g2000cwa.googlegroups.com> References: <1129647504.536405.156280@g43g2000cwa.googlegroups.com> <1129795405.446874.294130@g43g2000cwa.googlegroups.com> Message-ID: <43589F1F.8080305@jessikat.fsnet.co.uk> Kay Schluehr wrote: > Robin Becker wrote: > > >>I thought that methods were always overridable. >>In this case the lookup on the >>class changes the behaviour of the one and only property. > > > How can something be made overridable that is actually overridable? I > didn't know how to better express the broken polymorphism of Pythons > properties than by stating it as a pleonasm about the used get and set > methods. This way a property don't ever have to be redefined in > subclasses if get_x, set_x etc. are changed. > > Kay > well I guess that's the ambiguity of human language. Clearly when I assign to a normal attribute I am changing its value; assigning to a property or descriptor does something that is not so obvious. Changing the behaviour of such an attribute could be done by inheritance as suggested. The new class has overridden the property. When I want to do that on an instance I have first to create a mutable version of the descriptor where the mutability is on the instance not the class. I call the action of changing the base descriptor behaviour 'overriding', but perhaps that's not the correct word. What do you suggest? -- Robin Becker From rrr at ronadam.com Tue Oct 25 17:49:38 2005 From: rrr at ronadam.com (Ron Adam) Date: Tue, 25 Oct 2005 21:49:38 GMT Subject: namespace dictionaries ok? In-Reply-To: <435e998e.950534346@news.oz.net> References: <9Xs7f.4060$Zd.3377@tornado.tampabay.rr.com> <435e998e.950534346@news.oz.net> Message-ID: Bengt Richter wrote: > On Tue, 25 Oct 2005 16:20:21 GMT, Ron Adam wrote: >>Or worse, the dictionary would become not functional depending on what >>methods were masked. >> >> >>And this approach reverses that, The dict values will be masked by the >>methods, so the values can't effect the dictionary methods. But those >>specific values are only retrievable with the standard dictionary notation. >> >> class namespace(dict): >> __getattr__ = dict.__getitem__ >> __setattr__ = dict.__setitem__ >> __delattr__ = dict.__delitem__ >> >> n = namespace() >> n.__getattr__ = 'yes' # doesn't mask __getattr__ method. >> >> print n['__getattr__'] -> 'yes' >> >>The value is there and __getattr__() still works. But n.__getattr__ >>returns the method not the value. >> >>So is there a way to keep the functionality without loosing the methods? >> >> >>BTW, I agree with Steven concerning data structures. This really isn't >>a substitute for a data structure. Many keys will not work with this. >> >> n.my name = 'Ron' >> n.(1,2) = 25 >> n.John's = [ ... ] >> >>The use case I'm thinking of is not as a shortcut for data structures, >>but instead, as a way to keep names as names, and maintaining those >>names in a group. Thus the namespace association. >> >> def foo(**kwds): >> kwds = namespace(kwds) >> print kwds.name >> print kwds.value >> ... >> >> name = 'ron' >> value = 25 >> foo( name=name, position=position ) >> > > Just had the thought that if you want to add bindings on the fly modifying the > original object, you could use the __call__ method, e.g., > > >>> class NameSpace(dict): > ... __getattr__ = dict.__getitem__ > ... __setattr__ = dict.__setitem__ > ... __delattr__ = dict.__delitem__ > ... def __call__(self, **upd): > ... self.update(upd) > ... return self > ... > >>> def show(x): print '-- showing %r'%x; return x > ... > >>> ns = NameSpace(initial=1) > >>> show(ns) > -- showing {'initial': 1} > {'initial': 1} > > And updating with a second keyword on the fly: > > >>> show(show(ns)(second=2)) > -- showing {'initial': 1} > -- showing {'second': 2, 'initial': 1} > {'second': 2, 'initial': 1} > > FWIW ;-) > > Regards, > Bengt Richter Getting better! ;-) That (or something similar) might avoid copying the whole thing in some situations, which is something I am concerned about. But how to change a dict to a namespace without copying the contents item by item? I'm not sure where or if this is going anywhere. It may tie back into the properties groups example (see below) I posted earlier and keep finding improvements for. ;-) cheers, Ron """ GPobject.py Grouped Properties Object: This need has presented itself while programming Tkinter applications where a *LOT* of keywords are used. I think property groups would also be good for general interface building. The external view is of a single cohesive object, while the internal mechanism keeps the attributes grouped so they can be forwarded easily as **kwds. class foo(GPobject): def __init__(self): self.properties(name, item_1, item_2, ... item_n) def getter(): ... def setter(): ... def remover(): ... self.name.doc( __doc__ string ) self.name.get = getter self.name.set = setter self.name.remove = remover * The properties() method can also accept a dictionary. This will set both the names and the values at the same time. self.properties(name, dictionary) class myclass(GPobject): def __init__(self, **kwds): self.properties('kwds', **kwds) * group.setup() allows easy initiation of get, set, remove, and doc group settings in one step. self.properties( name, *members ) self.name.setup( get=myget, set='set', del='del', doc='a property group' ) * Using string flags to indicate default values lets you shorten the expression further. self.properties( name, *members ) self.name.setup( myget, 'set', 'del', 'a property group') The following is only somewhat tested... but it seems to work. """ class GPdict(dict): doc = "a property group" def doc(self, docstring): self.__doc__ = docstring def get(self, item): return self[item] def set(self, item, value): self[item] = value def remove(self, item): del self[item] def setup( self, fget='get', fset='set', fdel='del', doc=doc ): if fget != 'get': self.get = fget if fset != 'set': self.set = fset if fdel != 'del': self.remove = fdel self.__doc__ = doc # Some useful common alternate methods to # replace get, set and remove. def readonly(self, *args): raise AttributeError, 'read only property' def setonce(self, item, value): if self[item] is None: self[item] = value else: raise AttributeError, 'set once property' def nonremovable(self, *args): raise AttributeError, 'non removable property' class GPobject(object): """ an object that can use grouped properties """ __properties__ = {} def __new__(cls, *args, **kwds): cls.__properties__ = {} return object.__new__(cls, *args, **kwds) def properties(self, *args, **kwds): dct = GPdict() for i in args[1:]: dct.setdefault(i,None) dct.update(kwds) self.__properties__[args[0]] = dct self.__dict__[args[0]] = dct def __getattr__(self, name): for dct in self.__properties__: if name in self.__properties__[dct]: return self.__properties__[dct].get(name) return self.__dict__[name] def __setattr__(self, name, value): notprop = True for dct in self.__properties__: if name in self.__properties__[dct]: self.__properties__[dct].set(name,value) notprop = False if notprop: self.__dict__[name] = value def __delattr__(self, name): for dct in self.__properties__: if name in self.__properties__[dct]: self.__properties__[dct].remove(name) return del self.__dict__[name] ================= ### Properties as keyword sorter example, ### (sort to groups, not ordered sort) class sorter(GPobject): text_group = str.split('text fill font') line_group = str.split('line fill arrows') def __init__( self, text=None, fill=None, line=None, arrows=None, font=None ): self.properties('_text', *self.text_group) self.properties('_line', *self.line_group) self.text = text self.fill = fill self.line = line self.arrows = arrows self.font = font s = sorter(text='hello', fill='black', line='solid', arrows='both') print 's._text =', s._text print 's._line =', s._line print s.__properties__ From mwm at mired.org Sat Oct 29 21:18:37 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 29 Oct 2005 21:18:37 -0400 Subject: Expanding Python as a macro language References: <1130545600.925061.287390@g49g2000cwa.googlegroups.com> <1130631958.683127.215300@g14g2000cwa.googlegroups.com> Message-ID: <868xwbdcpe.fsf@bhuda.mired.org> qwweeeit at yahoo.it writes: > My answer is the same as that given to Michael about low level > programming. > But I must thank anyway Alex for giving informations to such a level > (I didn't know that under Linux there was such a level of > sophistication with the possibility for an application to discover fake > keystrokes...). > > If this fake keystroke is used to fire an event (like pressing a > button), the fake flag is propagated to the action taken by the button? The action is internal to the application, so whether or not it propogates the "fake" flag is up to the application. In between the X event and the action is the GUI library, which may also choose to not propogate the flag. > For the other Alex observations (about Mac OsX and my examples of > automation centered on web automation) I have a PC, and the fact that > Python is very good at dealing with the web, doesn't help too much > in this case... > In any case a macro language like AutoIt is a general purpose > application. > > At last I must thank Mike Meyer for his suggestion to use python-xlib > to avoid low level programming... Just to clarify - python-xlib will let you avoid the need for C functions to do things like send X events. In that sense, it helps you avoid low-level programming. On the other hand, you're still sending X events, so in *that* sense, you're not avoiding low-level programming. In general, application scripting facilities are one thing that Unix hasn't dealt with well. Windows and OS X both do better (but neither do as well later versions of AmigaDOS). Whereas those systems come with a (or a selection) mechanism that applications can use to allow macro programming, Unix doesn't, so each application is left up to it's own devices. The most popular solution is to embed a custom language for scripting - which is where something like Python comes in. Some of them now export APIs that can be hooked up to a variety of languages. IIRC, Gnome has embraced CORBA as an interface for such, but it didn't seem well supported the last time I looked. The bottom line is that when it comes to scripting applications on Unix, your solution is going to be tailored to the application. The Unix variant with the best system-provided scripting facility is probably Plan 9. Some Linux variants are moving in that direction, but I don't know of any Linux applications that provide support for it. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From louis_pastorik at symantec.com Wed Oct 26 13:32:33 2005 From: louis_pastorik at symantec.com (louis_pastorik at symantec.com) Date: 26 Oct 2005 10:32:33 -0700 Subject: 64 bit python binaries (or builds) for Xeon and Opteron architectures on Windows platforms Message-ID: <1130347953.003322.288350@o13g2000cwo.googlegroups.com> Does anyone have any information about 64 bit python support for Xeon and Opteron architectures on Windows platforms? If anyone has built the python runtime on either of these platforms before I would be really interested. Thanks. From robert.kern at gmail.com Tue Oct 11 14:09:25 2005 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 11 Oct 2005 11:09:25 -0700 Subject: Wrapper function In-Reply-To: <1129053625.591216.116340@z14g2000cwz.googlegroups.com> References: <1129052312.444144.142950@g44g2000cwa.googlegroups.com> <3r2c91FhamghU1@uni-berlin.de> <1129053625.591216.116340@z14g2000cwz.googlegroups.com> Message-ID: Java and Swing wrote: > When I compile, I get two warnings..which are ok. Then when I build my > DLL I get.. > > Linking... > Creating library Release/MyDLL.lib and object Release/MyDLL.exp > test.obj : error LNK2001: unresolved external symbol _PyBuildValue > Release/MyDLL.dll : fatal error LNK1120: 1 unresolved externals > Error executing link.exe. > > MyDLL.dll - 2 error(s), 0 warning(s) > > ..Any ideas? Are you using distutils to build your extension module? You should be. -- 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 bearophileHUGS at lycos.com Sun Oct 23 04:13:47 2005 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 23 Oct 2005 01:13:47 -0700 Subject: Syntax across languages In-Reply-To: References: <1130052687.396109.145420@o13g2000cwo.googlegroups.com> Message-ID: <1130055226.967456.266220@z14g2000cwz.googlegroups.com> Thank you for the comments, Fredrik Lundh. >(that's (mostly) CPython-dependent, and should be avoided)< Then a non CPython-dependent way of doing it can be even more useful. >sure looks like four possible outcomes.< Right (but to me four explicit answers seem better than three answers and an exception still). >id(a)< I think in Python it can be something more like (but it's of little use): def identity(x): return x Or: identity = lambda x: x >(cloning is usually a sign of a design problem in python. if you think you need it, you probably don't. if you really think you need it, import copy.)< I agree (importing a module is worse than using a standard copy method, but I think this can be seen as a way to discourage the use of copy in Python). >if you can define the semantics, it's a few lines of code. if you're not sure about the semantics, a built-in won't help you...< I think the language needs a fast built-in version of it. If something is both inside Mathematica and Ruby, then probably it can be useful in Python too :-) Bye and thank you, bearophile From deets at nospam.web.de Thu Oct 20 18:03:26 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 21 Oct 2005 00:03:26 +0200 Subject: Set operations for lists: pythonic hints please! In-Reply-To: <1129842342.308921.201270@f14g2000cwb.googlegroups.com> References: <1129842342.308921.201270@f14g2000cwb.googlegroups.com> Message-ID: <3rqiheFkv765U1@uni-berlin.de> jmdeschamps at gmail.com wrote: > Working with several thousand tagged items on a Tkinter Canvas, I want > to change different configurations of objects having a certain group of > tags. > > I've used the sets module, on the tuple returned by Tkinter.Canvas. > find_withtag() method. > > Since this method takes only one tag at time, I use it for each tag > that is part of the look-up group, create a set object for each tuple > and intersect the resulting sets, that I tuple out again to feed a loop > to change the configuration of the items. > > Anyone have a more pythonic way (or better performing ) way to suggest > ? It depends. If the search on tags is implemented linear, it might be better to loop over all items and filter suing a compound predicate, like this: rouge_artefacts = [item for m1.all_itmes() if item.has_tag("rouge") and item.has_tag("artefact")] Please note that I don't know TKinter's API, but I can't imagine that it lacks the possibility to fettch a list of all items and query an item for it tags. The synopsis may vary from above, thogh. But if tkinter stores the tagged items as mapping of tag -> set/list, then I think your approach is as fast as you can get. Time it out. And maybe another thing would be to manage that tagging relation yourself. Regards, Diez From antonyliu2002 at yahoo.com Mon Oct 24 00:37:17 2005 From: antonyliu2002 at yahoo.com (Anthony Liu) Date: Sun, 23 Oct 2005 21:37:17 -0700 (PDT) Subject: An interesting question about "print '\a'" Message-ID: <20051024043717.48540.qmail@web35805.mail.mud.yahoo.com> We know that if we do print '\a' the bell will sound. Now, why do I hear the sound on my local machine when I run a python script on a remote host? I understand if I hear it when I do print '\a' on my local machine. Does the command get sent back to the client machine? Thanks. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From jimmy at retzlaff.com Tue Oct 4 20:01:20 2005 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Tue, 4 Oct 2005 17:01:20 -0700 Subject: py2exe has a new maintainer Message-ID: I am taking over the maintenance and support of py2exe from Thomas Heller. As he announced a few weeks ago he is looking to focus on other things. py2exe has been very useful to me over the years and I look forward to keeping it every bit as useful in the future. I plan to make the transition as smooth as possible for users of py2exe. I don't plan to make changes to the license other than adding my name to the list of people not to sue. I will try to be as helpful as Thomas has been in supporting py2exe on the py2exe mailing list and comp.lang.python. The mailing list, the SourceForge project, and the Wiki will continue in their current locations. The web site is moving to http://www.py2exe.org and the old site will forward to the new one so any bookmarks should still work. I will be releasing version 0.6.3 very soon with a few changes Thomas and others have made over the last few weeks. After that my priorities for py2exe will be: - Support - Documentation (which should help familiarize me with the code) - Automated tests (to point out when I haven't familiarized myself enough) - Bug fixes Any help on any of these fronts will be greatly appreciated. After I feel comfortable with things, I hope to work with other projects in the Python packaging community (e.g., cx_Freeze, PyInstaller/McMillan, py2app, setuptools, etc.) to see if we can't find synergies that will make all of them better. I recognize that different packagers are better for different audiences because of licensing, platform, Python versions, and module support among other things. Working together on the common parts (identifying dependencies, customized handling of modules with unique needs, etc.) should make all of the packagers serve their niches better. I'd like to thank Thomas for the great work he's done with py2exe over the years. He's set a very high standard for me to try and maintain. Jimmy From john at castleamber.com Tue Oct 18 02:20:56 2005 From: john at castleamber.com (John Bokma) Date: 18 Oct 2005 06:20:56 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <%jV4f.3121$tV6.2659@newssvr27.news.prodigy.net> Message-ID: "Mike Schilling" wrote: > "John Bokma" wrote in message [ w3c "standard" v.s. ISO ] > You haven't said why you thinbk "standards" are more valuable than > "recommendations". We apparently both agree they're no more likely to be > observed, so what is the reason? That an HTML standard (ISO/IEC 15445:2000) and an HTML recommendation by w3c (4.01 for example) are two different things, and mixing them up by calling both standards is a bad thing. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From godoy at ieee.org Tue Oct 25 07:21:39 2005 From: godoy at ieee.org (Jorge Godoy) Date: Tue, 25 Oct 2005 09:21:39 -0200 Subject: more than 100 capturing groups in a regex References: <1130160675.270886.208420@z14g2000cwz.googlegroups.com> <1130225565.592108.197670@z14g2000cwz.googlegroups.com> <1130237717.557334.277910@g44g2000cwa.googlegroups.com> Message-ID: <87ll0hlu4c.fsf@ieee.org> "Joerg Schuster" writes: > No limitation at all would be best. If a limitation is necessary, then > the more capturing groups, the better. At the time being, I would be > really happy about having the possibility to use 10000 capturing > groups. I'm sorry, I missed the beginning of this thread and it has already expired on my news server, but what is the reason for so much capturing groups? I imagine that coding this and keeping code maintenable is a huge effort. Oh, and I came from Perl, where I used to think in regexps... In Python I almost never use them. -- Jorge Godoy From mde at micah.elliott.name Mon Oct 10 18:02:36 2005 From: mde at micah.elliott.name (Micah Elliott) Date: Mon, 10 Oct 2005 15:02:36 -0700 Subject: how to check if file is in use? In-Reply-To: <434ad15a$0$26210$9b4e6d93@newsread2.arcor-online.net> References: <434ad15a$0$26210$9b4e6d93@newsread2.arcor-online.net> Message-ID: <20051010220236.GA9066@kitchen.client.attbi.com> On Oct 10, Stefan Siegel wrote: > can anybody give me (a python newbie) give a hint how to check in > python wether a file is in use by another program? This was previously discussed on c.l.py. In short, "you can't". A detailed answer is in this thread: http://mail.python.org/pipermail/python-list/2003-May/165908.html -- Micah Elliott From fredrik at pythonware.com Sun Oct 9 15:12:33 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 9 Oct 2005 21:12:33 +0200 Subject: Python's Performance References: <20051008040614.47429.qmail@web30607.mail.mud.yahoo.com><43495259$0$29124$626a14ce@news.free.fr> <178B879D-FDB6-458C-BE00-A03820D98703@advfn.com> Message-ID: Alex Stapleton wrote > Except it is interpreted. except that it isn't. Python source code is compiled to byte code, which is then executed by a virtual machine. if the byte code for a module is up to date, the Python runtime doesn't even look at the source code. > What is your point? that some people have trouble distinguishing interpreters from compilers, and find mixed paradigms confusing? From fredrik at pythonware.com Thu Oct 13 11:28:39 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 13 Oct 2005 17:28:39 +0200 Subject: cgi python References: <1129215225.778017.20340@g47g2000cwa.googlegroups.com> <1129216439.418378.308760@z14g2000cwz.googlegroups.com> Message-ID: Paul Boddie wrote: > Testing Web applications can be hard, but the traceback tells you > everything you need to know here. especially if you make sure to use the cgitb module: http://docs.python.org/lib/module-cgitb.html while developing/debugging. From maketo at norge.freeshell.org Sun Oct 16 16:52:10 2005 From: maketo at norge.freeshell.org (Ognen Duzlevski) Date: Sun, 16 Oct 2005 20:52:10 +0000 (UTC) Subject: Comparing lists - somewhat OT, but still ... References: <1129216693.445956.155490@g47g2000cwa.googlegroups.com> Message-ID: Steven D'Aprano wrote: > On Sun, 16 Oct 2005 15:16:39 +0200, Christian Stapfer wrote: > > It turned out that the VAX compiler had been > > clever enough to hoist his simple-minded test > > code out of the driving loop. > Optimizations have a tendency to make a complete mess of Big O > calculations, usually for the better. How does this support your > theory that Big O is a reliable predictor of program speed? There are many things that you cannot predict, however if the compiler was sufficiently documented and you had the knowledge of the abovementioned peculiarity/optimization, you could take it into account. Bear in mind that the example was given to show a problem with a purely experimental approach - it tends to show a tree and ignore the forest. Sometimes this tree can be respresentative of a forest but many times it might not be. The way I understood these notations was in terms of algorithmic behavior and data input sizes. It is generally expected that certain basic operations will have a certain complexity. If this is not the case on a particular platform (language, interpreter, cpu etc.) then there are several questions to ask: a) is such a deviation documented?, b) why is there such a deviation in the first place? For example, if something is generally known to be O(1) and your particular platform makes it O(n) then you have to ask why that is so. There might be a perfectly good reason but this should still either be obvious or documented. IMHO, I would rather first explore the theoretical boundaries to a certain approach before wasting time on coding up stuff. If it is immediately obvious that such an approach will not yield anything acceptable for my own purposes then what is the point of squeezing performance out of what will be dead-beat code anyways? Knowing the tool/language/os in depth is a formidable strength and it is always a pleasure to see someone squeeze time out of a piece of code solely based on knowing the internals of the compiler and/or runtime environment. However, it is most usually the case that this person will be squeezing time out of a certain order of performance - no amount of this kind of optimization will move the code to the next order. Ognen From a_mccarthy at hotmail.com Fri Oct 28 09:59:40 2005 From: a_mccarthy at hotmail.com (Andrew McCarthy) Date: 28 Oct 2005 13:59:40 GMT Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> Message-ID: On 2005-10-28, pinkfloydhomer at gmail.com wrote: > I'm now down to: > > f = open("filename", "rb") > s = f.read() > sub = "\x00\x00\x01\x00" > count = s.count(sub) > print count > > Which is quite fast. The only problems is that the file might be huge. > I really have no need for reading the entire file into a string as I am > doing here. All I want is to count occurences this substring. Can I > somehow count occurences in a file without reading it into a string > first? Yes - use memory mapping (the mmap module). An mmap object is like a cross between a file and a string, but the data is only read into RAM when, and for as long as, necessary. An mmap object doesn't have a count() method, but you can just use find() in a while loop instead. Andrew From steve at REMOVETHIScyber.com.au Tue Oct 25 12:12:34 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Wed, 26 Oct 2005 02:12:34 +1000 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: On Tue, 25 Oct 2005 11:00:58 -0500, joe wrote: > In other words, I was recognizing that a lot of > people don't think what MS does is a crime, and until MS gets > convicted of a crime, it's a matter of opinion. I was trying to say > something else. And again, they HAVE been convicted of crimes, plural, and not just in one court, but in multiple, in the US, Japan, Europe, and in civil suits in front of juries. Apologists for Microsoft like David Schwartz seem to be taking a three-prong argument: "They haven't done the things you say, and even if they have, they aren't illegal, and even if they are illegal, they shouldn't be." The first two points are factually wrong, and the third is an opinion based on the concept, as far as I can see, that Microsoft should be allowed to do anything they like, even if those actions harm others. -- Steven. From martin.witte at gmail.com Wed Oct 19 14:56:23 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 19 Oct 2005 11:56:23 -0700 Subject: Controlling exception handling of logging module In-Reply-To: <1129746812.846802.216550@g14g2000cwa.googlegroups.com> References: <1129746812.846802.216550@g14g2000cwa.googlegroups.com> Message-ID: <1129748183.204853.75350@g47g2000cwa.googlegroups.com> make the second statement 'logging.info("%d %d", 1, 2)' or 'logging.info("%d %d %d", 1, 2, 3)', and all works. for every argument you want to log you need one format specifier From ptb at oboe.it.uc3m.es Sat Oct 15 14:02:16 2005 From: ptb at oboe.it.uc3m.es (Peter T. Breuer) Date: Sat, 15 Oct 2005 20:02:16 +0200 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <11l29j29rq4jh18@corp.supernews.com> Message-ID: <8qs723-dr7.ln1@news.it.uc3m.es> In comp.os.linux.misc John Wingate wrote: > Peter T. Breuer wrote: >> In comp.os.linux.misc Jeroen Wenting wrote: >>> Without Microsoft 90% of us would never have seen a computer more powerful >>> than a ZX-81 and 90% of the rest of us would never have used only dumb >>> mainframe terminals. >> >> Uh - when microsoft produced dos 1.0, or whatever it was, I was sitting >> at my Sun 360 workstation (with 4M of RAM, later upgraded to 8M), >> running SunOS 3.8 or thereabouts. > Peter, if you are serious, and not just pulling our legs, your memory is > failing. Well, it might be a bit off. I am talking about 1986. > MS-DOS 1.0 came out in August 1981; SunOS 3.0 in February 1986. Seems about right. So what version of msdos was around at that time? Obviously I didn't use it! > Sun Microsystems was incorporated (with four employees) in February 1982. > There never was a SunOS 3.8. (SunOS 3.5 was succeeded by 4.0.) And I'm It seems to me that I was using 3.x. Maybe it was 3.1? I seem to remember an earlier major ... was there a 2.8 or 2.9? > not sure what you mean by "Sun 360"--a Sun 3/60, maybe? Seems likely. I recall it as a Sun 360m. "Monica" by name, following the cpu serial number, mncaxxx (or something close). "Sun 3" definitely rings a bell. Peter From netvaibhav at gmail.com Sat Oct 29 22:02:16 2005 From: netvaibhav at gmail.com (netvaibhav at gmail.com) Date: 29 Oct 2005 19:02:16 -0700 Subject: Scanning a file In-Reply-To: References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <1130614532.765771.288960@g43g2000cwa.googlegroups.com> Message-ID: <1130637600.659212.66140@g43g2000cwa.googlegroups.com> Steve Holden wrote: > Indeed, but reading one byte at a time is about the slowest way to > process a file, in Python or any other language, because it fails to > amortize the overhead cost of function calls over many characters. > > Buffering wasn't invented because early programmers had nothing better > to occupy their minds, remember :-) Buffer, and then read one byte at a time from the buffer. Vaibhav From jepler at unpythonic.net Sat Oct 1 18:09:48 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Sat, 1 Oct 2005 17:09:48 -0500 Subject: Printing and prompting adds a mysterious extra space In-Reply-To: <20051001214428.GA22491@torf.workaround.org> References: <1128197861.418869.221640@g43g2000cwa.googlegroups.com> <20051001214428.GA22491@torf.workaround.org> Message-ID: <20051001220948.GA3403@unpythonic.net> Use sys.stdout.write instead of print. It will solve these problems you are having. If you really want to know what's going on, read the language manual, http://docs.python.org/ref/print.html It explains the behavior of this extra space, which is output by a successive 'print' statement. The implementation uses an attribute called 'softspace', which is described in http://docs.python.org/lib/bltin-file-objects.html Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From grunar at gmail.com Thu Oct 20 19:04:01 2005 From: grunar at gmail.com (grunar at gmail.com) Date: 20 Oct 2005 16:04:01 -0700 Subject: sqlstring -- a library to build a SELECT statement In-Reply-To: References: <1129774730.887128.314960@z14g2000cwz.googlegroups.com> <1129784130.596225.174860@z14g2000cwz.googlegroups.com> <1129823975.023490.287440@g43g2000cwa.googlegroups.com> Message-ID: <1129849441.603557.160990@g47g2000cwa.googlegroups.com> Tom Anderson wrote: > On Thu, 20 Oct 2005, grunar at gmail.com wrote: > > > On this line of thought, what about the += operator? That might be more > > intuative than //. I could even use -= for not in. > > You're going to have to explain to me how using an assignment operator for > something other than assignment is intuitive! > > -1 on this one from me, i'm afraid. Point. I do think it looks strange, because we're used to seeing += in code. But the concept is more along the lines of the == and != comparison operators. Python does expose other nice things, such as &= and %=, which (since people aren't used to seeing them used much), might be better candidates. Does %= seem more agreeable? (I'm already using % for a like statement). So, a statement could look like this: person ** ( (person.type_id == 'customer') & (person.id %= phone(phone.person_id))) ) becomes: select * from person where person.type_id = 'customer' and person.id in (select person_id from phone) > Using 'in' would be good. It does require some truly puke-inducing > contortions, though; since 'in' calls __contains__ on the right-hand > operand, and that's likely to be a list, or some other type that's not > under your control, you have to cross your fingers and hope that whatever > it is implements __contains__ with equality tests with the probe object on > the left-hand side and the candidates on the right (as lists do, at least > in 2.4.1). then, you just have to make your table names do the right thing > when compared to strings. > __contains__, while allowing side-effects on the object in question (even if though it's on the right), only returns true/false (not a custom object) afaik, so it breaks in a complex expression -- (a == b) & (c in d), won't work. You could modify D, but you can't pass that value to the whole Condition Expression. From bearophileHUGS at lycos.com Sat Oct 1 14:59:35 2005 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 1 Oct 2005 11:59:35 -0700 Subject: Nufox : Xul + Python In-Reply-To: References: <1128163366.631178.74800@o13g2000cwo.googlegroups.com> <1128182754.232912.9980@z14g2000cwz.googlegroups.com> Message-ID: <1128193175.298947.78350@g47g2000cwa.googlegroups.com> Nufox seems a really interesting thing (probably it can even be used to design GUIs for local desktop apps), but the site seems down at the moment. Bye, bearophile From theller at python.net Wed Oct 26 04:46:07 2005 From: theller at python.net (Thomas Heller) Date: Wed, 26 Oct 2005 10:46:07 +0200 Subject: p2exe using wine/cxoffice References: <200509151243.53106.jstroud@mbi.ucla.edu> Message-ID: Jon Perez writes: > James Stroud wrote: > >> "better". The only reason I want this functionality is to make my software >> available to windoze users--despite their unfortunate ignorance, they are >> people too. That's what I always say. > > Actually, I think it's many unix/linux users who are ignorant of just > how nice, stable and productive Windows can be as a desktop environment. > > ... and I really mean that. ;-). I was waiting for someone to say that. +1. Thomas From enleverlesO.OmcO at OmclaveauO.com Mon Oct 3 02:06:05 2005 From: enleverlesO.OmcO at OmclaveauO.com (Do Re Mi chel La Si Do) Date: Mon, 3 Oct 2005 08:06:05 +0200 Subject: Parrot & Python ? References: <4340393e$0$16536$626a14ce@news.free.fr> Message-ID: <4340cdfc$0$4298$626a14ce@news.free.fr> Hi ! Thank for links. @-salutations Michel Claveau From jon_usenet at capisco.com Fri Oct 14 12:11:51 2005 From: jon_usenet at capisco.com (jon) Date: 14 Oct 2005 09:11:51 -0700 Subject: array subset could be improved? -repost ;) In-Reply-To: References: Message-ID: <1129306311.917537.184890@f14g2000cwb.googlegroups.com> Jim O'D wrote: > Hi all > > I have an array a=array([2,3,-1]). > > I want to extract an array with all the elements of a that are less than 0. > > Method 1. > new = array([i for i in a if i < 0]) > > Method 2. > new = a[nonzero(a<0)] > > I'm using Numeric arrays but can't seem to find a function that does this. > > Am I missing a more obvious way to do it quickly? > > Thanks > > Jim a2=Numeric.compress(a<0,a) From bearophileHUGS at lycos.com Sun Oct 23 05:57:01 2005 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 23 Oct 2005 02:57:01 -0700 Subject: Syntax across languages In-Reply-To: References: <1130052687.396109.145420@o13g2000cwo.googlegroups.com> <1130055226.967456.266220@z14g2000cwz.googlegroups.com> Message-ID: <1130061421.835890.156890@g44g2000cwa.googlegroups.com> Thank you Fredrik Lundh for showing everybody that indeed lot of people feel the need of such function in Python too. >to create a generic version, you have to decide which sequences to treat like sequences< In my version I give the function some parameter(s) to define what I want to flatten. I'll probably put it in the cookbook... Bye, Bearophile From fredrik at pythonware.com Mon Oct 10 12:31:23 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 10 Oct 2005 18:31:23 +0200 Subject: Changing an AST References: <1128941690.030540.258790@g43g2000cwa.googlegroups.com> <1128944299.588849.167030@g43g2000cwa.googlegroups.com> Message-ID: "beza1e1" wrote: > Thank you! this "compile/exec in context" is the thing i wanted. > > It is not that performant i think. it's about as fast as it can get, as long as you only call compile when the expressions change. (the example didn't show it, but the "expr" code object can of course be reused with different contexts) From apardon at forel.vub.ac.be Wed Oct 26 04:37:42 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 26 Oct 2005 08:37:42 GMT Subject: Would there be support for a more general cmp/__cmp__ References: Message-ID: Op 2005-10-25, Steven D'Aprano schreef : > On Tue, 25 Oct 2005 10:09:29 -0400, Christopher Subich wrote: > >>>>By analogy, one can ask, "is the cat inside the box?" and get the answer >>>>"No", but this does not imply that therefore the box must be inside the >>>>cat. >>> >>> >>> Bad analogy, this doesn't define a mathematical ordering, the subset >>> relationship does. >> >> Yes, it does. Consider "in" as a mathematical operator: >> >> For the set (box, cat-in-box) >> >> box in box: False >> box in cat-in-box: False >> cat-in-box in box: True >> cat-in-box in cat-in-box: False >> >> For the set (box, smart-cat) # cat's too smart to get in the box >> >> box in box: False >> box in smart-cat: False >> smart-cat in box: False >> smart-cat in smart-cat: False >> >> In both these cases, the "in" operator is irreflexive, asymmetric, and >> transitive (extend to mouse-in-cat if you really care about transitive), >> so "in" is a partial order sans equality. A useless one, but a partial >> order nonetheless. > > What do you mean "in" is a useless ordering? It makes a huge difference > whether "nuclear bomb in New York" is true or not. > > In fact, I'm quite surprised that Antoon should object to "in" as "this > doesn't define a mathematical ordering, the subset relationship does" when > "subset" is just "in" for sets: set S is a subset of set T if for all > elements x in S, x is also in T. Informally, subset S is in set T. I was misunderstaning where Christopher was heading to. > Can somebody remind me, what is the problem Antoon is trying to solve here? Well there are two issues. One about correct behaviour and one about practicallity. The first problem is cmp. This is what the documentation states: cmp(x, y) Compare the two objects x and y and return an integer according to the outcome. The return value is negative if x < y, zero if x == y and strictly positive if x > y. The problem is, that if someone implements a partial ordered class, with the rich comparisons, cmp doesn't behave correct. It can't behave correct because it will always give an number as a result and such a number implies one of three relations between two elements, but with partial ordered classes, it is possible none of these relations exist between those two elements. So IMO cmp should be changed to reflect this. This can be done either by cmp returning None or UnequalValues. or by cmp raising UnequalValues in such a case. The second part is one of practicallity. Once you have accepted cmp, should reflect this possibility, it makes sense that the __cmp__ method should get the same possibilities, so that where it is more pratical to do so, the programmer can implement his partial order through one __cmp__ method instead of having to write six. In my opinion such a change would break no existing code. This is because there are two possibilities. 1) The user is using cmp on objects that form a total order. In such circumstances the behaviour of cmp doesn't change. 2) The user is using cmp on objects that don't form a total order. In such circumstances cmp doesn't give consistent results, so the code is already broken. -- Antoon Pardon From jstroud at mbi.ucla.edu Wed Oct 26 15:19:17 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 26 Oct 2005 12:19:17 -0700 Subject: Windows vs Linux [was: p2exe using wine/cxoffice] In-Reply-To: <9A28C052FF32734DACB0A288A3533991044D22A6@vogbs009.gb.vo.local> References: <9A28C052FF32734DACB0A288A3533991044D22A6@vogbs009.gb.vo.local> Message-ID: <200510261219.17059.jstroud@mbi.ucla.edu> On Wednesday 26 October 2005 07:20, Tim Golden wrote: > I'm sure you're right: given moderately naive users, a Windows box > is *extremely* likely to be zombified. It's just that it doesn't > have to be that way with the proper care and attention. With $200 dollars of antivirus software (on top of the $200 OS), incessant reminding of users to not open email attachments or install "free" screensavers and such, disabling vbasic on every program, daily iterations through the windoze updating cycle, and putting the machine behind a Linux firewall, your windows machine probably wont get zombified. Or you could just do the reasonable thing and erase the hard drive and install Linux. -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From fredrik at pythonware.com Wed Oct 5 09:16:50 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 5 Oct 2005 15:16:50 +0200 Subject: Help with chaos math extensions. References: <43433982.8080008@yahoo.com> <4343C318.3090902@yahoo.com> Message-ID: Brandon K" wrote: > Here's the Script it was being used in (forgive it if it seems a bit > messy, i have been tinkering with variables and such to try different > ideas and haven't really cleaned it up). the C compiler does in fact provide you with some clues: c:\test\c_lib.cpp(22) : warning C4700: local variable 'c' used without having been initialized here's the culprit: Py_complex *c; Complex* cplx; if(!PyArg_ParseTuple(args,"D",c)) return NULL; PyArg_ParseTuple expects a pointer to a Py_complex object, but you're passing in an initialized pointer. this works better: Py_complex c; Complex* cplx; if(!PyArg_ParseTuple(args,"D",&c)) return NULL; cplx = new Complex(&c); return Py_BuildValue("D",cplx->toOld()); here's the next warning: c:\test\complex.cpp(50) : warning C4700: local variable 'c' used without having been initialized this is your toOld function, which has a similar problem: Py_complex* Complex::toOld(void) { Py_complex* c; c->real = this->real; c->imag = this->imag; return c; } since c isn't initialized, you'll overwrite some random memory locations when you assign things to it. here's a brute-force hack: Py_complex* Complex::toOld(void) { static Py_complex c; c.real = this->real; c.imag = this->imag; return &c; } here's a better fix: Py_complex Complex::toOld(void) { Py_complex c; c.real = this->real; c.imag = this->imag; return c; } which requires you to change return Py_BuildValue("D",cplx->toOld()); to return Py_BuildValue("D",&cplx->toOld()); I only got this far before I ran out of time; there might be more bugs in there. From darkpaladin79 at hotmail.com Fri Oct 7 22:21:38 2005 From: darkpaladin79 at hotmail.com (Ivan Shevanski) Date: Fri, 07 Oct 2005 22:21:38 -0400 Subject: noob question Letters in words? In-Reply-To: Message-ID: Yes, I realize that. . .Heres another question then. I was trying somehting before so that if the user just pressed enter by accident, it would not accept the input and ask them to put in another. But the thing is I couldnt get it to work. I tryed if choice1 == None it would loop and ask for a new input but that didnt seem to work. . .Any ideas for that? Thanks, Ivan _________________________________________________________________ Don?t just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/ From eric.pederson at gmail.com Mon Oct 10 01:06:32 2005 From: eric.pederson at gmail.com (eric.pederson at gmail.com) Date: 9 Oct 2005 22:06:32 -0700 Subject: The missing ingredient? Message-ID: <1128920791.974347.313090@o13g2000cwo.googlegroups.com> Python is a great programming language, and it seems there was a sense of fun in developing it -- as far as I can ascertain, it wasn't exactly brought to life to comply with Government tax regulations; or to assist a consigliere with covering up ghastly mob crimes ala "Godfather". Though there is some guy named Guido involved... [and not neccesarily Father Guido Sarducci...] Is Python still as fun to develop (develop, not develop in)? Can the pioneers weigh in on this? "Fun" is held by many to be the (or one of the) most creative, inventive, and productive frames of mind. For example I suspect, despite all the varied things they may be exposed to, very few patents are filed by IRS agents; unless, perhaps, they get ideas while unwinding late at night watching Monty Python reruns (which activity may be career limiting in Government service!) Is developing the next iteration/step-forward in Python still as fun as the old days? Is it fun? What can we do to keep Python (development of and development in) as fun as possible? [this post triggered by reading this article on "-Ofun" here: http://www.oreillynet.com/pub/wlg/7996] EP From lsumnler at uniqueinsuranceco.com Thu Oct 6 20:25:43 2005 From: lsumnler at uniqueinsuranceco.com (LenS) Date: 6 Oct 2005 17:25:43 -0700 Subject: Newbie using python to update sql table Message-ID: <1128644743.257310.117320@f14g2000cwb.googlegroups.com> I have created a python program that takes a flat file and changes some of the data and create a new flat file with the changes. Part of this process requires that I try to find a particular model car in an MS Sql table. This part of the program is now working great. It has come to my attention that some of the information in the flat file could be used to update our information in the MS Sql table that I currently run the query on. Basicly I create a recordset of vehicles from the MS Sql table based on vehicle year and make and once I have this recordset I run it through logic which does a reqular expression compare on the vehicle VIN no to the VIN number in the table to get a match. I would like to update this record in the table with info. in the flat file. I believe there should be some way to update the fields in this record of the recordset and then update the table. I am not an sql expert and would appreciate someone pointing me in the right direction. Contained below is a listing of my code; # The following code creates a connection object, # assigns the connection string, opens the # connection object, and then verifies a good # connection. oConn = Dispatch('ADODB.Connection') oConn.ConnectionString = "Provider=SQLOLEDB.1;" +\ "Data Source=uicesv05;" +\ "uid=aiis;" +\ "pwd=aiis;" +\ "database=auto_mo_001" oConn.Open() if oConn.State == adStateOpen: print "Database connection SUCCEEDED" else: print "Database connection FAILED" # The following code creates a command object, # assigns the command to the connection object, # sets the query, creates the parameters objects to # be passed to the command object and requests the # query to be prepared (compiled by the SQL system). oCmd = Dispatch('ADODB.Command') oCmd.ActiveConnection = oConn oCmd.CommandType = adCmdText oCmd.CommandText = """\ SELECT VA_MK_YEAR,VA_MK_DESCRIP,VO_VIN_NO,VO_MODEL,VO_BODY, VO_DESCRIPTION,VO_MODEL_ID FROM D014800 INNER JOIN D014900 ON VA_MK_NUMBER_VER = VO_MAKE_NO AND VA_MK_YEAR = VO_YEAR WHERE VA_MK_YEAR = ? AND VA_MK_DESCRIP = ? """ vyear = '' vmake = '' oParmYear = oCmd.CreateParameter(vyear,adChar,adParamInput) oParmYear.Size = 4 oParmMake = oCmd.CreateParameter(vmake,adChar,adParamInput) oParmMake.Size = 10 oCmd.Parameters.Append(oParmYear) oCmd.Parameters.Append(oParmMake) oCmd.Prepared = True ... def wrkveh(ifile,strstart,maxcnt): """ wrkveh function does an SQL record lookup to try an select the correct vehicle in the V1sta make and model files. If the correct model is found I move V1sta's make model and body descriptions to the flat file. Currently, I hard code a 1 for vehicle use. The drive segment is an occurs 6""" cnt = 0 vehwrk = '' while cnt < maxcnt: if ifile[strstart:strstart + 10] == ' ': vehwrk = vehwrk + ifile[strstart:strstart + 133] else: vmake = ifile[strstart:strstart + 10] vyear = ifile[strstart + 98:strstart + 102] vvin4_8 = ifile[strstart +53:strstart + 58] vmodel = '' vbody = '' oParmYear.Value = vyear oParmMake.Value = vmake (oRS, result) = oCmd.Execute() while not oRS.EOF: wvin = oRS.Fields.Item("VO_VIN_NO").Value.replace('*','.') wvin.replace('*','.') wvin = wvin[0:5] r1 = re.compile(wvin) if r1.match(vvin4_8): vmake = oRS.Fields.Item("VA_MK_DESCRIP").Value vmodel = oRS.Fields.Item("VO_MODEL").Value vbody = oRS.Fields.Item("VO_DESCRIPTION").Value vmodelid = oRS.Fields.Item("VO_MODEL_ID").Value print 'DRC model ' + vmake + ' ' + vyear + ' ' + vmodel + \ ' ' + vmodelid break else: oRS.MoveNext() else: print 'DRC model NOT FOUND' vehwrk = vehwrk + vmake + vmodel + vbody vehwrk = vehwrk + ifile[strstart + 50:strstart + 107] vehwrk = vehwrk + '1' vehwrk = vehwrk + ifile[strstart + 108:strstart + 133] strstart += 133 cnt += 1 return vehwrk From mwm at mired.org Tue Oct 25 16:13:43 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 25 Oct 2005 16:13:43 -0400 Subject: Read/Write from/to a process References: <1130163642.868252.148070@g44g2000cwa.googlegroups.com> <1130174259.472124.114790@f14g2000cwb.googlegroups.com> <1130242940.918480.65020@f14g2000cwb.googlegroups.com> <1130245185.304132.110840@g43g2000cwa.googlegroups.com> <1130254148.192702@yasure> Message-ID: <864q754ao8.fsf@bhuda.mired.org> Dennis Lee Bieber writes: > Followed by the Amiga... The Amiga IPC used "message ports" (linked > lists owned by the creating process to which, if "public" [named], other > processes could send message packets). The Amiga port of REXX made use > of message ports as its native IPC... > > address SOME_APPLICATION > > would redirect all "non-REXX" statements to the message port named > "SOME_APPLICATION"; the default being "address COMMAND" -- a shell > interpreter. Then, any non-REXX statement would be processed by the > shell interpreter -- and the easiest way to force a non-REXX statement > was to put a quote mark around it (or the first word of it) > > "delete" my_file_var > > would translate my_file_var to whatever had been assigned to it earlier, > and pass a delete command to the shell. > > address ED > > would now route such statements to the "ed" editor These things weren't unique to the Amiga port of Rexx. Rexx on VM/CMS did all these things. Tying them to the native IPC mechanism as a brilliant move. Add in the shared library for supporting Rexx so that adding Rexx support to an application (or to a language!) was trivial, and Rexx the end result was that Rexx was used far more heavily on the Amiga than on VM/CMS. The downside was that variables had a default value of their name in upper case, and any statement that wasn't recognized evaluated as a string expresion and then fed to the current command processor. So that the quote marks weren't needed - if you hadn't assigned a value to the variable delete, then you could just do delete my_file_var and it would do the right thing. Of course, almost anything you typed like that was valid, creating interesting bugs. I made it a habit to keep "0" and "1" commands around that just logged errors, as those would catch such things. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From aleaxit at yahoo.com Fri Oct 21 21:21:46 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 21 Oct 2005 18:21:46 -0700 Subject: sort problem References: <4357c22d$0$8481$5fc30a8@news.tiscali.it> <1129825485.883210.297890@f14g2000cwb.googlegroups.com> <4357c9a4$0$8498$5fc30a8@news.tiscali.it> Message-ID: <1h4qxx1.flepxy1fwdhunN%aleaxit@yahoo.com> Michele Petrazzo wrote: > Lasse V?gs?ther Karlsen wrote: > > How about: > > > > list.sort(key=lambda x: x[3]) > > > > Does that work? > > Yes, on my linux-test-box it work, but I my developer pc I don't have > the 2.4 yet. I think that this is a good reason for update :) Updating is a good idea, and will let you get even faster by avoiding the lambda: import operator thelist.sort(key=operator.itemgetter(3)) However, until you can upgrade you might be happy enough with a direct implementation of the decorate-sort-undecorate (DSU) idiom which they new "key=" named argument to sort implements. To wit: aux = [ (x[3], x) for x in thelist ] aux.sort() thelist[:] = [ x[-1] for x in aux ] Note that the "decoration" can include as many "columns" as you want, transformations obtained by calling int(...) or str(...) on some of the columns, and so on. This applies to "key=" in 2.4 just as well as to the (slightly slower) direct implementation in 2.3 and earlier. Alex From my_email_is_posted_on_my_website at munged.invalid Wed Oct 19 04:42:03 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 19 Oct 2005 08:42:03 GMT Subject: Microsoft Hatred FAQ References: <867jcbzdw9.fsf@bhuda.mired.org> <4vcbl1dkek9kr86embmgrj70vk945t99ho@4ax.com> <35jbl1dprs4v1o87i0tapc2husjqiqm6fi@4ax.com> Message-ID: <8l1cl1plroff0mt8asqk1j8pocaf7kormo@4ax.com> On Tue, 18 Oct 2005 23:16:32 -0700, "David Schwartz" wrote or quoted : > No, I did not. I said that their obligation is to their shareholders. > >> If that is not what you mean, I think you need to hedge more. > > I was perfectly clear. This is a lot of deliberate misunderstanding >going on in this thread and very little of it is from my side. > You have a problem because there are many other people saying similar things to you who mean something much more extreme. If you don't intend that, you need to be more precise in your language. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From peter at engcorp.com Wed Oct 26 19:20:44 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 26 Oct 2005 19:20:44 -0400 Subject: Missing modules '_ssl', 'ext.IsDOMString', 'ext.SplitQName' In-Reply-To: <1130311678.936969.302020@g43g2000cwa.googlegroups.com> References: <1130003715.743391.237890@f14g2000cwb.googlegroups.com> <1130230864.068474.118500@g43g2000cwa.googlegroups.com> <1130311678.936969.302020@g43g2000cwa.googlegroups.com> Message-ID: uid09012_ti at collinsrealtime.com wrote: > Hi, > > yes of course the traceback could be helpfull so here it is... > > Traceback (most recent call last): > File "App1.py", line 6, in ? > File "Frame1.pyc", line 16, in ? > File "brain.pyc", line 4, in ? > File "xml\dom\ext\reader\__init__.pyc", line 20, in ? > LookupError: unknown encoding: utf-8 Which version of py2exe are you using? Does this page help? http://starship.python.net/crew/theller/moin.cgi/EncodingsAgain -Peter From mwm at mired.org Sat Oct 1 11:59:16 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 01 Oct 2005 11:59:16 -0400 Subject: Will python never intend to support private, protected and public? References: <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xll1gvk7w.fsf@ruckus.brouhaha.com> <1128001308.905398.321670@g44g2000cwa.googlegroups.com> <311b5ce105092908332c12164c@mail.gmail.com> <7xbr2btv84.fsf@ruckus.brouhaha.com> <7xy85fvxny.fsf@ruckus.brouhaha.com> <86vf0inlt3.fsf@bhuda.mired.org> <7xd5mq9ir9.fsf@ruckus.brouhaha.com> <86wtkym33t.fsf@bhuda.mired.org> <7xll1d7l2c.fsf@ruckus.brouhaha.com> Message-ID: <86slvlmdnv.fsf@bhuda.mired.org> Paul Rubin writes: > Mike Meyer writes: >> Unless your compiler detects and flags passing private variables to >> external functions all you've got is a convention that you don't pass >> private variables to external functions. > Yes, the point is that it's something that you can check for by > examining the class in question without having to examine any other > classes. That's a pretty restrictive convention to follow. For instance, I might want an error dialog to be a private variable of a class representing a window - after all, I don't want anyone else writing to it, or using it in any way. Except, of course, for any GUI framework routines I have to pass it to in order to use it. This problem crops up for every utility routine in every library I might want to use. Opening files by name, concatenatting strings (or are we going to have a convention that implicit invocation of functions with the operator syntax don't count, and another one that you don't overload operators with destructive functions, and so on), etc. So it turns out that getting the behavior you desire involves following a lot of conventions. >> I you going to try and tell me thas using builtin functions on >> private variables is something you don't allow in your projects? > > You have to treat builtin functions as part of the language. Of > course Python has this situation where someone could rebind the name > "len" to some other function, so you have to deal with that too, maybe > just at the file scope. File scope isn't good enough for python. import madhouse madhouse.len = my_len_breaker fool = madhouse.Fool() print fool.break() and fool._foo is broken again. > An OOP approach (lst.len() instead of len(lst)) that binds the > builtin names to datatypes might be preferable in some situations > but I'll leave that one for the theorists. In other words, to get this to work the way you want, you need yet another convention - this one being about how one goes about writing utility functions. It may be that you can design a language and support libraries so that the compiler can enforce all your conventions. There are languages that try to do that. I recall one I ran into in the 70s that distinguished between "functions" (which returned values) and "procedures" (which had side effects), and the compiler enforced (or tried to) the distinction. I think you'd need something like that. But that isn't what we've got. What we've got is Python. Which means you need a whole boatload of conventions to make this work the way you want. In other words, by adding private to python, you're making it so that bugs involving overwriting a private attribute will involve only the owning classes code so long as everyone follows the conventions that exist about the use of such variables. This should be contrasted with the current situation, where bugs that involve overwriting an _-prefixed attribute will involve only the owning classes code so long as everyone follows the conventions that exist about the use of such variables. Yeah, I guess private makes things a lot better. >> Of course, there's nothing wrong with catching errors earlier. Might I >> suggest that you file a change request for pylint (or your favorite >> error checker) asking that it start issuing warnings for >> object._variable? > > I don't see how pylint could know which instances to flag, without > doing type inference on all the objects to know that the variable > belonged to an instance of some other class. I was thinking it would flag any use of such a variable where the target variable wasn't "self". That may be a stronger constraint than you wanted - but that's good, right? http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From robert.kern at gmail.com Fri Oct 7 09:05:34 2005 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 07 Oct 2005 06:05:34 -0700 Subject: Continuous system simulation in Python In-Reply-To: <20051007124153.GA8760@phenix.progiciels-bpi.ca> References: <20051007011222.1aeab426@linuxcestcomplique.fr> <20051007124153.GA8760@phenix.progiciels-bpi.ca> Message-ID: Fran?ois Pinard wrote: > [Robert Kern] > >>[...] an ODE integrator would probably want to adaptively select its >>timesteps as opposed to laying out a uniform discretization upfront. > > Eons ago, I gave myself such a little beast (but really found in an > Appendix of a book on simulation), which I use since then whenever I > need it, not so often in these days. If you are curious, see: > > http://fp-etc.progiciels-bpi.ca/rke.html > > yet I'm sure there is just plenty of such things, all around. > > The above is in C, not in Python. I vaguely remember having once > rewritten the thing in Python, then discarded the result as not fast > enough for the need I then had. If I really needed to use it nowadays, > I'll probably try to quickly link it through Pyrex. Or just look around > a bit for some already made, and maybe better solution. :-) scipy has wrapped LSODA and VODE from ODEPACK. There are a few more integrators in ODEPACK which could easily be wrapped with f2py should someone feel the urge. We'd probably wrap yours, too, if it weren't GPLed. ;-) -- 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 Wed Oct 12 02:54:33 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 12 Oct 2005 08:54:33 +0200 Subject: piping out binaries properly References: Message-ID: Andy Leszczynski wrote: > when I run under Unix I got: > > $ python u.py > u.bin > $ od -t x1 u.bin > 0000000 41 41 0a 41 41 > > and under Windows/Cygwin following: > > $ python u.py > u.bin > $ od -t x1 u.bin > 0000000 41 41 0d 0a 41 41 > 0000006 > > The question is how can I pipe out binary content properly and platform > independently? $ python -h usage: python [option] ... [-c cmd | file | -] [arg] ... Options and arguments (and corresponding environment variables): ... -u : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x) ... From usenet at marduk.letterboxes.org Wed Oct 5 16:06:37 2005 From: usenet at marduk.letterboxes.org (marduk) Date: Wed, 05 Oct 2005 20:06:37 GMT Subject: how to keep collection of existing instances and return one on instantiation In-Reply-To: <3qihbfFerdqjU1@uni-berlin.de> References: <1128529206.4560.13.camel@blackwidow> <3qid8sFeigdeU1@uni-berlin.de> <1128532128.4560.21.camel@blackwidow> <3qihbfFerdqjU1@uni-berlin.de> Message-ID: <1128542791.4560.34.camel@blackwidow> On Wed, 2005-10-05 at 19:37 +0200, Diez B. Roggisch wrote: > > What I wanted is multiple calls to create a new object with the same > > parameters points to the "original" object instead of creating a new > > one. > > Read the comments. What you say is essentially the same - the data > matters, after all. What do you care if there are several instances > around? > > Diez In my case it matters more that the objects are the same. For example I want set([Spam(1), Spam(2), Spam(3)]).intersect(set([Spam(1), Spam(2)]) to contain two items instead of 0. For this and many other reasons it's important that Spam(n) is Spam(n). From gregpinero at gmail.com Wed Oct 26 13:20:03 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Wed, 26 Oct 2005 13:20:03 -0400 Subject: xml.dom.minidom - parseString - How to avoid ExpatError? In-Reply-To: <435F9C6C.50707@plus.net> References: <312cfe2b0510251159p5e2501cbxf21e4f62f3d70b1c@mail.gmail.com> <312cfe2b0510260738j460b075ch998371a460c39df8@mail.gmail.com> <435F9C6C.50707@plus.net> Message-ID: <312cfe2b0510261020w1d485c98m526e325d6ada1082@mail.gmail.com> What do you mean by well-formed? What is required to make XML well formed? -Greg On 10/26/05, John Abel wrote: > > Try this page: > > http://docs.python.org/lib/module-xml.sax.saxutils.html > > I've just tried the code, taking out the  , and adding in the belo, > as the XML is not well formed, otherwise. > > > > The code then works. > > HTH > > J > > Gregory Pi?ero wrote: > > > Should I try some sort of XML group instead? I'm still stuck on this. > > > > -Greg > > > > > > On 10/25/05, *Gregory Pi?ero* > > wrote: > > > > Hi guys, > > > > I was hoping some XML expert could help me make this code work. > > Below is sample code with sample XML similar to what I'm dealing with. > > > > How can I make the weird characters in the XML not break the > > parser? I'll do anything to make this work! > > > > (Note: the   broke my parser yesterday but doesn't seem to in > > this sample code) But really I'm looking for solutions that will > > handles lots > > of unusual characters. > > > > Much thanks, > > > > Greg > > > > > > > > from xml.dom.minidom import parseString > > data=""" > > > > > > This is sample problem text.   ?500.00 > > > > > > """ > > myDOM=parseString(data) > > > > > > > > Traceback (most recent call last): > > File > > > "C:\Python23\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", > > line 307, in RunScript > > debugger.run(codeObject, __main__.__dict__, start_stepping=0) > > File > > "C:\Python23\Lib\site-packages\pythonwin\pywin\debugger\__init__.py", > > line 60, in run > > _GetCurrentDebugger().run(cmd, globals,locals, start_stepping) > > File > > "C:\Python23\Lib\site-packages\pythonwin\pywin\debugger\debugger.py", > > line 631, in run > > exec cmd in globals, locals > > File "C:\Documents and Settings\Gregory\My Documents\Python\xml > > help\xmlproc.py", line 9, in ? > > myDOM=parseString(data) > > File "C:\Python23\lib\xml\dom\minidom.py", line 1929, in parseString > > return expatbuilder.parseString(string) > > File "C:\Python23\lib\xml\dom\expatbuilder.py", line 940, in > > parseString > > return builder.parseString(string) > > File "C:\Python23\lib\xml\dom\expatbuilder.py", line 223, in > > parseString > > parser.Parse(string, True) > > ExpatError: undefined entity: line 4, column 29 > > > > > > > > > > -- > > Gregory Pi?ero > > Chief Innovation Officer > > Blended Technologies > > (www.blendedtechnologies.com < > http://www.blendedtechnologies.com>) > > > > > > > > > > -- > > Gregory Pi?ero > > Chief Innovation Officer > > Blended Technologies > > (www.blendedtechnologies.com < > http://www.blendedtechnologies.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 mwm at mired.org Mon Oct 31 18:44:06 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 31 Oct 2005 18:44:06 -0500 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <86acgulv5z.fsf@localhost.localdomain> <7xvezi8ypy.fsf@ruckus.brouhaha.com> <86y84ehd3j.fsf@bhuda.mired.org> <86hdb2h750.fsf@bhuda.mired.org> <86zmoufiww.fsf@bhuda.mired.org> <86oe59e57v.fsf@bhuda.mired.org> <868xwcevke.fsf@bhuda.mired.org> <86br1530w7.fsf@bhuda.mired.org> <867jbt2xyb.fsf@bhuda.mired.org> <863bmh2t7x.fsf@bhuda.mired.org> Message-ID: <86u0ex1cc9.fsf@bhuda.mired.org> "David Schwartz" writes: > "Mike Meyer" wrote in message > news:863bmh2t7x.fsf at bhuda.mired.org... >> "David Schwartz" writes: >>>> I'm trying to find out why you regularly ignore that difference for >>>> everyone but MS. >>> To substantiate that claim, you'd have to point to some cases where I >>> talk about something other than MS. >> You do that *every time* someone compares MS with other criminals - >> you immediately refer to "criminals with guns" and refuse to discuss >> the issue further. And yes, you've already claimed that you only do >> that when the other reference is to "actual use of force", and I've >> already disproved that. > You have not disproved that. The closest you've come to a disproof is > one case where the word "theft" was used (while earlier in the thread, > actual physical force had been used, but not in that specific spot) where > the context strongly suggested that it meant theft by force. Now you're simply lieing. I never discussed force earlier in the thread. > You are correct that it is possible to steal something without actually > using physical force. But that's not an important difference. The hugely > important difference, and the one that you and others *are* seeking to > obliterate, is the difference between inherently unjust actions such as > force and fraud and actions that are neither forceful nor fraudulent. And now you change your story again. You've gone from referring to all other criminal acts as "criminals with guns" to "actual use of force" to "using force or fraud." >> The only consistency here has been >> trying to treat MS's crimes as somehow different from other peoples >> crimes. > That's because the only crimes that have come up in this thread are > Microsoft's crimes (that don't involve force or fraud) and other crimes > (such as theft, threats of force, and the like) which do. Duh. Actually, they don't necessarily, but that's relevant. You simply label *all* crime other than MS's as "criminals with guns" and refuse to discuss them. > There were a few narrow cases where Microsoft was actually accused of > actions that I do consider force or fraud. That's true. They committed a fraud - by lieing to federal officials in court - and *you* responded by calling those federal officials "criminals with guns", and using that to *excuse* MS's criminal acts in this case. Which is more of the same old song and dance from you: treating MS's criminal acts as somehow different from any other criminals acts. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From gregpinero at gmail.com Thu Oct 27 14:00:58 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Thu, 27 Oct 2005 14:00:58 -0400 Subject: syntax question - if 1:print 'a';else:print 'b' In-Reply-To: <20051027174139.GC2575@kitchen.client.attbi.com> References: <312cfe2b0510261507m2732e947p2be6fdae99a7c3d7@mail.gmail.com> <312cfe2b0510270757o51d3cfa7h2fccc775068b5549@mail.gmail.com> <8c7f10c60510270806y65510087t@mail.gmail.com> <312cfe2b0510270931r52a18d0em29168b9702d2c748@mail.gmail.com> <20051027174139.GC2575@kitchen.client.attbi.com> Message-ID: <312cfe2b0510271100y32f6163es8a27524ccc37747c@mail.gmail.com> Not quite because if something(3) fails, I still want something(4) to run. On 10/27/05, Micah Elliott wrote: > > > > If you just want to ignore the exceptions while saving space/typing, > you could equivalently do:: > > try: > something(1) > something(2) > # ... > except: > pass > > or:: > > try: > something(1); something(2); # ... > except: > pass > > or:: > > try: > for i in range(yourlimit): > something(i) > except: > pass > > -- > _ _ ___ > |V|icah |- lliott http://micah.elliott.name mde at micah.elliott.name > " " """ > -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com ) -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve.horsley at gmail.com Fri Oct 21 15:31:41 2005 From: steve.horsley at gmail.com (Steve Horsley) Date: Fri, 21 Oct 2005 20:31:41 +0100 Subject: newbie question about SocketServer In-Reply-To: <1129842796.819897.309040@g49g2000cwa.googlegroups.com> References: <1129842796.819897.309040@g49g2000cwa.googlegroups.com> Message-ID: akameswaran at gmail.com wrote: > Is it just me or do the server_close() methods do squat? I'm primarily > working with a ThreadingTCPServer object and trying to create a simple > server that can shut itself down. But even simplest cases don't seem > to work. > > Admittedly I am trying it from within my handler class, but for some > odd reason, the server is allways willing to handle one more request > before dying. Then it dies. > I suspect that the server thread itself is stuck in socket.accept(), and won't exit until the next call arrives. Try calling server_close and then making a brief connection to the server to wake it up. HTH Steve From peter at engcorp.com Tue Oct 11 07:23:37 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 11 Oct 2005 07:23:37 -0400 Subject: Python's Performance In-Reply-To: <434B9CD5.6050904@engcorp.com> References: <20051008040614.47429.qmail@web30607.mail.mud.yahoo.com> <178B879D-FDB6-458C-BE00-A03820D98703@advfn.com> <1128969275.804305.193460@f14g2000cwb.googlegroups.com> <434B9CD5.6050904@engcorp.com> Message-ID: <434BA0B9.5040501@engcorp.com> Peter Hansen wrote: > But I'm also not sure I ought to post that to the group, so I'll spare > them and just inflict the thought on you! Or, maybe I'll just fail to trim the newsgroup line and accidentally post to the group anyway. Yes, that's just what I'll do. Sorry folks. :-) -Peter From robin at reportlab.com Fri Oct 7 13:24:28 2005 From: robin at reportlab.com (Robin Becker) Date: Fri, 07 Oct 2005 18:24:28 +0100 Subject: [Info] PEP 308 accepted - new conditional expressions In-Reply-To: <42e3723cfd2de0aca23e730139e4dd71@xs4all.nl> References: <3q4ro9Fd770nU3@individual.net> <0qh%e.20023$Ix4.15230@okepread03> <43464262.3040406@chamonix.reportlab.co.uk> <42e3723cfd2de0aca23e730139e4dd71@xs4all.nl> Message-ID: <4346AF4C.708@chamonix.reportlab.co.uk> Eric Nieuwland wrote: > > > Ever cared to check what committees can do to a language ;-) > .... well there goes democracy :( -the happy slaves eat and are contented-ly yrs- Robin Becker From leszczynscyATnospam.yahoo.com.nospam Tue Oct 11 22:29:13 2005 From: leszczynscyATnospam.yahoo.com.nospam (Andy Leszczynski) Date: Tue, 11 Oct 2005 21:29:13 -0500 Subject: TurboGears /.-ed, >new == True< or >new == "True"< Message-ID: watch this: http://www.turbogears.org.nyud.net:8090/docs/wiki20/20MinuteWiki.mov or read this: http://www.turbogears.org.nyud.net:8090/docs/wiki2 0/page4.html should not it be: 2 def save(self, pagename, data, submit, new): 3 hub.begin() 4 if new == True: 5 page = Page(pagename=pagename, data=data) 6 else: 7 page = Page.byPagename(pagename) 8 page.data = data instead of: 4 if new == "True": From fiedzia at fiedzia.prv.pl Fri Oct 21 15:42:36 2005 From: fiedzia at fiedzia.prv.pl (Maciej Dziardziel) Date: Fri, 21 Oct 2005 21:42:36 +0200 Subject: subprocess exiting in an incomprehensible fashion References: <1129916005.543449.305390@g44g2000cwa.googlegroups.com> Message-ID: <20051021194237.3AA2.0.NOFFLE@fiedzia.homeip.net> Will wrote: > After the first number is input, the subprocess is exiting after the > first communicate. I do not understand why. As help(calc.communicate) says: Read data from stdout and stderr, until end-of-file is reached. Wait for process to _terminate_. > Any help would be much appreciated. I have been hunting quite a bit for > he answer to no avail. Simplest solution: #!/usr/bin/python2.4 import subprocess calc = subprocess.Popen("dc", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) max = 5 for value in range(1, max): calc.stdin.write("%d\n" % value) if value > 1: calc.stdin.write("*\n") calc.stdin.write("p\n") calc.stdin.write("q\n") calc.stdin.flush() status = calc.wait() print calc.stdout.read() -- Maciej "Fiedzia" Dziardziel (fiedzia (at) fiedzia (dot) prv (dot) pl) www.fiedzia.prv.pl From steve at holdenweb.com Sat Oct 29 17:43:18 2005 From: steve at holdenweb.com (Steve Holden) Date: Sat, 29 Oct 2005 22:43:18 +0100 Subject: Scanning a file In-Reply-To: <1130614532.765771.288960@g43g2000cwa.googlegroups.com> References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <1130614532.765771.288960@g43g2000cwa.googlegroups.com> Message-ID: netvaibhav at gmail.com wrote: > I think implementing a finite state automaton would be a good (best?) > solution. I have drawn a FSM for you (try viewing the following in > fixed width font). Just increment the count when you reach state 5. > > <---------------| > | | > 0 0 | 1 0 |0 > -->[1]--->[2]--->[3]--->[4]--->[5]-| > ^ | | ^ | | | > 1| |<---| | | |1 |1 > |_| 1 |_| | | > ^ 0 | | > |---------------------|<-----| > > If you don't understand FSM's, try getting a book on computational > theory (the book by Hopcroft & Ullman is great.) > > Here you don't have special cases whether reading in blocks or reading > whole at once (as you only need one byte at a time). > Indeed, but reading one byte at a time is about the slowest way to process a file, in Python or any other language, because it fails to amortize the overhead cost of function calls over many characters. Buffering wasn't invented because early programmers had nothing better to occupy their minds, remember :-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From kylotan at gmail.com Thu Oct 27 04:44:13 2005 From: kylotan at gmail.com (Ben Sizer) Date: 27 Oct 2005 01:44:13 -0700 Subject: loop help In-Reply-To: References: Message-ID: <1130402653.534939.131340@o13g2000cwo.googlegroups.com> What do you mean by 'it starts accumulating' in this context? Are you talking about the fact that numbers gain decimal places? Or the fact that using a number between 0 and 1 will make your values diverge to infinity? Either way, it's just mathematics for you, I'm afraid, and there's little Python can do about it. ;) Which part of the code issues the overflow error? I'm guessing it's the draw.point() call since that's the only bit I can't test. -- Ben Sizer From rrr at ronadam.com Sat Oct 22 17:41:58 2005 From: rrr at ronadam.com (Ron Adam) Date: Sat, 22 Oct 2005 21:41:58 GMT Subject: best way to replace first word in string? In-Reply-To: References: <1129822003.246170.303920@f14g2000cwb.googlegroups.com> Message-ID: Steven D'Aprano wrote: > def replace_word(source, newword): > """Replace the first word of source with newword.""" > return newword + " " + "".join(source.split(None, 1)[1:]) > > import time > def test(): > t = time.time() > for i in range(10000): > s = replace_word("aa to become", "/aa/") > print ((time.time() - t)/10000), "s" > > py> test() > 3.6199092865e-06 s > > > Is that fast enough for you? I agree in most cases it's premature optimization. But little tests like this do help in learning to write good performing code in general. Don't forget a string can be sliced. In this case testing before you leap is a win. ;-) import time def test(func, n): t = time.time() s = '' for i in range(n): s = func("aa to become", "/aa/") tfunc = t-time.time() print func.__name__,':', (tfunc/n), "s" print s def replace_word1(source, newword): """Replace the first word of source with newword.""" return newword + " " + "".join(source.split(None, 1)[1:]) def replace_word2(source, newword): """Replace the first word of source with newword.""" if ' ' in source: return newword + source[source.index(' '):] return newword test(replace_word1, 10000) test(replace_word2, 10000) ======= replace_word1 : -3.09998989105e-006 s /aa/ to become replace_word2 : -1.60000324249e-006 s /aa/ to become From steve at REMOVEMEcyber.com.au Wed Oct 12 00:24:02 2005 From: steve at REMOVEMEcyber.com.au (Steven D'Aprano) Date: Wed, 12 Oct 2005 14:24:02 +1000 Subject: non descriptive error References: <4346002C.3080504@open-networks.net><200510070240.56350.hancock@anansispaceworks.com> <4349A55C.90203@open-networks.net> Message-ID: <434C8FE2.2090505@REMOVEMEcyber.com.au> Timothy Smith wrote: >>> i have NO idea what in there could be making it have such a strange >>> error. it just says "error" when you try run it. there nothing terribly >>> strange being done. > i am still coming across this error it's driving me nuts. usually i can > find what's wrong, but it is becoming an increasingly annoying problem. > i also get the same problem on a windows machine with the same > installed. this time it's nothing to do with the decimal module. help! Go back to first principles. Can you grab all the modules being used, and search them for the string "error"? Ignore any hits which are in a comment. One of the others is almost certainly responsible. You can test that by changing the string to "this is a PITA" and see if your mysterious error message changes or not. -- Steven. From robert.kern at gmail.com Sat Oct 29 00:53:42 2005 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 28 Oct 2005 21:53:42 -0700 Subject: Generic utility class for passing data In-Reply-To: <1130560720.166693.239460@g44g2000cwa.googlegroups.com> References: <1u-dnSkSzdnsfP_enZ2dnUVZ_tGdnZ2d@comcast.com> <1h55r01.ovyr63zw37r6N%aleaxit@yahoo.com> <1130560720.166693.239460@g44g2000cwa.googlegroups.com> Message-ID: bonono at gmail.com wrote: > just curious, since python don't care what object is being passing > around and the receiving function has to 'decode' it(be it tuple or > dict or whatever). What is the advantage of dummy class ? The convenience of the attribute notation. For the record, my favorite variation is as follows: class Bunch(dict): def __init__(self, *args, **kwds): dict.__init__(self, *args, **kwds) self.__dict__ = self -- 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 Fri Oct 28 10:23:34 2005 From: roccomoretti at hotpop.com (Rocco Moretti) Date: Fri, 28 Oct 2005 09:23:34 -0500 Subject: Suggestion for (re)try statement In-Reply-To: References: Message-ID: Sori Schwimmer wrote: > Hi, > > I think that would be useful to have an improved > version of the "try" statement, as follows: > > try(retrys=0,timeout=0): > # things to try > except: > # what to do if failed > > and having the following semantic: > > for i in range(retrys): > try: > # things to try > except: > if i < retrys: > i += 1 > sleep(timeout) > else: > # what to do if failed > else: > break The gold standard for language syntax changes is "compelling use cases" - if introduced, how often will the construct be used? Is there a python program out there (preferably in the standard library) which would be *markedly* improved by the change? What is so repugnant about the equivalent, currently valid way of writing it? -- Hypothetical and theoretical arguments don't carry much weight in the Python community ("Practicality beats purity" and all that.) And remember - your goal isn't ultimately to convince me or someother person on comp.lang.python, it's to convince Guido. From lasse at vkarlsen.no Sun Oct 9 07:34:31 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Sun, 09 Oct 2005 13:34:31 +0200 Subject: new forum -- homework help/chit chat/easy communication In-Reply-To: References: <1128798687.305818.66010@g49g2000cwa.googlegroups.com><1128810677_124183@spool6-east.superfeed.net> Message-ID: Fredrik Lundh wrote: > "Unlike mainstream component programming, scripts usually > do not introduce new components but simply "wire" existing > ones. Scripts can be seen as introducing behavior but no > new state. /.../ Of course, there is nothing to stop a > "scripting" language from introducing persistent state -- it > then simply turns into a normal programming language." > > -- Clemens Szyperski, in "Component Software": That description seems to describe whatever is written more than whatever it is written in, or in other words, it describes the difference between a script and a program, not between a scripting language and a programming language. I think that at one time, scripting languages was something that lived within other programs, like Office, and couldn't be used by themselves without running it inside that program, and as thus was a way to add minor functions and things to that program. Nowadays a lot of the scripting languages have turned programming languages so I think the difference is small. -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From codecraig at gmail.com Tue Oct 11 13:07:57 2005 From: codecraig at gmail.com (Java and Swing) Date: 11 Oct 2005 10:07:57 -0700 Subject: Help creating extension for C function In-Reply-To: <1129049460.649101.96890@g47g2000cwa.googlegroups.com> References: <1128714478.552412.135950@g47g2000cwa.googlegroups.com> <1129049460.649101.96890@g47g2000cwa.googlegroups.com> Message-ID: <1129050477.600590.89140@o13g2000cwo.googlegroups.com> also, I noticed you did python build-ext ....does that mean for any computer I want to run myapp on, I need to build the extension on it as well? Or can I build it once and just copy the files to another computer that has python already installed? If I just copy files, which files and where would they go? Thanks! Java and Swing wrote: > So is "module.c" a new C file or do I add it to my existing, myapp.c? > > > Fredrik Lundh wrote: > > > seq = PySequence_Fast(data, "expected a sequence"); > > > if (!seq) > > > return NULL; > > > > here's some more information on the PySequence_Fast API: > > > > http://www.effbot.org/zone/python-capi-sequences.htm > > > > From __peter__ at web.de Wed Oct 26 05:30:17 2005 From: __peter__ at web.de (Peter Otten) Date: Wed, 26 Oct 2005 11:30:17 +0200 Subject: Looping Problem (Generating files - only the last record generates a file) References: <1130316544.381673.209190@g44g2000cwa.googlegroups.com> Message-ID: vasilijepetkovic at yahoo.com wrote: > Once I execute the program (see below) only one file (instead of x > files) is created. The file created is based on the last record in > datafile.txt. > #! python > > HEADER = "This page displays longitude-latitude information" > SUBHEADER = "City" > > for line in open("datafile.txt"): > > > town, latlong = line.split('\t') In Python whitespace is significant. For the following to be executed in the for-loop it has to be indented to the same level as the line above. > f = open(town + ".txt", "w+") > > f.write(HEADER + "\n") > f.write(SUBHEADER + ": " + town + "\n") > f.write("LAT/LONG" + ": " + latlong + "\n") > f.close() > > > # end > ==================================== The effect of aligning it with the for-statement is that it is executed only once /after/ the loop has run to completion. At that point town and latlong are still bound to the values they were assigned in the last iteration (with an empty datafile.txt the loop would never be executed and you would get a NameError). Peter From http Sat Oct 8 01:18:59 2005 From: http (Paul Rubin) Date: 07 Oct 2005 22:18:59 -0700 Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <1h42zdb.1hqmbvr101wlsoN%aleax@mail.comcast.net> Message-ID: <7xk6goh9h8.fsf@ruckus.brouhaha.com> aleax at mail.comcast.net (Alex Martelli) writes: > ap.py:4: No global (test) found > ap.py:5: Local variable (ego1d) not used > Helen:/tmp alex$ > > If you're so typo-prone and averse to unittests that you consider this > kind of issue to be a serious problem, just use pychecker and get > informed about any such typo, just as above. That's very helpful, but why isn't it built into Python? From schng6 at yahoo.com Mon Oct 10 19:34:35 2005 From: schng6 at yahoo.com (saw huan chng) Date: Mon, 10 Oct 2005 16:34:35 -0700 (PDT) Subject: WMI - Restore Setting in Python Message-ID: <20051010233435.58991.qmail@web35201.mail.mud.yahoo.com> Hi, I am beginner in Python. I have some questions on WMI Service in Python. I was able to use properties of Class Restore in WMI, but not able to use the method. Here is the sample code that I done, anyone can help me? import win32com.client strComputer = "." objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator") objSWbemServices = objWMIService.ConnectServer(strComputer,"root\DEFAULT") testobj = objSWbemServices.Get("SystemRestore") sequence_number = 11 result = testobj.Restore(sequence_number) Traceback (most recent call last): File "C:\Documents and Settings\Fish\Desktop\RP_test.py", line 18, in ? result = testobj.Restore(sequence_number) File "c:\Python23\Lib\site-packages\win32com\client\dynamic.py", line 471, in __getattr__ raise pythoncom.com_error, details pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'SWbemObjectEx', 'Invalid parameter ', None, 0, -2147217400), None) Thanks. --------------------------------- Yahoo! Music Unlimited - Access over 1 million songs. Try it free. -------------- next part -------------- An HTML attachment was scrubbed... URL: From alainpoint at yahoo.fr Fri Oct 7 09:45:06 2005 From: alainpoint at yahoo.fr (alainpoint at yahoo.fr) Date: 7 Oct 2005 06:45:06 -0700 Subject: Python interpreter bug In-Reply-To: References: <1128686833.994339.295780@f14g2000cwb.googlegroups.com> Message-ID: <1128692705.964188.5720@z14g2000cwz.googlegroups.com> Sorry Fredrik but I don't understand. Just comment out the assert and you have different results depending on whether an unrelated sort function is defined. This seems weird to me ! From mwm at mired.org Sun Oct 9 20:54:18 2005 From: mwm at mired.org (Mike Meyer) Date: Sun, 09 Oct 2005 20:54:18 -0400 Subject: searching a project to contribute to References: <1128881668.508095.29320@g49g2000cwa.googlegroups.com> Message-ID: <8664s6kx8l.fsf@bhuda.mired.org> "Clint Norton" writes: > Hi all, > I'm a student currently in the beginning of my master's degree and > I'm searching for an interesting open source project written in Python > to contribute to. > I have worked as a programmer for the past few years (mostly in > academia but also as a typical full time code monkey in a commercial > company), some of it in python, some in Java (commercial companies > really seem to like Java). > Anyway, which python projects would be a good start? I generally > like working on algorithmic parts or "Business Logic" and really don't > like doing interface work. The software I like producing has a tendency > to make use of the random and/or math modules, if that says something > about the nature of the work I've done... I really want to give > something back to the community I've taken so much from in the past. Well, if there's some software you use on a regular basis, that's a good start. Python itself is a candidate. If the goal is just to contribute, start going through the bugs database, and see if you can contribute patches that fix some of the reporrted bugs. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From piet at cs.uu.nl Fri Oct 14 17:20:12 2005 From: piet at cs.uu.nl (Piet van Oostrum) Date: Fri, 14 Oct 2005 23:20:12 +0200 Subject: confusion between global names and instantiated object variable names References: <1129322411.776202.314290@g43g2000cwa.googlegroups.com> Message-ID: >>>>> "wanwan" (w) wrote: >w> I'm trying to make a GUI, but for some of the instantiated object >w> variable names, the interpreter is looking at them as global names. >w> Here is an example of what I did: >w> class mygui: >w> def __init__(self, root): >w> self.menubar = Menu(root) >w> # Game Menu >w> self.menu1 = Menu(self.menubar, tearoff=0) >w> self.menu1.add_command(label="Open File", command=donothing) >w> self.menu1.add_separator() >w> self.menu1.add_command(label="Exit", command=root.quit) >w> self.menubar.add_cascade(label="File", menu=self.menu1) >w> # ignoring the rest of the program ... >w> when I run my example, an error shows: >w> "NameError: global name'menubar' is not defined" If it talks about global name, it can't be self.menubar or anything.menubar. So there must be a soloist menubar reference somewhere. Doesn't it tell you the line number? -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From nnorwitz at gmail.com Sun Oct 9 22:13:43 2005 From: nnorwitz at gmail.com (Neal Norwitz) Date: 9 Oct 2005 19:13:43 -0700 Subject: Python reliability In-Reply-To: References: Message-ID: <1128910423.872733.303580@g14g2000cwa.googlegroups.com> Ville Voipio wrote: > > The software should be running continously for > practically forever (at least a year without a reboot). > Is the Python interpreter (on Linux) stable and > leak-free enough to achieve this? Jp gave you the answer that he has done this. I've spent quite a bit of time since 2.1 days trying to improve the reliability. I think it has gotten much better. Valgrind is run on (nearly) every release. We look for various kinds of problems. I try to review C code for these sorts of problems etc. There are very few known issues that can crash the interpreter. I don't know of any memory leaks. socket code is pretty well tested and heavily used, so you should be in fairly safe territory, particularly on Unix. n From rNOSPAMon at flownet.com Thu Oct 13 02:24:36 2005 From: rNOSPAMon at flownet.com (Ron Garret) Date: Wed, 12 Oct 2005 23:24:36 -0700 Subject: Setdefault bypasses __setitem__ Message-ID: Is this a bug or a feature? class mydict(dict): def __setitem__(self, key, val): print 'foo' dict.__setitem__(self, key, val) >>> d=mydict() >>> d[1]=2 foo >>> d.setdefault(2,3) 3 rg From mhellwig at xs4all.nl Sun Oct 9 06:35:27 2005 From: mhellwig at xs4all.nl (Martin P. Hellwig) Date: Sun, 09 Oct 2005 12:35:27 +0200 Subject: Daisy Daisy, give me your answer do In-Reply-To: References: <1128802217.156887.234490@g43g2000cwa.googlegroups.com> Message-ID: <4348f2f5$0$11062$e4fe514c@news.xs4all.nl> Michael Goettsche wrote: > You're asking "tech geekers" and "morons" to do this job? Isn't that a task > for somebody more professional like you? I think he's doing a shot to the position of open-source leader, judging on the replies he has got till so far, that shot was not really effective. In dutch we have a saying for these kind of people, it goes like this: "12 ambachten, 13 ongelukken". -- mph From peter at engcorp.com Mon Oct 24 02:23:56 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 24 Oct 2005 02:23:56 -0400 Subject: testing '192.168.1.4' is in '192.168.1.0/24' ? In-Reply-To: <1130131120.695320.180030@z14g2000cwz.googlegroups.com> References: <1130131120.695320.180030@z14g2000cwz.googlegroups.com> Message-ID: bonono at gmail.com wrote: > Is there standard library modules handling this ? currently I need to > turn it into a long integer and do the shift and compare. A little Googling turned up this: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440560 -Peter From fredrik at pythonware.com Mon Oct 10 02:58:43 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 10 Oct 2005 08:58:43 +0200 Subject: line References: <1d987df30510092220x2ab85939rd1a895718b619685@mail.gmail.com> Message-ID: Shi Mu wrote_ > There are four points with coordinates: > 2,3;4,9;1,6;3,10. > How to use Python to draw one perpendicular bisector > between (2,3) and (4,9); the same was as you'd do it in any other computer language ? once you know the algorithm, implementing it in Python should be trivial. maybe you should look for some geometrics site/group first ? (sci.math or alt.math.recreational and their associated FAQs and archives might be good choices) (your questions do look a lot like homework assigments, btw. are you sure they're not homework? or if they are, that you're supposed to have others do you homework for you?) From jason at pengale.com Thu Oct 20 10:02:34 2005 From: jason at pengale.com (Jason Stitt) Date: Thu, 20 Oct 2005 09:02:34 -0500 Subject: sqlstring -- a library to build a SELECT statement In-Reply-To: References: <1129774730.887128.314960@z14g2000cwz.googlegroups.com> Message-ID: On Oct 20, 2005, at 2:19 AM, Steve Holden wrote: > Jason Stitt wrote: >> Using // for 'in' looks really weird, too. It's too bad you can't >> overload Python's 'in' operator. (Can you? It seems to be hard-coded >> to iterate through an iterable and look for the value, rather than >> calling a private method like some other builtins do.) >> >>>> class inplus(object): >>>> > ... def __contains__(self, thing): > ... print "Do I have a", thing, "?" > ... return True > ... I stand corrected. Python.org was intermittently down yesterday so I was trying to play around with the interactive interpreter and missed it. For future reference: http://www.python.org/doc/ref/specialnames.html However 'in' seems to coerce the return value of __contains__ to True or False, even if you return an object reference. - Jason From christoph.soellner at web.de Tue Oct 18 07:27:54 2005 From: christoph.soellner at web.de (Christoph Söllner) Date: Tue, 18 Oct 2005 13:27:54 +0200 Subject: HTTPResponse.read() returns an empty string? References: Message-ID: ok got it: One cannot close the connection before reading the answer. Seems that in my original source the new assigned variable 'answ' is destroyed or emptied with the connection.close() command; very strange behaviour. > """ > import httplib > conn = httplib.HTTPConnection('www.python.org'); > conn.request("GET", "/index.html"); > answ = conn.getresponse(); > print answ.status, answ.reason >>>> 200 OK > conn.close(); > print "Start"; >>>> Start > print answ.read(); >>>> > print len(answ.read()); >>>> 0 From aahz at pythoncraft.com Mon Oct 31 17:52:54 2005 From: aahz at pythoncraft.com (Aahz) Date: 31 Oct 2005 14:52:54 -0800 Subject: Storing empties (was Re: Automatic binding of **kwargs to variables) References: <1130539752.667045.183460@g14g2000cwa.googlegroups.com> <1h57spy.bpig8y1g0rvzfN%aleaxit@yahoo.com> <1130650215.537552.231990@g49g2000cwa.googlegroups.com> <1h58k4p.12xd7rj1t5peh0N%aleaxit@yahoo.com> Message-ID: In article <1h58k4p.12xd7rj1t5peh0N%aleaxit at yahoo.com>, Alex Martelli wrote: > >the canonical idiom when you need such distinction is: > >_not_there = object() >def foo(bar=_not_there, baz=_not_there, bap=_not_there): > if bar is _not_there: ... > >Other unique objects can be substituted for the 'sentinel', but I prefer >an empty "object()" because it has no other possible meaning except that >of a distinguishable, identifiable sentinel. IOW, you could set the >_not_there name to [] or {} or many other things, but that could be >slightly confusing for the reader (since the other things might have >other meanings and purposes) while 'object()' shouldn't be. What's your preferred idiom when you're dealing with storable objects? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." --Red Adair From jepler at unpythonic.net Tue Oct 11 15:51:17 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Tue, 11 Oct 2005 14:51:17 -0500 Subject: unable to import os In-Reply-To: <1129059294.346530.19780@g47g2000cwa.googlegroups.com> References: <1129054769.405747.170570@o13g2000cwo.googlegroups.com> <1129059294.346530.19780@g47g2000cwa.googlegroups.com> Message-ID: <20051011195116.GE21569@unpythonic.net> Concatenating filenames with "+" is seldom what you want. Instead, you should use os.path.join (or, to decrease portability, nt.path.join). Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From john at castleamber.com Sat Oct 15 03:07:11 2005 From: john at castleamber.com (John Bokma) Date: 15 Oct 2005 07:07:11 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: "Jeroen Wenting" wrote: > no, they got their by clever marketing and generally having a product > that was easier to use for the average user than anything the > competition made and a lot more powerful than other products created > for their main target market. I agree with the first part of your sentence, the rest is BS of course. > Without Microsoft 90% of us would never have seen a computer more > powerful than a ZX-81 and 90% of the rest of us would never have used > only dumb mainframe terminals. More BS of course. > IBM's prediction that there would be 5 computers (not counting game > computers like the Comodores and Spectrums) by 2000 would likely have > come true. Yeah, sure, and we all would be living in caves. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From fredrik at pythonware.com Mon Oct 3 14:35:01 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 3 Oct 2005 20:35:01 +0200 Subject: python getopt functionality References: <4341786B.1030901@grads.ece.mcmaster.ca> Message-ID: "M.N.A.Smadi" wrote: > I have a perl script that I need to port to python. The script takes > input from the command line. Is there a standard way of processing > command line arguments based on the -flag preceeding the argument? http://docs.python.org/lib/module-getopt.html http://docs.python.org/lib/module-optparse.html From kyle.tk at gmail.com Fri Oct 7 21:55:34 2005 From: kyle.tk at gmail.com (kyle.tk) Date: 7 Oct 2005 18:55:34 -0700 Subject: Best way to share a python list of objects Message-ID: <1128736534.695525.255410@g43g2000cwa.googlegroups.com> So I have a central list of python objects that I want to be able to share between different process that are possibly on different computers on the network. Some of the processes will add objects to list and another process will be a GUI that will view objects in the list. I want this all to happen in real-time (e.g once a processes adds an object to the list the GUI will see it.) What would be the best way to accomplish this. Some of my ideas: - An XML file r/w-able by all processes - Send pickled objects between all processes and each keeps it own list locally - A ascii type protocol akin to ftp the hands out all the info to the processes Any other ideas? What would work the best From fredrik at pythonware.com Wed Oct 19 12:41:07 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 19 Oct 2005 18:41:07 +0200 Subject: Converting 2bit hex representation to integer ? References: <43567027$0$41144$14726298@news.sunsite.dk><-_2dndLn4eEm78veRVn-qg@comcast.com> <4356740c$0$41148$14726298@news.sunsite.dk> Message-ID: Madhusudan Singh wrote: >> Can you give us an example. I don't know what two bit >> hex means (takes at least 4 bits to make a hex digit). > > Like 64(base 16)=100. > I am referring to 64 in the above. that's two digits, not two bits. >>> print int("64", 16) 100 >> Now I'm going to try to guess: >> >> If the data is binary then all you need to do is to >> use the struct.unpack module to convert to integer. > > Doesn't unpack presume that the input is a string ? If so, is it safe to > convert binary data to string using str() ? since Python uses string objects to hold binary data, that shouldn't be necessary. (struct also supports the CPython low-level buffer protocol, so it works with any type that sees itself as a string of bytes). From __peter__ at web.de Wed Oct 12 10:37:59 2005 From: __peter__ at web.de (Peter Otten) Date: Wed, 12 Oct 2005 16:37:59 +0200 Subject: can we save print msg into a file when script running ? References: <1129079641.137785.320000@g44g2000cwa.googlegroups.com> Message-ID: black wrote: > in my .py file there are a few print to trace out some message and i > wonder if we can save it into a specified file when that script get > running. if so, i may just check that file to c how the script is > running. can anyone show me a right direction ? If you don't feel comfortable with the command line you can stick import sys sys.stdout = open("mylogfile.txt", "w") at the beginning of your file. Peter From vasilijepetkovic at yahoo.com Fri Oct 21 13:23:42 2005 From: vasilijepetkovic at yahoo.com (vasilijepetkovic at yahoo.com) Date: 21 Oct 2005 10:23:42 -0700 Subject: Help with language, dev tool selection Message-ID: <1129915422.693950.97000@g43g2000cwa.googlegroups.com> I have a problem that I have to solve programmatically and since HTML is pretty much the only code I have been exposed to I need an advice on how to develop the programmatic solution to the problem I have. In the nutshell, it'd be great if you can give me guidance in terms of: 1) What programming language to use 2) What development tools to use 3) Tips on how to code the solution So, here is my challenge: I have a flat text file, 30000 records, each record has two columns, the columns are tab separated. The file looks like this (approximately) Sarajevo 431104-133111 Mostar 441242-133421 Zagreb 432322-134423 The first value is a name of a town, and the second value represent longitude-latitude in degrees, minutes and seconds. For each record I have to create an html file that will be named as the name of the town (i.e. Sarajevo.html). The content of the file will be rather simple; in the first row it will contain the header (i.e. "This page displays longitude-latitude information") - The second row will have the following word: "Grad" - and the third row will contain the name of the city and the fourth row will have the longitude-latitude info. The program also needs to prompt me (before it starts spitting the html pages) and ask what test should be entered in line one (I would than manually enter "This page displays longitude-latitude information") and it also need to prompt me about the text that should be entered in line two (I'd go and manually enter "grad"). I'd greatly appreciate any coment and/or guidance. Best, Vasilije Petkovic Vasa From davids at webmaster.com Tue Oct 25 03:44:17 2005 From: davids at webmaster.com (David Schwartz) Date: Tue, 25 Oct 2005 00:44:17 -0700 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <2n3133-19g.ln1@news.it.uc3m.es> Message-ID: "Peter T. Breuer" wrote in message news:2n3133-19g.ln1 at news.it.uc3m.es... >> Essentially, Microsoft asked for exclusive arrangements. That is, >> arrangements wherein you could not sell competing products if you wished >> to >> sell Microsoft products. That's not even remotely unusual. > It soitenly is, stanley. In case you hadn't noticed, the shops sell > more than one kind of washing powder. Your argument is nonsensical. Because you can find one category of goods that don't have the property I'm talking about it follows that the property is unusual?! Operating systems are not like washing powder at all. Try to sell both Big Macs and Whoppers in one store. Heck, try to sell Craftsman tools without being a Sears. Microsoft gets to decide whether they sell their operating systems software like washing powder or like burgers, not you. > Please stop this shillism. If you could produce a strong argument, it might make sense to accuse me of shilling. DS From joeyjwc at gmail.com Tue Oct 25 05:36:56 2005 From: joeyjwc at gmail.com (Joey C.) Date: 25 Oct 2005 02:36:56 -0700 Subject: Setting a Limit to the Maximum Size of an Upload In-Reply-To: <1130232152.429900.109710@g44g2000cwa.googlegroups.com> References: <1130147553.883353.141410@g14g2000cwa.googlegroups.com> <1130185501.221232.17370@g14g2000cwa.googlegroups.com> <1130232152.429900.109710@g44g2000cwa.googlegroups.com> Message-ID: <1130233016.889478.104380@g47g2000cwa.googlegroups.com> Oh, I'm sorry, I didn't understand what you meant at first. Then I read your reply over again and noticed that you said that the problem lied in os.path.getsize() when I tried to run it on the contents of an open file. I'll try the method you outlined now. From http Mon Oct 10 20:04:47 2005 From: http (Paul Rubin) Date: 10 Oct 2005 17:04:47 -0700 Subject: Function decorator that caches function results References: <7x4q7rt3yl.fsf@ruckus.brouhaha.com> Message-ID: <7xwtkk6hr4.fsf@ruckus.brouhaha.com> Tom Anderson writes: > Okay, a crack at a definition: a closure is a function in which some > of the variable names refer to variables outside the function. That's misleading, I'd say a closure is a combination of a function (executable code) and a lexical environment (the values of the function's free variables, as taken from surrounding scopes at the time the function was created). For example: def f(n): def g(): return n return g h1 = f(1) h2 = f(2) h1 and h2 are two different closures. They have the same executable code but their environments are different. In h1, n=1, but in h2, n=2. So, h1() will return 1 but h2() will return 2. Is there really anything confusing about this? All that's happened is that when you call f, f allocates a memory slot for n. g makes a reference to the slot and then f returns. Since the reference to the slot still exists, the slot doesn't get GC'd. When you call f again, it allocates a new slot. This is all described in SICP (mitpress.mit.edu/sicp). From erniedude at gmail.com Fri Oct 21 11:34:45 2005 From: erniedude at gmail.com (Ernesto) Date: 21 Oct 2005 08:34:45 -0700 Subject: Compile C program -> .pyc file In-Reply-To: References: <1129905417.451369.114840@o13g2000cwo.googlegroups.com> Message-ID: <1129908885.343748.130460@o13g2000cwo.googlegroups.com> Fredrik Lundh wrote: > "Ernesto" wrote: > > > Is there a way to compile a C program into a .pyc file that has the > > same behavior as the compiled C program? > > unless you find a C->Python compiler, no. PYC files contain Python bytecode, > C compilers usually generate native code for a given machine platform. > > Yeah, I know it can't really be done in ONE step, but I was hoping it was possible in 'n' steps. From davids at webmaster.com Thu Oct 27 21:40:13 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 18:40:13 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <66u633-etj.ln1@news.it.uc3m.es> <7xbr1aewtq.fsf@ruckus.brouhaha.com> <86acgulv5z.fsf@localhost.localdomain> <7xvezi8ypy.fsf@ruckus.brouhaha.com> <86y84ehd3j.fsf@bhuda.mired.org> <86hdb2h750.fsf@bhuda.mired.org> Message-ID: "Mike Meyer" wrote in message news:86hdb2h750.fsf at bhuda.mired.org... >> "Ironically, while no one else has so much as compared MS to criminals >> with >> guns". I defy you to find *one* place where I complain that MS behavior >> is >> equated to the actual use of force where that is not in fact done in >> precisely the thread I'm replying to. > The first one is at: > > http://groups.google.com/group/comp.lang.python/msg/8422f41c9fe137b0?dmode=source&hl=en > > The original comment was: > >>> No, they didn't ask for more than Windows were worth. They tilted the >>> playing field against MS competitors by causing consumers to pay MS >>> money for products they didn't receive. In most countries, taking >>> money from unwilling victims without giving them anything in exchange >>> is called "theft". > > Note that no mention is made of guns or force - just a definition of > theft. Unless you're so narrowminded that nothing short of pointing a > gun at someone and demanding money from them is stealing from them, > there is no way that this can be equated to the actual use of > force. And if you do believe that definition of stealing, I'll do your > bookkeeping for free - and I won't steal from you. > > Your reply: > >> It is not theft if you can simply say "no" to the deal and all that >>happens is that you don't get the product. Your argument is preposterous. >>If >>you accept arguments that equate guns with arguments, the next step is >>that >>using a gun is a rational response to an argument one doesn't like. Oh >>wait, >>you're already there. > > Wherein you accuse me of equating MS's actions with using guns, which > is *exactly* what I said you do. This thread is large and complex, and I can't always know exactly what's a reply to what reply to what. So what's said in what part of a thread may carry over to another part of that same thread. > There are lots more examples of you doing this kind of thing. Like I > said, everytime someone compares MS's behavior with some less > controversial criminal behavior, you act like they accused MS of > holding people up at gunpoint. They are. Read the quotes. Here they are again: "We are talking junior Mafia style enforcement." >Did Microsoft ever use or threaten force? "YES . Have you not read a word I said." "It will be very hard to prosecute MS for their crimes because they commit them much the way the Mafia does. ... Everyone was terrified of MS and would never dream of going public. I have talked about this publicly many times because it always looked as if I were going to die in a few years anyway." There are many more. >Unless you're so narrowminded that nothing short of pointing a >gun at someone and demanding money from them is stealing from them, >there is no way that this can be equated to the actual use of >force. And if you do believe that definition of stealing, I'll do your >bookkeeping for free - and I won't steal from you. You are seriously saying that people in this thread have not consistently described Microsoft's actions as analogous to an actual use of force? Have you read any of the thread? Do I need to dig out more quotes? These are all from early in the thread, long before the posts you are complaining about: "The choice was go along with MS arm twisting or go out of business." and "To my way of thinking what MS did was similar to a the only magasine wholesaler in town telling retailers it had to sell kiddie porn under the table or pay full retail for all magazines." However, you may be right that some of my replies to you may not have been justified as responses to just what you said. It'd take a lot of digging through the thread to figure that out. ;) DS From nicopernetty at nowhere.fr Fri Oct 7 16:45:33 2005 From: nicopernetty at nowhere.fr (Nicolas Pernetty) Date: Fri, 7 Oct 2005 22:45:33 +0200 Subject: Continuous system simulation in Python References: <20051007011222.1aeab426@linuxcestcomplique.fr> <1128708054.819697.232950@o13g2000cwo.googlegroups.com> Message-ID: <20051007224533.08bde751@linuxcestcomplique.fr> Hello Phil, Yes I have considered Octave. In fact I'm already using Matlab and decided to 'reject' it for Python + Numeric/numarray + SciPy because I think you could do more in Python and in more simple ways. Problem is that neither Octave, Matlab and Python offer today a framework to build continuous system simulator (in fact Matlab with Simulink and SimMechanics, do propose, but I was not convinced at all). Regards, *********** REPLY SEPARATOR *********** On 7 Oct 2005 11:00:54 -0700, phil_nospam_schmidt at yahoo.com wrote : > Nicholas, > > Have you looked at Octave? It is not Python, but I believe it can talk > to Python. > Octave is comparable to Matlab for many things, including having ODE > solvers. I have successfully used it to model and simulate simple > systems. Complex system would be easy to model as well, provided that > you model your dynamic elements with (systems of) differential > equations. > From gsakkis at rutgers.edu Mon Oct 10 09:53:12 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Mon, 10 Oct 2005 09:53:12 -0400 Subject: Comparing lists References: <1128930699.799657.146210@g47g2000cwa.googlegroups.com> Message-ID: <1128952417.0544cc73190bbbd4e683448c137969c8@teranews> "Christian Stapfer" wrote: > wrote: > > try to use set. > > Sorting the two lists and then extracting > A-B, B-A, A|B, A & B and A ^ B in one single > pass seems to me very likely to be much faster > for large lists. Why don't you implement it, test it and time it to be more convincing about your intuition ? George From http Wed Oct 5 04:48:42 2005 From: http (Paul Rubin) Date: 05 Oct 2005 01:48:42 -0700 Subject: dictionary interface References: Message-ID: <7xll18gxhx.fsf@ruckus.brouhaha.com> Antoon Pardon writes: > But that is contradicted by the unittest. If you have a unittest for > comparing dictionaries, that means comparing dictionaries has a > testable characteristic and thus is further defined. No, I don't think so. The unittest makes sure that a particular implementation works as intended. That doesn't mean that every part of the of how that particular implementation works is required by the language definition. It can have some non-required (but non-forbidden) characteristics and those could still get tested. From mwm at mired.org Fri Oct 21 19:00:25 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 21 Oct 2005 19:00:25 -0400 Subject: how to modify text in html form from python References: <0Ra6f.5050$q%.616@newssvr12.news.prodigy.com> <86d5lyu0j8.fsf@bhuda.mired.org> <%Tb6f.5062$q%.3600@newssvr12.news.prodigy.com> <864q7atxcv.fsf@bhuda.mired.org> Message-ID: <86vezqscfq.fsf@bhuda.mired.org> "Philippe C. Martin" writes: >> You've got lots of stuff going on here. I count at least five programs >> and three network connections. How much is working, and which parts >> are you trying to do in Python? > > I am starting from existing applications (cross-platform - and in python > 99% ) that work even through tcp-ip (sockets). > > I am just trying to apply them to a web environement. > > So prior to any user interaction with the page, I need some data exchange > between the plugin and the server (authentication). I don't know much about plugins. I believe they get started when the page loads, which gives you a chance to do the authentication when you want it done. > So _if_ (I'm a web newbie) the server and the clien(plugin) could exchange > data through some form field, my prototype would be much further along. That won't work very well. HTML goes to the client to display. The server can put data in hidden form elements that code running on the client side can get to - and change - via the document object model (DOM). However, the only way to send the changed data back to the server is to get the client to submit the form. You can automate that, but the results will be disconcerting to the user: they load a page, and it reloads multiple times as the plugin exchanges data with the server. > Here is a small picture: > Smart Card <-> driver <-> cgi <-> apache ...... [NET]........ browser <-> > plugin <-> driver <-> Smart Card The problem with this is that the apache<->browser connection isn't "a" connection, it's a series of HTTP request/repsonse pairs. Originally, this implied tearing down and setting up a TCP connection for every request. Modern software will leave the link open and reuse it - but modern software also tends to have multiple connetions open, so it can fetch images and other embedded objects in parallel. You can make this work, but doing it like that requires making multiple HTTP requests via the browser, which will be disconcerting. I'd recommend taking the browser out of the loop. Have the plugin talk directly to the server to do the authentication. That's what the latest web buzzword (AJAX) does: client-side software makes independent requests of the server (or *any* server) to get data, and possibly updates the document the browser is viewing as a result of that. So here's a scenario: the first cgi script gets info from the smart card that puts it in a hidden form element and sends the page to the browser. The plugin - started when the page loads - uses the DOM to get that data, then makes an *independent* HTTP request to the server, thus passing whatever it generated from the data in the form field to a second cgi script. This happens several times, then the plugin changes the HTML form to put whatever the cgi script generated into the form, so that when the user finally submits the form, the third cgi script - the one that handles the submitted form - sees the data from the second script. Actually, the exchanges between the plugin and the server don't need to be HTTP requests. If you've got this working over some other TCP protocol, there's no reason you can't keep doing it that way. A word of warning: authentication protocols are fragile; they tend to stop being resistant to attacks after even relatively minor changes, so you want to be very carefull about changing the protocol. Web-based things are very open. You can't really do much to prevent the client end from doing *whatever they want* with the HTML you send them, or you generate for them on the fly. This also has serious security implications. Think carefully about what happens when the user pulls one of your forms out of the browser history, or bookmarks a page. Then make sure you get a thorough audit of the resulting system/protocol done by people who know what they're doing. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From fredrik at pythonware.com Sat Oct 8 10:22:06 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 8 Oct 2005 16:22:06 +0200 Subject: Help creating extension for C function References: <1128714478.552412.135950@g47g2000cwa.googlegroups.com> Message-ID: "Java and Swing" wrote: >I need to write an extension for a C function so that I can call it > from python. > > C code (myapp.c) > ====== > typedef unsigned long MY_LONG; > > char *DoStuff(char *input, MY_LONG *x) { ... } > > so you pass in a string and an array of MY_LONGS...such as > > MY_LONGS vals[10] = {....}; > char *input = "this is my input"; > char *result; > > result = DoStuff(input, vals); > > ...I need to create an extension so that I can call this from Python > such as... > >>> import myapp >>> vals = [1,2,3,4,5,6,7,8,9,10] >>> input = "this is my input" >>> result = myapp.DoStuff(input, vals) >>> print result > > ideally the result would be a String, vals would be a list and input > would be a string. $ more module.c /* $Id$ */ /* a module */ #include "Python.h" static long* get_long_array(PyObject* data, int* data_size) { int i, size; long* out; PyObject* seq; seq = PySequence_Fast(data, "expected a sequence"); if (!seq) return NULL; size = PySequence_Size(seq); if (size < 0) return NULL; if (data_size) *data_size = size; out = (long*) PyMem_Malloc(size * sizeof(long)); if (!out) { Py_DECREF(seq); PyErr_NoMemory(); return NULL; } for (i = 0; i < size; i++) out[i] = PyInt_AsLong(PySequence_Fast_GET_ITEM(seq, i)); Py_DECREF(seq); if (PyErr_Occurred()) { PyMem_Free(out); out = NULL; } return out; } static PyObject* do_stuff(PyObject* self, PyObject* args) { int i; long* vals; int vals_size; char* my_result; char* input; PyObject* vals_in; if (!PyArg_ParseTuple(args, "sO:do_stuff", &input, &vals_in)) return NULL; vals = get_long_array(vals_in, &vals_size); if (!vals) return NULL; if (vals_size != 10) { PyErr_SetString(PyExc_ValueError, "expected 10 values"); PyMem_Free(vals); return NULL; } /* do stuff */ printf("input = %s\n", input); for (i = 0; i < 10; i++) printf("vals[%d] = %ld\n", i, vals[i]); my_result = "result"; /* done */ PyMem_Free(vals); return PyString_FromString(my_result); } static PyMethodDef functions[] = { {"do_stuff", do_stuff, METH_VARARGS}, {NULL, NULL} }; PyMODINIT_FUNC initmodule(void) { Py_InitModule4( "module", functions, "my module", NULL, PYTHON_API_VERSION ); } $ more setup.py # $Id$ # a setup file from distutils.core import setup, Extension setup( name="module", ext_modules = [Extension("module", ["module.c"])] ) $ python setup.py build_ext -i ... $ python >>> import module >>> vals = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> input = "this is some input" >>> result = module.do_stuff(input, vals) input = this is some input vals[0] = 1 vals[1] = 2 vals[2] = 3 vals[3] = 4 vals[4] = 5 vals[5] = 6 vals[6] = 7 vals[7] = 8 vals[8] = 9 vals[9] = 10 >>> result 'result' From duncan.booth at invalid.invalid Thu Oct 6 17:03:49 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 6 Oct 2005 21:03:49 GMT Subject: Lambda evaluation References: Message-ID: Jp Calderone wrote: > On Thu, 06 Oct 2005 16:18:15 -0400, Joshua Ginsberg > wrote: >>So this part makes total sense to me: >> >>>>> d = {} >>>>> for x in [1,2,3]: >>... d[x] = lambda y: y*x >>... >>>>> d[1](3) >>9 >> >>Because x in the lambda definition isn't evaluated until the lambda is >>executed, at which point x is 3. >> >>Is there a way to specifically hard code into that lambda definition >>the contemporary value of an external variable? In other words, is >>there a way to rewrite the line "d[x] = lambda y: y*x" so that it is >>always the case that d[1](3) = 3? > > There are several ways, but this one involves the least additional > typing: > > >>> d = {} > >>> for x in 1, 2, 3: > ... d[x] = lambda y, x=x: y * x > ... > >>> d[1](3) > 3 > > Who needs closures, anyway? :) > Just for completeness, here's the lambda free closure version: >>> def timesx_factory(x): def timesx(y): return y * x return timesx >>> d = dict((x, timesx_factory(x)) for x in range(1,4)) >>> d[1](3) 3 >>> d[2](3) 6 >>> From pmartin at snakecard.com Mon Oct 24 16:41:57 2005 From: pmartin at snakecard.com (Philippe C. Martin) Date: Mon, 24 Oct 2005 20:41:57 GMT Subject: python cgi script not understood as html References: <80b7f.6738$tV6.6215@newssvr27.news.prodigy.net> Message-ID: It is, thanks. Philippe Peter Hansen wrote: > Philippe C. Martin wrote: >> The following code outputs the actual HTML text to the browser, not the >> interpreted text. >> >> html_ok = """ >> Content-Type: text/html\n >> > "http://www.w3.org/TR/html4/loose.dtd">\n > > HTTP header lines must end with \r\n, not just with \n. Not sure this > is the solution to your specific problem though... > > -Peter From dhwild at talktalk.net Tue Oct 4 14:11:56 2005 From: dhwild at talktalk.net (David H Wild) Date: Tue, 04 Oct 2005 19:11:56 +0100 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> Message-ID: <4db4aeba37dhwild@talktalk.net> In article <3nd5k1dhv77j1bs88qjdl66cc0jnattvka at 4ax.com>, Roedy Green wrote: > >I think e-mail should be text only. > I disagree. Your problem is spam, not HTML. Spam is associated with > HTML and people have in Pavlovian fashion come to hate HTML. > But HTML is not the problem! HTML in email is a problem. It makes emails much bigger, and senders often "show off" by including irrelevant things in what they send just because they can. > That is like hating all choirs because televangelists use them. It is not unreasonable to hate choirs singing advertising jingles. Choirs, like HTML, have their place, but it isn't in emails. -- David Wild using RISC OS on broadband From robert.kern at gmail.com Mon Oct 10 11:25:00 2005 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 10 Oct 2005 08:25:00 -0700 Subject: Confused on Kid In-Reply-To: <1128957144_131989@spool6-east.superfeed.net> References: <1128957144_131989@spool6-east.superfeed.net> Message-ID: Brandon K wrote: > Hey, so I heard about the TurboGears posting and decided to investigate. > I watched some of their video on building a wiki in 20 minutes and > was totally blown away because I'm used to python...straight python, not > melding together 4 different APIs into one to blah blah. ANYWAY. I was > investigating each subproject individually and could not, for the life > of me figure out how Kid worked. I understand that it takes a > well-formed XML document and transforms it, but I could not figure out > where it transforms it, or how to transform a document. They have > plenty of template examples, but I'm left say, "What do I do with this?" > I know I can't just pop in it a browser because it has no sort of style > sheet or anything so it would just render as an XML document. What do > you do after you have a kid template? Did you read the documentation? http://kid.lesscode.org/guide.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 rbt at athop1.ath.vt.edu Fri Oct 7 16:58:28 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Fri, 07 Oct 2005 16:58:28 -0400 Subject: socketServer questions In-Reply-To: <7xll15paha.fsf@ruckus.brouhaha.com> References: <1128699247.9040.15.camel@athop1.ath.vt.edu> <7xll15paha.fsf@ruckus.brouhaha.com> Message-ID: <1128718708.7800.2.camel@athop1.ath.vt.edu> On Fri, 2005-10-07 at 09:17 -0700, Paul Rubinhttp: wrote: > > 3. How do I keep people from tampering with the server? The clients > > send strings of data to the server. All the strings start with x and > > end with y and have z in the middle. Is requiring x at the front and > > y at the back and z someplace in the middle enough to keep people > > out? I'm open to suggestions. > > It only keeps them out if they don't know to use that x..y..z pattern > and maybe not even then. Get a copy of "Security Engineering" by > Ross Anderson to have an idea of what you're dealing with, especially > if your server controls something valuable. The server just logs data, nothing else. It's not private or important data... just sys admin type stuff (ip, mac addy, etc.). I just don't want some script kiddie discovering it and trying to 'hack' it. By doing so, they'd fill the log up with crap. So, If the data doesn't contain x, y, and z and if the data is too big or too small, I record it to a 'tamper' log and tell the leet hacker to 'go away'. From lasse at vkarlsen.no Thu Oct 27 09:12:47 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Thu, 27 Oct 2005 15:12:47 +0200 Subject: Microsoft Hatred FAQ In-Reply-To: <9bj1m11k5l9h5pq2dt4evpp5a2qbsqgfsn@4ax.com> References: <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> <9bj1m11k5l9h5pq2dt4evpp5a2qbsqgfsn@4ax.com> Message-ID: Roedy Green wrote: > On Thu, 27 Oct 2005 04:06:16 -0700, "David Schwartz" > wrote, quoted or indirectly quoted someone who > said : > > >> Right I understand that. You could have complied simply by only selling >>computers with Windows preinstalled. In other words, you could have treated >>this the same as a demand for franchise or exclusivity if you had wanted to. > > > It is obvious to everyone WHY MS did this, to maintain monopoly. But > ignore motive for a while and see what they actually did and exactly > how they intended to carry out he threat of destroying my business. > What they did is clearly criminal. The hard part is proving it. Like > any smart criminal who makes a threat, MS left no paper trail.. > 2. it was a threat to force me to commit a criminal act -- namely > extract money from people and hand it to Microsoft and give those What, specifically, is the criminal act of which you speak? -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From mwm at mired.org Fri Oct 7 08:53:06 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 07 Oct 2005 08:53:06 -0400 Subject: Python recipes: list mixin, improved timeit, etc References: Message-ID: <86u0fto5e5.fsf@bhuda.mired.org> Steven D'Aprano writes: > On Thu, 06 Oct 2005 21:03:33 -0700, barnesc wrote: >> I added some recipes to the Python Cookbook: >> >> - listmixin >> >> Use ListMixin to create custom list classes from a small subset of >> list methods: >> >> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440656 > > That looks great. Now, if only I understood mixins: what are they, and > what they are for, and in particular, how they differ from mere > subclassing. One way to look at it is that mixins are a special case of subclassing. They aren't different, just specific. Mixins are abstract. Using Paul's example, you'd never declare a ScrollBar object, only subclasses that also inherit from some form of Window. Mixins are about behavior, not type. If you have real mixins, then an object of a class that inherits from a mixin is not an instance of the mixin class. Mixins are one way to deal with the lack of multiple inheritance. But even languages with multiple inheritance find the idea useful. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From my_email_is_posted_on_my_website at munged.invalid Sun Oct 9 16:15:12 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sun, 09 Oct 2005 20:15:12 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <868xx3m2ve.fsf@bhuda.mired.org> Message-ID: On Sun, 09 Oct 2005 05:55:01 -0400, Mike Meyer wrote or quoted : >Virus writers will love the ability to >change peoples address books remotely. Since this is just a broad brush view, I find it odd you can predict just what bugs there will be in the early implementations. You sound almost as if you were the author of the current system and feel personally attacked by others looking for ways to improve it. In my scheme, every message is digitally signed, even a change of address message. Surely for a virus to send out a digitally signed change of address message is more difficult than sending out an unsigned one, which they can do today. You have two problems you want to avoid: 1. the practical problem: failure to inform your correspondents, not just your address list, of your new address (at least the ones you don't consider spam or pests). 2. the potential problem: rogue software sending out fake change of address notices. In my scheme, The receiver of the change of address message ignores it unless it is properly signed. Surely that is a more secure system than we have today and that handles (1) without effort. At worst, a very clever virus could change the one address book entry, the one for this computer, in other's machines. It could not generally corrupt other machines. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From mail at tuxipuxi.org Sat Oct 8 15:36:00 2005 From: mail at tuxipuxi.org (Michael Goettsche) Date: Sat, 8 Oct 2005 21:36:00 +0200 Subject: new forum -- homework help/chit chat/easy communication In-Reply-To: References: <1128798687.305818.66010@g49g2000cwa.googlegroups.com> Message-ID: <200510082136.00441.mail@tuxipuxi.org> On Saturday 08 October 2005 21:15, Lasse V?gs?ther Karlsen wrote: > csheppard91 at gmail.com wrote: > > I've launched a new forum not too long ago, and I invite you all to go > > there: www.wizardsolutionsusa.com (click on the forum link). We offer > > all kinds of help, and for those of you who just like to talk, there's > > a chit chat section just for you...Just remember that forum > > communication is much easier, safer, and faster. > > Easier than what? Having to look into each forum to see if something is > new? That's easier? > Safer than what? Using a web browser? That's safe? > Faster? That page loads 10 posts in the same speed I get 700 posts with > usenet. Besides that, it's cheap advertising. Would it have been harder to post the direct forum link than to link to his company's website? From rupole at hotmail.com Fri Oct 21 09:49:43 2005 From: rupole at hotmail.com (Roger Upole) Date: Fri, 21 Oct 2005 09:49:43 -0400 Subject: pushing python to multiple windows machines References: <1129895063.490493.26360@g44g2000cwa.googlegroups.com> Message-ID: <1129902835_5439@spool6-east.superfeed.net> wrote: >I am working on a project that requires python to be installed on a > large number of windows servers and was wondering if anyone has found a > method to do this. I found the article from 2003, but nobody ever > stated that they have found an option for this. > > http://groups.google.com/group/comp.lang.python/browse_frm/thread/f42f0813bc271995?tvc=1&q=%22Pushing+Python+to+Windows+workstations%22 > > -shawn > You can use WMI to install an Msi installer on a remote machine. The Win32_Product class has an Install method: import win32com.client wmi=win32com.client.gencache.EnsureDispatch('wbemscripting.swbemlocator',0) s=wmi.ConnectServer('servername') p=s.Get('win32_product') inparams=p.Methods_('Install').InParameters inparams.Properties_('PackageLocation').Value=r'\\someserver\someshare\python-2.4.2.msi' inparams.Properties_('AllUsers').Value=True outparams=p.ExecMethod_('Install',inparams) print outparams.Properties_('ReturnValue') ## zero on success Roger ----== 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 http Fri Oct 7 13:04:03 2005 From: http (Paul Rubin) Date: 07 Oct 2005 10:04:03 -0700 Subject: Objects with different data views References: Message-ID: <7xhdbtdzss.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Anyone have any good ideas for how I should implement this? These days you can use properties. Before, you'd have had to do it manually with __setattr__ / __getattr__ methods. Here's how I'd do it with properties, if I have the math right. You're using a and b as the canonical values of the variables, computing x and y from them, and adjusting them when x and y change. class Parrot(object): x = property(getx, setx) y = property(gety, sety) def getx(self): return self.a + self.b def setx(self, x): y = self.y # calls gety self.a, self.b = 2*x - y, y-x def gety(self): return self.a + 2*self.b def sety(self, y): x = self.x # calls getx self.a, self.b = 2*x - y, y-x From steve at holdenweb.com Fri Oct 14 00:34:29 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 14 Oct 2005 05:34:29 +0100 Subject: FORM data in cgi In-Reply-To: <864q7lugp2.fsf@bhuda.mired.org> References: <864q7lugp2.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > "jponiato" writes: > > >>Greetings. >>An HTML form submits it's data to a python cgi script on my server. This script accepts this POST data, and uses urllib.urlopen() to call a different cgi script (on an external server), passing this same data. I'm using cgi.FieldStorage() to create a mapping of the FORM data, then using urllib.urlencode() to turn it back into form data for urlopen(). >>Question - is there a more efficient way to do this? > > > Yes. But the question you should be asking is "Is there an easier way > to do it that's worth doing?" > > Unless you're passing around files, or really huge forms, the amount > of time you spend doing decoding and encodinng the form data will be > pretty trivial. Unless you're really pressed for cycles, why bother > fixing it? And if you're really pressed for cycles, you should start > by instrumenting things to make sure that you're optimizing something > that will do you some good. > > Anyway, the general idea is to skip cgi.FieldStorage, and parse the > request yourself. You'll have to deal with the headers. But you can > just grab the post data with a read(). I'm not sure you can use urllib > to send pre-encoded POST data; you'll have to check that yourself. If > not, you'll have to do the HTTP request processing by yourself. That's > not hard, though. > > References: <43498D3C.90908@cc.umanitoba.ca> Message-ID: <4349A3CA.5050402@cc.umanitoba.ca> Fredrik Lundh said unto the world upon 2005-10-09 17:49: > Brian van den Broek wrote: > > >>But the academic issue "How/Can it be done?" still itches. > > > class __TwoUnderBase(object): > def __init__(self): > if self.__class__.__name__ == "__TwoUnderBase": > print "From __TwoUnderBase" > else: > print "From subclass", > > Thanks Fredrik. Brian vdB From davids at webmaster.com Thu Oct 27 09:14:35 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 06:14:35 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <1130417205.892409.230580@g14g2000cwa.googlegroups.com> Message-ID: Lasse V?gs?ther Karlsen wrote: > I would think that if I set up a shop and wanted to have the word > "Microsoft" as part of the shop name, there would be some rules > dictating what products I could and could not sell, yes. Wether those > rules are set forth in a law somewhere or Microsoft set them forth > themselves, I would find it hard to believe that the law would > prohibit them from doing so. > Otherwise I could set up a shop, call it "Microsoft Porsgrunn" and > sell machines with only Linux installed. > I think Microsoft would be allowed to say "No, you can't do that". Burger King won't let you sell Whoppers or buy their burger patties wholesale no matter what you want to call your store unless you take the whole franchise deal. It's an all-or-nothing package. With very few limits, companies do get to choose how their products are branded, marketed, and sold. DS From steve at holdenweb.com Sun Oct 16 05:42:00 2005 From: steve at holdenweb.com (Steve Holden) Date: Sun, 16 Oct 2005 10:42:00 +0100 Subject: Good news and bad news!! In-Reply-To: <1129306635.757572.214590@f14g2000cwb.googlegroups.com> References: <1129306635.757572.214590@f14g2000cwb.googlegroups.com> Message-ID: grant.bodie at gmail.com wrote: > The Bad news is i am an IT Recruiter......The good news is that i have > a great role for a developer with strong Python skills. > > Ideally along with that they will have Java and either an understanding > of Agile development or experience in using Ruby. > > ?35 - ?45k, London > > Contact me for more information > 01189897601 > grant at connectionsrecruit.co.uk > Grant: For future reference, did you know about jobs at python.org? Mailings to that address will (mostly, this is a volunteer effort) result in a posting on http://www.python.org./Jobs.html. Read the HOWTO link there for more details. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From onurb at xiludom.gro Tue Oct 18 04:28:23 2005 From: onurb at xiludom.gro (bruno modulix) Date: Tue, 18 Oct 2005 10:28:23 +0200 Subject: Vim capable IDE? In-Reply-To: <1129603486.291175.167860@f14g2000cwb.googlegroups.com> References: <1129603486.291175.167860@f14g2000cwb.googlegroups.com> Message-ID: <4354b229$0$21286$626a54ce@news.free.fr> Chris Lasher wrote: > Hello, > Is there a Python-sensitive, Linux compatible IDE out there with > standard bells and whistles (source browser, symbolic debugger, etc.) > but with the action-per-keystroke editing capabilities of Vim? I have > failed to turn up such an IDE in my Googling and IDE project-page > browsing. :-( What about a Python IDE that embed Vim as it's editor ? http://pida.berlios.de/index.php/Main_Page HTH -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From juicy_killa at hotmail.com Tue Oct 4 06:02:34 2005 From: juicy_killa at hotmail.com (accolades) Date: 4 Oct 2005 03:02:34 -0700 Subject: IDE crash Message-ID: <1128417896.844932.154240@o13g2000cwo.googlegroups.com> We've discussed this before in the group; IDEs that crash on completion of a PyGame or PyOgre (or any other graphics library) script. I have had this result with pretty much every IDE that I have tried. Except Eclipse. I just wanted to let everyone know, (in case anyone else out there is picky about being able to launch their program from within an IDE) that Eclipse with PyDev or TruStudio does not crash upon exit of graphics mode applications. I have been using Eclipse with PyDev exclusively for a few weeks now, and I am very pleased with the results. From felix at keyremovethisghost.com Wed Oct 19 23:55:39 2005 From: felix at keyremovethisghost.com (Felix Collins) Date: Thu, 20 Oct 2005 16:55:39 +1300 Subject: Trouble with win32com and MS Project In-Reply-To: References: Message-ID: <%yE5f.1520$S24.104343@news.xtra.co.nz> Felix Collins wrote: > Hi, > > I'm trying to assign a resource to a task in MS Project by using the > example from MSDN for VB... > > > "Use the Add method to add an Assignment object to the Assignments > collection. The following example adds a resource identified by the > number of 212 as a new assignment for the specified task. > > ActiveProject.Tasks(1).Assignments.Add ResourceID:=212" > > My code fragment for Python... > > proj.Tasks(3).Assignments.Add(ResourceID=2) I managed to get this to work by providing the TaskID which is supposed to be an optional argument. I wonder if the win32com wrapper is stuffing this up. Is late binding responsible perhaps? So the code that works is... proj.Tasks(3).Assignments.Add(TaskID= 3,ResourceID=2) incidently this also works... proj.Tasks(3).Assignments.Add(TaskID= 5,ResourceID=2) which does seems a bit strange.... From larry.bates at websafe.com Fri Oct 21 11:49:52 2005 From: larry.bates at websafe.com (Larry Bates) Date: Fri, 21 Oct 2005 10:49:52 -0500 Subject: HELP! py2exe error - No module named decimal In-Reply-To: References: Message-ID: <43590E20.5020908@websafe.com> FYI there is a separate newsgroup for py2exe at gmane.comp.python.py2exe. You may want to post there also. Just as a suggestion, put an import decimal at the top of your program. It looks like _mssql might be doing dynamic imports in __load method which will "confuse" py2exe because it can't know about dynamic imports which happen at runtime. -Larry Bates Chris wrote: > I've just completed a project using the following (Windows XP, python > 2.4.1, wxpython 2.6, and pymssql 0.7.3). The program runs great, but > after I convert it to an exe (required for this project), it gives me > the following error when I try to run it. > > Traceback (most recent call last): > File "EstUpdate.py", line 6, in ? > File "frmSplash.pyc", line 9, in ? > File "pymssql.pyc", line 23, in ? > File "_mssql.pyc", line 9, in ? > File "_mssql.pyc", line 7, in __load > ImportError: No module named decimal > > However, when I look in c:\python24\lib on the machine which ran py2exe, > I see decimal.py and decimal.pyc. > > Can someone please help with this? I'm supposed to start testing the > program today and I can't seem to move past this first step. > > Thanks!! > Chris From aleax at mail.comcast.net Mon Oct 31 10:00:49 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Mon, 31 Oct 2005 08:00:49 -0700 Subject: mixin helper class for unknown attribute access? References: Message-ID: <1h5ad4d.1a4a3zy1g39e3N%aleax@mail.comcast.net> Steven D'Aprano wrote: ... > Trying to prevent setting new attributes is a pretty heavy-handed act just > to prevent a tiny subset of errors. Many people argue strongly that even > if you could do it, it would be pointless -- or at least, the cost is far > greater than whatever small benefit there is. I entirely agree with you (also about the use of __slots__ being a particularly WRONG way to achieve this). When I have to suggest a mixin to avoid accidental setting of misspelled attributes (which does appear to be a clinically certifiable phobia of programmers coming to Python from certain other languages) I suggest something like: class Rats(object): def __setattr__(self, name, value): if hasattr(self, name): super(Rats, self).__setattr__(name, value) else: raise AttributeError, "can't set attribute %r" % (name,) The key idea is to exploit hasattr's semantics -- it checks the class as well as the specific instance. Example use case: class Bah(Rats): foo = bar = baz = 23 now, given b=Bah(), you can set b.foo, b.bar and b.baz, but no other attribute of b (of course you can bypass the restriction easily -- such restrictions are always intended against *accidental* cases, not against deliberate attacks). Differently from __slots__, Rats gives no problems with pickling, inheritance, etc, etc. Alex From cj at nowhere.com Sun Oct 9 03:02:52 2005 From: cj at nowhere.com (CJ) Date: Sun, 09 Oct 2005 07:02:52 GMT Subject: Here I am again, same old arguments Message-ID: Okay, same program, different issue. Thanks to the help that I was given I was able to complete my program to find variables in a list that were repeated, and display them once, and how many times they appeared in the list. And it worked great! But, being the perfectionist that I am, I wanted to make the proggie allow any size of list, and not have to be recoded every time. So step one was to not make the program reliant on the list itself being of X length all the time. Well, for some reason, the FOR loop is altering two of my lists. Using PRINT magic, I was able to narrow down the lines that were causing it. But the question remains: Why is it doing this? I'm sure there's a simple answer that I just overlooked in the manual or something. So without further ado, the code: #setup variables grub=[3,25,3,5,3,"a","a","BOB",3,3,45,36,26,25,"a",3,3,3,"bob","BOB",67] grubrpt=grub cntro=0 cntrt=0 rpt=0 skipped=0 #set up for variable length of grub ttllen=len(grub)-1 print "The heck is this for loop doing?" for point in range(0,ttllen,1): print "Here's Grub=",grub print "And grubrpt=",grubrpt grubrpt[point]="blk" #Makes sure that there are not multiple prints. def alrdy_dn(grub,grubrpt): if grub[cntro] in grubrpt: return grubrpt else: print grub[cntro],"appears in list",rpt,"times." grubrpt[grubrpt.index("blk")]=grub[cntro] return grubrpt #removes display of variables not repeated def no_rpts(skipped,grubrpt): if rpt==0: skipped=skipped+1 else: grubrpt=alrdy_dn(grub,grubrpt) return skipped #Main body of code print "The List is:",grub while cntro<>len(grub)-1: if grub[cntro]==grub[cntrt]: rpt=rpt+1 cntrt=cntrt+1 else: cntrt=cntrt+1 if cntrt==len(grub): skipped=no_rpts(skipped,grubrpt) cntro=cntro+1 cntrt=0 rpt=-1 print skipped,"list elements are unique." And the award winning Output: The heck is this for loop doing? Here's Grub= [3, 25, 3, 5, 3, 'a', 'a', 'BOB', 3, 3, 45, 36, 26, 25, 'a', 3, 3, 3, 'bob', 'BOB', 67] And grubrpt= [3, 25, 3, 5, 3, 'a', 'a', 'BOB', 3, 3, 45, 36, 26, 25, 'a', 3, 3, 3, 'bob', 'BOB', 67] Here's Grub= ['blk', 25, 3, 5, 3, 'a', 'a', 'BOB', 3, 3, 45, 36, 26, 25, 'a', 3, 3, 3, 'bob', 'BOB', 67] And grubrpt= ['blk', 25, 3, 5, 3, 'a', 'a', 'BOB', 3, 3, 45, 36, 26, 25, 'a', 3, 3, 3, 'bob', 'BOB', 67] Here's Grub= ['blk', 'blk', 3, 5, 3, 'a', 'a', 'BOB', 3, 3, 45, 36, 26, 25, 'a', 3, 3, 3, 'bob', 'BOB', 67] And grubrpt= ['blk', 'blk', 3, 5, 3, 'a', 'a', 'BOB', 3, 3, 45, 36, 26, 25, 'a', 3, 3, 3, 'bob', 'BOB', 67] It goes on like that, I'm not going to put all of it here for obvious reasons. But, if I take out the whole for loop and the lines relating to it and statically assign grubrpt as ["blk","blk"...] then the program runs wonderfully. From what I understand, you can never have too many functions, so I tried to make the grub "blk" a function and got the same result. I'm still nailing them down, so if my functions look a little weird you know why. Also, I do realize that there is an easier way to do this, I just created a little project for myself to learn the basics of the language. Thanks for all the help! -CJ From jmdeschamps at cvm.qc.ca Wed Oct 19 22:55:56 2005 From: jmdeschamps at cvm.qc.ca (jean-marc) Date: 19 Oct 2005 19:55:56 -0700 Subject: Python vs Ruby In-Reply-To: References: Message-ID: <1129776956.254389.188040@z14g2000cwz.googlegroups.com> I'd believe that would be Lua, but then again what is common to one might not be to another ;-) From zhu_dave at yahoo.com Mon Oct 10 18:02:30 2005 From: zhu_dave at yahoo.com (Dave) Date: Mon, 10 Oct 2005 15:02:30 -0700 (PDT) Subject: Python name lookups Message-ID: <20051010220230.98030.qmail@web30607.mail.mud.yahoo.com> Hello All, As far as I understand, Python deals with a lot of string objects, i.e. it looks up all names. Is there a way to find out how many name lookup operations take place in a Python program? Is it the name lookup operation or hash operation that degrades performance? What function does Python use for name lookup operations? Is it the lookdict function in Objects/dictobject.c? Thank you for your help! __________________________________ Start your day with Yahoo! - Make it your home page! http://www.yahoo.com/r/hs From lycka at carmen.se Fri Oct 14 10:12:27 2005 From: lycka at carmen.se (Magnus Lycka) Date: Fri, 14 Oct 2005 16:12:27 +0200 Subject: Adding a __filename__ predefined attribute to 2.5? In-Reply-To: <1129230950.305013.302200@g49g2000cwa.googlegroups.com> References: <1129098667.336115.303060@g47g2000cwa.googlegroups.com> <1129150883.303899.259570@g43g2000cwa.googlegroups.com> <1129230950.305013.302200@g49g2000cwa.googlegroups.com> Message-ID: Rune Strand wrote: > I've read a lot of your comments the last years. Your friendliness > always strikes me. Trying to be ironic? He *is* always right though! ;) If ones ideas are getting shut down by people like Fredrik and Steve, the rational reaction would be to assume that they are right and that it was a bad idea. Sure, it's ok to ask follow-up questions to understand why, but you can't expect everybody to spend as much time explaining as Alex did, and comments like "in your rush to pin-point lousy code, you didn't read that, I suppose" aren't exactly constructive. There are certainly postings made by various people in fora such as comp.lang.python that seem less friendly than one would prefer, and text based fora such as these obviously don't give the same immediate emotional feedback as face to face communication, so it's easy to hurt or get hurt, even if that's not what people intend. This is a small "cost" that comes with usenet and mailing lists, and I think it's clearly worth it for us who ask for help. If you've read a lot of Fredrik's comments the last years, I assume you've figured out by now that he knows Python very, very well, and spends a lot of time helping a lot of people. He also belongs to the fairly small group of people who've made significant contributions to the Python core and also written excellent third party modules. You might feel that he's a bit grumpy for your taste, but I think that we all owe him and many others on comp.lang.python a lot. Don't bite the hand that feeds you. I certainly prefer grumpy but good advice over friendly rubbish. /Magnus From rsteiner at visi.com Mon Oct 17 23:32:42 2005 From: rsteiner at visi.com (Richard Steiner) Date: Mon, 17 Oct 2005 23:32:42 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <11l29j29rq4jh18@corp.supernews.com> <8qs723-dr7.ln1@news.it.uc3m.es> <11l3kmgggj66800@corp.supernews.com> Message-ID: Here in comp.os.linux.misc, John Wingate spake unto us, saying: >Peter T. Breuer wrote: >> It seems to me that I was using 3.x. Maybe it was 3.1? I seem to >> remember an earlier major ... was there a 2.8 or 2.9? > >Dunno. The first version I used was 3.4, in 1987. MS-DOS 3.3 was the most popular DOS release back in 1987/1988. I don't recall there ever being a 3.4 release, though. -- -Rich Steiner >>>---> http://www.visi.com/~rsteiner >>>---> Mableton, GA USA OS/2 + eCS + Linux + Win95 + DOS + PC/GEOS + Executor = PC Hobbyist Heaven! WARNING: I've seen FIELDATA FORTRAN V and I know how to use it! The Theorem Theorem: If If, Then Then. From pmartin at snakecard.com Fri Oct 21 17:00:26 2005 From: pmartin at snakecard.com (Philippe C. Martin) Date: Fri, 21 Oct 2005 21:00:26 GMT Subject: how to modify text in html form from python References: <0Ra6f.5050$q%.616@newssvr12.news.prodigy.com> <86d5lyu0j8.fsf@bhuda.mired.org> <%Tb6f.5062$q%.3600@newssvr12.news.prodigy.com> <864q7atxcv.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > "Philippe C. Martin" writes: > > > > Some. To continue clarifying: > > The phrase "cgi script" refers to a server-side script that is run in > response to the user clicking something on the client. That's what you > expect it to be, right? > Yes, the cgi script on the server side hooks up to the local (server) smart card > Do you expect the plugin to display a form? Or to ouput a form that > the client will display? No, I want of all the "html" stuff to be handled by the server > > You've got lots of stuff going on here. I count at least five programs > and three network connections. How much is working, and which parts > are you trying to do in Python? I am starting from existing applications (cross-platform - and in python 99% ) that work even through tcp-ip (sockets). I am just trying to apply them to a web environement. So prior to any user interaction with the page, I need some data exchange between the plugin and the server (authentication). So _if_ (I'm a web newbie) the server and the clien(plugin) could exchange data through some form field, my prototype would be much further along. Here is a small picture: Smart Card <-> driver <-> cgi <-> apache ...... [NET]........ browser <-> plugin <-> driver <-> Smart Card Regards, Philippe > > <1128930699.799657.146210@g47g2000cwa.googlegroups.com><1128952417.0544cc73190bbbd4e683448c137969c8@teranews><434ba977@nntp0.pdx.net><1129216693.445956.155490@g47g2000cwa.googlegroups.com> Message-ID: "Fredrik Lundh" wrote in message news:mailman.2137.1129475887.509.python-list at python.org... > Christian Stapfer wrote: > >> As to the value of complexity theory for creativity >> in programming (even though you seem to believe that >> a theoretical bent of mind can only serve to stifle >> creativity), the story of the discovery of an efficient >> string searching algorithm by D.E.Knuth provides an >> interesting case in point. Knuth based himself on >> seemingly quite "uncreatively theoretical work" (from >> *your* point of view) that gave a *better* value for >> the computuational complexity of string searching >> than any of the then known algorithms could provide. > > are you talking about KMP? Yes. I cannot give you the source of the story, unfortunately, because I only have the *memory* of it but don't know exactly *where* I happended to read it. There, Knuth was said to have first analyzed the theoretical argument very, very carefully to figure out *why* it was that the theoretical bound was so much better than all "practically known" algorithms. It was by studing the theoretical work on computational complexity *only* that the light dawned upon him. (But of course, Knuth is "an uncreative dumbo fit only for production work" - I am speaking ironically here, which should be obvious.) > I'm not sure that's really a good example of > how useful "theoretical work" really is in practice: Oh sure, yes, yes, it is. But my problem is to find a good source of the original story. Maybe one of the readers of this thread can provide it? > the "better" computational complexity of KMP has > turned out to be mostly useless, in practice. Well, that's how things might turn out in the long run. Still, at the time, to all appearances, it *was* a case of practical creativity *triggered* by apparently purely theoretical work in complexity theory. More interesting than your trying to shoot down one special case of the more general phenomenon of theory engendering creativity would be to know your position on the more general question... It happens *often* in physics, you known. Einstein is only one example of many. Pauli's prediction of the existence of the neutrino is another. It took experimentalists a great deal of time and patience (about 20 years, I am told) until they could finally muster something amounting to "experimental proof" of Pauli's conjecture. Regards, Christian -- "Experience without theory is blind, but theory without experience is mere intellectual play." - Immanuel Kant ?Experience remains, of course, the sole criterion of the *utility* of a mathematical construction. But *the*creative*principle* resides in mathematics.? - Albert Einstein: ?The World As I See It? ?The astronomer Walter Baade told me that, when he was dining with Pauli one day, Pauli exclaimed, "Today I have done the worst thing for a theoretical physicist. I have invented something which can never be detected experimentally." Baade immediately offered to bet a crate of champagne that the elusive neutrino would one day prove amenable to experimental discovery. Pauli accepted, unwisely failing to specify any time limit, which made it impossible for him ever to win the bet. Baade collected his crate of champagne (as I can testify, having helped Baade consume a bottle of it) when, just over twenty years later, in 1953, Cowan and Reines did indeed succeed in detecting Pauli?s particle.? - Fred Hoyle: ?Astronomy and Cosmology? From gandalf at designaproduct.biz Wed Oct 5 12:17:49 2005 From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy) Date: Wed, 05 Oct 2005 18:17:49 +0200 Subject: change a value to NULL? In-Reply-To: <2387F0EED10A4545A840B231BBAAC722607F0D@slcimail1.slcgov.com> References: <2387F0EED10A4545A840B231BBAAC722607F0D@slcimail1.slcgov.com> Message-ID: <4343FCAD.9020102@designaproduct.biz> Bell, Kevin wrote: >I'm pulling a list of numbers from MS Excel, but occasionally if there >is no data from excel, the value is an asterisk, but I need to make it >null. > >What is the best way to do that? Thus far, I'm using: > > >for value in myRange: > try: > intV = int(value) > print intV > except: > print "its an asterisk" > > I'm affraid I did not understand what is your real problem. Here is an answer, anyway. When converting a string intoto an int, you should use TypeError to trap type errors only: try: intV = int(value) except TypeError: intV = None print intV # It will be None if 'value' is not an int Best, Les From steve at holdenweb.com Thu Oct 20 11:44:57 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 20 Oct 2005 16:44:57 +0100 Subject: __getattr__, __setattr__ In-Reply-To: References: Message-ID: Thomas Heller wrote: > Just wondering about this behaviour, why is it this way? > > Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>>>object.__setattr__ > > > >>>>object.__getattr__ > > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: type object 'object' has no attribute '__getattr__' > 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. >>> object.__getattribute__ Ring any bells? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From rpmuller at gmail.com Tue Oct 25 13:35:53 2005 From: rpmuller at gmail.com (RickMuller) Date: 25 Oct 2005 10:35:53 -0700 Subject: distutils - distributing non-python data files Message-ID: <1130261753.871759.11690@g14g2000cwa.googlegroups.com> I really appreciate the ease that the distutils make distributing Python modules. However, I have a question about using them to distribute non-Python (i.e. text) data files that support Python modules. Currently when I have data of this type, I parse it into python objects and make a python module from it. In other words, given a data file like % cat grocery_list.txt eggs spam cheese I would make a data structure like grocery_list = ['eggs', 'spam', 'cheese'] which can be easily imported from a python file, and which the distutils installation programs make it easy for me to find on the Python path. Of course, the data I'm using is much more complex than this, but you get the idea. I'm starting to feel like this is a Bad Thing, because if the data file is distributed as a plain text file (e.g. data values in columns), I'm putting a barrier to updating the data if I have to parse a new file into Python. But I don't know whether there is a better way to include a file like 'grocery_list.txt' in my python distutils-distributed module so that I can get it from my other python modules? From onurb at xiludom.gro Mon Oct 24 04:14:04 2005 From: onurb at xiludom.gro (bruno modulix) Date: Mon, 24 Oct 2005 10:14:04 +0200 Subject: Python vs Ruby In-Reply-To: References: <4358d9f6$0$19694$626a14ce@news.free.fr> Message-ID: <435c97cd$0$14034$636a15ce@news.free.fr> Michael Ekstrand wrote: > On Friday 21 October 2005 07:07, bruno modulix wrote: > >>>>Python is more like Java. >> >> >>Err... Python is more like what Java would have been if Java was a >>smart dynamic hi-level object oriented language !-) >> > > > +1. Python is easily applicable to most of the problem domain of Java, > but solves problems much more elegantly. It just isn't shipped embedded > in all leading browsers :-(. It's been a long time since I last saw a Java applet on a website. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From mhellwig at xs4all.nl Sat Oct 15 15:55:16 2005 From: mhellwig at xs4all.nl (Martin P. Hellwig) Date: Sat, 15 Oct 2005 21:55:16 +0200 Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <4350b0ee$0$11061$e4fe514c@news.xs4all.nl> Message-ID: <43515eab$0$11078$e4fe514c@news.xs4all.nl> John Bokma wrote: > You mean like the lamp that keeps burning forever, like Philips has? > No more like all the hydrogen technologies that shell has in their possession for the last decades and only recently has begun to restart those projects. >> Although Commodore where never serious competitors, > > Because there programming skills were as worse as MS? I mean, their > BASIC had only 2 instuctions: PEEK and POKE? eehm Amiga? > > Yet you call NT slightly better compared to Windows 95. So you have no > clue what you're talking about. So I see you never worked serious with 3.5 . > >> hey I make money of them administrating them, >> however to state that if we didn't had MS we would been in the IT >> stone ages is blatantly wrong, > > Now there is truth. > >> I think we would have been a lot >> further > > No, since companies are just companies, not little gods like some want > them to be. > >> then where we are now. Perhaps we even had a other mainstream >> architecture like sparcs and powerpc's. > > But "crippled" like Intel. Yeah right sparc is crippled... From jepler at unpythonic.net Sun Oct 2 16:54:50 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Sun, 2 Oct 2005 15:54:50 -0500 Subject: Statement orders In-Reply-To: <3qaqvpFe1bjcU1@news.dfncis.de> References: <1128236799.839645.101270@g14g2000cwa.googlegroups.com> <3qanooFdu6okU1@news.dfncis.de> <3qaqvpFe1bjcU1@news.dfncis.de> Message-ID: <20051002205450.GA16201@unpythonic.net> > would it be advisable to guard against this with something like this? > > def perform_longrunning_calculation(): > if not app.busy: > app.busy = 1 [...] By using that kind of construct, instead of using update_idletasks(), you force all code to be aware of and manage the app.busy flag. Another difference is that with the original code changed to use update_idletasks(), perform_longrunning_calculation *will* be called twice, the second time after the first one completes. With your code, it will be called once if the second keypress comes within one second, and twice if called after one second is up. (though a second update before setting busy back to false will make it be called only once) So in also depends on what you want your application to do in these cases. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From almondb at gmail.com Mon Oct 31 19:35:31 2005 From: almondb at gmail.com (Brian) Date: 31 Oct 2005 16:35:31 -0800 Subject: looking for a good python module for MS SQL server In-Reply-To: References: Message-ID: <1130805331.741384.298320@g14g2000cwa.googlegroups.com> I've had good results with adodbapi as well. From grante at visi.com Tue Oct 11 10:29:37 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 11 Oct 2005 14:29:37 -0000 Subject: When someone from Britain speaks, Americans hear a "British accent"... References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <200510071643.11162.hancock@anansispaceworks.com> Message-ID: <11knj2hipq4q3b@corp.supernews.com> On 2005-10-10, Terry Hancock wrote: >> I must have been working at NASA at the time; they are well known for >> embiggening prices. > > Not nearly as much as the DoD, from what I hear. > > Truthfully, I think those stories are bit exaggerated -- I think the > real problem is somebody making a bad make/buy decision. They decide > to make something that they could easily have bought at the hardware > store. That and the combination of low volumes and the cost of testing. They want something seemingly simple (say a hammer), but they want it tested and certified to a particular set of functional and environmental specs. That takes literally man-years of effort, and then they only end up buying 3 of them. The cost of the testing gets divided by three and added onto the unit cost. -- Grant Edwards grante Yow! Jesus is my at POSTMASTER GENERAL... visi.com From steve at holdenweb.com Wed Oct 12 03:02:51 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 12 Oct 2005 08:02:51 +0100 Subject: A problem while using urllib In-Reply-To: <1129089078.852454.153800@f14g2000cwb.googlegroups.com> References: <1129024641.113182.74420@g49g2000cwa.googlegroups.com> <1h49slu.1gaj0nnmdk5ghN%aleax@mail.comcast.net> <1129089078.852454.153800@f14g2000cwb.googlegroups.com> Message-ID: Johnny Lee wrote: > Alex Martelli wrote: > >>Johnny Lee wrote: >> ... >> >>> try: >>> webPage = urllib2.urlopen(url) >>> except urllib2.URLError: >> >> ... >> >>> webPage.close() >>> return True >>>---------------------------------------------------- >>> >>> But every time when I ran to the 70 to 75 urls (that means 70-75 >>>urls have been tested via this way), the program will crash and all the >>>urls left will raise urllib2.URLError until the program exits. I tried >>>many ways to work it out, using urllib, set a sleep(1) in the filter (I >>>thought it was the massive urls crashed the program). But none works. >>>BTW, if I set the url from which the program crashed to base url, the >>>program will still crashed at the 70-75 url. How can I solve this >>>problem? thanks for your help >> >>Sure looks like a resource leak somewhere (probably leaving a file open >>until your program hits some wall of maximum simultaneously open files), >>but I can't reproduce it here (MacOSX, tried both Python 2.3.5 and >>2.4.1). What version of Python are you using, and on what platform? >>Maybe a simple Python upgrade might fix your problem... >> >> >>Alex > > > Thanks for the info you provided. I'm using 2.4.1 on cygwin of WinXP. > If you want to reproduce the problem, I can send the source to you. > > This morning I found that this is caused by urllib2. When I use urllib > instead of urllib2, it won't crash any more. But the matters is that I > want to catch the HTTP 404 Error which is handled by FancyURLopener in > urllib.open(). So I can't catch it. > I'm using exactly that configuration, so if you let me have that source I could take a look at it for you. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From lasse at vkarlsen.no Sat Oct 8 14:51:08 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Sat, 08 Oct 2005 20:51:08 +0200 Subject: Function decorator that caches function results In-Reply-To: <1128796692.f0f5a29fda81a72649660a18751c0512@teranews> References: <1128796692.f0f5a29fda81a72649660a18751c0512@teranews> Message-ID: George Sakkis wrote: > Cool, you re-invented the memoization pattern: > http://en.wikipedia.org/wiki/Memoization > http://aspn.activestate.com/ASPN/search?query=memoize&x=0&y=0§ion=PYTHONCKBK&type=Subsection > > Yes, it's kinda discouraging that most interesting ideas have already been conceived, implemented > and used by others... I know, I've been scouring over the ASPN recipes and digging through code like there's no tomorrow. But, I don't view it as pointless even though there are existing implementations and solutions out there. First of all, I don't like to stuff a lot of what is obviously library type of code into a project, unless I can reference a library that got that function or class or whatnot. Creates a rather big maintenance nightmare :) So, I would have to stuff that into a library, which is what I did with my "own" function (thank you for helping btw). The recipe on ASPN is probably better than what I got, but... I understand how my solution came about and what makes it tick. Secondly, I've been "programming" Python for, what, about 11 days now or so, so I want to re-implement as much as possibly right now, even to the point where I create a worse solution than an existing one, as long as it works for me, just to be able to learn the nuances of Python, because Python is ... different than what I'm used to. For instance, in C# and .NET you got attributes, but they don't actually do anything on their own, in other words you can't tag a method and have the operation of that method deviate from a similar method without the attribute, unless you pick one of the attributes the compiler knows about, so it's just meta-data that sits silent until some other method goes around to look for it. In Python I've now learned that a function is just an object like everything else and I can wrap a new object around it to modify its behaviour, and I can use the decorator pattern to do it. I'm probably going to be back here in a few days or even hours with another "task" where you can probably cough up dozens of existing source code solutions that I could use. For instance, there's this thing I've heard of called the "wheel"..... :) -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From gsakkis at rutgers.edu Fri Oct 7 09:28:24 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Fri, 7 Oct 2005 09:28:24 -0400 Subject: Merging sorted lists/iterators/generators into one stream of values... References: <1128667968.421469.180910@g47g2000cwa.googlegroups.com> Message-ID: <1128691708.c6930b5cb9f3673ed3abe8755178d163@teranews> "Lasse V?gs?ther Karlsen" wrote: > Ok, that one looks more sleak than what I came up with. For the most efficient and elegant solution, check out Raymond Hettinger's reply to: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/141934 George From csubich.spam.block at spam.subich.block.com Wed Oct 19 08:46:38 2005 From: csubich.spam.block at spam.subich.block.com (Christopher Subich) Date: Wed, 19 Oct 2005 08:46:38 -0400 Subject: Yes, this is a python question, and a serious one at that (moving to Win XP) In-Reply-To: References: <434f8a54$0$16641$626a14ce@news.free.fr> Message-ID: Chris Lambacher wrote: > The shell that comes with MSys (from the MinGW guys). Is pretty good, although > it does have a bit of a problem with stdout output before a process exits, ie > it will hold back output until the process exits. > > As a bonus, the file system is a little more sane, and if you are interested > in compiling software that is not open source, you are not tied to the Cygwin > DLL which is GPLed. Worth mentioning here that cygwin's gcc does allow a -mno-cygwin compile-time flag to not link against the cygwin dll. Cygwin's packaging system also includes the MinGW development libraries as an easily installable option, for compiling against mingw's stuff; I've done it for Python extensions, in fact. From karczma at info.unicaen.fr Thu Oct 13 12:12:01 2005 From: karczma at info.unicaen.fr (Jerzy Karczmarczuk) Date: Thu, 13 Oct 2005 18:12:01 +0200 Subject: Technical question on complexity. Message-ID: Anybody knows where I can find a concrete and guaranteed answer to the following extremely basic and simple question? What is the complexity of appending an element at the end of a list? Concatenating with another? The point is that I don't know what is the allocation policy... If Python lists are standard pointer-chained small chunks, then obviously linear. But perhaps there is some optimisation, after all a tuple uses a contiguous chunk, so it *might* be possible that a list is essentially equivalent to an array, with its length stored within, and adding something may be done in constant time (unless the whole stuff is copied, which again makes the complexity related to the size of existing structure...) It is probably possible to retrieve this information from the sources, but I try first an easier way. Thank you. Jerzy Karczmarczuk From cfajohnson at gmail.com Wed Oct 26 18:59:17 2005 From: cfajohnson at gmail.com (Chris F.A. Johnson) Date: Wed, 26 Oct 2005 18:59:17 -0400 Subject: Windows vs Linux [was: p2exe using wine/cxoffice] References: Message-ID: <5be533-3nh.ln1@rogers.com> On 2005-10-26, Tim Golden wrote: > [Sybren Stuvel] > > Tim Golden enlightened us with: >> > Well, I'm with you. I'm sure a lot of people will chime in to point >> > out just how flexible and useful and productive Linux is as a >> > workstation, but every time I try to use it -- and I make an honest >> > effort -- I end up back in Windows > >> I'm curious, what do you mean with "it" in the part "every time I try >> to use it"? > > Fair question. I have, over the years, installed and used Gentoo, > Vector, RH, Ubuntu Breezy (my current choice) and various other > flavours and distros. When I "use it" I mean typically that I use > whatever desktop-type thing presents itself to me -- Gnome or XFCE > or Fluxbox, say -- one or more editors (I tend to try things out to > see if they suit), and one or more command shells. All distros look the same to me, because I have an environment that I like, and I keep my home directory acros distros. > As it happens, (and I suspect I'll have to don my flameproof suit here), > I prefer the Windows command line to bash/readline for day-to-day use, > including in Python. Why? Because it does what I can't for the life of > me get readline to do: you can type the first few letters of a > previously-entered command and press F8. This brings up (going backwards > with further presses) the last command which starts like that. And > *then* you can just down-arrow to retrieve the commands which > followed it. If someone can tell me how to do this with > bash/readline I will be indebted to them and it will increase my > chances of switching to Linux a bit! (Although not at work where I > have no choice!) In my ~/.inputrc: "\e[a": history-search-backward ## shift+up-arrow "\e[b": history-search-forward ## shift+down-arrow -- Chris F.A. Johnson ================================================================== Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress From qwweeeit at yahoo.it Sat Oct 29 09:35:35 2005 From: qwweeeit at yahoo.it (qwweeeit at yahoo.it) Date: 29 Oct 2005 06:35:35 -0700 Subject: Expanding Python as a macro language References: <1130545600.925061.287390@g49g2000cwa.googlegroups.com> Message-ID: <1130592935.839750.322930@g14g2000cwa.googlegroups.com> Thank you for your replays (both for WMI and AutoIt beta-release) but I would be satisfied if I had in Linux something similar to the standard version of AutoIt! Concerning WMI, a part the fact that it works only under Windows, from the examples I have seen, IMHO it is much less powerful than AutoIt. In Linux you can easily obtain almost the same results by using shell programming or by emulation of the shell by means of os.system("shell command string") in Python. But the problem is that in Linux you can't even send a keystroke to a running GUI application! I want to find a solution in Linux, with the help of experts (if they don't use only Windows...) for two reasons: - the reduced availability in Windows of "free" or "open" applications - the more severe security problems in Windows. Concerning the second point, you can correctly argue that this is, at least partly, due to the wider market share of Windows but IMHO Linux is more robust in this field, and ...at the present times the situation is like that! As I want to use automation mainly in Internet, I am worried of security and I don't want to spend time and money in anti-virus and firewalls... I want to give you an idea of possible applications of automation. Imagine you want to access a big database from a html server which only allows you to access such data in chunks pressing a "next" button on an ASP file. It will take several hours to click the button and then save the new data supplied by the server! That is a typical task of AutoIt, very easily programmable, a part that, during the script execution, you are under virus or other security treat! Another example of application is to emulate a spider program to make searches or downloads in Internet. By emulating a user you can bypass the restrictions imposed by search engines or html servers on automatic operations (like wget or urlib). A last example is for protecting the privacy using several "anonymizers". That can only be possible with a macro language for automatic connection to the web anonymizers. Also the subsequent web operations must be carried out (IMHO!) in an automatic manner. There are of course plenty of possible application of a macro language and above all it can save me from be obliged to learn C++ (for Qt). For example, to make a graph you are not obliged to make a program in C++ or PyQt to draw and possibly print the graph of your data, but you need only to program the data preparation then send the data to a drawing application... Bye. From my_email_is_posted_on_my_website at munged.invalid Tue Oct 18 04:32:07 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Tue, 18 Oct 2005 08:32:07 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <86y853mzmr.fsf@bhuda.mired.org> <86mzlil269.fsf@bhuda.mired.org> <7xu0fkw6ps.fsf@ruckus.brouhaha.com> Message-ID: On Tue, 18 Oct 2005 07:40:26 GMT, Tim Tyler wrote or quoted : >I didn't think unicode domain names existed. you can even buy them. See http://mindprod.com/jgloss/domainnames.html under "Chinese Domain Names". -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From rosco at roscopeco.remove.co.uk Wed Oct 12 20:18:03 2005 From: rosco at roscopeco.remove.co.uk (Ross Bamford) Date: Thu, 13 Oct 2005 01:18:03 +0100 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <11kj8ghonmialfc@corp.supernews.com> Message-ID: On Wed, 12 Oct 2005 23:27:26 +0100, Roedy Green wrote: > On Sun, 09 Oct 2005 23:04:49 -0000, gordonb.pru8x at burditt.org (Gordon > Burditt) wrote or quoted : > >> I think one necessary function of email and USENET is that it should >> allow you to SAFELY communicate with strangers or, worse, people >> you know but do not trust at all, > > Yes, but with spam ANY communication with an unwanted stranger is a > nuisance. > > Roedy, I would just _love_ to see the response from the industry when you tell them they should dump their whole mail infrastructure, and switch over to a whole new system (new protocols, new security holes, new problems start to finish). I gather that's the gist of the suggestion, a new protocol with built in public key (a fine, well known, accepted term, IMHO it doesn't need changing) cryptography and signature support? IMAP is in many ways better than POP3, but you would be surprised at the weight of an accepted standard I think. -- Ross Bamford - rosco at roscopeco.remove.co.uk From davids at webmaster.com Sun Oct 16 01:28:02 2005 From: davids at webmaster.com (David Schwartz) Date: Sat, 15 Oct 2005 22:28:02 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: "Steven D'Aprano" wrote in message news:pan.2005.10.16.03.01.20.667844 at REMOVETHIScyber.com.au... > On Sat, 15 Oct 2005 15:48:18 -0700, David Schwartz wrote: >> "Mike Meyer" wrote in message >> news:86ll0vs1sw.fsf at bhuda.mired.org... >>> What you call "clever marketing" the DOJ calls "monopolistic >>> practices". The courts agreed with the DOJ. Having had several large >>> PC manufacturers refuse to sell me a system without some form of >>> Windows because MS made it impossible for them to compete if they >>> didn't agree to do so, I agree with the courts and the DOJ. >> >> Go down to your local car dealer and see if you can buy a new car >> without an engine. > That's a false analogy. A better analogy is, "go to your local car dealer > and see if you can buy a new car with the tyres of your choice." How is that better? Nothing in your car depends upon what tires you have on. But all of the rest of the software on your computer is dependent upon your choice of OS. > Even non-technical types can choose to run a non-Windows operating system > on an Intel-compatible PC. So why do the tier-one vendors and all laptop > manufacturers make their machines available only with Windows? Or on the > very few occasions they will offer a naked PC, the price is the same as > for PC + Windows. I don't really know why and I don't particularly care. I think it has a lot to do with support costs and may also have to do with the type of deals Microsoft offers. The point is, they do. And there's nothing unusual, immoral, or problemmatic about it. If you don't think the total package is worth the total package price, buy elsewhere. DS From jgrahn-nntq at algonet.se Mon Oct 31 09:22:36 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 31 Oct 2005 14:22:36 GMT Subject: Automatically creating a HOME environ variable on Windows? References: <1130549236.679806.297670@g43g2000cwa.googlegroups.com> <1130590817.728832.291020@g44g2000cwa.googlegroups.com> <20051029164345.54C1.0.NOFFLE@fiedzia.homeip.net> <20051031112631.261A.0.NOFFLE@fiedzia.homeip.net> Message-ID: On Mon, 31 Oct 2005 12:26:30 +0100, Maciej Dziardziel wrote: > Jorgen Grahn wrote: > >>> Best solution would be to have portable function that returns >>> user home directory and knows about all platfom quirks. >> >> Why is that better than Python creating a HOME in os.environ, if it >> doesn't >> already exist? I can think of a few reasons it's better, and a few >> reasons it's worse. > > First, it is possible that HOME viariable already exists and has different > meaning, (if python is used as embedded scripting language it can be > defined by application), And on systems where $HOME exists, that's what this new abstraction would have to use internally anyway, so us Unix users won't lose anything. OK, I accept the reasoning. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From fredrik at pythonware.com Wed Oct 5 01:46:49 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 5 Oct 2005 07:46:49 +0200 Subject: Newbie Text Processing Question References: <1128481479.661502.14020@g14g2000cwa.googlegroups.com> <312cfe2b0510042013t1c3854ecg29ae5648cef5a12f@mail.gmail.com> Message-ID: Gregory Pi?ero wrote: >That's how Python works. You read in the whole file, edit it, and write it > back out. that's how file systems work. if file systems generally supported insert operations, Python would of course support that feature. From my_email_is_posted_on_my_website at munged.invalid Sun Oct 16 12:26:10 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sun, 16 Oct 2005 16:26:10 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: On 16 Oct 2005 00:47:09 GMT, John Bokma wrote or quoted : >Ok, let me spell it out for you: If all your applications are web based, >and the OS shouldn't matter, why do Linux distributions matter? The point is you make your choice based on quality of the OS and distribution, not whether it can run a given piece of software. Web apps, Java and other multiplatform tools force OSes to compete on quality, not on proprietary lockin. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From brian at sweetapp.com Thu Oct 6 04:55:19 2005 From: brian at sweetapp.com (Brian Quinlan) Date: Thu, 06 Oct 2005 10:55:19 +0200 Subject: "no variable or argument declarations are necessary." In-Reply-To: <7xirwbn1kl.fsf@ruckus.brouhaha.com> References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> <434245F5.6060500@REMOVEMEcyber.com.au> <7xr7b14lk0.fsf@ruckus.brouhaha.com> <7xu0fx9l7y.fsf@ruckus.brouhaha.com> <7xwtks2tnw.fsf@ruckus.brouhaha.com> <7xek70xhzz.fsf@ruckus.brouhaha.com> <7xirwbn1kl.fsf@ruckus.brouhaha.com> Message-ID: <4344E677.4030703@sweetapp.com> Paul Rubin wrote: > Brian Quinlan writes: > >>OK. The Python compiler would check that the name is declared but it >>would not check that it is defined before use? So this would be >>acceptable: >> >>def foo(): >> local x >> return x > > > Come on, you are asking silly questions. Any reasonable C compiler > would flag something like that and Python (with the flag set) should > do the same. If you want to ask substantive questions, that's fine, > but stop wasting our time with silly stuff. I'm not trying to be silly. I am trying to get a handle on the semantics that you are proposing. So we now have two requirements for the new declaration syntax (please let me know if I'm wrong): o the variable must be declared o the variable must be assigned I would assume that you would make it so that assignment and delaration happen as part of the same statement? > If type checking is implemented then the stdlib should be updated to > add declarations for public symbols. If not, the compiler would flag > the undeclared symbol. You could always declare it to be of type 'object'. Fair enough. > >> try: >> unicode >> except NameError: >> XML_NAMESPACE = "..." >> else: >> XML_NAMESPACE = u"..." > > > This wouldn't be allowed. OK, that sucks. > >>2. the compiler does not have access to the names in other modules anyway > > > You're being silly again. The compiler would examine the other module > when it processes the import statement, just like it does now. Right now, the compiler DOES NOT examine the contents of the other modules. All it does is generate an IMPORT_NAME instruction which is evaluation during runtime. So are you proposing that the compiler now scan other modules during compilation? >>How would you find the class definition for the Node object at >>compile-time? > > > By processing the xml.dom module when it's imported. Import happens at runtime (see above). But you seem to want compile-time type checking. Cheers, Brian From quiteblack at gmail.com Tue Oct 11 10:57:35 2005 From: quiteblack at gmail.com (quiteblack at gmail.com) Date: 11 Oct 2005 07:57:35 -0700 Subject: how to(can we ?) pass argument to .py script ? In-Reply-To: <1129042115.926410.71880@g47g2000cwa.googlegroups.com> References: <1129039664.425406.265670@f14g2000cwb.googlegroups.com> <1129042115.926410.71880@g47g2000cwa.googlegroups.com> Message-ID: <1129042655.097833.307550@o13g2000cwo.googlegroups.com> hey i got it ! tks guys ! From lasse at vkarlsen.no Sat Oct 8 11:32:16 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Sat, 08 Oct 2005 17:32:16 +0200 Subject: Function decorator that caches function results In-Reply-To: References: <1128783738.588723.200130@g43g2000cwa.googlegroups.com> Message-ID: Lasse V?gs?ther Karlsen wrote: > Sam Pointon wrote: > >> What about not storing args at all? Something like this: Ok, here's my updated version: class cache(object): def __init__(self, timeout=0): self.timeout = timeout self.cache = {} def __call__(self, fn): arg_names = inspect.getargspec(fn)[0] def cached_result(*args, **kwargs): # Update named arguments with positional argument values kwargs.update(dict(zip(arg_names, args))) # Work out key as a tuple of ('argname', value) pairs key = tuple(sorted(kwargs.items())) # Check cache and return cached value if possible if key in self.cache: (value, last_time) = self.cache[key] if self.timeout <= 0 or time.time() - last_time <= self.timeout: return value # Work out new value, cache it and return it result = fn(**kwargs) self.cache[key] = (result, time.time()) return result # Return wrapper function return cached_result Changed from previous versions: - converted to class, must use () on decorator now - added timeout, results will be recalculated when it expires - timeout=0 means no timeout, results will always be reused - now handles both positional and keyword arguments -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From usenet at marduk.letterboxes.org Tue Oct 11 02:37:48 2005 From: usenet at marduk.letterboxes.org (marduk) Date: Tue, 11 Oct 2005 06:37:48 GMT Subject: Let My Terminal Go In-Reply-To: <1129010288.251817.147690@z14g2000cwz.googlegroups.com> References: <1129010288.251817.147690@z14g2000cwz.googlegroups.com> Message-ID: <1129012665.29863.2.camel@blackwidow> On Mon, 2005-10-10 at 22:58 -0700, mystilleef at gmail.com wrote: > Hello, > > A user of my application points me to a behavior in gVim, > the text editor, that I would like to implement in my > application. > > When gVim is launched from a shell terminal, it completely > frees the terminal. You can continue to use the terminal for > whatever purpose you wish, including closing and exiting it, > without any effect on the running gVim instance. > > How do I implement this in my application written in python? > I would like to believe it does not involve me forking my > application in a new process. Maybe there is signal I can > send to the operating system to achieve this, right? gvim forks. Why do you want to avoid it? import os, sys pid = os.fork() if pid !=0: # exit parent sys.exit(0) # child continues From mlist at fastwebnet.it Sun Oct 2 19:41:01 2005 From: mlist at fastwebnet.it (billie) Date: Mon, 3 Oct 2005 01:41:01 +0200 Subject: python guru.. for a short conversation regarding bittorrent.. References: <7xvf0fu7ky.fsf@ruckus.brouhaha.com> Message-ID: If it can helps you "ABC" is a (good) bittorent client written in py. From steve at holdenweb.com Fri Oct 28 14:13:06 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 28 Oct 2005 19:13:06 +0100 Subject: tkinter blues (greens, reds, ...) In-Reply-To: <1130519159.921821.164420@z14g2000cwz.googlegroups.com> References: <1130519159.921821.164420@z14g2000cwz.googlegroups.com> Message-ID: Sean McIlroy wrote: > hi all > > i recently wrote a script that implements a puzzle. the interface > mostly consists of a bunch of colored disks on a tkinter canvas. the > problem is that the disks change their colors in ways other than the > way they're supposed to. it certainly isn't just a bug in my script, > since i can sometimes change the color of certain disks just by taking > focus off of the window and then bringing it back again! does this > sound like some known bug in tkinter? and if so, is there a recommended > way of working around it? if it matters, i'm using python 2.3 under > windows 95. any advice will be much appreciated. > It sounds to me much more like a bug in your script, to me at least. Change of focus generates windowing events in much the same way as clicking a button or hitting a key does, so I don't understand why you think that "just [by] taking the focus off the window and bringing it back again" shouldn't change anything. For more specific insights we'd need to see some code, but sometimes just changing your own focus from "Tkinter has a bug" to "my code has a bug" is enough to help one find out what the problem really is. If you have a soft toy I'd recommend you sit it down somewhere and explain to it in great detail exactly why it can't be a bug in your program. You may find you discover the error with no further assistance. If not, fire the toy and ask again :-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From fredrik at pythonware.com Sun Oct 9 18:49:41 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 10 Oct 2005 00:49:41 +0200 Subject: __Classes and type tests References: <43498D3C.90908@cc.umanitoba.ca> Message-ID: Brian van den Broek wrote: > But the academic issue "How/Can it be done?" still itches. class __TwoUnderBase(object): def __init__(self): if self.__class__.__name__ == "__TwoUnderBase": print "From __TwoUnderBase" else: print "From subclass", From lasse at vkarlsen.no Sun Oct 16 13:33:45 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Sun, 16 Oct 2005 19:33:45 +0200 Subject: Function to execute only once In-Reply-To: <43527aa9.156193794@news.oz.net> References: <1129317118.937439.159550@g43g2000cwa.googlegroups.com> <43527aa9.156193794@news.oz.net> Message-ID: <8oqdnTdFif2VEs_eRVnzvA@telenor.com> Bengt Richter wrote: > >>> tmp = 0 > >>> def execute(): > ... global tmp, execute > ... tmp = cellvar = tmp + 1 > ... def execute(): > ... return cellvar > ... return tmp On man did this put my head into a spin :P -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From aleaxit at yahoo.com Fri Oct 28 23:07:48 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 28 Oct 2005 20:07:48 -0700 Subject: Why doesn't this work? :) References: Message-ID: <1h55rvo.g65rvw1eaqg8kN%aleaxit@yahoo.com> Jeremy Moles wrote: > Am I misunderstanding something fundamental about the builtin __* > functions? Can they not be "static?" They can and must be static when their specification say they are (e.g., __new__) and they cannot and must not be static when their specification says otherwise (just about all of them). Alex From jim.eggleston at gmail.com Sat Oct 29 09:00:17 2005 From: jim.eggleston at gmail.com (jim.eggleston at gmail.com) Date: 29 Oct 2005 06:00:17 -0700 Subject: Automatically creating a HOME environ variable on Windows? In-Reply-To: References: <1130549236.679806.297670@g43g2000cwa.googlegroups.com> Message-ID: <1130590817.728832.291020@g44g2000cwa.googlegroups.com> Cool, even better. So what's best, having code to add HOME (=USERPROFILE) to os.environ, or change the various places that HOME is used to check for USERPROFILE? From andreas.zwinkau at googlemail.com Mon Oct 10 07:38:19 2005 From: andreas.zwinkau at googlemail.com (beza1e1) Date: 10 Oct 2005 04:38:19 -0700 Subject: Changing an AST In-Reply-To: References: <1128941690.030540.258790@g43g2000cwa.googlegroups.com> Message-ID: <1128944299.588849.167030@g43g2000cwa.googlegroups.com> Thank you! this "compile/exec in context" is the thing i wanted. It is not that performant i think. But it should ease the prototyping. From franz.steinhaeusler at gmx.at Wed Oct 5 09:07:49 2005 From: franz.steinhaeusler at gmx.at (Franz Steinhaeusler) Date: Wed, 05 Oct 2005 15:07:49 +0200 Subject: how to debug when "Segmentation fault" References: Message-ID: On Wed, 05 Oct 2005 14:53:45 +0200, Tamer Fahmy wrote: >On Tue, 04 Oct 2005 19:13:10 +0300, Maksim Kasimov wrote: >> my programm sometime gives "Segmentation fault" message (no matter how >> long the programm had run (1 day or 2 weeks). And there is nothing in >> log-files that can points the problem. My question is how it possible to >> find out where is the problem in the code? Thanks for any help. >> >> Python 2.2.3 >> FreeBSD > >you could start your program within a gdb session like so: > >$ gdb python >GNU gdb 6.1.1 [FreeBSD] >Copyright 2004 Free Software Foundation, Inc. GDB is free software, >covered by the GNU General Public License, and you are welcome to change >it and/or distribute copies of it under certain conditions. Type "show >copying" to see the conditions. There is absolutely no warranty for GDB. >Type "show warranty" for details. This GDB was configured as >"i386-marcel-freebsd"...(no debugging symbols found)... >(gdb) r foo.py >Starting program: /usr/bin/python foo.py ... > >once your progmam segfaults you can then inspect the stack through: > >(gdb) bt > >cheers, > tamer. Tamer, thanks for your tip. I tried Jeff's code: import marshal f = lambda: None code = marshal.loads(marshal.dumps(f.func_code).replace('d\0\0S','d\xff\xffS')) f.func_code = code f() saved it as foo.py, than C:\Python24\Lib>gdb python GNU gdb 5.1.1 (mingw experimental) Copyright 2002 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "mingw32"...(no debugging symbols found)... (gdb) r foo.py Starting program: C:\Python24/python.exe foo.py Program received signal SIGSEGV, Segmentation fault. 0x1e027b23 in ?? () (gdb) bt #0 0x1e027b23 in ?? () #1 0x00977240 in ?? () #2 0x1e1a82b8 in ?? () Cannot access memory at address 0x7 (gdb) How can I interpret this results? ;) Am I right, that I need a debug build of python built with mingw or cygwin in Windows? -- Franz Steinhaeusler From bonono at gmail.com Sun Oct 16 11:51:59 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 16 Oct 2005 08:51:59 -0700 Subject: subtle side effect of generator/generator expression In-Reply-To: <1129477118.700187.17570@g44g2000cwa.googlegroups.com> References: <1129470158.623786.135010@g14g2000cwa.googlegroups.com> <1129472425.591880.11500@g14g2000cwa.googlegroups.com> <1129477118.700187.17570@g44g2000cwa.googlegroups.com> Message-ID: <1129477919.731857.326050@z14g2000cwz.googlegroups.com> thanks. I was looking for scanl in itertools but can't find it so I implement my own then run into some subtle bugs which first made me think my scanl is the problem. Then notice my wrong perception about generator(and iterable in general, though the built-in iterables like list, dict don't seem to have this characteristic). Simon Percivall wrote: > If you find that you want to iterate over an iterable multiple times, > have a look at the solution that the tee() function in the itertools > module provides (http://docs.python.org/lib/itertools-functions.html). > (Have a look at the rest of the itertools module as well, for that > matter.) From gsakkis at rutgers.edu Mon Oct 10 09:19:58 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Mon, 10 Oct 2005 09:19:58 -0400 Subject: Merging sorted lists/iterators/generators into one stream of values... References: <1128667968.421469.180910@g47g2000cwa.googlegroups.com> <1128691708.c6930b5cb9f3673ed3abe8755178d163@teranews> <1128692196.410209.252100@g14g2000cwa.googlegroups.com> <1128695317.c6a5acb3e62787f011310c96f0c7cc35@teranews> <1h439qe.pz7c451jcec6hN%aleax@mail.comcast.net> <1128795319.09c32ac9943b0580a86b7bcada7facc1@teranews> <1128797447.501582.24560@o13g2000cwo.googlegroups.com> <1h47iae.6d2ps91u8eafuN%aleax@mail.comcast.net> Message-ID: <1128950434.39fd35611ed1ab1bc0f2addf2fbd88c5@teranews> "Alex Martelli" wrote: > George Sakkis wrote: > ... > > > manipulation of a heap to place an item in the right spot, but with 4-5 > > > or a few more sources might not make an impact at all. > > > > Unless you're talking about hundreds or thousands sources, it probably > > won't. I would still go for the heap solution since IMO the resulting > > code it's more readable and easier to understand. > > I'm not so sure about either sentence...: > > Helen:~/pynut/samp alex$ python merger.py --numstreams=10 --minlen=100 > --how=S > Best time for 10 loops: 0.247116088867 > > Helen:~/pynut/samp alex$ python merger.py --numstreams=10 --minlen=100 > --how=H > Best time for 10 loops: 0.10344004631 > > i.e., a heap solution may be over 4 times faster than a sort-based one > (in the following implementations). Interesting; I thought timsort on small almost ordered lists would be practically as fast as the heap. Still, how is 0.10344 over 4 times faster than 0.247116 ? > Readability seems quite comparable > (skipping the rest of the infrastructure, which generates random sorted > streams and ensures a stream is exhausted and verifies it etc etc): > > def merge_by_sort(streams): > sources = [[s.next(), i, s.next] for i, s in enumerate(streams)] > while sources: > sources.sort(reverse=True) > best_source = sources[-1] > yield best_source[0] > try: best_source[0] = best_source[-1]() > except StopIteration: sources.pop() > > def merge_by_heap(streams): > sources = [[s.next(), i, s.next] for i, s in enumerate(streams)] > heapq.heapify(sources) > while sources: > best_source = sources[0] > yield best_source[0] > try: best_source[0] = best_source[-1]() > except StopIteration: heapq.heappop(sources) > else: heapq.heapreplace(sources, best_source) Indeed, these are almost equivalent as far as readability goes; the previous examples in the thread were less clear. By the way, why do you need 'i' and enumerate above ? > Hmmm, I wonder if something like merge_by_heap would be a good candidate > for itertool. Raymond...? > > > Alex Yes, it would be nice to make it into 2.5. George From deets at nospam.web.de Thu Oct 6 09:19:40 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 06 Oct 2005 15:19:40 +0200 Subject: updating local() In-Reply-To: <1128603314.197733.119160@g47g2000cwa.googlegroups.com> References: <1128530014.323801.290360@g47g2000cwa.googlegroups.com> <1128603314.197733.119160@g47g2000cwa.googlegroups.com> Message-ID: <3qkmjcFfbem9U1@uni-berlin.de> Flavio wrote: > Ok, > > I got it! > > Its vey insecure, and it is not guaranteed to work. Fine. > > Now what would you do if you wanted to pass a lot of variables (like a > thousand) to a function and did not wanted the declare them in the > function header? use a dict or list? This is almost certainly a design smell - and a pretty strong one, too.. Nobody is using so many variables and actually typing them - so there certainly is some naming scheme that could be used to access the values from a dict. Or, to put it differently: show us the code that uses thousands of variables, and we show you how to improve that. Diez From OurLab at gmail.com Sun Oct 30 18:23:49 2005 From: OurLab at gmail.com (Alex) Date: 30 Oct 2005 15:23:49 -0800 Subject: Pickling and unpickling inherited attributes In-Reply-To: <1130713951.953157.270130@g14g2000cwa.googlegroups.com> References: <1130713951.953157.270130@g14g2000cwa.googlegroups.com> Message-ID: <1130714629.049424.237250@z14g2000cwz.googlegroups.com> Sorry, I copied and pasted a wrong piece from shell at one part of the code: objct.Z=4 was in fact obj.Z=4 and it did refuse to accept Z (because it is not in __slots__). But the question remains: why the value of attribute A is not preserved during pickling and unpickling and what can be done about it, if anything? From ptmcg at austin.rr.com Wed Oct 26 15:27:53 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 26 Oct 2005 12:27:53 -0700 Subject: Raw string fu In-Reply-To: References: Message-ID: <1130354873.546887.271850@z14g2000cwz.googlegroups.com> "Raw string fu"? A new martial art? From bokr at oz.net Mon Oct 3 02:12:04 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 03 Oct 2005 06:12:04 GMT Subject: Will python never intend to support private, protected and public? References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xd5mstqab.fsf@ruckus.brouhaha.com> <7xzmpwuxd0.fsf@ruckus.brouhaha.com> <20050930075313.67b9b676.jk@ospaz.ru> <7xbr2a6dlz.fsf@ruckus.brouhaha.com> <7xk6gyoibc.fsf@ruckus.brouhaha.com> <433f56a3.2969039483@news.oz.net> <1128274267.064255.306980@f14g2000cwb.googlegroups.com> Message-ID: <4340c626.3063122897@news.oz.net> On 2 Oct 2005 10:31:07 -0700, "El Pitonero" wrote: >Bengt Richter wrote: >> >> I decided to read this thread today, and I still don't know exactly >> what your requirements are for "private" whatevers. > >No name collision in subclassing. Notice that even if you use > >self._x = 3 > >in a parent class, it can be overriden in a sub-sub-class accidentally. I noticed that, and suggested a GUID-based possible approach ;-) > >> Or maybe, what are your real requirements? >> ;-) > >No need for this type of joke. I'm not sure what you mean, but I meant no offence, just a nudge to refine the requirements statement, and it seems (and I hope) Paul took it that way. [...] >Would any Python programmer trade the benefits of a highly dynamic >language with an unessential feature like Java-style "private" data >members? My guess is not. ISTM it's not a case of either-or here ;-) > >--------------- > >What do I say Java-style "private" is unessential? > >If your Python class/object needs a real Java-style private working >namespace, you have to ask yourself: do the private variables REALLY >belong to the class? Depends on what you mean by "belong" I think ;-) > >In my opinion, the answer is: NO. Whenever you have Java-style private >variables (i.e, non-temporary variables that need to persist from one >method call to the next time the class node is accessed), those >variables/features may be better described as another object, separate >from your main class hierarchy. Why not move them into a foreign worker >class/object instead, and let that foreign worker object hold those >private names, and separate them from the main class hierarchy? (In >Microsoft's jargon: why not use "containment" instead of >"aggregation"?) > >That is, the moment you need Java-style private variables, I think you >might as well create another class to hold those names and >functionalities, since they do not belong to the core functionality of >the main class hierarchy. Whatever inside the core functionality of the >main class, should perhaps be inheritable, sharable and modifiable. Such "another class" is what I was suggesting the automatic hidden creation of when I said """ Alternatively, it might be possible to define (in the metaclass call) __getattribute__ for the class so that it notices when method_foo or method_bar are being accessed to create bound methods, and then bind in a proxy "self" instead that would have self.private_var on its own "self" and delegate public attribute accesses to the normal self. Maybe this could get around byte-code-munging at the cost of easier breakin than via inspect etc., and less run time efficiency. Just musing ... """ What kind of implementation were you thinking of? > >If you use containment instead of aggregation, the chance for name >collision reduces dramatically. And in my opinion, it's the Pythonic >way of dealing with the "private" problem: move things that don't >belong to this object to some other object, and be happy again. > Yes, but how do you propose to implement access the "private" variables without changing the the "spelling" too much? Regards, Bengt Richter From kent37 at tds.net Fri Oct 21 18:40:57 2005 From: kent37 at tds.net (Kent Johnson) Date: Fri, 21 Oct 2005 18:40:57 -0400 Subject: Redirect os.system output In-Reply-To: <1129927486.854143.169670@g49g2000cwa.googlegroups.com> References: <1129927486.854143.169670@g49g2000cwa.googlegroups.com> Message-ID: <43596c70$1_3@newspeer2.tds.net> jas wrote: > I would like to redirect the output from os.system to a variable, but > am having trouble. I tried using os.popen(..).read() ...but that > doesn't give me exactly what i want. Here is an example using subprocess: http://groups.google.com/group/comp.lang.python/msg/9fa3a3c287e8e2a3?hl=en& Kent > > ..this is windows by the way. > > For example: > tmp = os.popen("hostname").read() > > ...works as expected. > > however, > > tmp = os.popen("cmd").read() > ...i would like to have access to the cmd process...i.e. enter commands > like a normal command line. os.system() allows this, but i dont want > output to the screen..i wanna store it to a variable. then send > content of variable elsewhere, receive more input and submit it. > almost emulate the windows command prompt. > > any ideas? > From spe.stani.be at gmail.com Mon Oct 17 14:27:07 2005 From: spe.stani.be at gmail.com (SPE - Stani's Python Editor) Date: 17 Oct 2005 11:27:07 -0700 Subject: How do you draw this layout with wxpython? In-Reply-To: <*firstname*nlsnews-FA8B2A.12310017102005@news.verizon.net> References: <1129531620.723991.53140@g14g2000cwa.googlegroups.com> <*firstname*nlsnews-FA8B2A.12310017102005@news.verizon.net> Message-ID: <1129573627.328049.308810@g43g2000cwa.googlegroups.com> Ask this question on the very active wxPython-users mailing list (http://lists.sourceforge.net/lists/listinfo/wxpython-users). For sure someone will help you out. If you don't want to write the code yourself, but use a visual gui designer I strongly recommend using wxGlade (http://wxglade.sourceforge.net/), which is very simple and neat. It uses sizers by default, which has the advantage that you're dialog box will be rescalable. Stani -- SPE - Stani's Python Editor (ships btw with wxGlade) http://pythonide.stani.be From strombrg at dcs.nac.uci.edu Mon Oct 10 20:39:02 2005 From: strombrg at dcs.nac.uci.edu (Dan Stromberg) Date: Tue, 11 Oct 2005 00:39:02 GMT Subject: rrdtool? References: <1128975509.418396.232840@g14g2000cwa.googlegroups.com> Message-ID: On Mon, 10 Oct 2005 13:18:29 -0700, Grig Gheorghiu wrote: > By sheer coincidence I was looking into the same thing today. I just > downloaded the latest rrdtool release (rrdtool-1.2.11) and I noticed a > /bindings/python subdirectory. I haven't played with it yet, as I still > need to install tons of prerequisites before I can build rrdtool. > > Grig Thanks for the response. I saw some python bindings for rrdtool, but what I had in mind was more like a graphing frontend in python that uses data stored in rrdtool... Anything like that out there? Thanks! From spe.stani.be at gmail.com Sun Oct 23 09:01:49 2005 From: spe.stani.be at gmail.com (SPE - Stani's Python Editor) Date: 23 Oct 2005 06:01:49 -0700 Subject: IDE recommendation please References: <1h4usyj.1ndvf691bu0zvuN%aleaxit@yahoo.com> <1130044581.644967.254230@g49g2000cwa.googlegroups.com> Message-ID: <1130072509.630373.146270@g43g2000cwa.googlegroups.com> Mac users of SPE collected money for me to buy a Mac. This means that in the near future SPE will be especially improved for Mac. So feedback from Mac users is more than welcome and will probably be taken into account. SPE is a free, open source IDE with a lot of features like a debugger, UML diagrams and a GUI designer. Stani -- http://pythonide.stani.be http://pythonide.stani.be/manual/html/manual.html From Sebastien.Boisgerault at gmail.com Mon Oct 10 06:47:31 2005 From: Sebastien.Boisgerault at gmail.com (=?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=) Date: 10 Oct 2005 03:47:31 -0700 Subject: Continuous system simulation in Python References: <20051007011222.1aeab426@linuxcestcomplique.fr> <1128708054.819697.232950@o13g2000cwo.googlegroups.com> <20051007224533.08bde751@linuxcestcomplique.fr> <1128794785.152776.116370@g47g2000cwa.googlegroups.com> <20051008233140.77ad2c2e@linuxcestcomplique.fr> Message-ID: <1128941251.054780.324900@g44g2000cwa.googlegroups.com> Nicolas, I am aware of some shortcomings and design flaws of Simulink, especially in the code generation area. I am interested by your paper nonetheless, please send me copy. However, Simulink is used by many people on a day-to-day basis in the context of big, industrial projects. The claim that it is "next to unusable" is, in my book, an overstatement ... Scicos is not perfect either but you can hardly say that is is a simple clone of Simulink. No time and space to go into the details ... Obviously, the python community is very dynamic, but how much support will you get in the very specific topic of continuous time systems simulation ? IMHO, an hybrid approach, such as the development of bridge to include Python components into Simulink/Scicos/Ptolemy/ Modelica/pick_your_favorite_simulator may grant you more interest from the simulation community. Cheers, SB Nicolas Pernetty wrote: > Simulink is well fitted for small simulators, but when you run into big > projects, I find many shortcomings appears which made the whole thing > next to unusable for our kind of projects. > That's why I'm interested in Python by the way, it is not a simple clone > like Scilab/Scicos. It is a real language which bring its own > advantages, and its own shortcomings, which I find well suited for our > activity. > > If you want, I can send you a paper I wrote last year, detailing all > Simulink shortcomings. I doubt that this mailing list is interested in > such things...(and it's in French...). > Concerning Scilab/Scicos, I'm not really interested in a technology > primarily developed (INRIA and ENSPC) and used by France. Python and all > its libraries and communities are so much more dynamic ! > And also I've heard that Scilab was developed in Fortran in a way which > make it rigid and that the sources are poorly documented, not a good > sign for an open source software (and Scilab isn't 'Free' for the FSF). > > Regards, > > > *********** REPLY SEPARATOR *********** > > On 8 Oct 2005 11:06:25 -0700, "S?bastien Boisg?rault" > wrote : > > > > > Simulink is a framework widely used by the control engineers ... > > It is not *perfect* but the ODEs piece is probably the best > > part of the simulator. Why were you not convinced ? > > > > You may also have a look at Scicos and Ptolemy II. These > > simulators are open-source ... but not based on Python. > > > > Cheers, > > > > SB > > > > > > > > > > > > Nicolas Pernetty a ?crit : > > > > > Hello Phil, > > > > > > Yes I have considered Octave. In fact I'm already using Matlab and > > > decided to 'reject' it for Python + Numeric/numarray + SciPy because > > > I think you could do more in Python and in more simple ways. > > > > > > Problem is that neither Octave, Matlab and Python offer today a > > > framework to build continuous system simulator (in fact Matlab with > > > Simulink and SimMechanics, do propose, but I was not convinced at > > > all). > > > > > > Regards, > > > > > > *********** REPLY SEPARATOR *********** > > > > > > On 7 Oct 2005 11:00:54 -0700, phil_nospam_schmidt at yahoo.com wrote : > > > > > > > Nicholas, > > > > > > > > Have you looked at Octave? It is not Python, but I believe it can > > > > talk to Python. > > > > Octave is comparable to Matlab for many things, including having > > > > ODE solvers. I have successfully used it to model and simulate > > > > simple systems. Complex system would be easy to model as well, > > > > provided that you model your dynamic elements with (systems of) > > > > differential equations. > > > > > > From mhellwig at xs4all.nl Tue Oct 25 14:24:40 2005 From: mhellwig at xs4all.nl (Martin P. Hellwig) Date: Tue, 25 Oct 2005 20:24:40 +0200 Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: <435e786f$0$11061$e4fe514c@news.xs4all.nl> Not Bill Gates wrote: > steve at REMOVETHIScyber.com.au wrote... >> On Tue, 25 Oct 2005 15:35:47 +0000, Not Bill Gates wrote: >> >>> Heck, I dunno. Like you, I don't even really care all that much. >> You don't care that innovation in desktop software has been crippled by >> the actions of the monopoly player Microsoft? > > You need to first prove innovation in desktop software has been > crippled, don't you? > How about their "java" implementation between 1998 and 2004? Sure killed the _easier_ write once run everywhere mantra, of course they where not alone in the killing, SUN helped a great deal. -- mph From http Sun Oct 9 17:13:04 2005 From: http (Paul Rubin) Date: 09 Oct 2005 14:13:04 -0700 Subject: Function decorator that caches function results References: <7x4q7rt3yl.fsf@ruckus.brouhaha.com> Message-ID: <7xzmpi1jj3.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > No. I'm obsessed with finding out what closures are, since nobody seems to > have a good definition of them! Why don't you read SICP: http://mitpress.mit.edu/sicp/full-text/book/book.html You will be a much wiser person for having done so. > However, I have learnt some things: closures are something which > functions HAVE, not ARE. Nah, that describes the data layout through which CPython implements closures, not the bigger idea of what closures are. > The func_closure attribute is just part of the implementation of the > closure. Some languages have closures and some don't. And a closure > is something that lets a function object access the lexical scope > that existed when the function object was created, e.g. the > namespace of the function which created it. I'd say, the closure is the function's executable code, plus the lexical environment that got recorded at the time the function was created. From dawenliu at gmail.com Sat Oct 29 16:29:27 2005 From: dawenliu at gmail.com (dawenliu at gmail.com) Date: 29 Oct 2005 13:29:27 -0700 Subject: how to discard a line if it's not a number? Message-ID: <1130617767.659563.158050@z14g2000cwz.googlegroups.com> Hi, I'm reading a file line by line, and whenever a line is not consisted of a single number (such as 0.315), I want to discard that line (and store only the single numbers). For example, 0.315 discarded this line of text 3.8 -1.44 forget about me also 2.6 Then I want to store only the four numbers into another file, without the two sentences. Suggestions are appreciated! From no at spam Wed Oct 5 16:59:54 2005 From: no at spam (Mike) Date: Wed, 05 Oct 2005 16:59:54 -0400 Subject: Replacing utf-8 characters In-Reply-To: References: <1128522921.72009@nntp.acecape.com> Message-ID: <1128545979.146190@nntp.acecape.com> In playing with this I found link.replace does work but when I use link.replace('&','&') it replaces it with & instead of just &. link.replace is working for me since if I changed the second option from & to something else I see the change. So it seems link.replace() function reads whether the first option is utf-8 and converts the second option automatically to utf-8? How do I prevent that? Thanks again. From andreas.zwinkau at googlemail.com Mon Oct 10 06:54:50 2005 From: andreas.zwinkau at googlemail.com (beza1e1) Date: 10 Oct 2005 03:54:50 -0700 Subject: Changing an AST Message-ID: <1128941690.030540.258790@g43g2000cwa.googlegroups.com> Is it possible compiler.parse a statement, then change and then execute/resolve it? Background: I'm probably to lazy to write my own parser. I have such a statement as string: "distance = x**2 + y**2" x and y are undefined, so it is no executable Python code, but it is parseable. Now i'd like traverse through the AST and change Name('x') for the value i have elsewhere. And finally let Python resolve the computation. More Background: I want to write a simulation game with many interdepended values. I don't want to create a class with dozens of functions, but let Python create/evaluate them. I hope this can be understood ;) From usenet at marduk.letterboxes.org Tue Oct 4 19:18:38 2005 From: usenet at marduk.letterboxes.org (marduk) Date: Tue, 04 Oct 2005 23:18:38 GMT Subject: Jargons of Info Tech industry In-Reply-To: <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> Message-ID: <1128467917.312.22.camel@blackwidow> [Removed X-posting] On Tue, 2005-10-04 at 17:14 +0000, Roedy Green wrote: > On Tue, 23 Aug 2005 08:32:09 -0500, l v wrote or quoted : > > >I think e-mail should be text only. > > I disagree. Your problem is spam, not HTML. Spam is associated with > HTML and people have in Pavlovian fashion come to hate HTML. > > But HTML is not the problem! And guns don't kill people: people kill people! Seriously though, plain-text is just plain [n]etiquette (for most newsgroups/mailing lists (at least the technical ones)). Follow the rules and avoid becoming a social outcast. If your particular forum allows/encourages HTML then away! ( This post is neither x-posted, HTML-ized, closed-captioned nor simulcast in Spanish or HD ) From gordonb.g6z7y at burditt.org Thu Oct 13 15:04:54 2005 From: gordonb.g6z7y at burditt.org (Gordon Burditt) Date: Thu, 13 Oct 2005 19:04:54 -0000 Subject: Jargons of Info Tech industry References: <1124804082_1011@spool6-east.superfeed.net> <11krdosli1jgla7@corp.supernews.com> Message-ID: <11ktbum1ira9le4@corp.supernews.com> >Hello? I don't think that should make any difference. I should be able >to visit absolutely any website on the Internet without any danger to my >computer or the data stored on it. Any browser which allows otherwise >has a bug. Then Javascript *as a language* is a bug. >Javascript is not inherently a virus vector. Flawed A virus vector is not the only security problem. Leaking information to the web site is also a problem. >implementations might be; the language itself is not. Does the language allow Javascript to open a new window? Does the language allow Javascript to trigger a function when a window is closed? I believe the answer to both questions is YES. Then it is possible to have a page that pops up two windows whenever you close one. This isn't theoretical: I've seen someone demonstrate this with certain nasty porn sites. The only way to recover was to kill off the browser and restart it. (Clicking HOME apparently fired off a cascade of closed windows which then opened more, running the browser out of virtual memory.) Because of this, he lost work in progress with another web site. (Apparently he accidentally clicked on a banner ad which lead to this booby-trapped site.) >Similarly for >anything else. In reality, with a properly-configured, good quality >operating system (probably a UNIX-type system), one ought to be able to >run full native code without any danger to one's computer or data >(think: under the NOBODY account on Linux). If it can reveal my email address to any web site, it's a bug. If it can access or alter my personal files or address book, it's a bug. If it can generate hits on web sites other than that specified in the HTML, it's a bug. If it can open sockets, it's a bug. If it can look at or set cookies stored on my system, it's a bug. If it can look at or alter the list of previously visited URLs, it's a bug. >> Browsers don't read unsolicited web sites. Email readers do, however, >> read unsolicited email, and email from downright hostile correspondents. >> And I consider "web bugs" and similar tracking methods to be a danger >> for something that's supposed to be ONLY "formatted text". Gordon L. Burditt From http Tue Oct 11 19:29:28 2005 From: http (Paul Rubin) Date: 11 Oct 2005 16:29:28 -0700 Subject: Nicer way of strip and replace? References: <7xpsqb6839.fsf@ruckus.brouhaha.com> Message-ID: <7xslv7d44n.fsf@ruckus.brouhaha.com> Markus Rosenstihl writes: > indeed, it did it correctly by default: > > read_file = csv.reader(open('2005_08_Rechnung_4963184011.dat', 'r'), > delimiter="\t") > for row in read_file: > rechnung.append(row) Oh cool. I think you could even say: rechnung = list(read_file) instead of the for loop. From david at jotax.com Sun Oct 16 05:24:03 2005 From: david at jotax.com (spinner) Date: 16 Oct 2005 02:24:03 -0700 Subject: Queue question In-Reply-To: <1129419092.954592.59630@z14g2000cwz.googlegroups.com> References: <1129413036.271162.279880@g43g2000cwa.googlegroups.com> <1129419092.954592.59630@z14g2000cwz.googlegroups.com> Message-ID: <1129454643.819112.174860@g49g2000cwa.googlegroups.com> Ahh the penny has dropped at last. I am using the WingIDE and .not_empty is one of the properties it exposes with it's intellisense. As such its use is not documented. No problem. Using the exception would more accurate - I can see that. In my simple case the queue is a one to one link, into and out of a single thread and so I can use the .empty() call with impunity. I can see that using queue's may be overkill in this instance but it has been good practice to get to know how they operate. Being new to python I am just getting used to syntax and conventions, your reply has clarrified the issue for me. Thank you for posting Steve. From gsakkis at rutgers.edu Tue Oct 18 00:49:35 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Tue, 18 Oct 2005 00:49:35 -0400 Subject: Mutual module imports References: <*firstname*nlsnews-B5E898.23113017102005@news.verizon.net> Message-ID: <1129610975.644a87d1c52b5dc7f014412969a5ba17@teranews> "Tony Nelson" <*firstname*nlsnews at georgea*lastname*.com> wrote: > [snipped] > > I have written a Python module that uses some C functions. I wrote the > module in two parts, one Python, one Pyrex (C). They need to share some > globals. > > [snipped] > > Now the Python module imports the Pyrex module and just shoves > references to its globals into the Pyrex module (the Pyrex module > defines them as None). The Pyrex module doesn't import the Python > module anymore. This also works, even when the Python module has a > different name (e.g. "__main__"). I just feel dirty about it. Well, I feel dirty every time I have to share globals . George From max at alcyone.com Mon Oct 17 16:05:30 2005 From: max at alcyone.com (Erik Max Francis) Date: Mon, 17 Oct 2005 13:05:30 -0700 Subject: List of strings to list of floats ? In-Reply-To: <4353d2a2$0$41138$14726298@news.sunsite.dk> References: <4351d29e$0$41148$14726298@news.sunsite.dk> <4353d2a2$0$41138$14726298@news.sunsite.dk> Message-ID: Madhusudan Singh wrote: > Thanks. Now, a slightly more complicated question. > > Say I have two lists of floats. And I wish to generate a list of floats that > is a user defined function of the two lists. result = [sqrt(x**2 + y**2) for x, y in zip(xs, ys)] -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis Did you ever love somebody / Did you ever really care -- Cassandra Wilson From matthew.garrish at sympatico.ca Sat Oct 15 19:13:20 2005 From: matthew.garrish at sympatico.ca (Matt Garrish) Date: Sat, 15 Oct 2005 19:13:20 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: "Tim Roberts" wrote in message news:a103l1tkejrc99s0385qjqqhm96d46dpc4 at 4ax.com... > "Jeroen Wenting" wrote: >> >>Microsoft isn't evil, they're not a monopoly either. >>If they were a monopoly they'd have 100% of the market and there'd be no >>other software manufacturers at all. > > This is wrong. The dictionary definition of a monopoly is when a > manufacturer has all or nearly all of a market. Microsoft DOES have a > monopoly on PC operating systems. > > That, in itself, is not necessarily illegal. However, Microsoft then USED > that monopoly power to stifle their competition, and that IS illegal. > > Part of their behavior really escape me. The whole thing about browser > wars confuses me. Web browsers represent a zero billion dollar a year > market. Why would you risk anything to own it? > It may not be worth loads of money in-and-of itself now (don't forget Netscape wasn't always free, though), but if you control how people view the Internet you can make a lot of money in other ways, especially if you build your browser into your operating system and warp standards so that people who design sites take advantage of the proprietary features. Eventually the hope is that your OS and browser will become the only means of accessing the internet. And if your OS and browser are the only way to access the Internet, who in their right mind would use another system? Matt From juho.schultz at helsinki.fi Wed Oct 5 03:10:31 2005 From: juho.schultz at helsinki.fi (Juho Schultz) Date: Wed, 05 Oct 2005 10:10:31 +0300 Subject: python plotting with greek symbols within labels recommendations? In-Reply-To: <1128469278.622461.249550@g49g2000cwa.googlegroups.com> References: <1128469278.622461.249550@g49g2000cwa.googlegroups.com> Message-ID: michael.s.gilbert at gmail.com wrote: > hello all, > > this message is geared toward those of you in the scientific community. > i'm looking for a python plotting library that can support rendering > greek symbols and other various characters on plot axes labels, etc. I > would prefer something that adheres to tex formatting (as implemented > in latex, matlab, etc and has the form $\alpha$ to represent the greek > character alpha for example). > > thus far, i've found that matplotlib > (http://matplotlib.sourceforge.net/) can do this, albeit the > implementation is so poor that you cannot mix standard text with > symbols on the same plot element. > > If you already have installed matplotlib, have a look at matplotlib-0.X.Y/examples/tex_demo.py It shows you how to mix text and symbols. The other examples in the directory could also be useful. Essentially you need to remember matplotlib.rc('text', usetex=True) before plotting. If you need complex stuff (fractions, sums, integrals) try putting an r before the string: pylab.ylabel( r"Density $\left(\rho =\frac{x^2+\frac{x+1}{x-1}}{\kappa(x)K_{ij}}\right)") works fine, at least on my system. From fumanchu at amor.org Fri Oct 21 17:01:14 2005 From: fumanchu at amor.org (Robert Brewer) Date: Fri, 21 Oct 2005 14:01:14 -0700 Subject: How to add one month to datetime? Message-ID: John W wrote: > I have been trying to figure out how to > easily add just one month to a datetime > object? ...I was wondering if there is > simple way of doing this with built in > datetime object? If you want the same day in the succeeding month, you can try: newdate = datetime.date(olddate.year, olddate.month + 1, olddate.day) ...but as you can see, that will run into problems quickly. See the "sane_date" function here: http://projects.amor.org/misc/browser/recur.py for a more robust solution, where: newdate = recur.sane_date(olddate.year, olddate.month + 1, olddate.day) will roll over any values which are out-of-bounds for their container. Robert Brewer System Architect Amor Ministries fumanchu at amor.org From kyle.tk at gmail.com Sun Oct 30 21:24:18 2005 From: kyle.tk at gmail.com (kyle.tk) Date: 30 Oct 2005 18:24:18 -0800 Subject: putting a string in Mac Address form Message-ID: <1130725458.938638.221840@z14g2000cwz.googlegroups.com> I came up with this. Is there a better (more pythonic) way to do it? import string def mac_to_norm(mac): def bad_char(char): if char not in string.hexdigits: return False return True mac = filter(bad_char,mac) if len(mac) is not 12: return None new_mac = '' c = 0 while len(new_mac) < 16: new_mac += mac[c:c+2] + ':' c=c+2 return new_mac[:-1].upper() print mac_to_norm('0012.ab23.b2cd') #shows: 00:12:AB:23:B2:CD The part I think is bad is the while loop part. Could it be better? From jpstewart at binaryfoundry.ca Tue Oct 25 11:29:14 2005 From: jpstewart at binaryfoundry.ca (John-Paul Stewart) Date: Tue, 25 Oct 2005 11:29:14 -0400 Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: David Schwartz wrote: > > If nobody wants > these operating systems, then it doesn't hurt him not to be able to sell > them. If people want them, then he could have shown Microsoft the door. If only 5% want another operating system, the vendor has to choose between selling to those 5% -or- to the 95% who want Microsoft. Had it not been for the underhanded tactics, he could have sold to *both* groups. From a purely economic standpoint, the sensible thing is to accept that 95% and let the 5% go elsewhere. But if *every* vendor has to make that same choice, there is no place for that other 5% to go to buy another operating system. So the other operating system(s) die off. And those 5% become customers of Microsoft since there's no other choice left. And *that* is where the legal problems start: they gained market share by preventing consumers from finding competing products. From chris.lasher at gmail.com Mon Oct 17 22:44:46 2005 From: chris.lasher at gmail.com (Chris Lasher) Date: 17 Oct 2005 19:44:46 -0700 Subject: Vim capable IDE? Message-ID: <1129603486.291175.167860@f14g2000cwb.googlegroups.com> Hello, Is there a Python-sensitive, Linux compatible IDE out there with standard bells and whistles (source browser, symbolic debugger, etc.) but with the action-per-keystroke editing capabilities of Vim? I have failed to turn up such an IDE in my Googling and IDE project-page browsing. :-( Thanks very much in advance, Chris From steve at REMOVETHIScyber.com.au Sun Oct 9 11:07:34 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 10 Oct 2005 01:07:34 +1000 Subject: Function decorator that caches function results References: <7x4q7rt3yl.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 09 Oct 2005 14:27:32 +0200, Fredrik Lundh wrote: > Steven D'Aprano wrote: > >> Yes I did. Did you read my post? > > given that the wikipedia page says > > "a closure is an abstraction representing a function, plus the > lexical environment (see static scoping) in which the function > was created." > > and you're still focussing on type(function), it sure looks as if you missed > certain parts of that explanation. > > let's take it again, with emphasis on some important words: > > "a closure is an ABSTRACTION representing a function, PLUS the > lexical ENVIRONMENT (see static scoping) in which the function > was created." > >> If you create a closure, using a memoization technique as per the original >> post, and then call type() on that closure, Python reports . > > that's because "closure" is an abstract concept. So are functions, modules, classes, instances, ints and strings. > there is no "closure" object > in Python, just as there is no "program" object. Clearly there is no DISTINCT closure object. If there were, I wouldn't need to ask how one can tell them apart, because type() would just report that one was a function and one was a closure. I don't have a problem with that. But read on... > function objects always con- > tain all the information they need about their context, and the sum of that is > what forms the closure. If what you say is true, then all functions are closures, and closure is just a synonym for function, and there is no difference between a function and a closure. Then why bother to create the term? Clearly, whoever invented the term did so to distinguish the two. At a practical, Python level, there is a difference between a function before and after it gets made into a closure using, e.g. the original poster's memoization technique. In Python at least, it is not true that a function and a function-turned-into-closure is the same thing. See, for example, this:- >>> def closefy(fn): ... def do_nothing(*args, **kwargs): ... return fn(*args, **kwargs) ... return do_nothing ... >>> def spam1(): ... return 0 ... >>> spam2 = closefy(spam1) >>> spam1() 0 >>> spam2() 0 >>> spam2 is spam1 False >>> spam1.func_closure is None True >>> spam2.func_closure (,) >>> hex(id(spam1)) '0xf6e0a144' In one case, the "raw" function has None stored in its func_closure attribute. In the other, it has a tuple containing at least one object of type cell. That cell object appears to contain a reference back to the original "raw" function. Now, I'll tell you what I think is going on: spam1() obviously has lexical scope, but that scope doesn't need to be saved with the function because it is implicitly understood by Python. The output of closefy(), on the other hand, has scope different from the "normal" Python scope. So its output has to package up enough information to re-create it's lexical scope in a cell object, and that gets stored in the output's func_closure attribute. So no, there is no "abstract" difference between a closure and a raw function, but there is a practical difference. Now perhaps in some other languages there is no practical difference either, but (as far as I can see) Python is not that language. Am I close? Here are another two code snippets that show something of what Python is doing:- >>> def thingo(): ... def shrubbery(): ... return 0 ... return shrubbery ... >>> spam3 = thingo() >>> spam3() 0 >>> spam3.func_closure is None True >>> def thingy(): ... n = 0 ... def shrubbery(): ... return n ... return shrubbery ... >>> spam4 = thingy() >>> spam4.func_closure (,) -- Steven. From ptb at oboe.it.uc3m.es Thu Oct 27 08:35:50 2005 From: ptb at oboe.it.uc3m.es (Peter T. Breuer) Date: Thu, 27 Oct 2005 14:35:50 +0200 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: <66u633-etj.ln1@news.it.uc3m.es> In comp.os.linux.misc David Schwartz wrote: > Peter T. Breuer wrote: >> In comp.os.linux.misc David Schwartz wrote: >>> Microsoft was not going to let a business >>> parasitically use Windows to build a business that touted the >>> advantages of competing products. >> Well, it should have, because that's what manufacturers of operating >> systems, washing machines, and so on, are supposed to do. And so says >> the legal system. Attempting to subvert market economics like that is >> illegal. > Actually, there are washing machines that are only available in > particular stores. I believe Kenmore washing machines, for example, are only > available wholesale as part of a franchise deal. Good for them - I guess nobody else would want them (I certainly wouldn't want something which hadn't been subjected to the test of a competetive market)! In case you hadn't noticed, there are also JAMs and TINNED CUCUMBERs which are only available in certain stores! It's called an "own brand", and they are normally cheaper than branded equivalents, not having paid for the advertising or in some cases actually using cheaper and generic products. That's UP TO THE FRIGGING STORE (in contrast to the MS situation). The store doesn't have to tell its supplier to make its product also availabel to other stores (but it probably will, under a differnt label - all these things come from the same canneries). It's not forced on them sellerby the manufacturer. And attempts by manufacturers (notably sports shoe brands) to dictate which shops may sell their brands (in order that they may control the pricing) have been rebuffed by the courts as well. > I don't know why you think > that's an attempt to subvert market economics, Because "it is". > it's actually just a normal > part of the way the market works. No it isn't. I think I'll just plonk you. Absurd and outlandish statements like that put you beyond the pale. The law has spoken on the matter - the courts have judged, and "that is illegal" and "that is a monopoly" and "that is an illegal trade practice" are its judgments. Peter From bretthoerner at gmail.com Thu Oct 13 13:41:03 2005 From: bretthoerner at gmail.com (Brett Hoerner) Date: 13 Oct 2005 10:41:03 -0700 Subject: installer for amd64 build of python? In-Reply-To: <1129192705.632826.145210@z14g2000cwz.googlegroups.com> References: <1129162224.131305.269060@g49g2000cwa.googlegroups.com> <434E1674.5010201@v.loewis.de> <1129192705.632826.145210@z14g2000cwz.googlegroups.com> Message-ID: <1129225263.705977.181050@o13g2000cwo.googlegroups.com> As an aside to this, are there any freely available C compilers for Windows that can compile 64-bit binaries? I find nothing for Cygwin or MinGW... From aleax at mail.comcast.net Fri Oct 14 17:46:35 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Fri, 14 Oct 2005 23:46:35 +0200 Subject: confusion between global names and instantiated object variable names References: <1129322411.776202.314290@g43g2000cwa.googlegroups.com> Message-ID: <1h4g4nw.1cfl5tn34bdetN%aleax@mail.comcast.net> wanwan wrote: ... > when I run my example, an error shows: > "NameError: global name'menubar' is not defined" > > I wonder why it doesn't work. Isn't that the way to define an object > variable? The code you posted should not trigger this error. Most likely problem: you have typed a comma where you meant to type a dot, for example instead of self.menubar you wrote self,menubar somewhere -- it's a hard error to spot with certain fonts. Alex From nephish at xit.net Sun Oct 30 21:01:11 2005 From: nephish at xit.net (nephish at xit.net) Date: 30 Oct 2005 18:01:11 -0800 Subject: need start point for getting html info from web Message-ID: <1130724071.688187.59230@g47g2000cwa.googlegroups.com> hey there, i have a small app that i am going to need to get information from a few tables on different websites. i have looked at urllib and httplib. the sites i need to get data from mostly have this data in tables. So that, i think would make it easier. Anyone suggest a good starting point for me to find out how to do this, or know of a link to a good how-to? thanks, sk From tdelaney at avaya.com Wed Oct 12 19:49:57 2005 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Thu, 13 Oct 2005 09:49:57 +1000 Subject: Python's garbage collection was Re: Python reliability Message-ID: <2773CAC687FD5F4689F526998C7E4E5F4DB6D6@au3010avexu1.global.avaya.com> Tom Anderson wrote: > Except that in smalltalk, this isn't true: in ST, every variable > *appears* to contain a reference to an object, but implementations > may not actually work like that. In particular, SmallTalk 80 (and > some earlier smalltalks, and all subsequent smalltalks, i think) > handles small integers (those that fit in wordsize-1 bits) > differently: all variables contain a word, whose bottom bit is a tag > bit; if it's one, the word is a genuine reference, and if it's zero, > the top bits of the word contain a signed integer. This type of implementation has been discussed on python-dev. IIRC it was decided by Guido that unless anyone wanted to implement it and show a significant performance advantage without any regressions on any platform, it wasn't worth it. Basically, put up or shut up ;) Tim Delaney From apardon at forel.vub.ac.be Mon Oct 31 03:56:09 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 31 Oct 2005 08:56:09 GMT Subject: Would there be support for a more general cmp/__cmp__ References: Message-ID: Op 2005-10-28, Ron Adam schreef : > > I haven't heard he was removing __cmp__, I read somewhere he was considering it. > but I would think the sort or > sorted functions would just use the available comparisons methods or > equivalent C code for base types. So I expect it would only matter if > you need a custom or modified sort. > > Although It is a thought that these cases could be improved by making > the sort value available to the underlying C sort function. Something > on the order of: > > __sortvalue__ == self.value. I doubt that will be possible in general. You can't even calculate such a __sortvalue__ for lists. -- Antoon Pardon From who2guess at xs4all.nl Thu Oct 27 11:02:58 2005 From: who2guess at xs4all.nl (W.H.Offenbach) Date: Thu, 27 Oct 2005 17:02:58 +0200 Subject: syntax question - if 1:print 'a';else:print 'b' In-Reply-To: <312cfe2b0510270757o51d3cfa7h2fccc775068b5549@mail.gmail.com> References: <312cfe2b0510261507m2732e947p2be6fdae99a7c3d7@mail.gmail.com> <312cfe2b0510270757o51d3cfa7h2fccc775068b5549@mail.gmail.com> Message-ID: <62e0012031f2fae1fb705a2d164556ce@xs4all.nl> Gregory Pi?ero wrote: > So much for writing my whole program on one line :-( Why bother with one liners? "The number of meaningful lines and pages a writer produces is a measure for his writer-ship" -- my old Literature professor From uche.ogbuji at gmail.com Fri Oct 28 16:37:19 2005 From: uche.ogbuji at gmail.com (uche.ogbuji at gmail.com) Date: 28 Oct 2005 13:37:19 -0700 Subject: XML Tree Discovery (script, tool, __?) In-Reply-To: <1130491182.405885.49010@g14g2000cwa.googlegroups.com> References: <1130183060.195730.178330@g47g2000cwa.googlegroups.com> <1130491182.405885.49010@g14g2000cwa.googlegroups.com> Message-ID: <1130531839.145106.287950@g44g2000cwa.googlegroups.com> """ I was looking for something similar (XML to DTD inference) but I didn't find anything related in python. Trang (http://www.thaiopensource.com/relaxng/trang-manual.html#introduction), on the other hand seems impressive after a few non-trivial tests. It would be neat to have it ported in python, at least the inference part. """ If you're OK with RELAX NG rather than DTD as the schema output (probably a good idea if you're using namespaces), consider Examplotron, which I've used on many such production tasks. http://www-128.ibm.com/developerworks/xml/library/x-xmptron/ It's XSLT rather than Python, but the good news is that XSLT is easy to invoke from Python using tools such as 4Suite. http://uche.ogbuji.net/tech/akara/nodes/2003-01-01/python-xslt -- Uche Ogbuji Fourthought, Inc. http://uche.ogbuji.net http://fourthought.com http://copia.ogbuji.net http://4Suite.org Articles: http://uche.ogbuji.net/tech/publications/ From apardon at forel.vub.ac.be Wed Oct 12 07:36:12 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 12 Oct 2005 11:36:12 GMT Subject: A Tree class, my $0.02 contribution to the python community. Message-ID: Comments are welcome: http://www.pardon-sleeuwaegen.be/antoon/avltree.html From jeremy.d.brewer at gmail.com Sat Oct 22 19:55:49 2005 From: jeremy.d.brewer at gmail.com (jbrewer) Date: 22 Oct 2005 16:55:49 -0700 Subject: Python cgi In-Reply-To: References: <1129930246.435616.291660@g44g2000cwa.googlegroups.com> Message-ID: <1130025348.958342.212330@f14g2000cwb.googlegroups.com> I added enctype="multipart/form-data" to the
tag, and that seemed to solve it. Thanks. Jeremy From cfajohnson at gmail.com Fri Oct 21 03:55:32 2005 From: cfajohnson at gmail.com (Chris F.A. Johnson) Date: Fri, 21 Oct 2005 03:55:32 -0400 Subject: Set an environment variable References: <43573022$0$155$edfadb0f@dread16.news.tele.dk> <1129798724.366618.194650@g44g2000cwa.googlegroups.com> <43589205$0$125$edfadb0f@dread16.news.tele.dk> <43589834$0$99986$edfadb0f@dread16.news.tele.dk> Message-ID: On 2005-10-21, Christian wrote: > Erik Max Francis wrote: >> Christian wrote: >> >>> Can I write a .py script that calls a .sh script that executes the >>> export command and then calls another .py script (and how would the >>> first .py script look)? >> >> No, the shell script that the Python program would invoke would be a >> different process and so commands executed in it would have no effect on >> the state of another. >> > > So executing an .sh script that calls a .py script works different when > executed from a command promt than when executed from a starter .py script? No; it's always the same: an environment variable will only be effective in the process in which it is set, and its children. When you call another program, whether it's a shell script, python script, or binary executable, you are starting a new process. Environment variables set in that process will not affect its parent (i.e., the process that called it). -- Chris F.A. Johnson ================================================================== Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress From fredrik at pythonware.com Fri Oct 14 08:46:58 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 14 Oct 2005 14:46:58 +0200 Subject: Python's Performance References: <20051008040614.47429.qmail@web30607.mail.mud.yahoo.com><178B879D-FDB6-458C-BE00-A03820D98703@advfn.com><1128888628.643764@yasure> <1128988055.798016.147970@g49g2000cwa.googlegroups.com> Message-ID: Paul Boddie wrote: > On the subject of other virtual machine implementations, I wonder what > happened to this one: > > http://effbot.org/zone/pytte.htm > > Fredrik? ;-) so much code, so little time... From john at castleamber.com Sun Oct 16 10:38:04 2005 From: john at castleamber.com (John Bokma) Date: 16 Oct 2005 14:38:04 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: "David Schwartz" wrote: > > "John Bokma" wrote in message > news:Xns96F0C9445F383castleamber at 130.133.1.4... > >> Ok, let me spell it out for you: If all your applications are web >> based, and the OS shouldn't matter, why do Linux distributions >> matter? It doesn't matter which one you use to run, for example, >> OpenOffice. Yet people pick a certain distribution. Why? Well, one >> reason is that people like to belong to a group. So even if it really >> doesn't matter which OS you are going to use to access a web >> application, or even which browser, people will pick a certain >> browser, and a certain OS, just because. > > You don't get it. The point is, you can pick any Linux > distribution and > still use the same applications. This is exactly what Microsoft > *doesn't* want. They want applications to be locked to Microsoft OSes. > For then to do this, applications have to be as tied to the OS as > possible. The browser as a target platform threatened this Microsoft > vision, so Microsoft reacted by trying to corner the browser market > and balkanize Java. And when are we going to see this browser as a target platform? > You can agree or disagree with the rationale and by sympathetic > with or > antagonistic to Microsoft's motive. But these are historical facts. No: the historical fact is that MS whiped Netscape of the planet. That you come up with "They were afraid that everybody would be running NS Office online using Netscape" is just a guess. MS just seems to ignore a certain development for some time, then state it's not significant, and next they are an important player. This is not limited to "MS missed the Internet, almost...". They don't miss anything, they just don't jump on every hype. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From deets at nospam.web.de Tue Oct 11 13:49:22 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 11 Oct 2005 19:49:22 +0200 Subject: Wrapper function In-Reply-To: <1129052312.444144.142950@g44g2000cwa.googlegroups.com> References: <1129052312.444144.142950@g44g2000cwa.googlegroups.com> Message-ID: <3r2c91FhamghU1@uni-berlin.de> > PyObject *wrap_doStuff(PyObject *, PyObject *args) { ^^^^^ I guess you need a parameter name here.... Diez From grante at visi.com Fri Oct 21 10:34:09 2005 From: grante at visi.com (Grant Edwards) Date: Fri, 21 Oct 2005 14:34:09 -0000 Subject: Set an environment variable References: <43573022$0$155$edfadb0f@dread16.news.tele.dk> <1129798724.366618.194650@g44g2000cwa.googlegroups.com> <43589205$0$125$edfadb0f@dread16.news.tele.dk> Message-ID: <11lhv31li8sgm0c@corp.supernews.com> On 2005-10-21, Christian wrote: >> >> The closest thing you can do is that: >> >> -myScript.py-------------------------------------- >> print 'export MY_VARIABLE=value' >> -------------------------------------------------- >> >> -myScript.sh-------------------------------------- >> python myScript.py > /tmp/chgvars.sh >> . /tmp/chgvars.sh >> -------------------------------------------------- Bullshit. Are people being intentionally misleading?? > Can I write a .py script that calls a .sh script that executes the > export command and then calls another .py script (and how would the > first .py script look)? Good grief, that's ugly. Just use os.putenv(). > That would be much more what is my basic problem. And even Google knows the correct answer http://www.google.com/search?hl=en&lr=&q=python+set+environment+variable Follow the first hit. -- Grant Edwards grante Yow! TONY RANDALL! Is YOUR at life a PATIO of FUN?? visi.com From hancock at anansispaceworks.com Fri Oct 21 22:14:27 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Fri, 21 Oct 2005 21:14:27 -0500 Subject: Python vs Ruby In-Reply-To: <11lin723i0e3k80@corp.supernews.com> References: <3nc*FXJ1q@news.chiark.greenend.org.uk> <11lin723i0e3k80@corp.supernews.com> Message-ID: <200510212114.27617.hancock@anansispaceworks.com> On Friday 21 October 2005 04:25 pm, Ed Jensen wrote: > Sion Arrowsmith wrote: > > I have here a library (it's the client side of a client-server > > interface including a pile of class definitions) which has > > implementations in pure C++, Java and Python, taking about 3000, > > 3500 and 1500 loc respectively. And there's an associated module > > (with no C++ implementation) that I remember being particular > > "impressed" while writing it to find being 3 times as long in Java > > as Python despite (a) extensive (and pretty much common) Javadoc/ > > docstrings and (b) implementing in the Python version a feature > > present in the standard Java library (scheduling a thread to run > > at specified intervals and time out). Strip the Javadoc/docstrings > > out and it's about at that 5:1 ratio. > > This claim seems pretty dubious to me. Why? -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From rrr at ronadam.com Tue Oct 25 12:57:07 2005 From: rrr at ronadam.com (Ron Adam) Date: Tue, 25 Oct 2005 16:57:07 GMT Subject: Missing modules '_ssl', 'ext.IsDOMString', 'ext.SplitQName' In-Reply-To: <1130230864.068474.118500@g43g2000cwa.googlegroups.com> References: <1130003715.743391.237890@f14g2000cwb.googlegroups.com> <1130230864.068474.118500@g43g2000cwa.googlegroups.com> Message-ID: uid09012_ti at collinsrealtime.com wrote: > Hi, > > unfortunately the result from py2exe won't run eventhough the original > script runs without problems. The trouble is I'm at a loss as to where > to start looking! > > Martin. Just a guess, Make sure any your file names aren't the same as any of the module names you are using. Cheers, Ron From nephish at xit.net Thu Oct 20 12:54:41 2005 From: nephish at xit.net (nephish at xit.net) Date: 20 Oct 2005 09:54:41 -0700 Subject: need some advice on x y plot In-Reply-To: References: <1129823043.104864.73750@f14g2000cwb.googlegroups.com> Message-ID: <1129827280.977047.269090@g43g2000cwa.googlegroups.com> i have thought about doing this, just a little different. i was going to list the value pairs. take the start time and end time and plot 100 empty plots between them. add the value pairs, sort by time, and then draw it. The only thing is it get kinda complicated when the times change a lot. they could span an hour, a month, anything in between. i like your idea, i will check various packages for how to plot 'none' thanks sk. From usenet at marduk.letterboxes.org Mon Oct 3 21:01:03 2005 From: usenet at marduk.letterboxes.org (marduk) Date: Tue, 04 Oct 2005 01:01:03 GMT Subject: "no variable or argument declarations are necessary." In-Reply-To: References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> Message-ID: <1128387663.3101.12.camel@blackwidow> > egold = 0: > while egold < 10: > if test(): > ego1d = egold + 1 > Both pylint and pychecker pick this up. I wrapped the code in a function (to prevent importing from running in an infinite loop) and ran both pylint and pychecker: plyint: W: 5:myfunc: Unused variable 'ego1d' pychecker: test.py:4: Local variable (ego1d) not used I make a habit to run pylint or pychecker on my code often. They pick up a lot of stuff like unused variables, etc. But you can also do this: /* initialize variables i'm gonna use */ int vara = 0; int varb = 0; while (vara < 10) { varb = vara + 1; } So we can make a similar mistake in C if you type the wrong (declared) variable name. Moreover, "gcc -Wall" did not report the "unused" variable so it might be even more difficult to track down the problem. From tokidokix at gmail.com Tue Oct 18 22:03:17 2005 From: tokidokix at gmail.com (toki doki) Date: Wed, 19 Oct 2005 04:03:17 +0200 Subject: How to organize Python files in a (relatively) big project Message-ID: Hello there, I have been programming python for a little while, now. But as I am beginning to do more complex stuff, I am running into small organization problems. It is possible that what I want to obtain is not possible, but I would appreciate the advice of more experienced python programmers. I am writing a relatively complex program in python that has now around 40 files. At first, I had all of my files in one single directory, but now, with the increasing number of files, it is becoming hard to browse my directory. So, I would want to be able to divide the files between 8 directory, according to their purpose. The problem is that it breaks the 'import's between my files. And besides,AFAIK, there is no easy way to import a file that is not in a subdirectory of the current file (I suppose I could adjust the os.path in every file, but that seems not very elegant to me). I thought about turning the whole into a package. But I have to change every 'import module_name' into 'from package_name.sub_directory_name import module_name' which is a little bit time consuming and not very flexible (if I change my mind about the subdirectory a file belongs to, I will have to track again every import to correct them) So, basically, here is the point: is there an 'elegant' way to keep my files in separate directory and still be able to import between them with simple 'import filename'? And if not, what would be the standard way to organize numerous python files belonging to the same project? Thanks a lot for any advice, TokiDoki -------------- next part -------------- An HTML attachment was scrubbed... URL: From dcrespo at gmail.com Sat Oct 15 08:41:32 2005 From: dcrespo at gmail.com (dcrespo) Date: 15 Oct 2005 05:41:32 -0700 Subject: How to get a raised exception from other thread In-Reply-To: References: <1129326320.914350.171460@o13g2000cwo.googlegroups.com> Message-ID: <1129380092.861750.229290@g43g2000cwa.googlegroups.com> Thanks for your answer, but I think that created thread in python should create a thread either on windows and linux. Can you give me Python example of how to do what I want to do? Thanks From fredrik at pythonware.com Sun Oct 9 08:04:06 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 9 Oct 2005 14:04:06 +0200 Subject: new forum -- homework help/chit chat/easy communication References: <1128798687.305818.66010@g49g2000cwa.googlegroups.com><1128810677_124183@spool6-east.superfeed.net> Message-ID: Lasse V?gs?ther Karlsen wrote: > > > "Unlike mainstream component programming, scripts usually > > do not introduce new components but simply "wire" existing > > ones. Scripts can be seen as introducing behavior but no > > new state. /.../ Of course, there is nothing to stop a > > "scripting" language from introducing persistent state -- it > > then simply turns into a normal programming language." > > > > -- Clemens Szyperski, in "Component Software": > > > That description seems to describe whatever is written more than > whatever it is written in, or in other words, it describes the > difference between a script and a program, not between a scripting > language and a programming language. well, yes and no. it basically implies that if a language doesn't have the internal mechanisms required to implement persistent storage on its own, it's a scripting language. examples are shell languages, the Windows BAT language, javascript running in certain environments, and the myriad of application-specific "command languages" that were popular in the "old days". > Nowadays a lot of the scripting languages have turned programming > languages so I think the difference is small. I think the trend is that when people are faced with a "scripting problem" (e.g. when they need "command languages" or other kinds of basic pro- grammability), it's no longer fashionable to invent yet another language. integrating an existing runtime is a lot easier. Tcl is an early example of a something that started as a "reusable command language" and turned into a "real programming language" along the way: http://www.tcl.tk/advocacy/tclHistory.html From my_email_is_posted_on_my_website at munged.invalid Tue Oct 18 22:46:14 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 19 Oct 2005 02:46:14 GMT Subject: Microsoft Hatred FAQ References: <1129491006.021102.43920@g14g2000cwa.googlegroups.com> <86zmp8zsjk.fsf@bhuda.mired.org> <3rjvdaFk0l1sU1@individual.net> Message-ID: On 18 Oct 2005 18:02:53 GMT, John Bokma wrote or quoted : >If you think you can direct the development of human behaviour by not >buying a Microsoft product, be my guest. Refusing to take any action against them is also immoral. I think you are morally obligated to take some reasonable action to counter Microsoft, effective in and of itself or not. Your counsel is similar to those who tell people it is futile to vote. ?All that is necessary for the triumph of evil is that good men do nothing.? ~ Edmund Burke I had an experience that changed my completely on that sort of issue. I started gay lib in my part of the world purely as a "futile moral gesture". Within 2 years to my utter amazement, we had the gay rights legislation. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From steve at holdenweb.com Sat Oct 1 05:21:46 2005 From: steve at holdenweb.com (Steve Holden) Date: Sat, 01 Oct 2005 10:21:46 +0100 Subject: Google Not Universal Panacea [was: Re: Where to find python c-sources] In-Reply-To: References: Message-ID: Erik Max Francis wrote: > Steve Holden wrote: > > >>While a snappish "go and look it up on Google" might suffice for a >>mouthy apprentice who's just asked their thirteenth question in the last >>half hour, it's (shall we say) a little on the brusque side for someone >>who only appears on the group last February, and has a history of asking >>reasonably pertinent though sometimes beginner-level questions. > > > I told him exactly where it was. I just also pointed out that he could > have trivially found out the answer on his own by using Google for > fifteen seconds. It would be one thing if I (and nobody else) answered > his question and just rudely pointed him to Google. But since I > actually answered his question, looks to me like someone just wanted to > stand on his soapbox today. > I don't think "The source tarball on python.org" could claim to be telling him "exactly where it was" given that my copy of the web site has 341 MB of stuff in it. Just that same, if you are saying that your behaviour didn't really merit my response then I'd probably agree. Your post was the straw that broke the camel's back rather than an egregious example of bad manners. So I'm sorry if it looked as though the soapboxing was directed primarily at you, which it wasn't. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From ms at cerenity.org Mon Oct 3 14:38:11 2005 From: ms at cerenity.org (Michael) Date: Mon, 03 Oct 2005 19:38:11 +0100 Subject: [Info] PEP 308 accepted - new conditional expressions References: <3q4ro9Fd770nU3@individual.net> <434087a4$0$49795$ed2e19e4@ptn-nntp-reader04.plus.net> <43412b45$0$21220$626a14ce@news.free.fr> Message-ID: <43417a66$0$49809$ed2e19e4@ptn-nntp-reader04.plus.net> Christophe wrote: > Michael a ?crit : >> Rocco Moretti wrote: >> >> >>>That is, what would happen with the following constructs: >>> >>>A if B else C if D else F >>>A if B if C else D else F >> >> >> The correct answer should be the person who wrote it would get told off >> for writing code that a person reading would have no idea what the code >> was doing (without understanding the precedence). >> >> Whilst it's good to have clear understandable, well defined rules for >> these things, that's no excuse for having unreadable code that other >> people can't read and understand without having to remember obscure >> rules. >> >> Personally, I'd hope that any code-linting tools would flag such >> expressions as potentially bad because they're not clear. (Whereas >> bracketed expressions instantly help here). > > Actually, you don't need to know operator precedence here because the > notation isn't ambiguous in those 2 examples. Of course, it takes some > time to understand the thing but it has more to do with the excessive > amount of "logic" in one line than with the syntax. I noted that. However it *does* slow people down which increases the chances of misconception (which is why I'd be in favour of bracketing these expressions). Michael. From ptb at oboe.it.uc3m.es Tue Oct 25 18:00:32 2005 From: ptb at oboe.it.uc3m.es (Peter T. Breuer) Date: Wed, 26 Oct 2005 00:00:32 +0200 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> <3s6l8mFmj3fjU1@individual.net> Message-ID: <0hm233-0ut.ln1@news.it.uc3m.es> In comp.os.linux.misc David Schwartz wrote: > "Peter T. Breuer" wrote in message > news:lgs133-7ub.ln1 at news.it.uc3m.es... >>> Yes, it certainly is. However, it is also Microsoft's right as a >>> seller >>> to refuse discounts to those who also sell competing products. You may >>> not >> No it is not their "right"! That would be a discriminatory practice, >> not to mention an anti-competitive practice. Totally. > Businesses have the right to be discriminatory and anti-competitive in > this way. No they don't. I'm simply open-jawed at such a statement. > McDonald's won't sell a Burger King their burger patties. McDonald's are not in the business of wholesale distribution of burger patties so your statement is simply sited in the wrong universe of discourse. Coming back to the current universe of discourse, I assure you that a McDonald's director can go into a Burger King and buy a burger like anyone else, so no discrimination. Mind you - I'm not sure if they'd let Ronald in. He's obviously dangerously nutty. > his is > both discriminatory and anti-competitive, It's neither. It's simply not part of their business. > but also perfectly legal, moral, > and proper. Dalse assumptions, hence invalid conclusions. > You only run into a problem under United States law if the company is a > monopoly. And I've already addressed that issue in this thread. If MacDonalds were wholesale suppliers of hamburgers to the distribution trade, then they couldn't discriminate among their customers for the purposes of altering the competitive nature of the market in hamburger sales to you and me across the counter. Companies have been sued for trying that - sports shoe manufacturers, I seem to recall. They've tried to make sure their shoes are sold only by specified outlets at specified prices, in order to artificially manage the market. That's illegal. Sued they got (or perhaps "suede"). Peter From fredrik at pythonware.com Tue Oct 4 17:35:45 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 4 Oct 2005 23:35:45 +0200 Subject: how to get any available port References: <11k5pgpp19v0ec@corp.supernews.com> Message-ID: Mohammed Smadi wrote: > what else would you do? I am using examples from the web and they all > bind to a port at the localhost before connecting to the remote host. pointers, please. > my code is like this > > #transmission socket > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) > s.bind(("",hp_port)) # do some error checking that's a typical server setup. > data="HI" > print data > s.connect(('192.168.2.13',port)) > s.send(data) and this is typical client setup. are you sure you're not cutting and pasting code from different examples? > any suggestions for alternative implementation? if you're writing a client, get rid of the setsockopt and bind stuff. From john at castleamber.com Tue Oct 18 13:59:10 2005 From: john at castleamber.com (John Bokma) Date: 18 Oct 2005 17:59:10 GMT Subject: Microsoft Hatred FAQ References: <%jV4f.3121$tV6.2659@newssvr27.news.prodigy.net> <2u59l1555jubv8qv09q57qh8m4skei9dqi@4ax.com> <3tc9l11oejnq3i2hnrld7akujouk3771tv@4ax.com> Message-ID: Roedy Green wrote: > On 18 Oct 2005 06:57:47 GMT, John Bokma wrote > or quoted : > >>>>That an HTML standard (ISO/IEC 15445:2000) and an HTML >>>>recommendation by w3c (4.01 for example) are two different things, >>>>and mixing them up by calling both standards is a bad thing. >>> >>> Because ... what are the consequences? >> >>If you mean if you are put in jail for 20 years, and tortured, none. > > No. ANY consequences. You have not explained the downside. ISO HTML and HTML 4.01 differ. If you were asked to write a validating parser for the HTML standard, (as in ISO), and you wrote one for HTML 4.01 (as in recommendation), you made quite a mistake. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From deets at nospam.web.de Thu Oct 20 18:15:27 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 21 Oct 2005 00:15:27 +0200 Subject: KeyboardInterrupt vs extension written in C In-Reply-To: <1129814875.226834.10260@g49g2000cwa.googlegroups.com> References: <1129814875.226834.10260@g49g2000cwa.googlegroups.com> Message-ID: <3rqj7vFhstbuU1@uni-berlin.de> Tamas Nepusz wrote: > Hi everyone, > > I have tried to do some googling before asking my question here, but I > haven't found any suitable answer. I am developing a Python API for a > graph library written in pure C. The library is doing an awful lot of > math computations, and some of them can take a pretty long time > (depending on the size of the input). If I invoke such calculation from > Python using my own extension, the interpreter locks until the > calculation is complete (I mean, it is not responding to Ctrl-C or > SIGINT). > > My question is: is there any way to allow the user to use Ctrl-C to > generate a KeyboardInterrupt and cancel such large computations? I'm > assuming that although pressing Ctrl-C may generate a KeyboardInterrupt > in Python, it is not propagated to the user level until the call into > the graph library returns. I tried to add Py_BEGIN_ALLOW_THREADS before > the call to the underlying C library and Py_END_ALLOW_THREADS after > returning from it, but I had no luck. I'm not especially an expert with C-extensions. So I'm not sure if I can be of any help here. But if what you really are after is "only" terminating the whole program (instead of just the computation, and then continue), you might consider threads. Do the calls in a separate thread, and make that a daemon-thread. Then things _should_ work as expected, as the main thread will receive the signal. Hopefully... if your call releases the GIL. Which Py_*_ALLOW_THREADS seems to do. So - give it a try :) Diez From robert.kern at gmail.com Mon Oct 10 01:05:34 2005 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 09 Oct 2005 22:05:34 -0700 Subject: non descriptive error In-Reply-To: <4349AE08.1000306@open-networks.net> References: <4346002C.3080504@open-networks.net> <200510070240.56350.hancock@anansispaceworks.com> <4349A55C.90203@open-networks.net> <4349AE08.1000306@open-networks.net> Message-ID: Timothy Smith wrote: > it is definately a bug in 2.3 when using the decimal module. i can > reproduce it. > > from decimal import Decimal > a = Decimal('0' > > and when you attempt to run it you will get "error" > > of course i do understand that decimal wasn't part of 2.3, but atleast > now when if anyone gets that terse message they know where to start > looking :) [~]$ cat foo.py from decimal import Decimal a = Decimal('0' [~]$ python2.3 foo.py File "foo.py", line 4 ^ SyntaxError: invalid syntax -- 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 klaus at seistrup.dk Wed Oct 5 16:14:04 2005 From: klaus at seistrup.dk (Klaus Alexander Seistrup) Date: Wed, 5 Oct 2005 20:14:04 +0000 (UTC) Subject: Replacing utf-8 characters References: <1128522921.72009@nntp.acecape.com> Message-ID: Mike wrote: > Hi, I am using Python to scrape web pages and I do not have problem > unless I run into a site that is utf-8. It seems & is changed to > & when the site is utf-8. > > [...] > Any ideas? How about using the universal feedparser from feedparser.org to fetch and parse the RSS from Reuters? That's what I do and it works like a charm. #v+ >>> import feedparser >>> rss = feedparser.parse('http://today.reuters.com/rss/topNews') >>> for what in ('link', 'title', 'summary'): ... print rss.entries[0][what] ... print ... http://today.reuters.com/news/newsarticle.aspx?type=topNews&storyid=2005-10-05T193846Z_01_DIT561620_RTRUKOC_0_US-COURT-SUICIDE.xml Top court seems closely divided on suicide law During arguments, the justices sharply questioned both sides on whether then-Attorney General John Ashcroft had the power under federal law in 2001 to bar distribution of controlled drugs to assist suicides, regardless of state law. >>> #v- Cheers, -- Klaus Alexander Seistrup Magnetic Ink, Copenhagen, Denmark http://magnetic-ink.dk/ From aleaxit at yahoo.com Tue Oct 18 14:40:54 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 18 Oct 2005 20:40:54 +0200 Subject: List of strings to list of floats ? References: <4351d29e$0$41148$14726298@news.sunsite.dk> <4353d2a2$0$41138$14726298@news.sunsite.dk> <43540cc0$0$41147$14726298@news.sunsite.dk> Message-ID: <1h4napk.yissq44hzbpiN%aleaxit@yahoo.com> Madhusudan Singh wrote: ... > >> Say I have two lists of floats. And I wish to generate a list of floats > >> that is a user defined function of the two lists. > > > > result = [sqrt(x**2 + y**2) for x, y in zip(xs, ys)] > > Works perfectly. Thanks ! If zip works and map doesn't, most likely your problem is that the two lists have different lengths. In this case, zip truncates to the shorter list, while map conceptually extends the shorter list with copies of None -- causing an error when you try to do arithmetic between a float towards the end of the longer list, and None...! Alex From nochiel at gmail.com Sat Oct 29 15:55:15 2005 From: nochiel at gmail.com (yoda) Date: 29 Oct 2005 12:55:15 -0700 Subject: py.log using decorators for DRY In-Reply-To: <1h56wng.106v8tn1lk8f2rN%aleaxit@yahoo.com> References: <1130606608.107621.138650@z14g2000cwz.googlegroups.com> <1h56wng.106v8tn1lk8f2rN%aleaxit@yahoo.com> Message-ID: <1130615715.178228.238640@g44g2000cwa.googlegroups.com> I feel so stupid... lol... now why didn't I think of that? Thanks Alex. From tim at tt1lock.org Fri Oct 14 04:00:24 2005 From: tim at tt1lock.org (Tim Tyler) Date: Fri, 14 Oct 2005 08:00:24 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <86y853mzmr.fsf@bhuda.mired.org> <86mzlil269.fsf@bhuda.mired.org> Message-ID: In comp.lang.java.programmer Mike Meyer wrote or quoted: > Tim Tyler writes: > > In comp.lang.java.programmer Mike Meyer wrote or quoted: > >> The technial problems have been solved for over a decade. NeXT shipped > >> systems that used text/richtext, which has none of the problems that > >> HTML has. The problems are *social* - you've got to arrange for > >> people to use mail/news readers that understand a rich text format > >> that isn't a vector for viruses. > > > > It's not HTML that has problems, it's Microsoft's crappy software. > > HTML is a problem on *other* peoples crappy software as well. It > wasn't designed to carry code content, but has been hacked up to do > that. Are there any examples of HTML email causing security problems - outside of Microsoft's software? I can think of one: the JPEG virus. However, that affected practically any program that could render JPEGs - not just HTML. > > Writing virus-free HTML renderers is not hard - but of course > > Microsoft can still screw it up. > > Sure - just disable all the features that make people want to use HTML > instead of something else. Not so: you disable Java, Javascript and plugins. You leave the ability to format, colour and hint documents. This is not /that/ difficult. > > Don't blame HTML for viruses - *every* document format Microsoft has > > anything to do with becomes a vector for viruses. > > Which would mean that every open format that MS has had anything to do > with comes a vector for viruses. Somehow, I'm not buying it. I exaggerate only slightly. -- __________ |im |yler http://timtyler.org/ tim at tt1lock.org Remove lock to reply. From alex at moreati.org.uk Fri Oct 7 08:30:13 2005 From: alex at moreati.org.uk (Alex Willmer) Date: Fri, 07 Oct 2005 12:30:13 GMT Subject: CSV like file format featured recently in Daily Python URL? Message-ID: <1128688213.7906.7.camel@localhost.localdomain> I'm trying to track down the name of a file format and python module, that was featured in the Daily Python URL some time in the last month or two. The format was ASCII with a multiline header defining types for the comma seperated column data below. It may have had the capability to store multiple tables in one file. There was news on the homepage that an alternate 'no data here' syntax was also supported. An example file had vaguely this structure: columnname as datatype columnname as datatype columnname as datatype columnname as datatype data,data,data,data data,"other data",data,data data,data,"",data Can anyone remember this file format/python module? With thanks Alex From http Fri Oct 7 10:25:14 2005 From: http (Paul Rubin) Date: 07 Oct 2005 07:25:14 -0700 Subject: Can't extend function type References: <7xoe61g4p7.fsf_-_@ruckus.brouhaha.com> <1128693651.822764.321010@g44g2000cwa.googlegroups.com> Message-ID: <7x7jcptned.fsf@ruckus.brouhaha.com> "Michele Simionato" writes: > If you google a bit on the newsgroup, you should find a message > from me asking about the ability to subclass FunctionType, and > a reply from Tim Peters saying that the only reason why this > was not done is lack of developer time and the fact that this was > not considered an important priority. Yeah, I just thought of it as a perverse but sort of cute way to implement composition and similar operations on functions. It could be handy though, and simple to implement, if functions supported the '*' operator for composition. The example with a callable class is a possible workaround, but ugly. From bonono at gmail.com Mon Oct 17 07:08:56 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 17 Oct 2005 04:08:56 -0700 Subject: generic xmerge ? In-Reply-To: <1h4kurr.y4wcn71rpq7x6N%aleaxit@yahoo.com> References: <1129545131.875544.122630@f14g2000cwb.googlegroups.com> <1h4kurr.y4wcn71rpq7x6N%aleaxit@yahoo.com> Message-ID: <1129547336.228373.10140@g49g2000cwa.googlegroups.com> oops, sorry. I meant l1=[(date,v1,v2,v3), ...] l2=[ another set of tuples ] Thanks. so I have to concat the multiple lists first(all of them are sorted already) ? Alex Martelli wrote: > I'm not sure what "my list is a tuple" mean (list and tuple being > different types) nor what this has to do with the recipe. Anyway... > sequences are compared lexicographically -- first items first, then > second items if the first items are equal, and so on. So, if you have a > list X whose items tuples and want X sorted on the tuples' first items, > X.sort() will suffice -- if the tuples never have equal first-items, or > if you're OK with second-items getting compared when the first-items are > equal. If you want to sort on first-items ONLY, leaving the tuples in > the same order in the list when their first-items are equal: > > import operator > X.sort(key=operator.itemgetter(0)) > > > Alex From grante at visi.com Fri Oct 7 20:28:52 2005 From: grante at visi.com (Grant Edwards) Date: Sat, 08 Oct 2005 00:28:52 -0000 Subject: Simulating low bandwidth network on localhost References: <1128728893.814798.44050@g49g2000cwa.googlegroups.com> Message-ID: <11ke4m4j04uau26@corp.supernews.com> On 2005-10-07, qvx wrote: > I would like to test my CherryPy application in varying > network conditions, ranging from localhost full speed to low > badwidth (ie. 14.4kbps) and variable latency from milliseconds > range to seconds range. If you've got a machine with two serial ports, you can connect them with a null-modem cable and set up a PPP connection between the two. You can set the baud rate as low as you want. There isn't any way to control latency, though. > How can I simulate this? Are there some tricks to be played > with Python or is there a specialized software for this kind > of things (preferably free). -- Grant Edwards grante Yow! Let's send the at Russians defective visi.com lifestyle accessories! From fredrik at pythonware.com Fri Oct 7 12:22:44 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 7 Oct 2005 18:22:44 +0200 Subject: os.access with wildcards References: <1128665933.923295.95580@f14g2000cwb.googlegroups.com><1128698336.836590.96080@g44g2000cwa.googlegroups.com> <1128701207.675536.126370@z14g2000cwz.googlegroups.com> Message-ID: "mike" wrote: > dude, you are the sap that wrote "it's not clear". followed by three possible solutions to the stated problem, one of which was marked as "most likely". > get a life. oh, sorry for wasting my time. can I *plonk* you now? From samrobertsmith at gmail.com Wed Oct 19 08:21:32 2005 From: samrobertsmith at gmail.com (Shi Mu) Date: Wed, 19 Oct 2005 05:21:32 -0700 Subject: path Message-ID: <1d987df30510190521o4c68b249j2f9c721e0167f89f@mail.gmail.com> I have installed Python 2.3 and I type "help()" and then "Keywords". I get a list of words. And it says that I can enter any of the words to get more help. I enter "and" and I get the following error message: "Sorry, topic and keyword documentation is not available because the Python HTML documentation files could not be found. If you have installed them, please set the environment variable PYTHONDOCS to indicate their location." but I have set both the environment variable, with the path to be C:\Python23\Doc which includes python23.chm Why I still got the above error message? From mtammerman at gmail.com Tue Oct 4 17:58:36 2005 From: mtammerman at gmail.com (Mike Tammerman) Date: 4 Oct 2005 14:58:36 -0700 Subject: Excel library with unicode support Message-ID: <1128463115.969232.146590@z14g2000cwz.googlegroups.com> Hi, I want to create an Excel file, but I don't to use com or any win32 object. Because, the file should be opened via OpenOffice. I found pyXLWriter, but it doesn't support unicode or non-ascii characters. Is there a python library, that is able to create Excel files with unicode characters. I think, pyXLWriter is a stopped project. Thanks, Mike From axel at white-eagle.invalid.uk Thu Oct 20 09:17:14 2005 From: axel at white-eagle.invalid.uk (axel at white-eagle.invalid.uk) Date: Thu, 20 Oct 2005 13:17:14 GMT Subject: Microsoft Hatred FAQ References: <867jcbzdw9.fsf@bhuda.mired.org> <4vcbl1dkek9kr86embmgrj70vk945t99ho@4ax.com> <35jbl1dprs4v1o87i0tapc2husjqiqm6fi@4ax.com> <4355ea72$1_3@news.melbourne.pipenetworks.com> Message-ID: In comp.lang.perl.misc Roedy Green wrote: > On Wed, 19 Oct 2005 03:15:03 -0700, "David Schwartz" > wrote or quoted : >> Did I say their obligation was to secure their shareholders as much >>profit as possible? I said their obligation was to their shareholders. > You are literally saying people work for a company have an obligation > to the shareholders. That is too obvious to be bothered with > announcing. The employees take the shareholder's money, so obviously > they have an obligation to produce something in return. When I read > your words, I think you really mean this is the prime or sole > obligation of an employee. I disagree with that. There are many > loyalties that compete. Employees have *no* obligations towards the shareholders of a company. They are not employed or paid by the shareholders, they are employed by the company itself which is a separate legal entity. It is a different matter for the board of directors of a company. Axel From apardon at forel.vub.ac.be Mon Oct 24 08:04:34 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 24 Oct 2005 12:04:34 GMT Subject: Would there be support for a more general cmp/__cmp__ References: Message-ID: Op 2005-10-24, Steve Holden schreef : > Antoon Pardon wrote: >> >>>>>set([1]) <= set([2]) >> >> False >> >>>>>set([2]) <= set([1]) >> >> False >> > Set orderingd are explicitly documented as being based on proper > subsetting. This is an abuse of the operators to make subset tests more > convenient rather than a definition of an ordering. It *is* a definition of an ordering. For something to be an ordering it has to be anti symmetric and transitive. The subset relationships on sets conform to these conditions so it is a (partial) ordering. Check your mathematic books, Why you would think this is abuse is beyond me. -- Antoon Pardon From bosteen at maysubdivide.org Mon Oct 31 05:01:55 2005 From: bosteen at maysubdivide.org (Ben O'Steen) Date: Mon, 31 Oct 2005 10:01:55 -0000 (GMT) Subject: Why the nonsense number appears? In-Reply-To: References: <1130749726.707175.293040@g43g2000cwa.googlegroups.com> Message-ID: <17750.213.235.52.66.1130752915.squirrel@www.maysubdivide.org> On Mon, October 31, 2005 9:39, Sybren Stuvel said: > Johnny Lee enlightened us with: >> Why are there so many nonsense tails? thanks for your help. > > Because if the same reason you can't write 1/3 in decimal: > > http://docs.python.org/tut/node16.html > > 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 > I think that the previous poster was asking something different. I think he was asking something like this: If >>> t1 = 0.500 >>> t2 = 0.461 >>> print t1-t2 0.039 Then why: >>> t1 += 12345678910 >>> t2 += 12345678910 >>> # Note, both t1 and t2 have been incremented by the same amount. >>> print t1-t2 0.0389995574951 It appears Yu-Xi Lim beat me to the punch. Using decimal as opposed to float sorts out this error as floats are not built to handle the size of number used here. Ben From scott.daniels at acm.org Thu Oct 6 10:07:09 2005 From: scott.daniels at acm.org (Scott David Daniels) Date: Thu, 06 Oct 2005 07:07:09 -0700 Subject: New Python book In-Reply-To: References: <6.2.1.2.2.20051005150954.0741e1d0@rcblue.com> Message-ID: <43452f51$1@nntp0.pdx.net> Jeremy Jones wrote (about Magnus Lie Hetland's _Beginning Python: From Novice to Professional_): > ... this would probably also be an excellent educational resource > for teachers in a classroom setting teaching students Python. I would > be interested to hear some teachers' opinion on that to see if > that's a correct assessment.... You could ask over on comp.lang.python.education (on Gmane as comp.python.education). -- -Scott David Daniels scott.daniels at acm.org From saruis at tiscali.it Sun Oct 30 15:47:24 2005 From: saruis at tiscali.it (DDany) Date: 30 Oct 2005 12:47:24 -0800 Subject: Problem with py2exe Message-ID: <1130705244.768027.147710@g14g2000cwa.googlegroups.com> HI! I've a problem with py2exe: well, first of all I say that I use python 2.4.1 , py2exe 0.6.3 and distutils 1.0.2 on winxp. To use py2exe I wrote a file setup.py like this: from distutils.core import setup import py2exe setup( version = "0.1", description = "Py2Exe Script", name = "App.exe", windows = ["C:\app\\app.py"], ) file that is launched in this way: D:\programs\python24\python.exe setup.py py2exe The command starts and at the beginning seems that all goes on with no problem, but at a certain point there's an error: copying D:\programs\python24\MSVCR71.dll -> D:\Applicazione\dist error: could not delete 'C:\app\dist\MSVCR71.dll': Permission denied However folders build and dist are created: in particular into the folder dist i have the w9xpopen.exe file, some *.pyd files and some dll's... among dll's I have the MSVCR71.dll too. I don't understand what's the problem so I ask you a help!!! See ya, bye! From bobrien18 at yahoo.com Fri Oct 14 16:06:28 2005 From: bobrien18 at yahoo.com (KraftDiner) Date: 14 Oct 2005 13:06:28 -0700 Subject: Inheritance... Message-ID: <1129320388.162897.257710@o13g2000cwo.googlegroups.com> I have a base class class geometry(object): def __init__(self): self.blue = 1 self.red = 2 def render(self): pass class square(geometry): def __init__(self): super(square, self).__init__() def render(self) print 'square' class circle(geometry): def __init__(self): super(square, self).__init__() def render(self) print 'square' objLst = [] objLst.append(square()) objLst.append(circle()) for obj in objLst: obj.render() print obj.blue What is wrong with this... I will not print blue... (1) From aleaxit at yahoo.com Sun Oct 30 11:21:29 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 30 Oct 2005 09:21:29 -0700 Subject: process and spinning slash References: <1130690731.654048.157590@g14g2000cwa.googlegroups.com> <1h58mez.1jo7cnd1lilqm2N%aleaxit@yahoo.com> Message-ID: <1h58n6p.o0v4sq13jwgztN%aleaxit@yahoo.com> Fredrik Lundh wrote: > Alex Martelli wrote: > > > Have the spin function accept the pid argument and exit the loop if said > > pid has terminated; to check the latter, e.g., os.kill(pid, 0) -- this > > will raise an OSError if no process with that pid exists, so you can use > > a try/except OSError: to catch that and break as appropriate. > > or use the subprocess module instead of fork/exec, pass the Popen instance > to spin, and use the poll() method to check if the process is still running. Much more elegant than the lower-level approach I was sketching, of course, if one can use Python 2.4 (one cannot always sensibly do that; e.g., Mac OS X Tiger [the latest release] includes Python 2.3.5, so if you want to write Mac applications in Python 2.3 packaging and distributing them is trivial, but if you want to use Python 2.4 you need to distribute that as well, or package it with your app and thus make it way bigger... so, limiting oneself to 2.3 is a reasonable choice here). Alex From ganzhi at gmail.com Tue Oct 18 21:39:48 2005 From: ganzhi at gmail.com (James Gan) Date: Wed, 19 Oct 2005 09:39:48 +0800 Subject: [newbie]Is there a module for print object in a readable format? References: Message-ID: Hi, Steven :) width parameter do the magic : >>> pprint.pprint([1,2,3,4,[0,1,2,[3,4]],5], width=1,indent=4) [ 1, 2, 3, 4, [ 0, 1, 2, [ 3, 4]], 5] >>> Steven D'Aprano wrote: > On Mon, 17 Oct 2005 11:31:46 +0200, enrico.sirola_NOSPAM wrote: > > >>>>>>>"James" == James Gan writes: >> >> James> I want the object printed in a readable format. For >> >>[...] >> >> James> I tried pickled, marshel. They do different work. Is there >> James> another module which do this kind of job? >> >>from pprint import pprint >>pprint(object) > > > I don't think that even comes *close* to what James wants. > > py> import pprint > py> pprint.pprint([1,2,3,4,[0,1,2], 5]) > [1, 2, 3, 4, [0, 1, 2], 5] > > From http Mon Oct 3 07:47:26 2005 From: http (Paul Rubin) Date: 03 Oct 2005 04:47:26 -0700 Subject: Will python never intend to support private, protected and public? References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xd5mstqab.fsf@ruckus.brouhaha.com> <7xzmpwuxd0.fsf@ruckus.brouhaha.com> <20050930075313.67b9b676.jk@ospaz.ru> <7xbr2a6dlz.fsf@ruckus.brouhaha.com> <7xk6gyoibc.fsf@ruckus.brouhaha.com> <433f56a3.2969039483@news.oz.net> <1128274267.064255.306980@f14g2000cwb.googlegroups.com> <7x8xxbgj4h.fsf@ruckus.brouhaha.com> <4340dfd2.3069694347@news.oz.net> Message-ID: <7x64sex1o1.fsf@ruckus.brouhaha.com> bokr at oz.net (Bengt Richter) writes: > Would you want to outlaw 'None' as an attribute name? > Python seems to be straddling the fence at this point: > >>> c.None = 'c.None' > SyntaxError: assignment to None Heehee, I think that's just a compiler artifact, the lexer is treating None as a keyword instead of a normal lexical symbol that the compiler treats separately. That's also why it raises SyntaxError instead of some other type of error. Yes, None should be ok as an attribute name. > I could see it as part of a debugging interface that might let you > mess more with frames in general. I wouldn't be surprised if a lot > of the under-the-hood access we enjoy as it is was a byproduct of > scratching debugging-tool-need itches. Such an interface should probably work like the Java one, i.e. it would have a special socket listener that you'd poke at the program through, not have debugging code running in the same interpreter space as the target app. From fredrik at pythonware.com Thu Oct 6 16:39:46 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 6 Oct 2005 22:39:46 +0200 Subject: Lambda evaluation References: <1128629895.5816.5.camel@localhost.localdomain> Message-ID: Joshua Ginsberg wrote: > So this part makes total sense to me: > > >>> d = {} > >>> for x in [1,2,3]: > ... d[x] = lambda y: y*x > ... > >>> d[1](3) > 9 > > Because x in the lambda definition isn't evaluated until the lambda is > executed, at which point x is 3. > > Is there a way to specifically hard code into that lambda definition the > contemporary value of an external variable? In other words, is there a > way to rewrite the line "d[x] = lambda y: y*x" so that it is always the > case that d[1](3) = 3? from earlier today: http://article.gmane.org/gmane.comp.python.general/424262 From steve at holdenweb.com Tue Oct 25 07:03:52 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 25 Oct 2005 12:03:52 +0100 Subject: pickle In-Reply-To: <1d987df30510250023u5d679c9co4cd6f960df6edf1b@mail.gmail.com> References: <1130223861.28336.6.camel@blackwidow> <1d987df30510250023u5d679c9co4cd6f960df6edf1b@mail.gmail.com> Message-ID: Shi Mu wrote: > what does the following code mean? > > y = pickle.load(file("cnumber.pickle", "r")) > Take it by parts: file("cnumber.pickle", "r") returns a file object as a result of opening the "cnumber.pickle" file, which is presumably a pickle someone wrote earlier. So pickle.load(file("cnumber.pickle", "r")) returns the first object stored in that pickle file. > also, I can not understand "f" in pickle.dump(x, f) > The beginning of the docs on pickle usage says: """dump( obj, file[, protocol[, bin]]) Write a pickled representation of obj to the open file object file.""" Isn't this reasopnably self-explanatory? regards Steve >[...] -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From gsakkis at rutgers.edu Sat Oct 8 19:09:34 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Sat, 8 Oct 2005 19:09:34 -0400 Subject: how do you pronounce wxpython References: <1128775425.507351.312980@f14g2000cwb.googlegroups.com> Message-ID: <1128812979.64e46e0be2c6fb7fe6fdb8dd3dab1e09@teranews> "Alex" wrote: > My native language is not English so I just wonder how you pronounce > wxPython. > > vi-ex python > double-you-ex python > wax-python > > or something else > > Thanks I am sure it is pronounced the same way as wxWidgets . George From eternalsquire at comcast.net Mon Oct 17 11:30:32 2005 From: eternalsquire at comcast.net (The Eternal Squire) Date: 17 Oct 2005 08:30:32 -0700 Subject: can a cut-down Python still be Python? In-Reply-To: <1129548481.197637.122710@g47g2000cwa.googlegroups.com> References: <1129531249.605353.204280@f14g2000cwb.googlegroups.com> <1129548481.197637.122710@g47g2000cwa.googlegroups.com> Message-ID: <1129563032.227240.106670@f14g2000cwb.googlegroups.com> No, but the BFDL has the corner on the Zen of Python. What he says, evidently goes. From kay.schluehr at gmx.net Fri Oct 14 10:45:05 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 14 Oct 2005 07:45:05 -0700 Subject: How to delete yourself???? References: <1129299904.130287.287680@g44g2000cwa.googlegroups.com> Message-ID: <1129301105.048023.36430@f14g2000cwb.googlegroups.com> christian.siegl at gmail.com wrote: > Hello, > > > I got a problem deleting objects, which are placed in a hirarchy.... > > Asume we have the following code: > ######################################################## > class parent: > > MyChilds = [] # this list is filled with childs.... > > def AddChild(self, child): > # add childs here, however this is done, it's not the point... > child.MyParent = self > > def RemoveChild(self, child): > # delete child from the list.... the way this is done is not > our > # problem here > > > class child: > > MyParent = 0 > > def deleteMe(self): > MyParent.RemoveChild(self) > ############################################################## Please help me understand the child class. It does not make much sense to me at all. Why is it not sufficient to call child.parent.remove(child) if the caller holds a child object but not the parent? Otherwise it should be sufficient to call parent.remove(child). Kay From erniedude at gmail.com Fri Oct 21 11:01:32 2005 From: erniedude at gmail.com (Ernesto) Date: 21 Oct 2005 08:01:32 -0700 Subject: Execute C code through Python In-Reply-To: <1129861083.010702.6770@g49g2000cwa.googlegroups.com> References: <1129844737.586396.61080@g47g2000cwa.googlegroups.com> <1129861083.010702.6770@g49g2000cwa.googlegroups.com> Message-ID: <1129906892.696582.288010@g43g2000cwa.googlegroups.com> Thanks. Can anyone provide an example of using *subprocess* to run helloWorld.C through the python interpreter. From nephish at xit.net Thu Oct 20 12:22:59 2005 From: nephish at xit.net (nephish at xit.net) Date: 20 Oct 2005 09:22:59 -0700 Subject: need some advice on x y plot In-Reply-To: <11lfgebn85liq1b@corp.supernews.com> References: <1129823043.104864.73750@f14g2000cwb.googlegroups.com> <11lfgebn85liq1b@corp.supernews.com> Message-ID: <1129825379.218308.242010@g47g2000cwa.googlegroups.com> how ? i have tried to use unix timestamps, and i have also tried with DateTime objects do i need to use a scale that isn't linear (default in most) ? how do i putt this off ? thanks btw. sk From steve at REMOVETHIScyber.com.au Sat Oct 22 05:12:55 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sat, 22 Oct 2005 19:12:55 +1000 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> Message-ID: On Fri, 21 Oct 2005 21:47:27 -0700, David Schwartz wrote: > > "Steven D'Aprano" wrote in message > news:pan.2005.10.22.03.58.40.332401 at REMOVETHIScyber.com.au... > >> That's basic economics. Something which can be allowed or ignored or even >> encouraged when done by small businesses in a competitive market can >> easily become harmful and bad for the economy when done by a monopolist or >> duopolist in an uncompetitive market. > > Microsoft goal is and should be their own success, not the success of > the economy or the market in general. Neither I, nor you, nor the government of any nation, should care a monkey's toss specifically for Microsoft's success. Microsoft is one special interest, out of a potentially unbounded number of possible players in the economy of a country and the world. Unless you or I are specifically shareholders in Microsoft, we should not care about their specific success; and the government should be entirely agnostic about who are the winners and losers in an economy. The government's role should be to ensure a level playing field, and minimum levels of health, safety and environmental standards. There is no place for government giving special-interests like Microsoft favours. Society regulates where and how we park our cars: for instance, none of us are allowed to park our car in the middle of busy road. and if we try, our car is likely to be impounded. This is not because there is anything in and of itself *wrong* with parking at such-and-such a place, but because of the effect it has on others. A sensible government cares for smooth flowing traffic on the roads, with the minimum of delays and the maximum flow practical. Perhaps Walmart or Safeway might find it convenient to park their trucks on public roads for any number of reasons. Too bad for them: the benefit to them does not outweigh the loss to everyone else, even if they don't specifically block access to their competitors. Microsoft's behaviour over-all has been just as anti-social, anti-competitive and harmful to the over-all running of the economy as a hypothetical Walmart or Safeway that regularly parked their trucks in the middle of the main road for a few hours while they unloaded. Maybe, just maybe, if Mom & Pop's Corner Store tried it once or twice, we could afford to turn a blind eye, especially if the disruption caused by towing their delivery van was greater than the disruption caused by their double-parking. Thousands of people break the law by double-parking for a few minutes, and society doesn't collapse. But something that we can afford to ignore when done by M&P's Corner Store becomes a serious problem if done by somebody with the economic power of Walmart, with their thousands of deliveries by 18-wheelers every day across the country. > Microsoft's status of a "monopolist" > is only meaningful if you define the market as "desktop operating systems > for 32-bit x86 computers". That is *precisely* the market we're talking about. Not "any item that runs off electricity", not "orange juice", not "pork bellies", not "all computing devices", but desktop PCs. What did you think the Justice Department's investigation was about? Motor vehicles? > There is no way Microsoft could have expected the > market to be defined in this way and no way to argue that Microsoft had any > reason to believe their conduct was illegal. Microsoft have lawyers. Microsoft destroyed emails and at least one senior manager perjured himself in court. Microsoft created a fake video demonstration which they then gave as evidence. Do you really believe that Microsoft's executives are so incompetent that they don't get legal advice before writing up contracts? Or that nobody in authority at Microsoft realised that destroying evidence and lying to a judge are crimes? In any case, even if you are right that Microsoft had no ideas... so what? Ignorance of the law never has been an excuse for criminal behaviour. It has always been every individual's responsibility to make sure that they do not act illegally, and that goes for companies as well. -- Steven. From jgrahn-nntq at algonet.se Thu Oct 6 11:57:33 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 6 Oct 2005 15:57:33 GMT Subject: Can Python replace TCL/Expect References: <1128578298.778640.313900@g49g2000cwa.googlegroups.com> <6ncf13-2ps.ln1@lairds.us> Message-ID: On Thu, 06 Oct 2005 11:08:09 GMT, Cameron Laird wrote: > In article , > Robert Kern wrote: >>xinchenvn at gmail.com wrote: >>> Hi >>> >>> I'm learning Python. I don't know whether Python can do something like >>> Expect can do. If yes, please show me how to do it. ... > 2. While Pexpect indeed "can do something like Expect", > it does NOT have all the facilities and polish of the > latter. > 3. But very, VERY few of Expect's users are aware of more > than a handful of Expect's functions, let alone use them, > so it's fair to say that Pexpect does everything Expect > does, within the realm of ordinary use. It depends. I do not feel /that/ advanced, but I've been bitten by pexpect's limitations several times in several places. ... which puts me in a weird position ;-) I /loathe/ the Tcl language, but I have to admit that its expect functionality is far superior to Python's. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From steve at holdenweb.com Sat Oct 29 13:14:11 2005 From: steve at holdenweb.com (Steve Holden) Date: Sat, 29 Oct 2005 18:14:11 +0100 Subject: Automatic binding of **kwargs to variables In-Reply-To: References: <1130539752.667045.183460@g14g2000cwa.googlegroups.com> Message-ID: Peter Otten wrote: > lbolognini at gmail.com wrote: > > >>I have a very long list of parameters coming from a web form to my >>method foo(self, **kwargs) >> >>I would like to avoid manually binding the variables to the values >>coming through the **kwargs dictionary, just to keep the code cleaner, >>I'd like to bind them automatically > > > Why don't you just change the method signature to foo(self, x, y, z, > whatever, **kwargs)? > > Peter > Probably because values are then required for those arguments. Plus it's a lot of work to specify "a very long list", and the list will also need maintaining. I must, however, agree with Mike's advice: it's unwise to try and pollute a function's namespace with arbitrary variables. Some kind of bunch-like object would seem to be the most satisfactory way to go. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From edgar_xavier493 at hotmail.com Mon Oct 10 11:08:25 2005 From: edgar_xavier493 at hotmail.com (Edgar) Date: Mon, 10 Oct 2005 11:08:25 -0400 Subject: read serial data from a barcode reader/scanner using python Message-ID: Hi. is there a way to program python to read serial data from a barcode reader/scanner and then using the parallel port of the PC to activate an electromagnetic door lock. edgar -------------- next part -------------- An HTML attachment was scrubbed... URL: From LISTSERV at LISTSERV.UARK.EDU Wed Oct 19 22:18:41 2005 From: LISTSERV at LISTSERV.UARK.EDU (University of Arkansas LISTSERV Server (14.4)) Date: Wed, 19 Oct 2005 21:18:41 -0500 Subject: Message ("Your message dated Thu, 20 Oct 2005 11:18:37...") Message-ID: Your message dated Thu, 20 Oct 2005 11:18:37 +0900 with subject "Returned mail: see transcript for details" has been submitted to the moderator of the ICTLIST list: Cynthia Smith . From pnau at sjm.com Tue Oct 4 13:22:51 2005 From: pnau at sjm.com (pnau at sjm.com) Date: 4 Oct 2005 10:22:51 -0700 Subject: semi-newbie module namespace confusion In-Reply-To: <3qev4iFash6dU1@news.dfncis.de> References: <1128404572.837225.41870@g47g2000cwa.googlegroups.com> <3qer81FeldcmU1@news.dfncis.de> <3qev4iFash6dU1@news.dfncis.de> Message-ID: <1128446571.096604.229500@g49g2000cwa.googlegroups.com> I'm not going to quote anything (except a URI), but thanks very much for your help, especially http://effbot.org/zone/import-confusion.htm. Almost certainly the source (and solution) to my problem lies in what you guys have brought out. I'm no longer stuck (at least I hope not), and I have knowledge to use in working out the solution. Kind Regards, ~Peter From pmartin at snakecard.com Tue Oct 4 17:05:00 2005 From: pmartin at snakecard.com (Philippe C. Martin) Date: Tue, 04 Oct 2005 21:05:00 GMT Subject: Idle References: Message-ID: <08C0f.517$ht7.198@newssvr21.news.prodigy.com> Hi, I remember having that when the wrong version of TCL/TK was installed on my system. Regards, Philippe Hrvoje Blazevic wrote: > How do I get Idle to work on Linux? > > I've tried to compile 2.4.2 on Fedora core 4, and Suse 9.3, but Idle is > after make install either missing (Fedora), or reports **Idle can't > import Tkinter... ** > > Thanks > > -- Hrvoje From fredrik at pythonware.com Sun Oct 23 03:52:34 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 23 Oct 2005 09:52:34 +0200 Subject: Syntax across languages References: <1130052687.396109.145420@o13g2000cwo.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > - Information about the current line and file as Ruby: > __LINE__ __FILE__ > Instead of the python version: > inspect.stack()[0][2] inspect.stack()[0][1] (that's (mostly) CPython-dependent, and should be avoided) > - ~== for approximate FP equality str(a) == str(b) > - comparison returns 4 values (i.e. inferior, equal, superior or not > comparable), as in Pliant: "compare" >>> cmp("a", "b") -1 >>> cmp("a", "a") 0 >>> cmp("b", "a") 1 >>> cmp("?", u"?") Traceback (most recent call last): File "", line 1, in ? UnicodeDecodeError: 'ascii' codec can't decode byte /.../ sure looks like four possible outcomes. > - identity function: "identity" as in Common Lisp (probably of little > use in Python). id(a) > - Exception retrying: after catching an exception, tell the snippet to > be re-run "retry" as in Ruby >>> x = 0 >>> while 1: ... try: ... x += 1 ... if x <= 5: ... raise ValueError ... except ValueError: ... print "retry" ... continue ... else: ... break ... retry retry retry retry retry >>> > - object cloning: obj.copy() obj.deepcopy() import copy (cloning is usually a sign of a design problem in python. if you think you need it, you probably don't. if you really think you need it, import copy.) > - recursive "flatten" as in Ruby (useful) if you can define the semantics, it's a few lines of code. if you're not sure about the semantics, a built-in won't help you... etc. From xah at xahlee.org Wed Oct 26 08:40:26 2005 From: xah at xahlee.org (Xah Lee) Date: 26 Oct 2005 05:40:26 -0700 Subject: tool for syntax coloring in html Message-ID: <1130330426.059794.282450@g49g2000cwa.googlegroups.com> in some online documentations, for examples: http://perldoc.perl.org/perlref.html http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z-H-17.html http://www.haskell.org/hawiki/HaskellDemo the codes are syntax colored. Is there a tool that produce codes in html with syntax coloring? Thanks. Xah xah at xahlee.org ? http://xahlee.org/ From noway at sorry.com Wed Oct 19 19:16:04 2005 From: noway at sorry.com (Giovanni Bajo) Date: Wed, 19 Oct 2005 23:16:04 GMT Subject: How to organize Python files in a (relatively) big project References: Message-ID: Jarek Zgoda wrote: > How to install this structure eg. on Linux? What layout do you > recommend? It's tempting to use /opt hierarchy for installation target > (as it gives relatively much freedom within application directory), > but > many administrators are reluctant to use this hierarchy and prefer > more standarized targets, such as /usr or /usr/local. I am not very experienced with Linux, but if you don't use something like PyInstaller, you could still install the main tree somewhere like /usr/local/myapp/ and then generate a simple script for /usr/local/bin which adds /usr/local/myapp to sys.path[0], and "import main" to boot the application. I'm not sure I have answered your question though :) -- Giovanni Bajo From aleax at mail.comcast.net Mon Oct 10 04:56:45 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Mon, 10 Oct 2005 10:56:45 +0200 Subject: New Python book References: <1128879054.054226.7220@f14g2000cwb.googlegroups.com> Message-ID: <1h47qe0.tqref21v0ck70N%aleax@mail.comcast.net> hrh1818 wrote: > This book is not a new book. It is an updated version of Magnus's 2002 > Practical Python book. Then it's probably a good book, because Practical Python sure was! Alex From andrea_gavana at tin.it Mon Oct 31 08:00:10 2005 From: andrea_gavana at tin.it (Andrea Gavana) Date: Mon, 31 Oct 2005 14:00:10 +0100 Subject: Problem with exe from py2exe References: <1130668290.546611.277970@g47g2000cwa.googlegroups.com> Message-ID: <4364c494$0$24646$4fafbaef@reader3.news.tin.it> Hello Martin, > My script runs fine with python, but the .exe produced with py2exe > crashes out with: > > Traceback (most recent call last): > File "App1.py", line 4, in ? > File "wx\__init__.pyc", line 42, in ? > File "wx\_core.pyc", line 3163, in ? > AttributeError: 'module' object has no attribute > 'wxEVT_SCROLL_ENDSCROLL' Noting that you use wxPython 2.6.1.0, are you still using the old namespace/import commands: from wxPython.wx import * ? If this is the case, please switch to the (relatively) new namespace/import command: import wx The new syntax does not have wxEVT_SCROLL_ENDSCROLL but it does have wx.EVT_SCROLL_ENDSCROLL. The syntax has changed about 1 year ago (if not more), so if you are still using the old namespace, I think the wxPython mailing list and the wxPython main page should report: "Use the NEW namespace" In red blinking characters. If this is not the case, I'm sorry I can't help you a lot. I always use py2exe but I never encountered such problems. HTH. Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.virgilio.it/infinity77 From kenneth.m.mcdonald at sbcglobal.net Wed Oct 19 17:31:42 2005 From: kenneth.m.mcdonald at sbcglobal.net (Kenneth McDonald) Date: Wed, 19 Oct 2005 16:31:42 -0500 Subject: Yes, this is a python question, and a serious one at that (moving to Win XP) In-Reply-To: <200510191222.14334.jstroud@mbi.ucla.edu> References: <1129574592.754495.72530@g43g2000cwa.googlegroups.com> <1129642964.690532.242710@g49g2000cwa.googlegroups.com> <200510191222.14334.jstroud@mbi.ucla.edu> Message-ID: <75DF16E6-AC4F-4ABE-A16C-0FAC7A089460@sbcglobal.net> Perhaps you didn't read my original post? I'm being forced to consider Windows for reasons beyond my control. Given that I wanted a decent shell in Windows, I thought I would ask about Python shells because I think Python is a great language, and such a beast would give me the flexibility I want on a machine I don't want to use. There is such a shell (though with a fifty page manual it'll be a little while before I start using it :-) ). End of matter, except for those who wish to discuss further Pythonish/shell related issues. Why this demands an OS comparison and an insult is beyond my understanding. Ken On 19-Oct-05, at 2:22 PM, James Stroud wrote: > The OP is obviously a troll. Or he doesn't realize that you can use > any shell > in OSX as the user default. I used OSX for 4 years and had to go > 100% Linux > because of my employer. OSX is the best of Linux and Windows-- > anybody who > can't see that has obviously not worked with these three types of > operating > systems enough and is basing conclusions on limited > information...Or is a > troll. The OP probably works for microsoft. > > James > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ivan at ivan-herman.net Sun Oct 2 05:51:55 2005 From: ivan at ivan-herman.net (Ivan Herman) Date: Sun, 02 Oct 2005 11:51:55 +0200 Subject: Python CGI Script In-Reply-To: <433f9875@news.bezeqint.net> References: <433f9875@news.bezeqint.net> Message-ID: <433FADBB.5050609@ivan-herman.net> Efrat, I am afraid a CGI script is never *executed* by the browser. Instead, it sends the URL to a server, expects the server to execute the script, and display the server's response. If you just put a file name then (it seems, I never even tried that) Firefox uses the local file store as a 'server' in that respect. If you want to test a CGI script on your own machine, you should run a web server on your own machine. That server should also be set up in a way that it recognizes a '.py' file as a CGI script to be executed by Python (not all servers may recognize the #! trick...). This may look scary, but it is not that bad. Apache has a number of precompiled binary versions that you can install on your machine; you can also use servers like W3C's jigsaw (this relies on Java) or others. These are all free and easy to install and, well, manageable to configure. Actually, in case you run on a MacOS X by any chance, Apache is already installed afaik... I hope this helps Ivan -------- Original Message -------- From: Efrat Regev To: Subject: Python CGI Script Date: 30/9/2005 12:50 > Hello, > > I'm a data-structures course TA trying to write a python CGI script > for automatically compiling and testing students' projects. > Unfortunately, I've run into some questions while writing this, which I > couldn't solve with the various (and helpful) python-CGI documentation. > (It's possible that I'm posting to the wrong group; if so, I'd > appreciate suggestions for the appropriate group.) > > > 1. In my HTML page, I have the following: > > enctype="multipart/form-data"> > ... > > > In the above, submission_processor.py is the python CGI script. I > didn't write a URL in the action field, since I'm first testing > everyting on a local machine (running FC4). The first line of > submission_processor.py is > > #!/usr/bin/python > > and I've done > > chmod +x submission_processor.py > > When I hit the "submit" button, my browser (Firefox on FC4) doesn't > run the script; it asks me whether it should open > submission_processor.py or save it to disk. I couldn't figure out why. > > 2. My HTML page has the option for an instructor to list the various > submissions and scores. Obviously, this should be inaccessible to > students. The instructor has a password for doing this, therefore. > Suppose I place the password inside a python script, and give this > script only +x permission for others. Is this adequate as far as security? > > > Thanks in advance for answering these questions. > > > Efrat From claird at lairds.us Thu Oct 6 13:08:03 2005 From: claird at lairds.us (Cameron Laird) Date: Thu, 06 Oct 2005 17:08:03 GMT Subject: Can Python replace TCL/Expect References: <1128578298.778640.313900@g49g2000cwa.googlegroups.com> <6ncf13-2ps.ln1@lairds.us> Message-ID: In article , Jorgen Grahn wrote: . . . >It depends. I do not feel /that/ advanced, but I've been bitten by pexpect's >limitations several times in several places. > >... which puts me in a weird position ;-) I /loathe/ the Tcl language, but I >have to admit that its expect functionality is far superior to Python's. . . . 'Salright. There are Tcl programmers who feel the same way, for example, about Python and its object orientation. On to more constructive matters: what are you doing about Pexpect's limitations? Have the maintainers responded to you when you write? Are you tempted to compose enhancements for yourself? From maravilloso at gmail.com Wed Oct 26 05:31:50 2005 From: maravilloso at gmail.com (Maravilloso) Date: 26 Oct 2005 02:31:50 -0700 Subject: Printing a document in the default network printer under Windows Message-ID: <1130319110.958321.111640@g44g2000cwa.googlegroups.com> Hi all: I'm getting mad trying to find the way for making a standard document (Word file, Postscript document, JPEG file...) to be sent/printed in the default network printer from a python script that runs on Win2K. Any idea? Thanks in advance. Maravilloso From fredrik at pythonware.com Wed Oct 26 03:40:06 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 26 Oct 2005 09:40:06 +0200 Subject: Weird import behavior References: <1130260282.027302.49370@g44g2000cwa.googlegroups.com> <1130265049.927710.155050@g44g2000cwa.googlegroups.com> Message-ID: "Tommytrojan" wrote: > thanks for your quick reply. I guess I should have included the output. > I thought I was clear in the error description. > The problem is that I never assign to 'string'. I only reference it (as > the error message correctly states). If you comment out the import > statement in the except clause the program runs fine. Now notice that > the exception hander never gets executed! Any explanation? the language reference has the full story: http://docs.python.org/ref/naming.html "If a name is bound in a block, it is a local variable of that block." /.../ "The following constructs bind names: formal parameters to functions, import statements, class and function definitions (these bind the class or function name in the defining block), and targets that are identifiers if occurring in an assignment, for loop header, or in the second position of an except clause header. The import statement of the form "from ... import *" binds all names defined in the imported module, except those beginning with an underscore. /.../ A target occurring in a del statement is also considered bound for this purpose (though the actual semantics are to unbind the name). /.../ If a name binding operation occurs anywhere within a code block, all uses of the name within the block are treated as references to the current block." From gsakkis at rutgers.edu Tue Oct 11 09:23:56 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: 11 Oct 2005 06:23:56 -0700 Subject: Merging sorted lists/iterators/generators into one stream of values... References: <1128667968.421469.180910@g47g2000cwa.googlegroups.com> <1128691708.c6930b5cb9f3673ed3abe8755178d163@teranews> <1128692196.410209.252100@g14g2000cwa.googlegroups.com> <1128695317.c6a5acb3e62787f011310c96f0c7cc35@teranews> <1h439qe.pz7c451jcec6hN%aleax@mail.comcast.net> <1128795319.09c32ac9943b0580a86b7bcada7facc1@teranews> <1128797447.501582.24560@o13g2000cwo.googlegroups.com> <1h47iae.6d2ps91u8eafuN%aleax@mail.comcast.net> <1h485kt.1bru0if72epwrN%aleax@mail.comcast.net> Message-ID: <1129037036.712254.94830@o13g2000cwo.googlegroups.com> > Function name is perhaps not the best one. It occurs to me that this > is the GROUP BY in SQL so perhaps a different name is better, but > then again this might be moot if such a already exists somewhere :) Amazing, you keep reinventing things, even with the exact same name :) from itertools import imap,groupby from operator import itemgetter for fruit,group in groupby(fruits, itemgetter(0)): print fruit, "has a sum of", sum(imap(itemgetter(1),group)) For this to work as intended, fruits has to be already sorted by the same key given to grouby; otherwise just replace fruits with sorted(fruits, itemgetter(0)). By the way, read all the functions in the itertools module (http://docs.python.org/lib/itertools-functions.html), it will save you a lot of time. George From richardjones at optushome.com.au Sun Oct 23 21:56:44 2005 From: richardjones at optushome.com.au (Richard Jones) Date: Mon, 24 Oct 2005 11:56:44 +1000 Subject: OSDC 2005 Registration Message-ID: <200510241156.44865.richardjones@optushome.com.au> G'day folks, This is a quick note to let you know that registrations for Australia's second Open Source Developers' Conference are now open. Last year's conference was a huge hit with 60 high quality talks running in three streams over three days. If you weren't able to join us last year make sure you don't miss out this year! If you register before EARLY BIRD DATE you will receive a conference t-shirt and financial discount. You can register at http://www.osdc.com.au/registration/index.html OSDC is a grass roots-style conference designed by developers for developers, covering open source languages, tools, libraries, operating systems, licences and business models. We're booking 3 lecture rooms each day for the 3 days to hold a new set 60 different talks. Talks topics range from the safety Perl's Safe.pm, to rapid game development in Python, to using PHP for unorthodox applications, to utilizing Java's Groovy in your next application. We also have talks on conference skills, database integration, digital forensics, Gumstix and Nagios. You can find the full list of speakers and talk titles at http://osdc2005.cgpublisher.com/session_descriptions.html Because there are so many good talks, you can be certain that there will be something that interests you in every talk session. Each day will start with a keynote by our excellent keynote speakers. These include Damian Conway, Jonathan Oxer, Richard Farnsworth (from the Australian Synchrotron) and Anthony Baxter. The rest of the day will be filled with up to 5 hours of talks and plentiful food breaks. Our catering choices should result in you being extraordinarily well fed throughout the days of the conference. There will also be several BOFs (yet to be organised), lots of opportunities to socialise, a semi-formal dinner, a partners' programme and other usual conference stuff. If you have any other questions about what is happening, please don't hesitate to ask: osdc-help at osdc.com.au -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From jabel at plus.net Thu Oct 27 04:10:55 2005 From: jabel at plus.net (John Abel) Date: Thu, 27 Oct 2005 09:10:55 +0100 Subject: xml.dom.minidom - parseString - How to avoid ExpatError? In-Reply-To: <312cfe2b0510261020w1d485c98m526e325d6ada1082@mail.gmail.com> References: <312cfe2b0510251159p5e2501cbxf21e4f62f3d70b1c@mail.gmail.com> <312cfe2b0510260738j460b075ch998371a460c39df8@mail.gmail.com> <435F9C6C.50707@plus.net> <312cfe2b0510261020w1d485c98m526e325d6ada1082@mail.gmail.com> Message-ID: <43608B8F.1000506@plus.net> Have a look on: http://xml.com/pub/a/98/10/guide0.html?page=4#WELLFORMED Explains it better then I can. J Gregory Pi?ero wrote: > What do you mean by well-formed? What is required to make XML well > formed? > > -Greg > > > On 10/26/05, *John Abel* > wrote: > > Try this page: > > http://docs.python.org/lib/module-xml.sax.saxutils.html > > I've just tried the code, taking out the  , and adding in the > belo, > as the XML is not well formed, otherwise. > > > > The code then works. > > HTH > > J > > Gregory Pi?ero wrote: > > > Should I try some sort of XML group instead? I'm still stuck on > this. > > > > -Greg > > > > > > On 10/25/05, *Gregory Pi?ero* > > >> wrote: > > > > Hi guys, > > > > I was hoping some XML expert could help me make this code work. > > Below is sample code with sample XML similar to what I'm > dealing with. > > > > How can I make the weird characters in the XML not break the > > parser? I'll do anything to make this work! > > > > (Note: the   broke my parser yesterday but doesn't seem > to in > > this sample code) But really I'm looking for solutions that > will > > handles lots > > of unusual characters. > > > > Much thanks, > > > > Greg > > > > > > > > from xml.dom.minidom import parseString > > data=""" > > > > > > This is sample problem text.   ?500.00 > > > > > > """ > > myDOM=parseString(data) > > > > > > > > Traceback (most recent call last): > > File > > > "C:\Python23\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", > > line 307, in RunScript > > debugger.run(codeObject, __main__.__dict__, > start_stepping=0) > > File > > > "C:\Python23\Lib\site-packages\pythonwin\pywin\debugger\__init__.py", > > line 60, in run > > _GetCurrentDebugger().run(cmd, globals,locals, > start_stepping) > > File > > > "C:\Python23\Lib\site-packages\pythonwin\pywin\debugger\debugger.py", > > line 631, in run > > exec cmd in globals, locals > > File "C:\Documents and Settings\Gregory\My > Documents\Python\xml > > help\xmlproc.py", line 9, in ? > > myDOM=parseString(data) > > File "C:\Python23\lib\xml\dom\minidom.py", line 1929, in > parseString > > return expatbuilder.parseString (string) > > File "C:\Python23\lib\xml\dom\expatbuilder.py", line 940, in > > parseString > > return builder.parseString(string) > > File "C:\Python23\lib\xml\dom\expatbuilder.py", line 223, in > > parseString > > parser.Parse(string, True) > > ExpatError: undefined entity: line 4, column 29 > > > > > > > > > > -- > > Gregory Pi?ero > > Chief Innovation Officer > > Blended Technologies > > (www.blendedtechnologies.com > > >) > > > > > > > > > > -- > > Gregory Pi?ero > > Chief Innovation Officer > > Blended Technologies > > (www.blendedtechnologies.com > > ) > > > -- > http://mail.python.org/mailman/listinfo/python-list > > > > > > -- > Gregory Pi?ero > Chief Innovation Officer > Blended Technologies > (www.blendedtechnologies.com ) From grunar at gmail.com Thu Oct 20 19:24:27 2005 From: grunar at gmail.com (grunar at gmail.com) Date: 20 Oct 2005 16:24:27 -0700 Subject: sqlstring -- a library to build a SELECT statement In-Reply-To: <1129849441.603557.160990@g47g2000cwa.googlegroups.com> References: <1129774730.887128.314960@z14g2000cwz.googlegroups.com> <1129784130.596225.174860@z14g2000cwz.googlegroups.com> <1129823975.023490.287440@g43g2000cwa.googlegroups.com> <1129849441.603557.160990@g47g2000cwa.googlegroups.com> Message-ID: <1129850667.692610.123750@g43g2000cwa.googlegroups.com> > person ** ( > (person.type_id == 'customer') > & (person.id %= phone(phone.person_id))) > ) > Nevermind. This doesn't work because all of the X= operators in question are assignment operators, and therefore generate a Syntax Error if in a nested expression. I think I've settled on just doing a table.column.IN(blah) syntax. This should be obvious to anyone reading the code, and doesn't require mangling of the name (since it's capitalized). Then we'd have similar functions for other non intuitive things, such as LIKE, EXISTS (on the table) and even a WHERE: person.WHERE( (person.type_id == 'customer') & (person.id.IN(phone(phone.person_id))) ) From bdesth.quelquechose at free.quelquepart.fr Tue Oct 4 17:10:59 2005 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Tue, 04 Oct 2005 23:10:59 +0200 Subject: Which SQL module to use? In-Reply-To: <1128433394.470896.89770@g44g2000cwa.googlegroups.com> References: <1128433394.470896.89770@g44g2000cwa.googlegroups.com> Message-ID: <4342e6c5$0$7381$636a55ce@news.free.fr> mrstephengross a ?crit : > I'd like to do some basic SQL stuff in Python. It seems like there are > a heck of a lot of SQL modules for Python. What's the simplest and > easiest one to use? Probably the one that go with your RDBMS. From gsakkis at rutgers.edu Sat Oct 8 14:37:38 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Sat, 8 Oct 2005 14:37:38 -0400 Subject: Function decorator that caches function results References: Message-ID: <1128796692.f0f5a29fda81a72649660a18751c0512@teranews> "Lasse V?gs?ther Karlsen" wrote: > [snip] > > Ok, so I thought, how about creating a decorator that caches the > function results and retrieves them from cache if possible, otherwise it > calls the function and store the value in the cache for the next invokation. > > [snip] Cool, you re-invented the memoization pattern: http://en.wikipedia.org/wiki/Memoization http://aspn.activestate.com/ASPN/search?query=memoize&x=0&y=0§ion=PYTHONCKBK&type=Subsection Yes, it's kinda discouraging that most interesting ideas have already been conceived, implemented and used by others... George From chemag at gmail.com Thu Oct 20 15:11:00 2005 From: chemag at gmail.com (chemag at gmail.com) Date: 20 Oct 2005 12:11:00 -0700 Subject: Question on re.IGNORECASE In-Reply-To: <1129834544.533189.301780@g14g2000cwa.googlegroups.com> References: <1129834544.533189.301780@g14g2000cwa.googlegroups.com> Message-ID: <1129835460.304276.44780@g43g2000cwa.googlegroups.com> OK, I got it. - The re module search function syntax is: search( pattern, string[, flags]) where re.IGNORECASE is a valid flag. - The RE Object search method syntax is: search( string[, pos[, endpos]]) where "The optional second parameter pos gives an index in the string where the search is to start; it defaults to 0" It turns out that re.IGNORECASE has the value 2. Am I the only person bitten by this? http://docs.python.org/lib/node115.html http://docs.python.org/lib/re-objects.html -myself From rrr at ronadam.com Sat Oct 8 14:02:30 2005 From: rrr at ronadam.com (Ron Adam) Date: Sat, 08 Oct 2005 18:02:30 GMT Subject: Weighted "random" selection from list of lists In-Reply-To: References: Message-ID: Jesse Noller wrote: > 60% from list 1 (main_list[0]) > 30% from list 2 (main_list[1]) > 10% from list 3 (main_list[2]) > > I know how to pull a random sequence (using random()) from the lists, > but I'm not sure how to pick it with the desired percentages. > > Any help is appreciated, thanks > > -jesse Just add up the total of all lists. total = len(list1)+len(list2)+len(list3) n1 = .60 * total # number from list 1 n2 = .30 * total # number from list 2 n3 = .10 * total # number from list 3 You'll need to decide how to handle when a list has too few items in it. Cheers, Ron From davids at webmaster.com Thu Oct 20 02:31:54 2005 From: davids at webmaster.com (David Schwartz) Date: Wed, 19 Oct 2005 23:31:54 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: "Peter T. Breuer" wrote in message news:b15923-vj4.ln1 at news.it.uc3m.es... > In comp.os.linux.misc David Schwartz wrote: >> I guess I wasn't explicit enough. Most people who want cars also want >> an >> engine. Some don't. Dealers could sell cars and engines separately. They >> just (generally) don't. There is nothing illegal or immoral about this. > There would be if an engine manufacturer refused to provide car > manufacturers with ANY engines for any model, unless all buyers were > charged for THEIR engine in every model, whether their engine was in > there or not. > > You want to cease this line of apologism. I'm sorry, that's just crazy. An engine manufacturer could refuse to provide car manufacturers with ANY engines at all if they wanted to. It's their engines. They can use any mutually agreeable method to determine the number of engines provided and the price. This is not apologism. Microsoft has nothing to apologize for here. Microsoft has no ability to make anyone pay a penny more for their software, or the right to distribute it, than it is worth to them. DS From usenet at marduk.letterboxes.org Tue Oct 4 19:03:32 2005 From: usenet at marduk.letterboxes.org (marduk) Date: Tue, 04 Oct 2005 23:03:32 GMT Subject: "no variable or argument declarations are necessary." In-Reply-To: <7xu0fx9l7y.fsf@ruckus.brouhaha.com> References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> <434245F5.6060500@REMOVEMEcyber.com.au> <7xr7b14lk0.fsf@ruckus.brouhaha.com> <7xu0fx9l7y.fsf@ruckus.brouhaha.com> Message-ID: <1128467011.312.15.camel@blackwidow> On Tue, 2005-10-04 at 11:43 -0700, Paul Rubinhttp: wrote: > What's the big deal? Perl has an option for flagging undeclared > variables with warnings ("perl -w") or errors ("use strict") and Perl > docs I've seen advise using at least "perl -w" routinely. Those > didn't have much impact. Python already has a "global" declaration; > how does it de-Pythonize the language if there's also a "local" > declaration and an option to flag any variable that's not declared as > one or the other? I would be happy with a "local" option. e.g. def myfunc(): local spam = ... local eggs = ... global juice breakfast = juice + spam + eggs # raises an exception (undeclared breakfast) What I'm *afraid* of is: def myfunc(MyClass myparam): int spam = 6 str eggs # etc i.e. typed declarations and type checking. This would annoy the heck out of me. From stefan.sonnenberg at freenet.de Fri Oct 28 18:01:00 2005 From: stefan.sonnenberg at freenet.de (Stefan Sonnenberg-Carstens) Date: Sat, 29 Oct 2005 00:01:00 +0200 Subject: newstyle classes and __getattribute__ In-Reply-To: References: <4362977f$0$7227$9b622d9e@news.freenet.de> Message-ID: <43629f9c$0$7140$9b622d9e@news.freenet.de> Stefan Sonnenberg-Carstens schrieb: > James Stroud schrieb: > >> On Friday 28 October 2005 14:26, Stefan Sonnenberg-Carstens wrote: >> >>> Hi there, >> >> >> [..clip..] >> >>> Now, I do this: >>> >>> class T(object): >>> def __init__(self,name='',port=80): >>> self.name=name >>> self.port=port >>> def __getattribute__(self,key): >>> if key=='somekey': >>> return None >> >> >> [..snip..] >> >>> But, then surprise: >>> >>> t = T(name="test123",port=443) >>> >>> dir(t) >>> >>> [] >>> >>> What the hell is going wrong here ? >> >> >> >> __getattribute__ is returning None in all cases and dir() is >> converting None to []. >> >> Anyway, you should have done this: >> >> py> class T(object): >> .... def __init__(self,name='',port=80): >> .... self.name=name >> .... def __getattribute__(self,key): >> .... if key=='somekey': >> .... return None >> .... else: >> .... return object.__getattribute__(self, key) >> .... >> py> t = T(name="test123",port=443) >> py> dir(t) >> ['__class__', '__delattr__', '__dict__', '__doc__', >> '__getattribute__', '__hash__', '__init__', '__module__', '__new__', >> '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', >> '__weakref__', 'name'] >> >> James >> > Sorry, but I am right that you explicitly call a "super" > __getattribute__ on object and pass it a reference to self and the > desired key ? > Only asking for clarification ... > > But why does that work under 2.4.1, and even under ActiveState's 2.4.1 ? > Was that changed between those 2 releases ? > Intuitive behaviour of __getattribute__ would be: > If a key is not handeld in that function, return what you already got. > > Cheers, > Stefan > Sorry,forget that. It never worked in those releases, I made some errors which made me belief that, sorry. From peter at commonlawgov.org Tue Oct 11 06:05:04 2005 From: peter at commonlawgov.org (Peter) Date: Tue, 11 Oct 2005 03:05:04 -0700 Subject: mod_python In-Reply-To: References: <1129016557.060339.136600@g49g2000cwa.googlegroups.com> Message-ID: <434B8E50.9020309@commonlawgov.org> deelan wrote: >Python_it wrote: >(...) > > >>But my problem is where I have to place te following code in de >>httpd.conf? >> >> >> AddHandler mod_python .py >> PythonHandler mptest >> PythonDebug On >> >> >>Because al the tutorials write this. But where? >> >> > >try put it at the end of your http.conf file. > > > > > If I try to put the code some where, > > apache give the following message by testing the configure: > > Multiple arguments not (yet) supported > > But what i have to change or replace. > > > >just an idea, try: > > >... > > >because it sounds like apache parser gets confused >with all those slashes. > > > I could be wrong, but i think i read something about apache expecting you to use forward slashes instead of backslashes when i was using windows... I seem to recall it being in the readme. ...? >>I test with the next file: >> >>C:\Program Files\Apache Group\Apache2\htdocs\project\ >>mptest.py >> >>from mod_python import apache >> >>def handler(req): >> req.content_type = 'text/plain' >> req.send_http_header() >> req.write('mptest.py\n') >> return apache.OK >> >>Is this code enough for testing? >> >> >> > >i believe so. > >also check this: >"Getting mod_python Working" > > > > HTH, Peter From robert.kern at gmail.com Fri Oct 7 11:05:29 2005 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 07 Oct 2005 08:05:29 -0700 Subject: Python interpreter bug In-Reply-To: <1128695602.718637.144720@g43g2000cwa.googlegroups.com> References: <1128686833.994339.295780@f14g2000cwb.googlegroups.com> <1128692705.964188.5720@z14g2000cwz.googlegroups.com> <1128694740.418262.95470@g44g2000cwa.googlegroups.com> <1128695602.718637.144720@g43g2000cwa.googlegroups.com> Message-ID: alainpoint at yahoo.fr wrote: > In fact, i want to sort the list based on the 'allocated attribute' and > at the same time, test membership based on the id attribute. > __cmp__ logically implies an ordering test, not an identity test. These > two notions seems to be confounded in python which is unfortunate. Two > objects could have the same rank while still being different. In that case, define __lt__ and __eq__ separately instead of __cmp__. list.sort() will use __lt__ if it's provided rather than __cmp__. -- 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 Sun Oct 30 08:44:50 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 30 Oct 2005 14:44:50 +0100 Subject: parsing a tuple in embedded python References: <1130673024.215437.53520@g44g2000cwa.googlegroups.com> Message-ID: jenkins.justin at gmail.com wrote: > I am returning a tuple from my python method and am stuck trying to > figure out how to read it into a C array using PyArg_Parse. > My C Code: > int array[3]; > PyArg_Parse(return, "(iii)", &array); > > My Python Code: > mytuple = (1,2,3) > return mytuple > > That gives me a segmentation fault. What am I doing wrong? you're not providing enough arguments; "iii" means three pointers, not one. try: PyArg_Parse(return, "(iii)", array, array+1, array+2) instead. or, if you prefer maximum clarity: PyArg_Parse(return, "(iii)", &array[0], &array[1], &array[2]) (I assume you left out the error handling code; ignoring the return value from PyArg_Parse is not a good idea) From rrr at ronadam.com Tue Oct 25 02:54:09 2005 From: rrr at ronadam.com (Ron Adam) Date: Tue, 25 Oct 2005 06:54:09 GMT Subject: namespace dictionaries ok? In-Reply-To: References: Message-ID: James Stroud wrote: > Here it goes with a little less overhead: > > > py> class namespace: > ... def __init__(self, adict): > ... self.__dict__.update(adict) > ... > py> n = namespace({'bob':1, 'carol':2, 'ted':3, 'alice':4}) > py> n.bob > 1 > py> n.ted > 3 > > James How about... class namespace(dict): __getattr__ = dict.__getitem__ __setattr__ = dict.__setitem__ __delattr__ = dict.__delitem__ This seems to work, and eliminates the indirect method calls. Cheers, Ron From rosco at roscopeco.remove.co.uk Thu Oct 13 04:17:45 2005 From: rosco at roscopeco.remove.co.uk (Ross Bamford) Date: Thu, 13 Oct 2005 09:17:45 +0100 Subject: Jargons of Info Tech industry References: <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <868xx3m2ve.fsf@bhuda.mired.org> <86irw6l1mc.fsf@bhuda.mired.org> <86r7aqugmk.fsf@bhuda.mired.org> <7xk6ghkflq.fsf@ruckus.brouhaha.com> Message-ID: On Thu, 13 Oct 2005 09:04:17 +0100, > wrote: > Roedy Green writes: >> Next Mr. Phish had to present his passport etc when he got his Thawte >> ID. Now Interpol has a much better handle on putting him in jail. >> He can't repudiate his phishing attempt. > > Any underage drinker in a college town can tell you a hundred ways to > get sufficient fake ID to get around that. > > See also: http://www.ahbl.org/funny/response1.php > > I'll let others here fill in the blanks. :) :) :) -- Ross Bamford - rosco at roscopeco.remove.co.uk From fredrik at pythonware.com Sat Oct 8 15:45:18 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 8 Oct 2005 21:45:18 +0200 Subject: Help creating extension for C function References: <1128714478.552412.135950@g47g2000cwa.googlegroups.com> Message-ID: > seq = PySequence_Fast(data, "expected a sequence"); > if (!seq) > return NULL; here's some more information on the PySequence_Fast API: http://www.effbot.org/zone/python-capi-sequences.htm From bokr at oz.net Tue Oct 25 19:45:28 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 25 Oct 2005 23:45:28 GMT Subject: Log rolling question References: <1130259387.787107.120740@g14g2000cwa.googlegroups.com> <1130260944.709944.129960@z14g2000cwz.googlegroups.com> Message-ID: <435e9cf8.951408463@news.oz.net> On 25 Oct 2005 10:22:24 -0700, "elake" wrote: >Is there a way to do this for a whole calendar month? > Yes, if you can specify exactly what you want to do. E.g., today is 2005-10-25. What date would you like as the earliest to keep for the four months? What if today's date was not available in the month of four months ago? Do you want to have cleansed logs always start on the first day of a month? if so, do you want to go back four prior months, or consider any current month days as being a month-log even if partial, and only include 3 prior months? You haven't defined your requirements ;-) if you wanted to go back to the first day of four months back, maybe you could call that earliest_time and delete all files where after import os, stat you remove files where os.stat(pathtofile)[stat.ST_MTIME] < earliest_time going back from current time might go something like >>> import time >>> y,m = time.localtime()[:2] >>> y,m (2005, 10) >>> y,m = divmod(y*12+m-1-4,12) # -1 for 0..11 months >>> m+=1 # back to 1..12 >>> y,m (2005, 6) >>> time.strptime('%04d-%02d-01'%(y,m), '%Y-%m-%d') (2005, 6, 1, 0, 0, 0, 2, 152, -1) >>> earliest_time = time.mktime(time.strptime('%04d-%02d-01'%(y,m), '%Y-%m-%d')) >>> earliest_time 1117609200.0 >>> time.ctime(earliest_time) 'Wed Jun 01 00:00:00 2005' Hm ... Jun, Jul, Aug, Sep, Oct -4 -3 -2 -1 -0 I guess that guarantees 4 full prior months. I used strptime to build a complete 9-tuple rather than doing it by hand, which I'm not sure off hand how to do ;-) There's another module that does date interval addition/subtraction, but it didn't come with the batteries in my version. BTW, make sure all your date stuff is using the same epoch base date, in case you have some odd variant source of numerically encoded dates, e.g., look at >>> import time >>> time.localtime(0) (1969, 12, 31, 16, 0, 0, 2, 365, 0) >>> time.ctime(0) 'Wed Dec 31 16:00:00 1969' >>> time.gmtime(0) (1970, 1, 1, 0, 0, 0, 3, 1, 0) Regards, Bengt Richter From john at castleamber.com Tue Oct 11 21:43:32 2005 From: john at castleamber.com (John Bokma) Date: 12 Oct 2005 01:43: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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <86y853mzmr.fsf@bhuda.mired.org> <86mzlil269.fsf@bhuda.mired.org> Message-ID: Roedy Green wrote: > So let's say I decide to send an email to Donald Knuth. :-) -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From steve at REMOVETHIScyber.com.au Sat Oct 22 20:36:29 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 23 Oct 2005 10:36:29 +1000 Subject: best way to replace first word in string? References: <1129822003.246170.303920@f14g2000cwb.googlegroups.com> Message-ID: On Sat, 22 Oct 2005 21:41:58 +0000, Ron Adam wrote: > Don't forget a string can be sliced. In this case testing before you > leap is a win. ;-) Not much of a win: only a factor of two, and unlikely to hold in all cases. Imagine trying it on *really long* strings with the first space close to the far end: the split-and-join algorithm has to walk the string once, while your test-then-index algorithm has to walk it twice. So for a mere factor of two benefit on short strings, I'd vote for the less complex split-and-join version, although it is just a matter of personal preference. -- Steven. From mwm at mired.org Sat Oct 15 02:07:51 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 15 Oct 2005 02:07:51 -0400 Subject: Problem splitting a string References: <20051015045208.28476.qmail@web35811.mail.mud.yahoo.com> Message-ID: <86u0fjs47c.fsf@bhuda.mired.org> Robert Kern writes: > Anthony Liu wrote: >> I have this simple string: >> >> mystr = 'this_NP is_VL funny_JJ' >> >> I want to split it and give me a list as >> >> ['this', 'NP', 'is', 'VL', 'funny', 'JJ'] > You could use regular expressions as Jason Stitt mentions, or you could > replace '_' with ' ' and then split. > > In [2]: mystr = 'this_NP is_VL funny_JJ' > > In [3]: mystr.replace('_', ' ').split() > Out[3]: ['this', 'NP', 'is', 'VL', 'funny', 'JJ'] A third alternative is to split once, then split the substrings a second time and stitch the results back together: >>> sum([x.split('_') for x in mystr.split()], []) ['this', 'NP', 'is', 'VL', 'funny', 'JJ'] Which is probably slow. To bad extend doesn't take multiple arguments. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From fmstasi at gmail.com Tue Oct 11 08:38:19 2005 From: fmstasi at gmail.com (Francesco Marchetti-Stasi) Date: Tue, 11 Oct 2005 14:38:19 +0200 Subject: python server? Message-ID: <8450c3400510110538p74a9373cx@mail.gmail.com> Hello everybody, I am the happy yet unsatisfied owner of an ipaq 3760. I am writing a python+pygtk editor optimized for an handheld, and in the future I'd like to write more applications (to-do-list and agenda are on top of my priorities, since the existing ones don't fit my needs). I was now thinking of a way to improve memory usage. Any python application I launch takes 9-10 MB, and this risks to be a major blocking factor, since the memory I have is only 64 MB. So I'd like to share the memory between programs, sort of an emacs-server mode. I have a vague idea of the way to implement this, with a python-server.py script which would take over programs from a launcher.py script, or maybe a single script which would run into the background, the first time it is launched, and feed the programs to an already running copy, when finding an already running instance. Since I am mainly interested to GUI applications, the resulting threads should cohexist nicely. I was wondering if something similar already existed, to use as-is or to adapt to my needs. I did a little googling, which pointed me to interesting, but rather different projects. Has anybody ever seen or heard something of this kind? Or maybe there is something almost-ready in the amazing python library (as you understand, I am rather new to python), and I missed it? Thanks, Francesco. From my_email_is_posted_on_my_website at munged.invalid Sun Oct 9 15:40:30 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sun, 09 Oct 2005 19:40:30 GMT Subject: Jargons of Info Tech industry References: <1124804082_1011@spool6-east.superfeed.net> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <41hhk195gcipfarnqu85ggs606aqi89ea1@4ax.com> <2dadnfArEfWwvdTeRVnzvA@telenor.com> Message-ID: <0trik1ldrtvuhsdvoai4a7h34q7la1pehl@4ax.com> On Mon, 10 Oct 2005 01:40:34 +1000, Steven D'Aprano wrote or quoted : > >Yes. It is called "eyes". I look at the image, and miracle upon miracles, >I recognise Johnny wearing a hat. Even for a limited application like children's birthday parties captions could say things like: Johnny with this friend Pete, the one I told you about who has leukemia.... Here is Johnny opening your present, the sweater you knitted him. If you want to communicate with text and with pictures obviously there are times when you want to communicate with both text and pictures. Imagine a main sending emailed floor tile samples to his wife on a business trip for her final veto and not being allowed to caption them. The point I can't pound enough is that rich text and pictures with captions are not INHERENTLY dangerous or spam. (Note that the most common spam is the Nigerian con and variants which comes as a non-formatted message.) Many have mentally linked rich text with danger and spam because of Microsoft's incompetent email software. The solution is to fix the software not block everyone from communicating with rich text and pictures. You don't have to use Outlook. see http://mindprod.com/jgloss/email.html -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From michele.simionato at gmail.com Tue Oct 18 11:42:12 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 18 Oct 2005 08:42:12 -0700 Subject: example of using urllib2 with https urls Message-ID: <1129650132.645135.155030@g44g2000cwa.googlegroups.com> Can somebody provide an example of how to retrieve a https url, given username and password? I don't find it in the standard documentation. TIA, Michele Simionato From hauck at gseos.com Tue Oct 25 13:11:22 2005 From: hauck at gseos.com (Tommytrojan) Date: 25 Oct 2005 10:11:22 -0700 Subject: Weird import behavior Message-ID: <1130260282.027302.49370@g44g2000cwa.googlegroups.com> Hi, I have been using Python for a while but today I came across a really strange behavior: While poking around in Queue.py due to problems with importing this module from a thread I got an error that a module that I imported on top of the file could not be accessed. I reduced the problem to this small script: import string import os class T: def __init__(self): try: print 'xxx nothing to do' except ImportError: print 'got an import error' import os as string print 'xxxx string module', string t=T() The import clause in the except statement (although never executed) removes the reference to the string module imported at the beginning of the script. Any idea why this is the case? Thanks, Tommy From jeremy at emperorlinux.com Wed Oct 5 22:48:17 2005 From: jeremy at emperorlinux.com (Jeremy Moles) Date: Wed, 05 Oct 2005 22:48:17 -0400 Subject: Absolultely confused... In-Reply-To: <7jcqbu2h.fsf@python.net> References: <7jcqbu2h.fsf@python.net> Message-ID: <1128566897.3513.18.camel@localhost.localdomain> Thanks for the reply. :) I may be missing something critical here, but I don't exactly grok what you're saying; how is it even possible to have two instances of PyType_vector3d? It is (like all the examples show and all the extension modules I've done in the past) a static structure declared and assigned to all at once, only once. Am I misunderstanding the point? :) /me ducks On Thu, 2005-10-06 at 16:26 +0200, Thomas Heller wrote: > Jeremy Moles writes: > > > So, here is my relevant code: > > > > PyArg_ParseTuple(args, "O!", &PyType_vector3d, &arg1) > > > > And here ismy error message: > > > > argument 1 must be pylf.core.vector3d, not pylf.core.vector3d > > > > I know PyType_vector3d "works" (as I can use them in the interpreter all > > day long), and I know I'm passing a pylf.core.vector3d (well, apparently > > not...) > > > > I've spent hours and hours on this and I'm finally just giving up and > > asking. I've tried everything to get my program to verify that arg1 is > > really a PyType_vector3d, but to no avail. > > > > If I take out the "!" in the format string and just use "O", I can at > > least get past PyArg_ParseTuple. Then I try something like... > > > > PyObject_TypeCheck(arg1, &PyType_vector3d) > > > > Which also fails, but I know for a fact that arg1's PyObject_Repr is > > what it should be. (pylf.core.vector3d) > > > > I guess my question is: what in the world could be causing this to fail? > > It seems like I'm just not able to use ParseType or BuildValue to create > > objects of my own type. > > > > I know I haven't provided a lot of information, but does anyone have any > > ideas or where I should start looking? > > Can it be that you have TWO instances of the pylf.core.vector3d object? > Debugging should reveal it... > > Thomas From steve at REMOVETHIScyber.com.au Sat Oct 22 19:52:10 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 23 Oct 2005 09:52:10 +1000 Subject: Binding a variable? References: <86hdbau65d.fsf@bhuda.mired.org> Message-ID: On Fri, 21 Oct 2005 13:33:18 -0400, Mike Meyer wrote: > Paul Dale writes: > >> Hi everyone, >> >> Is it possible to bind a list member or variable to a variable such that >> >> temp = 5 >> >> list = [ temp ] Don't use the names of built-in functions as variables. >> temp == 6 >> >> list >> >> would show >> >> list = [ 6 ] > > No. You need to either put a mutable in the list, or subclass list so > that indexing gets the value, looks it up in the appropriate > namespace, and returns that value. Or something even conceptually simpler than having to muck about with looking up different namespaces: class Data: def __init__(self, obj): self.value = obj def __str__(self): return self.value temp = Data(5) L = [temp] print L will give 5. temp.value = 6 print L will now give 6. -- Steven. From en.karpachov at ospaz.ru Sat Oct 1 14:16:01 2005 From: en.karpachov at ospaz.ru (en.karpachov at ospaz.ru) Date: Sat, 1 Oct 2005 22:16:01 +0400 Subject: [Info] PEP 308 accepted - new conditional expressions In-Reply-To: References: <3q4ro9Fd770nU3@individual.net> <0qh%e.20023$Ix4.15230@okepread03> Message-ID: <20051001221601.1d301959.jk@ospaz.ru> On Fri, 30 Sep 2005 21:28:26 -0400 Terry Reedy wrote: > > The lesson for me is to spend much less time on Python discussion and much > more on unfinished projects. So even if I never use the new syntax, I will > have gained something ;-) QOTW? -- jk From apgwoz at gmail.com Sat Oct 8 15:25:01 2005 From: apgwoz at gmail.com (Andrew Gwozdziewycz) Date: Sat, 8 Oct 2005 15:25:01 -0400 Subject: Geocoding and python Message-ID: <22BB6AA0-7B20-43C1-9ADE-828277DD9006@gmail.com> Does anyone know of a python module that can read and search the tiger line data for geolocation? Currently, I can use xmlrpc to query geocoder.us but I'd rather not be querying their server if I don't have to. Thanks --- Andrew Gwozdziewycz apgwoz at gmail.com http://ihadagreatview.org http://plasticandroid.org From xah at xahlee.org Fri Oct 7 06:58:42 2005 From: xah at xahlee.org (Xah Lee) Date: 7 Oct 2005 03:58:42 -0700 Subject: check html file size In-Reply-To: <1128473042.653989.175990@o13g2000cwo.googlegroups.com> References: <1128473042.653989.175990@o13g2000cwo.googlegroups.com> Message-ID: <1128682722.213703.279200@g43g2000cwa.googlegroups.com> Xah Lee wrote: ? would anyone like to translate the following perl script to Python or Scheme (scsh)?? Here's the Python version. # -*- coding: utf-8 -*- # Python # Wed Oct 5 15:50:31 PDT 2005 # given a dir, report all html file's size. (counting inline images) # XahLee.org import re, os.path, sys inpath= '/Users/t/web/' while inpath[-1] == '/': inpath = inpath[0:-1] # get rid of trailing slash if (not os.path.exists(inpath)): print "dir " + inpath + " doesn't exist!" sys.exit(1) ################################################## # subroutines def getInlineImg(file_full_path): '''getInlineImg($file_full_path) returns a array that is a list of inline images. For example, it may return ['xx.jpg','../image.png']''' FF = open(file_full_path,'rb') txt_segs = re.split( r'src', unicode(FF.read(),'utf-8')) txt_segs.pop(0) FF.close() linx=[] for linkBlock in txt_segs: matchResult = re.search(r'\s*=\s*\"([^\"]+)\"', linkBlock) if matchResult: linx.append( matchResult.group(1) ) return linx def linkFullPath(dir,locallink): '''linkFullPath(dir, locallink) returns a string that is the full path to the local link. For example, linkFullPath('/Users/t/public_html/a/b', '../image/t.png') returns 'Users/t/public_html/a/image/t.png'. The returned result will not contain double slash or '../' string.''' result = dir + '/' + locallink result = re.sub(r'//+', r'/', result) while re.search(r'/[^\/]+\/\.\.', result): result = re.sub(r'/[^\/]+\/\.\.', '', result) return result def listInlineImg(htmlfile): '''listInlineImg($html_file_full_path) returns a array where each element is a full path to inline images in the html.''' dir=os.path.dirname(htmlfile) imgPaths = getInlineImg(htmlfile) result = [] for aPath in imgPaths: result.append(linkFullPath( dir, aPath)) return result ################################################## # main fileSizeList=[] def checkLink(dummy, dirPath, fileList): for fileName in fileList: if '.html' == os.path.splitext(fileName)[1] and os.path.isfile(dirPath+'/'+fileName): totalSize = os.path.getsize(dirPath+'/'+fileName) imagePathList = listInlineImg(dirPath+'/'+fileName) for imgPath in imagePathList: totalSize += os.path.getsize(imgPath) fileSizeList.append([totalSize, dirPath+'/'+fileName]) os.path.walk(inpath, checkLink, 'dummy') fileSizeList.sort(key=lambda x:x[0],reverse=True) for it in fileSizeList: print it print "done reporting." ------------------------------------------------- This Python version is a direct translation of the Perl version. They match pretty much line by line. for both the Python version and the Perl version, see: http://xahlee.org/perl-python/check_html_size.html Would any lisper provides a Scheme version? i don't think i'll do a Scheme version anytime soon. Please, Schemers, show us some fanfare. Xah xah at xahlee.org ? http://xahlee.org/ From ndbecker2 at gmail.com Tue Oct 11 09:38:04 2005 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 11 Oct 2005 09:38:04 -0400 Subject: Can module access global from __main__? Message-ID: Suppose I have a main program, e.g., A.py. In A.py we have: X = 2 import B Now B is a module B.py. In B, how can we access the value of X? From brakjoller at gmail.com Sat Oct 22 07:36:10 2005 From: brakjoller at gmail.com (Mathias Dahl) Date: Sat, 22 Oct 2005 13:36:10 +0200 Subject: Listening for keypress in the background Message-ID: I have created a small Python program that is running on my desktop. How can I make it listen for a certain keypress (say, Windows-key + space) in a controlled fashion even when it is not the program having focus? I need to do this running under GNOME in Mandrake GN/Linux 10. /Mathias From projecktzero at yahoo.com Tue Oct 4 09:15:21 2005 From: projecktzero at yahoo.com (projecktzero) Date: 4 Oct 2005 06:15:21 -0700 Subject: ssh or other python editor References: <1128430526.531749.68600@g47g2000cwa.googlegroups.com> Message-ID: <1128431721.153846.236930@g43g2000cwa.googlegroups.com> martijn at gamecreators.nl wrote: > H! > > I'm using a windows machine. > And a FreeBSD server where I run my python scripts. > > I'm working/making my python scripts in a windows OS with putty now. > But I really want the python text colors and tab spacing like the > python windows IDE but the problem is that I can't find a good program. > > Thanks So you're using Putty to telenet/ssh into the FreeBSD server, but what editor on you using on the FreeBSD server? I use VIM on my Windows workstation to edit files on a linux server. I have a network drive mounted to the linux server. Samba needs to be running on the server. If the FreeBSD server has samba running, you can mount a drive and use your Python Windows IDE. If samba isn't available/set-up, you can try using FTP. You can then use Crimson Editor which does the syntax coloring and can ftp to/from a server. From jfdoyon at methane.ca Sat Oct 1 19:13:20 2005 From: jfdoyon at methane.ca (=?ISO-8859-1?Q?Jean-Fran=E7ois_Doyon?=) Date: Sat, 01 Oct 2005 19:13:20 -0400 Subject: Class Help In-Reply-To: References: Message-ID: You have to crate an instanciation of the class before you can use one. So you want to do: instance = Xyz() instance.y() You won't get any output though, might want to do: class Xyz: def y(self): print 'y worked!' it's more satisfying :) Basically, look into the difference between a class, and the INSTANCE of a class. Cheers, J.F. Ivan Shevanski wrote: > To continue with my previous problems, now I'm trying out classes. But > I have a problem (which I bet is easily solveable) that I really don't > get. The numerous tutorials I've looked at just confsed me.For intance: > >>>> class Xyz: > > ... def y(self): > ... q = 2 > ... > >>>> Xyz.y() > > Traceback (most recent call last): > File "", line 1, in ? > TypeError: unbound method y() must be called with Xyz instance as first > argument > (got nothing instead) > > > So. . .What do I have to do? I know this is an extremley noob question > but I think maybe if a person explained it to me I would finally get it =/ > > > thanks in advance, > > -Ivan > > _________________________________________________________________ > Express yourself instantly with MSN Messenger! Download today - it's > FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ > From bokr at oz.net Mon Oct 3 11:29:36 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 03 Oct 2005 15:29:36 GMT Subject: Will python never intend to support private, protected and public? References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xd5mstqab.fsf@ruckus.brouhaha.com> <7xzmpwuxd0.fsf@ruckus.brouhaha.com> <20050930075313.67b9b676.jk@ospaz.ru> <7xbr2a6dlz.fsf@ruckus.brouhaha.com> <7xk6gyoibc.fsf@ruckus.brouhaha.com> <433f56a3.2969039483@news.oz.net> <1128274267.064255.306980@f14g2000cwb.googlegroups.com> <7x8xxbgj4h.fsf@ruckus.brouhaha.com> <4340dfd2.3069694347@news.oz.net> <7x64sex1o1.fsf@ruckus.brouhaha.com> Message-ID: <43414a14.3096896000@news.oz.net> On 03 Oct 2005 04:47:26 -0700, Paul Rubin wrote: >bokr at oz.net (Bengt Richter) writes: >> Would you want to outlaw 'None' as an attribute name? >> Python seems to be straddling the fence at this point: >> >>> c.None = 'c.None' >> SyntaxError: assignment to None > >Heehee, I think that's just a compiler artifact, the lexer is treating >None as a keyword instead of a normal lexical symbol that the compiler >treats separately. That's also why it raises SyntaxError instead of >some other type of error. Yes, None should be ok as an attribute name. > Not sure whether which compiler. This one seems to differ from the C version. >>> import compiler >>> compiler.parse("c.None = 'c.None'") Module(None, Stmt([Assign([AssAttr(Name('c'), 'None', 'OP_ASSIGN')], Const('c.None'))])) >>> compiler.compile("c.None = 'c.None'", '', 'exec') at 02EE7FA0, file "", line 1> >>> import dis >>> dis.dis(compiler.compile("c.None = 'c.None'", '', 'exec')) 1 0 LOAD_CONST 1 ('c.None') 3 LOAD_NAME 0 (c) 6 STORE_ATTR 1 (None) 9 LOAD_CONST 0 (None) 12 RETURN_VALUE >>> c = type('',(),{})() >>> exec (compiler.compile("c.None = 'c.None'", '', 'exec')) >>> c.None 'c.None' So the compiler module is happy to generate code that you can execute, but the builtin compiler seems not to be: >>> c.None = 'c.None' SyntaxError: assignment to None and definitely not run-time: >>> def foo(): ... c.None = 'c.None' ... File "", line 2 SyntaxError: assignment to None Seems like a bug wrt the intent of making compiler.compile work exactly like the builtin C version. But maybe it has been fixed -- I am still running 2.4 from the beta I built with mingw (because the new microsoft msi loader won't run on my version of NT4 without upgrading that I've got too much dll hell to do on this box. I should also upgrade mingw/msys and recompile, but I spend time here instead ;-/ ) 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. Regards, Bengt Richter From dcrespo at gmail.com Wed Oct 19 10:54:00 2005 From: dcrespo at gmail.com (dcrespo) Date: 19 Oct 2005 07:54:00 -0700 Subject: Is there a module for print object in a readable format? In-Reply-To: References: Message-ID: <1129733640.047687.194990@g44g2000cwa.googlegroups.com> Maybe you don't have an up to date python version. I'm using 2.4.2. I tried: import pprint pprint.pprint([1,2,3,4,[0,1,2,[3,4]],5], width=1,indent=4) [ 1, 2, 3, 4, [ 0, 1, 2, [ 3, 4]], 5] Works fine. From christian at spam.no Thu Oct 13 11:56:14 2005 From: christian at spam.no (Christian) Date: Thu, 13 Oct 2005 17:56:14 +0200 Subject: How to call a script from another? In-Reply-To: <434e7e85$1@nntp0.pdx.net> References: <434e6f56$0$90426$edfadb0f@dread16.news.tele.dk> <434e7e85$1@nntp0.pdx.net> Message-ID: <434e83a2$0$90437$edfadb0f@dread16.news.tele.dk> Thanks guy's, you have opened my eyes and made my next step a whole lot easier. Chris From kst-u at mib.org Wed Oct 12 21:13:28 2005 From: kst-u at mib.org (Keith Thompson) Date: Thu, 13 Oct 2005 01:13:28 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <868xx3m2ve.fsf@bhuda.mired.org> <86irw6l1mc.fsf@bhuda.mired.org> Message-ID: Roedy Green writes: [...] > Especially with spam, there are no perfect solutions, but at least we > could do many times better than what we are living with and put the > spammers out of business. A partial solution to spam, or at least to pollution of Usenet newsgroups, would be to STOP POSTING THIS STUFF TO NEWSGROUPS WHERE IT'S NOT RELEVANT. There are several newsgroups that deal with e-mail abuse. This discussion isn't being posted to any of them. Please stop. -- 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 __peter__ at web.de Tue Oct 11 06:10:01 2005 From: __peter__ at web.de (Peter Otten) Date: Tue, 11 Oct 2005 12:10:01 +0200 Subject: Looking for info on Python's memory allocation References: <434B1A99.8040107@REMOVEMEcyber.com.au> Message-ID: Lasse V?gs?ther Karlsen wrote: > If I have a generator or other iterable producing a vast number of > items, and use it like this: > > s = [k for k in iterable] > > if I know beforehand how many items iterable would possibly yield, would > a construct like this be faster and "use" less memory? > > s = [0] * len(iterable) > for i in xrange(len(iterable)): > s[i] = iterable.next() You can easily answer the speed aspect of your question using the timeit module: ~ $ python2.4 -m timeit -s'iterable=range(1000)' '[k for k in iterable]' 10000 loops, best of 3: 111 usec per loop ~ $ python2.4 -m timeit -s'iterable=range(1000)' 's = [0]*len(iterable); it = iter(iterable)' 'for i in xrange(len(iterable)): s[i] = it.next()' 1000 loops, best of 3: 513 usec per loop ~ $ python2.4 -m timeit -s'iterable=range(1000)' 's = [0]*len(iterable)' 'for i, v in enumerate(iterable): s[i] = v' 1000 loops, best of 3: 269 usec per loop ~ $ python2.4 -m timeit -s'iterable=range(1000)' 'list(iterable)' 100000 loops, best of 3: 7.33 usec per loop Peter From mwm at mired.org Sat Oct 15 02:29:20 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 15 Oct 2005 02:29:20 -0400 Subject: MD5 module Pythonicity References: Message-ID: <86psq7s37j.fsf@bhuda.mired.org> Leandro Lameiro writes: > What's wrong in having a function like the one I said, that would > split files for you, feed md5.update and, when it is over, return the > digest? Nothing in particular; it's just a trivial thing to write. If you add every usefull utility function to the standard library, you wind up with a multi-thousand page library documentation. The line has to be drawn somewhere. > It is easier, doesn't require MD5 objects creation, works well on > small and big files, makes the code more readable and simple. Also, > calculating MD5 of files seems to be a common enough task to be put in > the library (well, at least on GNU/Linux we have one command just for > this - md5sum) Wanting to sum a file at the command line isn't that uncommon, so a utility makes some sense. But how often does a program need the md5 sum of a file? Especially compared to how often it wants to take the md5 sum of some string that isn't in a file? It might be worth adding. Except that md5 isn't really trusted anymore; you really want to be using sha1 (and you presumably have an sha1sum utility. FreeBSD has md5 and sha1 commands). But the sha module doesn't have a file handler either. You might try posting a patch to sourceforge, and see if it gets accepted. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From my_email_is_posted_on_my_website at munged.invalid Thu Oct 27 02:15:03 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Thu, 27 Oct 2005 06:15:03 GMT Subject: Microsoft Hatred FAQ References: <3s6l8mFmj3fjU1@individual.net> <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> Message-ID: On Wed, 26 Oct 2005 19:50:07 -0700, "David Schwartz" wrote, quoted or indirectly quoted someone who said : > There is no different to Microsoft beween a bare computer and one >preloaded with Linux or FreeBSD. One can quickly be converted to other with >minimal cost of effort. In the market, bare PCs really do compete with >Windows PCs. You think it is OK to force someone into a choice of committing a criminal act with the alternative of losing their established business and having to put 8 employees out of work. What religion do you belong to? -- Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching. From david at jotax.com Tue Oct 25 11:14:47 2005 From: david at jotax.com (David Poundall) Date: 25 Oct 2005 08:14:47 -0700 Subject: Tricky import question. In-Reply-To: References: <1130247555.359770.169070@o13g2000cwo.googlegroups.com> Message-ID: <1130253287.721535.322370@g47g2000cwa.googlegroups.com> Sadly I get this reply when I try that. AttributeError: 'module' object has no attribute 'main' I am getting the impression that the value returned from the __import__() function is only a string reference NOT an object. I am going to have a go at trying this with the imp' module as that specifically mentions that an object is returned. From codecraig at gmail.com Fri Oct 28 12:14:25 2005 From: codecraig at gmail.com (py) Date: 28 Oct 2005 09:14:25 -0700 Subject: SNMP In-Reply-To: <1130515702.436348.190240@g43g2000cwa.googlegroups.com> References: <1130515702.436348.190240@g43g2000cwa.googlegroups.com> Message-ID: <1130516065.407854.325980@g14g2000cwa.googlegroups.com> ...also I am looking to work with windows, as well as linux. From steve at holdenweb.com Mon Oct 10 09:42:35 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 10 Oct 2005 14:42:35 +0100 Subject: One last thing about SocketServer In-Reply-To: <1128949186.15247.11.camel@athop1.ath.vt.edu> References: <1128949186.15247.11.camel@athop1.ath.vt.edu> Message-ID: rbt wrote: > I've read more about sockets and now, I have a better understanding of > them. However, I still have a few SocketServer module questions: > > When used with SocketServer how exactly does socket.setdefaulttimeout() > work? Does it timeout the initial connect request to the socket server > or does it timeout the session between the connecting client socket and > the client socket the server generated to handle the incoming request? > setdefaulttimeout() simply sets the default timeout for all sockets created thereafter. This timeout applies to any socket operation, I believe (though I am unsure about "accept()"). > Also, since the *only* thing a 'socket server' does is to create 'client > sockets' to handle requests, how do I use socket object features on > these generated clients to manage and/or monitor them? > When the accept() call on a socket returns a tuple(socket, address): the first element of the returned tuple is the socket you use to communicate with that particular client (in other words, it represents the server end of the connection that's just been accept()ed). So you can read and write that socket to communicate with that client over that specific connection. Of course, if you don't use either the ThreadingMixIn or the ForkingMixIn then communication with one client will effectively stop you form accept()ing any more connections, hence the need for the mix-in classes. > The SocketServer module is great, but it seems to hide too many details > of what it's up to! > Well, of course, that is what abstractions are for! You should bear in mind that SocketServer isn't necessarily the most efficient or effective way to handle multiple clients concurrently, but it's very convenient when you are just getting started. Later you might want to consider an asyncore-based approach, or perhaps using the Twisted package. Both of these solutions are a little more robust for production code. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From cyril.bazin at gmail.com Mon Oct 31 04:25:57 2005 From: cyril.bazin at gmail.com (Cyril Bazin) Date: Mon, 31 Oct 2005 10:25:57 +0100 Subject: meschach + Python Message-ID: Hello, I need to compute eigenvalues and eigenvectors on sparse matrix. I found a C library "meschach" which seems to do the work. Unfortunatly, this libray doesn't seem to be interfaced in Python. Has anyone ever used this library and interfaced it in Python or has a solution to compute eigenvalues and eigenvalues on sparse matrix efficiently in Python? Thanks in advance, Cyril -------------- next part -------------- An HTML attachment was scrubbed... URL: From cfajohnson at gmail.com Mon Oct 24 00:40:20 2005 From: cfajohnson at gmail.com (Chris F.A. Johnson) Date: Mon, 24 Oct 2005 00:40:20 -0400 Subject: An interesting question about "print '\a'" References: Message-ID: On 2005-10-24, Anthony Liu wrote: > We know that if we do > > print '\a' > > the bell will sound. > > Now, why do I hear the sound on my local machine when > I run a python script on a remote host? > > I understand if I hear it when I do > > print '\a' > > on my local machine. > > Does the command get sent back to the client machine? The code is printed to stdout, which is your terminal. Your terminal interprets ^G as a beep. -- Chris F.A. Johnson ================================================================== Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress From davids at webmaster.com Tue Oct 18 14:53:29 2005 From: davids at webmaster.com (David Schwartz) Date: Tue, 18 Oct 2005 11:53:29 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <867jcbzdw9.fsf@bhuda.mired.org> Message-ID: "John W. Kennedy" wrote in message news:Orb5f.29427$Ge5.26368 at fe10.lga... > Mike Meyer wrote: >> "David Schwartz" writes: >> >>> It is not Microsoft's obligation to be "fair". It is Microsoft's >>> obligation to push their vision of the future of computing, one with >>> Microsoft's products at the center, using anything short of force or >>> fraud. >> >> >> Wrong. The only obligation Microsoft has is to their shareholders. > > If you genuinely believe that, you are a psychopath. That's almost as convincing as "that's what you think". DS From http Wed Oct 19 03:44:05 2005 From: http (Paul Rubin) Date: 19 Oct 2005 00:44:05 -0700 Subject: UI toolkits for Python References: <7xslv56ud1.fsf@ruckus.brouhaha.com> <3ras6oFit2djU1@individual.net> <4350dd34$0$6774$9b4e6d93@newsread4.arcor-online.net> <863bn12k6i.fsf@bhuda.mired.org> <7xslv02aoj.fsf@ruckus.brouhaha.com> <87psq39aur.fsf@wilson.rwth-aachen.de> <7xwtkbud5q.fsf@ruckus.brouhaha.com> <1h4mhm2.1rmv4fh1czi843N%aleaxit@yahoo.com> <86r7aiyg4g.fsf@bhuda.mired.org> <1h4n6ag.5uhq7a7xe1v4N%aleaxit@yahoo.com> <86ach6y6ta.fsf@bhuda.mired.org> <1h4o6eo.4gi3s6xgesmzN%aleaxit@yahoo.com> Message-ID: <7xll0qdk8q.fsf@ruckus.brouhaha.com> aleaxit at yahoo.com (Alex Martelli) writes: > > You mean like google? Until recently, they're an outstanding example > > of doing things right, and providing functionality that degrades > > gracefully as the clients capabilities go down. > > I'm not sure what you mean by "until recently" in this context. AFAIK, > we've NEVER wasted our efforts by pouring them into the quixotic task of > supporting *100%* of possible browsers that may hit us, with the near > infinite number of combinations of browsers, versions and disabled > feature that this would require. The non-graphics-oriented Google services like search, news, and groups, have worked perfectly well with lynx until recently. No javascript required, no image display required, and no cookies required. From sw at wordtech-software.com Mon Oct 31 13:57:00 2005 From: sw at wordtech-software.com (Kevin Walzer) Date: Mon, 31 Oct 2005 13:57:00 -0500 Subject: MacOS Extension Carbon.File.FSCatalogInfo file sizes should be UInt64? In-Reply-To: <1130736502.902026.91020@g43g2000cwa.googlegroups.com> References: <1130736502.902026.91020@g43g2000cwa.googlegroups.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 donbro wrote: | If my read of the extension source (Mac/Modules/file/_Filemodule.c) is | correct, the parameter sizes specified for data and resource file sizes | are UInt32 where they should be UInt64. | | In both OS9 and OSX Carbon, the MacOS File Manager (Files.h) uses | UInt64 values for data and resource filesizes. | | Testing Python 2.3 and 2.4.2 on MacOS 10.3 returns 0L for the file size | values and correct values for other elements such as parentDirID: | | |>>>fsRef = FSRef('LICENSE') |>>>catinfo, d1, d2, d3 = fsRef.FSGetCatalogInfo(-1L) |>>>catinfo.dataPhysicalSize | | 0 | |>>>catinfo.parentDirID | | 2026177 | | | in Files.h, both OS9 and OSX Carbon, the elements are UInt64: | | struct FSCatalogInfo { | [...] | UInt64 dataLogicalSize; | UInt64 dataPhysicalSize; | UInt64 rsrcLogicalSize; | UInt64 rsrcPhysicalSize; | [...] | } | | in _Filemodule.c the spec looks to be 32 bit: | | static PyObject *FSCatalogInfo_get_dataLogicalSize(FSCatalogInfoObject | *self, void *closure) | { | return Py_BuildValue("l", self->ob_itself.dataLogicalSize); | } | | I have, perhaps naively, just changed my local copy to use a BuildValue | parameter of "L" instead of "l" for each of these get and set methods | and this has survived my initial testing: | | static PyObject *FSCatalogInfo_get_dataLogicalSize(FSCatalogInfoObject | *self, void *closure) | { | return Py_BuildValue("L", self->ob_itself.dataLogicalSize); | } | | But my questions are: | | Has anyone else seen this? | | Does this seem like the right fix? | | There is another routine in _Filemodule.c: FSCatalogInfo_tp_init() that | also seems to hold information relevant to parameter size. Should this | be changed as well? | | If this is a bug, what's the best procedure to report this? | Sourceforge? This mailing list? | | I'm porting a MacOS9 application from C++ to python and I expect to be | seeing a lot of these python macintosh filesystem extensions in the | near future! | | Thanks for any help | | Don | You're most likely to get a good answer to this question on the MacPython mailing list--give that a try if you don't get a response here. - -- Cheers, Kevin Walzer, PhD WordTech Software - "Tame the Terminal" http://www.wordtech-software.com sw at wordtech-software.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (Darwin) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDZmj8JmdQs+6YVcoRAtkTAJ9CEYbIRy6VLY7qp304JPmcl+iXUQCdHTMT KmJljW7loFJNKFsjFkB2aNA= =vEVV -----END PGP SIGNATURE----- From deets at web.de Fri Oct 7 08:12:26 2005 From: deets at web.de (Diez B. Roggisch) Date: 7 Oct 2005 05:12:26 -0700 Subject: "no variable or argument declarations are necessary." In-Reply-To: References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <3qi8erFf252rU1@uni-berlin.de> <3qkdbrFfgga9U1@uni-berlin.de> <3qkn7qFffkl6U1@uni-berlin.de> <3qkr1hFfgj5uU1@uni-berlin.de> Message-ID: <1128687145.965133.251150@g47g2000cwa.googlegroups.com> > It is not about falling back on generic declarartion, it is about > how such object will be treated. Diez seems to think that > strongly-typed language can only deal with generic declarations > by using something that allows circumventing the type system. No, I don't - now it's you who makes assumptions about what I think. ML and other FPs show that genericity can be done without circumvening. Templates and generics in C++ partially do so. > > > In other words, you want Python to be strongly-typed, but sometimes you > > want to allow a reference to be to any object whatsoever. In which case > > you can't possibly do any sensible type-checking on it, so this new > > Python+ or whatever you want to call it will suffer from the same > > shortcomings that C++ and java do, which is to say type checking can't > > possibly do anything useful when the acceptable type of a reference is > > specified as ANY. > > And you are wrong. The problem with the C void* construct (I'm not that > familiar with java) is that all type information is lost. When you > use such a parameter in a function you have no idea what you are > working with. You don't know JAVA - I do. And nobody said that it lost that type-information. It doesn't. Still, errors occur - namely ClassCastEcxeptions. That indicates that going back and forth via ANY doesn't necessarily lose any type information, but the capability of today's type-systems to keep that information across such a transition. This won't work: Object foo = A(); B bar = (B) foo; And please, pretty please don't argue with the simplicity of that example - think of a bazillion statements between these two, possibly done with run-time-instantiated classes that weren't known at compile-time. > But that doesn't need to be if you have a typesystem with an ANY type. > Such a type declaration would mean that object of any type could be > used here. However that doesn't imply that the type information > of the actual objects used, has to be lost. That type information > may still be available and usefull for further type checking. JAVA has that. > That you and Diez can only think about C, C++ or java constructs > when I mention an ANY type, is your limitation. It doesn't > need to be the limitation of a specific type system. Again: where are the specifics of this system? In your head? Tell us the gory detail, please. Diez From peter at engcorp.com Tue Oct 18 22:26:59 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 18 Oct 2005 22:26:59 -0400 Subject: write a loopin one line; process file paths In-Reply-To: <1129675636.740977.151760@z14g2000cwz.googlegroups.com> References: <1129672592.328278.41490@g14g2000cwa.googlegroups.com> <1129675636.740977.151760@z14g2000cwz.googlegroups.com> Message-ID: Xah Lee wrote: > If you think i have a point, ... You have neither that, nor a clue. (Newsgroups line trimmed to reduce the effects of cross-posting trolls.) -Peter From sjdevnull at yahoo.com Tue Oct 18 18:45:47 2005 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: 18 Oct 2005 15:45:47 -0700 Subject: Vim IS a capable IDE [was Re: Vim capable IDE?] In-Reply-To: References: <1129603486.291175.167860@f14g2000cwb.googlegroups.com> <4354b229$0$21286$626a54ce@news.free.fr> <1129644971.811765.105900@g49g2000cwa.googlegroups.com> <22a5f.20376$ae.2646@tornado.tampabay.rr.com> <1129663697.620665.99040@g44g2000cwa.googlegroups.com> Message-ID: <1129675547.108377.246320@o13g2000cwo.googlegroups.com> Chris Lambacher wrote: > > * Usage tips/tooltips: Also something I found in PythonWin. During the > > writing of the method, a little tip box pops up advising me what the > > inputs are for a method or an instance construction for a class. Very > > nice, very productive. > VIm 7 may support that out of the box since there were a lot of supporter > votes for it: > http://www.vim.org/sponsor/vote_results.php It will, Omni Complete (akin to "Intellisense" and such) is already in the Vim 7 tree. From codecraig at gmail.com Tue Oct 25 14:26:29 2005 From: codecraig at gmail.com (jas) Date: 25 Oct 2005 11:26:29 -0700 Subject: Read/Write from/to a process In-Reply-To: References: <1130163642.868252.148070@g44g2000cwa.googlegroups.com> <1130174259.472124.114790@f14g2000cwb.googlegroups.com> <1130242940.918480.65020@f14g2000cwb.googlegroups.com> Message-ID: <1130264789.562249.153310@z14g2000cwz.googlegroups.com> I have setup multiple threads and a queue...which is working pretty good. But I have one other issue...I have a new thread (since it is different issue) here: http://groups.google.com/group/comp.lang.python/browse_frm/thread/ec81d8982d1a0130 if you get chance, would you mind checking that out. Thanks! From myles at geocities.com Tue Oct 4 01:47:44 2005 From: myles at geocities.com (Myles Strous) Date: 3 Oct 2005 22:47:44 -0700 Subject: Controlling who can run an executable References: <1128395422.904212.318930@g44g2000cwa.googlegroups.com> <86y85ahs1j.fsf@bhuda.mired.org> Message-ID: <1128404864.966640.323710@g14g2000cwa.googlegroups.com> Mike Meyer wrote: > You don't need to install special hardware to get that. There are a > number of pieces of hardware that you can find in a modern computer > that may have a unique serial number you can use as a > dongle. Possibilities include a CPU serial number, an HD serial > number, and the MAC address of any network cards: ethernet, wireless, > and apparently FireWire drivers have them. People have used all of > them in the past. What's more, Tim Golden's wmi module (see http://tgolden.sc.sabren.com/python/wmi.html) makes getting at these numbers very easy: import wmi c = wmi.WMI () for thingy in c.Win32_NetworkAdapter(): print "Network Adaptor", thingy.MACAddress for thingy in c.Win32_Processor(): print "Processor", thingy.ProcessorId for thingy in c.Win32_BIOS(): print "BIOS", thingy.SerialNumber for thingy in c.Win32_BaseBoard(): print "BaseBoard", thingy.SerialNumber for thingy in c.Win32_SystemEnclosure(): print "System Enclosure", thingy.SerialNumber for thingy in c.Win32_DiskDrive(): print "Disk Drive", thingy.PNPDeviceID for thingy in c.Win32_PhysicalMedia(): print "Physical Media", thingy.SerialNumber Regards, Myles. From david at jotax.com Fri Oct 28 03:21:28 2005 From: david at jotax.com (David Poundall) Date: 28 Oct 2005 00:21:28 -0700 Subject: Counting Threads In-Reply-To: References: <1130435220.846203.86320@g44g2000cwa.googlegroups.com> <1130435796.917475.295830@g14g2000cwa.googlegroups.com> <1130456316.569328.323480@f14g2000cwb.googlegroups.com> Message-ID: <1130484088.324170.269810@g43g2000cwa.googlegroups.com> Sorry Denis - but could you give me an example. I can't for the life of me see how the syntax for that would go. From usenet at eikepreuss.de Fri Oct 28 04:11:17 2005 From: usenet at eikepreuss.de (Eike Preuss) Date: Fri, 28 Oct 2005 10:11:17 +0200 Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> <3s8t89FmdnriU1@individual.net> Message-ID: <3se4jbFnjch1U1@individual.net> David Schwartz wrote: > "Eike Preuss" wrote in message > news:3s8t89FmdnriU1 at individual.net... > > >>> Right, except that's utterly absurd. If every vendor takes their tiny >>>cut of the 95%, a huge cut of the 5% is starting to look *REALLY* good. > > >>Sure, that would be true if the market would be / would have been really >>global. In practice if you have a shop you have a limited 'region of >>influence'. Optimally you are the only shop in this region that sells >>the stuff, or perhaps there are a few shops that compete with you. Lets >>say in your region are two shops competing with you, and you must decide >>wether to sell product A (95%) or B (5%), but you may not sell both. >>Decision 1: Sell A, share the 95% of the local market with two -> about >>32% of the local market for all of you, if all perform equally good >>Decision 2: Sell B -> you get the 5% of the market, the others 47% each >> >>This calculation is probably still a very bad approximation of the >>truth, but things are definitely not as easy as you state them. > > > It depends upon how different the products are and how easy it is to > shop out of your local market. If the products are equally good and > reasonably interchangeable and it's hard to shop out of your local market, > then you're right. The more the smaller product is better than the larger > product, the less interchangeable they are, and the easier it is to shop out > of your local market, the more wrong you are. > > How often do you hear, "I'd like to use Linux, but I just can't get > ahold of it"? > > And how many people do you hear saying, "I'd like to use Linux, but I'm > not willing to shell out the bucks to buy it since I already bought Windows > with my computer". > > On the other hand, where you might be right is in the possibility that > Microsoft's lock on the market prevented other companies from making > operating systems at all. That is, that had Microsoft used different > policies, other companies would have introduced operating systems to compete > with Microsoft, and we'd all have better operating systems for it. If > Microsoft's conduct was legal, this argument establishes that the conduct > was necessary. > > DS > > Yes, as I said: It is much more complicated than your beautiful argument 'well, then, taking a huge portion of 5% would be much more preferable anyway' suggests. From bdesth.quelquechose at free.quelquepart.fr Sun Oct 9 14:04:11 2005 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sun, 09 Oct 2005 20:04:11 +0200 Subject: Python's Performance In-Reply-To: References: <20051008040614.47429.qmail@web30607.mail.mud.yahoo.com> Message-ID: <43495259$0$29124$626a14ce@news.free.fr> Laszlo Zsolt Nagy a ?crit : > Dave wrote: > >> Hello All, >> >> I would like to gather some information on Python's runtime >> performance. As far as I understand, it deals with a lot of string >> objects. Does it require a lot string processing during program >> execution? How does it handle such time-consuming operations? Is there >> a way to find out how many string operations (perhaps in the >> underlying system) ) it does during program execution? > > > Do you want to know how many internal string operations are done inside > the Python interpreter? I believe it is not a useful information. There > are benchmarks testing the *real performance* of Python. > > For example: http://www.osnews.com/story.php?news_id=5602 > A benchmark stating that Python is interpreted is bullshit. > Les > From michele.petrazzo at TOGLIunipex.it Wed Oct 26 09:26:39 2005 From: michele.petrazzo at TOGLIunipex.it (Michele Petrazzo) Date: Wed, 26 Oct 2005 15:26:39 +0200 Subject: wxPython import error In-Reply-To: References: Message-ID: <435f83f3$0$8491$5fc30a8@news.tiscali.it> contact at ljbsoftware.com ha scritto: > I have tried several times to install wxPython on Fedora Core 2. The > installation seems to go fine (from sources), but when I try to import the > wx module I keep getting the following error: > <-cut-> > Any help or explanation would be greatly appreciated. For a my customer I had tried a lot of time, but without success to compile and install wx 2.6.x But luckily there is a precompiled package on wxpython.org. Have you try it? Michele From onurb at xiludom.gro Mon Oct 3 09:13:43 2005 From: onurb at xiludom.gro (bruno modulix) Date: Mon, 03 Oct 2005 15:13:43 +0200 Subject: "no variable or argument declarations are necessary." In-Reply-To: References: Message-ID: <43412e88$0$16536$626a14ce@news.free.fr> James A. Donald wrote: > James A. Donald: > >> > Surely that means that if I misspell a variable name, my program will >> > mysteriously fail to work with no error message. > > > On Sun, 02 Oct 2005 17:11:13 -0400, Jean-Fran?ois Doyon > >>No, the error message will be pretty clear actually :) > > > Now why, I wonder, does this loop never end :-) > egold = 0 > while egold < 10: > ego1d = egold+1 > A more pythonic style would be: egold = 0 while egold < 10: ego1d += 1 And that one raises a name error !-) -- 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 yahoo.com Fri Oct 28 23:07:47 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 28 Oct 2005 20:07:47 -0700 Subject: Opaque documentation References: <1130513632.359922.113550@g47g2000cwa.googlegroups.com> <86wtjxeahk.fsf@bhuda.mired.org> Message-ID: <1h55rti.1yu9cz318dg815N%aleaxit@yahoo.com> Mike Meyer wrote: > "Ben Sizer" writes: > > Documentation is often a problem with Python and its libraries, sadly. > > The same almost certainly goes for most open source projects. > > You over-specified the last clause. It should say "most software > projects." You over-specified the last clause. It should say "most projects." Alex From michaelschneider at fuse.net Thu Oct 6 12:33:38 2005 From: michaelschneider at fuse.net (Michael Schneider) Date: Thu, 06 Oct 2005 12:33:38 -0400 Subject: So far In-Reply-To: References: Message-ID: <434551E2.5090109@fuse.net> Take a look at: http://wingware.com/ It is only $35.00 for an IDE. (30 day free eval version) I use eclipse for java, and have become quite fond of tab completion. Mike CppNewB wrote: > I am absolutely loving my experience with Python. Even vs. Ruby, the syntax > feels very clean with an emphasis on simplification. > > My only complaint is that there doesn't appear to be a great commercial IDE > for the language. I've tried Komodo, etc and they are nice applications, > but they don't feel like they give me the "power" like a Visual Studio or > Delphi (I wish I could articulate better the differences). Finding a > descent GUI builder has been a challenge as well. Most of them have support > for Dialogs, but what about more complex UI's? I may need a resizable frame > within a resizable frame? I haven''t found a GUI builder with a great feel > yet. > > Other than that, my experience has been wonderful. Even after my > complaints, I plan on sticking with Python for a while. > > From nemesis at nowhere.invalid Thu Oct 13 15:52:21 2005 From: nemesis at nowhere.invalid (Nemesis) Date: Thu, 13 Oct 2005 19:52:21 GMT Subject: [ANN] XPN 0.5.5 released Message-ID: <20051013194207.1700.5269.XPN@orion.homeinvalid> XPN (X Python Newsreader) is a multi-platform newsreader with Unicode support. It is written with Python+GTK. It has features like scoring/actions, X-Face and Face decoding, muting of quoted text, newsrc import/export, find article and search in the body, spoiler char/rot13, random taglines and configurable attribution lines. You can find it on: http://xpn.altervista.org/index-en.html or http://sf.net/projects/xpn Changes in this release: * improved support for outgoing/draft articles, now is possible to re-edit queued articles. * added a simple SSL connection support (no certificates checks) * added multipart article support (no binary attachments support) * added German translation (thanks to Rene Fischer) * fixed a bug that caused crashes with strange Date fields * fixed a bug in newsrc importing, now is alse possible to import not standard newsrc files like the Xnews ones. * fixed a bug in the newsrc system that caused a crash with groups containings lots of articles * a lot of little bug-fixes and little enhancements XPN is translated in Italian French and German, if you'd like to translate it in your language and you are familiar with gettext and po-files editing please contact me (xpn at altervista.org). -- This is not a beer belly. It's a fuel tank for a sex machine. |\ | |HomePage : http://nem01.altervista.org | \|emesis |XPN (my nr): http://xpn.altervista.org From michele.simionato at gmail.com Wed Oct 26 09:01:31 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 26 Oct 2005 06:01:31 -0700 Subject: tool for syntax coloring in html In-Reply-To: References: <1130330426.059794.282450@g49g2000cwa.googlegroups.com> Message-ID: <1130331691.558414.93870@g14g2000cwa.googlegroups.com> Gerhard wrote: > http://initd.org/pub/software/pysqlite/doc/usage-guide.html Can I suggest you to use a larger font for the code?It is pretty difficult to parse with my current screen resolution. BTW, pysqlite2 is pretty cool ;) Michele Simionato From python at gentoolinux.demon.nl Wed Oct 19 15:07:32 2005 From: python at gentoolinux.demon.nl (the_crazy88) Date: 19 Oct 2005 12:07:32 -0700 Subject: Python Doc Error: os.makedirs In-Reply-To: <1129685449.372717.56900@z14g2000cwz.googlegroups.com> References: <1129685449.372717.56900@z14g2000cwz.googlegroups.com> Message-ID: <1129748852.009676.39830@o13g2000cwo.googlegroups.com> if not os.path.isdir("your_dir_name"): makedirs("your_dir_name") From samrobertsmith at gmail.com Tue Oct 25 04:50:28 2005 From: samrobertsmith at gmail.com (Shi Mu) Date: Tue, 25 Oct 2005 01:50:28 -0700 Subject: cell and row Message-ID: <1d987df30510250150mb4f0f97y79d6e93c0c0d66ff@mail.gmail.com> I can not understand the use of "cell" and "row" in the code: # convert the matrix to a 1D list matrix = [[13,2,3,4,5],[0,10,6,0,0],[7,0,0,0,9]] items = [cell for row in matrix for cell in row] print items From spammers-go-here at spam.invalid Sat Oct 15 21:48:12 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Sat, 15 Oct 2005 21:48:12 -0400 Subject: Length of read in in python-gpib References: <4351a665$0$41142$14726298@news.sunsite.dk> Message-ID: <4351b136$0$41143$14726298@news.sunsite.dk> Further, if I use 131072 (2^17) as the length, I get an error : Traceback (most recent call last): File "takedata.py", line 74, in ? x=sr.querytrca(srs,1,0,4000,131072) File "/home/labmonkey/code/oledpmt/sr830.py", line 62, in querytrca trca=sr.read(n) File "/usr/lib/python2.3/site-packages/Gpib.py", line 22, in read self.res = gpib.read(self.id,len) gpib.error: Read Error: ibrd() failed Following this, an attempt to run the script again chokes at the first (harmless - just setting some instrument parameter - ibwrt() fails) gpib command and then locks the bus, freezing the whole system unless I reboot the system. This has happened twice. I am using the Agilent82357a USB to GPIB convertor. Have used it for numerous purposes with the same setup, but the library seems to be choking on this new application. The instrument I am trying to use is an SR830 lockin amplifier. From gregpinero at gmail.com Fri Oct 14 14:03:50 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Fri, 14 Oct 2005 14:03:50 -0400 Subject: NYLUG meeting: The Python Object Model with Alex Martelli & Google(open bar and food!) In-Reply-To: <1129312792.c8c0370da34fd63e5cace1fe6133aff9@teranews> References: <1129312792.c8c0370da34fd63e5cace1fe6133aff9@teranews> Message-ID: <312cfe2b0510141103i162034a1x8009b9123d041717@mail.gmail.com> > > A reasonable question ... What date is it ? It isn't mentioned at the web site either. > > George > > > > -- > 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 uval at rz.uni-karlsruhe.de Fri Oct 21 20:37:34 2005 From: uval at rz.uni-karlsruhe.de (=?ISO-8859-1?Q?Daniel_Sch=FCle?=) Date: Sat, 22 Oct 2005 02:37:34 +0200 Subject: Redirect os.system output In-Reply-To: <1129927486.854143.169670@g49g2000cwa.googlegroups.com> References: <1129927486.854143.169670@g49g2000cwa.googlegroups.com> Message-ID: maybe you should look at subprocess module I have one expamle, this is Linux though >>> import subprocess as sp >>> p1 = sp.Popen(["ls", "-l"], stdout = sp.PIPE) >>> p2 = sp.Popen(["wc", "-c"], stdin = p1.stdout, stdout = sp.PIPE) >>> print p2.stdout.read() 226 hth, Daniel From fairwinds at eastlink.ca Thu Oct 13 22:57:11 2005 From: fairwinds at eastlink.ca (David Pratt) Date: Thu, 13 Oct 2005 23:57:11 -0300 Subject: CSV module and Mac excel format problem In-Reply-To: <1129255820.418348.24070@o13g2000cwo.googlegroups.com> Message-ID: <372F951A-3C5E-11DA-9C8A-000A27B3B070@eastlink.ca> Hi. I have had good success with CSV module but recently came across problem with reading excel from Mac Office. The trouble is with line endings. Instead of \r\n you have just \r and the file as a whole appears as a single line. CSV coughs and provides this exception: _csv.Error: newline inside string Saving as Windows (text) in Mac Office solves this but I don't necessarily want to force users to save this way just to avoid modifying my code. There is a lineterminator in the package. Adding parameter lineterminator='\r' did not correct the problem. The way I am reading tab delimited to dictionary: lines = sample.readlines() headers = csv.reader(lines, delimiter='\t').next() rows = csv.DictReader(lines, headers, delimiter='\t') for row in rows: print row Regards, David From twic at urchin.earth.li Wed Oct 12 19:41:39 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Thu, 13 Oct 2005 00:41:39 +0100 Subject: Python's garbage collection was Re: Python reliability In-Reply-To: <7xfyr9hv13.fsf@ruckus.brouhaha.com> References: <7xr7au1hr5.fsf@ruckus.brouhaha.com> <7xwtkl21hn.fsf@ruckus.brouhaha.com> <7xll11twc2.fsf@ruckus.brouhaha.com> <7xfyr9hv13.fsf@ruckus.brouhaha.com> Message-ID: On Mon, 10 Oct 2005, it was written: > Tom Anderson writes: > >> Has anyone looked into using a real GC for python? I realise it would >> be a lot more complexity in the interpreter itself, but it would be >> faster, more reliable, and would reduce the complexity of extensions. > > The next PyPy sprint (this week I think) is going to focus partly on GC. Good stuff! >> Hmm. Maybe it wouldn't make extensions easier or more reliable. You'd >> still need some way of figuring out which variables in C-land held >> pointers to objects; if anything, that might be harder, unless you want >> to impose a horrendous JAI-like bondage-and-discipline interface. > > I'm not sure what JAI is (do you mean JNI?) Yes. Excuse the braino - JAI is Java Advanced Imaging, a component whose horribleness exceed even that of JNI, hence the confusion. > but you might look at how Emacs Lisp does it. You have to call a macro > to protect intermediate heap results in C functions from GC'd, so it's > possible to make errors, but it cleans up after itself and is generally > less fraught with hazards than Python's method is. That makes a lot of sense. tom -- That's no moon! From shkelley at gmail.com Fri Oct 21 09:22:47 2005 From: shkelley at gmail.com (shkelley at gmail.com) Date: 21 Oct 2005 06:22:47 -0700 Subject: pushing python to multiple windows machines In-Reply-To: References: Message-ID: <1129900967.169902.5500@g49g2000cwa.googlegroups.com> hey tim - Thanks for you input. I'm looking at it from the Windows perspective of needing to push a python interpreter out to multiple machines. I'll check out Moveable Python as you suggested. thanks -shawn From kevin.bell at slcgov.com Thu Oct 6 14:09:08 2005 From: kevin.bell at slcgov.com (Bell, Kevin) Date: Thu, 6 Oct 2005 12:09:08 -0600 Subject: date reformatting Message-ID: <2387F0EED10A4545A840B231BBAAC722607F18@slcimail1.slcgov.com> Anyone aware of existing code to turn a date string "8-15-05" into the number 20050815? The dateutil module has a parse method that looks perfect, I downloaded and unzipped it, but could figure out how to install it. I using windows XP and py2.4. Any ideas? Kev From franz.steinhaeusler at gmx.at Mon Oct 24 05:22:36 2005 From: franz.steinhaeusler at gmx.at (Franz Steinhaeusler) Date: Mon, 24 Oct 2005 11:22:36 +0200 Subject: IDE recommendation please References: Message-ID: On Sun, 23 Oct 2005 14:54:38 +1000, microsnot wrote: >I'm new to Python but am wondering what IDE Python developers use? I use DrPython ;) >I use Mac >OS X 10.4.2. I have PythonIDE which comes with MacPython but I don't think >that has even rudimentary "intellisense". DrPython has a "Code Completition" plugin. It combines "Autocompletion" and "Calltips" -- Franz Steinhaeusler From mwm at mired.org Sun Oct 16 18:58:59 2005 From: mwm at mired.org (Mike Meyer) Date: Sun, 16 Oct 2005 18:58:59 -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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <43518dc6.95550404@news.oz.net> Message-ID: <86d5m5132k.fsf@bhuda.mired.org> Roedy Green writes: > On Sat, 15 Oct 2005 23:24:21 GMT, bokr at oz.net (Bengt Richter) wrote or > quoted : >>How about pdf? > My complaint with it is it is Adobe proprietary. This make the tools > very expensive. No, it isn't. The standard is publicly available, so anyone can write tools that produce and/or manipulate PDF. Lots of people do. Pretty much any WP or DP package worth using will generate PDF at out of the box - and some of those are free. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From codecraig at gmail.com Fri Oct 21 10:12:34 2005 From: codecraig at gmail.com (Java and Swing) Date: 21 Oct 2005 07:12:34 -0700 Subject: win32 process information, using win32 extension Message-ID: <1129903954.839508.298270@o13g2000cwo.googlegroups.com> i need to get information about the processes running on a windows pc (98, 2k, xp) i can get the pid's using, win32process.EnumProcesses()...and I can get a handle on a process using an id..such as handle = win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION, 0, pids[0]) ..but how can i get the name of the process, path to process, etc. I have the win32 extensions (pywin32) on python 2.4. thanks. From davids at webmaster.com Thu Oct 27 08:22:24 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 05:22:24 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: Peter T. Breuer wrote: > In comp.os.linux.misc David Schwartz wrote: >> Microsoft was not going to let a business >> parasitically use Windows to build a business that touted the >> advantages of competing products. > Well, it should have, because that's what manufacturers of operating > systems, washing machines, and so on, are supposed to do. And so says > the legal system. Attempting to subvert market economics like that is > illegal. Actually, there are washing machines that are only available in particular stores. I believe Kenmore washing machines, for example, are only available wholesale as part of a franchise deal. I don't know why you think that's an attempt to subvert market economics, it's actually just a normal part of the way the market works. >> (Just as Burger King corporate will not you sell Big >> Macs in the same store in which you sell Whoppers.) > They're not obliged to. There is no comparison. Not even the same kind > of business in the abstract. Try :- Cow Meat Inc. will see that no > supplier will ever sell you cow meat again if you also sell vegetables > in your totally independent restaurant. So you are saying Microsoft wouldn't sell Windows wholesale to business A if totally independent business B wouldn't pay them a per-system-sold royalty? That makes no sense. The comparison is perfect. Microsoft made Windows available wholesale for resale only as part of a franchise-style agreement. This is a completely typical thing to do. (Though I don't think it's typical for operating systems, I'd be very surprised if it hadn't been done with an operating system before. Sun seems to have similar restrictions now, in fact.) DS From kenneth.m.mcdonald at sbcglobal.net Thu Oct 13 18:20:58 2005 From: kenneth.m.mcdonald at sbcglobal.net (Kenneth McDonald) Date: Thu, 13 Oct 2005 17:20:58 -0500 Subject: UI toolkits for Python In-Reply-To: References: <7xslv56ud1.fsf@ruckus.brouhaha.com> Message-ID: This improved appearance has been a nice thing to see, but looks were never really the reason I decided to leave Tkinter. It's much more the fundamental issues of Tk, plus the fact that Tkinter was never really "completed" (not a comment on the original author--there's only so much one person can do) that has made me decide to leave Tk behind. As an example of the worst Tk issues (at least for what I was doing): 1) Marks screw up when they come to occupy the position. For example, let's say { symbolizes a text mark with right gravity, and } a text mark with left gravity. Remember that marks all have names, so they can all be referred to uniquely. Now construct some text like this: {here} is {some} marked {text}. Delete all the text. The marks still exist. Now, try to recreate the original text by inserting the appropriate words at the appropriate marks. It won't work for two reasons, the worst of which is that marks that come to occupy the same index in the text can actually change their relative order. 2) There are no abstract references; everything is referred to by its string name. This causes serious problems with name clashes and code abstraction. Tkinter hides some of this, but not enough. 3) Window nesting is completely determined by window naming, which only compounds the problem mentioned in (2). I don't really mean to diss Tk, I just get so frustrated when I think of what it could have been... Thanks, Ken On 13-Oct-05, at 4:02 PM, Mark Roseman wrote: > People should probably be more aware of work that has been going on > with > Tk recently (after a fairly long hiatus) in terms of greatly improving > its appearance, adding theming, and more. It's worth checking out, > and > of course, if there's a way to help get some of these changes into > Tkinter, the Tk folks would I'm sure be helpful. > > Here's a portion of a note that Jeff Hobbs posted to the Ruby group > recently, on a similar topic: > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kcoffie at hotmail.com Wed Oct 5 17:26:51 2005 From: kcoffie at hotmail.com (k8) Date: 5 Oct 2005 14:26:51 -0700 Subject: Using command line args on Windows In-Reply-To: <3qitrdFf7cpaU1@uni-berlin.de> References: <1128544715.139551.15960@g43g2000cwa.googlegroups.com> <3qitrdFf7cpaU1@uni-berlin.de> Message-ID: <1128547611.050408.295600@o13g2000cwo.googlegroups.com> Thank you thank you thank you- The windows command line sol worked. -k8 From christian.hausknecht at tu-clausthal.de Thu Oct 13 11:09:53 2005 From: christian.hausknecht at tu-clausthal.de (Christian Hausknecht) Date: Thu, 13 Oct 2005 17:09:53 +0200 Subject: cgi python References: <1129215225.778017.20340@g47g2000cwa.googlegroups.com> Message-ID: Python_it wrote: > I going to use the cgi-handler (mod_python): > > http://www.modpython.org/live/mod_python-3.2.2b/doc-html/hand-cgi.html > > > If I test a simply py script it works > > code: > =========== > print "Content-type: text/html\n" > print """ > > >

TEST

> > > """ > ============ > > But if I test a py script with cgi comments (import cgi): > > Part of the code > ============ > import cgi > > #get HTTP query parameters > query = cgi.FieldStorage() > > #Get the selected year and month > selectedYear = int(query["year"].value) > selectedMonth = int(query["x"].value) + 1 > > #Get the monthly revenue > monthlyRevenue = float(query["value"].value) > ============ > > I get the following error: > > errormessage: > ========================== > Mod_python error: "PythonHandler mod_python.cgihandler" > > Traceback (most recent call last): > > File "C:\Program > Files\Python24\Lib\site-packages\mod_python\apache.py", line 299, in > HandlerDispatch > result = object(req) > > File "C:\Program > Files\Python24\Lib\site-packages\mod_python\cgihandler.py", line 96, in > handler > imp.load_module(module_name, fd, path, desc) > > File "C:/Program Files/Apache > Group/Apache2/htdocs/clue/modules/templates\clickpie.py", line 9, in ? > selectedYear = int(query["year"].value) > > File "C:\Program Files\Python24\Lib\cgi.py", line 559, in __getitem__ > raise KeyError, key > > KeyError: 'year' > > > Who can help me? There is no Parameter 'year' in the Format-String sent by the Webserver! You can test it like this: if(query.has_key("yaer")): xyz = query["year"].value If you want to get a Parameter called 'year', you must call the cgi-Script like this: http://host/path-to-cgi-dir/script.py?year=2005 Another method is, to use a form in the calling html-Page and put a hidden value into it. Ciao, Christian From mrosenstihl at macnews.de Tue Oct 11 17:34:21 2005 From: mrosenstihl at macnews.de (Markus Rosenstihl) Date: Tue, 11 Oct 2005 23:34:21 +0200 Subject: Nicer way of strip and replace? Message-ID: Hi, I wonder if i can make this nicer: In my case a list is created from a bill which is a tab seperated file and each line looks like this: "Verbindungen Deutsche Telekom vom 03.08.2005 bis 10.08.2005" "ISDN" "Deutsche Telekom AG" "Rufnummer" "123456789" "3" "Verbindungen zu T-Mobile AktivPlus xxl sunday" "19483" "19" "0,1719" "3,27" "16" I create the list in the following way: rechnung_raw=open('filename', 'r').readlines() for line in rechnung_raw: the_line=string.split(line, '\t') rechnung.append(the_line) Now, I have a loop which does basically: for element in anotherlist: #anotherlist contains line numbers euro=euro + float(string.replace(string.strip(rechnung[element][10], '"'), ',' , '.')) I replace commata with dots, then delete leading/trailing "s then add to a sum after converting it to a float. This looks ugly (I htink) and I wonder if there is a nicer way to strip commata and change the comma to a dot already when reading in. Or should i do it with a shell script before processing in python? Regards Markus From larry.bates at websafe.com Wed Oct 12 19:26:11 2005 From: larry.bates at websafe.com (Larry Bates) Date: Wed, 12 Oct 2005 18:26:11 -0500 Subject: File compare In-Reply-To: <1129150273.991158.203660@g49g2000cwa.googlegroups.com> References: <1129150273.991158.203660@g49g2000cwa.googlegroups.com> Message-ID: <434D9B93.7090300@websafe.com> Sounds a little like "homework", but I'll help you out. There are lots of ways, but this works. import sys class fobject: def __init__(self, inputfilename): try: fp=open(inputfilename, 'r') self.lines=fp.readlines() except IOError: print "Unable to open and read inputfilename=%s" % inputfilename sys.exit(3) self.datadict={} for line in self.lines: line=line.strip() line=line.strip("'") key, values=line.split(' ',1) self.datadict[key]=values return def keys(self): return self.datadict.keys() def compare(self, otherobject): keys=otherobject.keys() match=0 for key in keys: if self.datadict[key] == otherobject.datadict[key]: match+=1 return float(match)/float(len(keys)) if __name__=="__main__": f1=fobject(r'f:\syscon\python\zbkup\f1.txt') f2=fobject(r'f:\syscon\python\zbkup\f2.txt') print f1.compare(f2) Larry Bates PyPK wrote: > I have two files > file1 in format > > 'AA' 1 T T > 'AB' 1 T F > > file2 same as file1 > > 'AA' 1 T T > 'AB' 1 T T > > Also the compare should be based on id. So it should look for line > starting with id 'AA' (for example) and then match the line so if in > second case. > > so this is what I am looking for: > 1. read both files. > 2. read id of first line in file1 check if it matches with the same id > in file2. > 3. repeat step 2 for all lines in file1. > 4. return a percent of success to failure. ie if one line matches and > one lines does'nt then return 0.5 or 50% > > I wrote a boolean version ..as a start > > def getdata(f): > try: > f1 = open(f,'r') > data=[] > for eachline in f1.readlines(): > data.append(re.split("", > re.sub('\n','',strip(re.split('\s\s+',eachline)[0])))) > return data > except IOError: > raise("Invalid File Input") > > if __name__=='__main__': > > data1 = getdata('file1') > data2 = getdata('file2') > > if data1 == data2: > print "True" > else: > print "False" > > hope I am clear... > From deets at nospam.web.de Sat Oct 22 11:43:46 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 22 Oct 2005 17:43:46 +0200 Subject: PID and/or handle assistance. . .? In-Reply-To: References: Message-ID: <3rv51hFlkvakU1@uni-berlin.de> Michael Williams wrote: > Hi All, > > Can anyone explain how to both spawn processes from PYTHON and acquire > their process IDs or a handle to them for use later? I'd also like to > acquire the stdout of each spawned process. Google dead today? Well, check out the modules subprocess, popen2 and os. Regards, Diez From luismgz at gmail.com Tue Oct 4 08:28:05 2005 From: luismgz at gmail.com (Luis M. Gonzalez) Date: 4 Oct 2005 05:28:05 -0700 Subject: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please! In-Reply-To: References: Message-ID: <1128428885.390019.304730@g43g2000cwa.googlegroups.com> > Boa Constructor, Iron Python etc... it seems all these projects get started, > but never finished. I don't know Boa (never liked it, never used it), but you could try PythonCard: much higher level, easier and more productive. As for Ironpython seems to be moving full steam towards a stable release (current version is 0.9.2). And once it's ready, integration with other MS technologies will be assured, so you shouldn't be concerned about that. If not Ironpython, Boo (which could be considered almost an static version of Python for .NET) would be a great choice. It is already integrated to SharpDevelop and soon it will be compliant with .NET 2.0. It seems your concerns are all related to the future, and I think that no matter what implementation of python you use, the future looks brighter than ever, because the same code base will run on .NET, Pypy (which will support many platforms) and java (through Jython) . What other language gives you so many options? From mwm at mired.org Sun Oct 23 14:03:09 2005 From: mwm at mired.org (Mike Meyer) Date: Sun, 23 Oct 2005 14:03:09 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <86k6g59ke6.fsf@bhuda.mired.org> <3EI6f.43974$MF6.5922@fe1.news.blueyonder.co.uk> Message-ID: <86irvo861u.fsf@bhuda.mired.org> entropy writes: > entropy at domain.invalid wrote... >> axel at white-eagle.invalid.uk wrote... >> > In comp.lang.perl.misc David Schwartz wrote: >> > > "Mike Meyer" wrote in message >> > >> Sorry, but nobody but the government actually owns property. In most >> > >> places, you can't make non-trivial changes to "your" property without >> > >> permission from the government. They even charge you rent on "your" >> > >> property, only they call it "property tax". >> > > I see you are a totalitarianist or perhaps a communist. If you want to >> > > live in America and discuss things that are relevent to America, let me >> > > know. >> > Why would you say that - Mike Meyer made a point to which you have >> > obviously no answer. Or do you deny that his comments on this matter >> > of property are true? >> Methinks David simply missed that Mike was being facetious. (Irony >> and facetiousness don't translate well into print, as Frank Zappa >> once noted.) > Uh, you _were_ being facetious there, weren't you Mike? No, I wasn't. The statements I made are true: the government charges you taxes on your property, and in most places restricts the changes you can make to it and the things you can do in it. I used the words "rent" and "ownership" in an unconventional way to emphasize the point. The conventional usage of "ownwership" ignores these kinds of facts. So you can talk about "your" house even if you're renting it, or if the bank still owns most of the house. There are political groups that are unhappy with these facts, and like to point out the inconsistencies in the usage of the word "ownership". See and for examples of this. David claimed that everyone had a right to do whatever they wanted with their property. This is simply false throughout most of the civilized world - zoning laws control what kinds of business you can run on your property, various laws designed to control the looks of the town dictate what you can do to the exterior or lawn, flood and earthquake laws state what kinds of structural changes you can make, and so on. I took the view of a political extremist to point out that he was wrong. David predictably used that to tar me as an extremist from the other end of the spectrum. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From dave at dbmdata.com Mon Oct 31 21:25:57 2005 From: dave at dbmdata.com (David Mitchell) Date: Mon, 31 Oct 2005 21:25:57 -0500 Subject: Where to save classes? How to access classes? Message-ID: <4366D235.8040702@dbmdata.com> Hi, I'm trying to get into the object oriented aspect of Python. If I create a custom class (in it's own file), how do I access that class in a function in a different file? In Java there's the notion of a CLASSPATH, where you can tell the compiler to look for classes. Is there something similar to this in Python? Thanks, Dave From jesper.olsen at gmail.com Sat Oct 8 11:34:29 2005 From: jesper.olsen at gmail.com (Jesper) Date: 8 Oct 2005 08:34:29 -0700 Subject: readline installation problem References: Message-ID: <1128785669.063610.256760@f14g2000cwb.googlegroups.com> Hi Jian, I just struggled with the same problem - seems the python 2.4.2 does not recognise readline 5 I finally "solved" the problem by installing readline 4.2, and explicitly pointing out to configure where the readline library is ./configure --with-libs=/usr/local/lib/libreadline.a That finally made it work ... Cheers Jesper From no.mail.here.at.here at gmail.com Fri Oct 7 02:54:00 2005 From: no.mail.here.at.here at gmail.com (mike) Date: 6 Oct 2005 23:54:00 -0700 Subject: os.access with wildcards In-Reply-To: References: <1128665933.923295.95580@f14g2000cwb.googlegroups.com> Message-ID: <1128668040.818787.73690@o13g2000cwo.googlegroups.com> thanks Leif. poor question on my part. I had been using glob.glob(path)==[] and was looking for something more readable, hence os.system('[ -e %s ]' % path ) but that doesn't seem like a good idiom for crossplatform. I thought there may either be a way to escape the wildcards, or an alternative to os.access, or .... any othr ideas? From piet at cs.uu.nl Wed Oct 12 07:09:01 2005 From: piet at cs.uu.nl (Piet van Oostrum) Date: Wed, 12 Oct 2005 13:09:01 +0200 Subject: bizarro world References: <1128937897.500935.254770@o13g2000cwo.googlegroups.com> <1129033426.009136.256600@g47g2000cwa.googlegroups.com> <1129071507.829655.252340@g44g2000cwa.googlegroups.com> Message-ID: >>>>> Bryan (B) wrote: >B> omg!!! wow!!! after reading this i feel like i just stepped in to some >B> bizarro world. So why do you have to repeat the whole thing?? I have kill-filed XL, and now you put the message in my face. Please don't react to this drivel. -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From davids at webmaster.com Thu Oct 27 13:37:28 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 10:37:28 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <66u633-etj.ln1@news.it.uc3m.es> <7xbr1aewtq.fsf@ruckus.brouhaha.com> <7xoe5asw3t.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > "David Schwartz" writes: >>> Of course it's legal for non-monopoly companies. You seem to think >>> Microsoft's illegal monopoly is an irrelevant detail. It is not. >> What is an "illegal monopoly"? > It's what Microsoft still stands convicted of having. > > http://cyber.law.harvard.edu/openlaw/msdoj/ I don't see anything there about what an "illegal monopoly" is or might be. Perhaps you could clarify. What do you think you mean when you say "illegal monopoly"? DS From stijndesaeger at gmail.com Sat Oct 1 06:46:45 2005 From: stijndesaeger at gmail.com (vdrab) Date: 1 Oct 2005 03:46:45 -0700 Subject: pywordnet install problems In-Reply-To: References: <1128057470.285356.211160@g49g2000cwa.googlegroups.com> Message-ID: <1128163605.623632.96660@o13g2000cwo.googlegroups.com> hello Steve, I had WordNet 2.0 installed but just now I tried it with 1.7.1 as well and the result was the same. It's a shame, glossing over the pywordnet page really made me want to give it a try. Are there any workarounds you can recommend ? I had a quick look at the wordnet.py file, and it looks readable enough to try and fiddle around with it, but if possible I'd like to avoid having to mess with the source file. Is there any other person / list I can ask for help on this? thanks a lot. vdrab. From lasse at vkarlsen.no Tue Oct 11 09:29:22 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Tue, 11 Oct 2005 15:29:22 +0200 Subject: Merging sorted lists/iterators/generators into one stream of values... References: <1128667968.421469.180910@g47g2000cwa.googlegroups.com> <1128691708.c6930b5cb9f3673ed3abe8755178d163@teranews> <1128692196.410209.252100@g14g2000cwa.googlegroups.com> <1128695317.c6a5acb3e62787f011310c96f0c7cc35@teranews> <1h439qe.pz7c451jcec6hN%aleax@mail.comcast.net> <1128795319.09c32ac9943b0580a86b7bcada7facc1@teranews> <1128797447.501582.24560@o13g2000cwo.googlegroups.com> <1h47iae.6d2ps91u8eafuN%aleax@mail.comcast.net> <1h485kt.1bru0if72epwrN%aleax@mail.comcast.net> <1129037036.712254.94830@o13g2000cwo.googlegroups.com> Message-ID: George Sakkis wrote: >>Function name is perhaps not the best one. It occurs to me that this >>is the GROUP BY in SQL so perhaps a different name is better, but >>then again this might be moot if such a already exists somewhere :) > > > Amazing, you keep reinventing things, even with the exact same name :) > > from itertools import imap,groupby > from operator import itemgetter > > for fruit,group in groupby(fruits, itemgetter(0)): > print fruit, "has a sum of", sum(imap(itemgetter(1),group)) > > For this to work as intended, fruits has to be already sorted by the > same key given to grouby; otherwise just replace fruits with > sorted(fruits, itemgetter(0)). > > By the way, read all the functions in the itertools module > (http://docs.python.org/lib/itertools-functions.html), it will save you > a lot of time. > > George > Itertools, meh, there's that wheel again :) Didn't know about this one so thank you :) -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From shafranov at gmail.com Tue Oct 18 15:54:27 2005 From: shafranov at gmail.com (shafran) Date: 18 Oct 2005 12:54:27 -0700 Subject: unittest of file-reading function In-Reply-To: References: Message-ID: <1129665266.957444.19460@g47g2000cwa.googlegroups.com> Hi! You can use tempfile.mktemp(), then write test contents to this temp file, pass it to your function, unlink tempfile. you can create / unlink temp file in setUp() / tearDown() methods. Alexander. From Ido.Yehieli at gmail.com Mon Oct 10 01:46:05 2005 From: Ido.Yehieli at gmail.com (Clint Norton) Date: 9 Oct 2005 22:46:05 -0700 Subject: searching a project to contribute to In-Reply-To: <86hdbqjfbp.fsf@bhuda.mired.org> References: <1128881668.508095.29320@g49g2000cwa.googlegroups.com> <8664s6kx8l.fsf@bhuda.mired.org> <1128906992.565860.327040@g14g2000cwa.googlegroups.com> <86hdbqjfbp.fsf@bhuda.mired.org> Message-ID: <1128923165.612313.124290@g14g2000cwa.googlegroups.com> Well, I meant python modules offcourse ;-) From dcrespo at gmail.com Fri Oct 14 17:25:20 2005 From: dcrespo at gmail.com (dcrespo) Date: 14 Oct 2005 14:25:20 -0700 Subject: A way to set levels of access to users Message-ID: <1129325120.794686.196210@z14g2000cwz.googlegroups.com> Hi all, I have this table on a database: Table: user coduser | username | password | securitylevel 1 | fcumana || 0123456789qwe where "securitylevel" is a string where the presence of each character is a permited key for running certain functions. For example: functions.py ------------------------------------------------- securitylevel=6 def function1(): print "This is the function 'function1'" ...and/or other functions ------------------------------------------------- Because securitylevel=6 exists in securitylevel in the database, the user running it is allowed to access. The lack here is that if there's a lot of functions and users, and I want to enable certain users to access certain functions, then, it will get confusing for maintain it. Any help? Daniel From greg.steffensen at gmail.com Fri Oct 14 01:24:49 2005 From: greg.steffensen at gmail.com (gsteff) Date: 13 Oct 2005 22:24:49 -0700 Subject: UI toolkits for Python In-Reply-To: References: Message-ID: <1129267489.263656.93610@g49g2000cwa.googlegroups.com> I've used wxpython and pygtk, and have a strong preference for pygtk. wxpython has some advantages: it has better OSX support (widgets look native, and it doesn't require the installation of the Fink x server), and better win32 support (a few gtk widgets, such as menus, don't look quite native on gtk, and multithreading with pygtk on win32 is problematic). But pygtk has better documentation, a MUCH cleaner api, integration with the Glade GUI designer (wxpython has wxglade, but its not in the same league), and a richer widget set. In addition, top itself is in the top tier of free software projects; wxwidgets is not as mature, and its development is not as active. So, if you're trying to choose between those two, go with wxpython if you need OSX support, or have specific issues with pygtk's win32 support. In all other cases, I'd reccomend pygtk. Greg From steve at holdenweb.com Fri Oct 21 07:40:37 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 21 Oct 2005 12:40:37 +0100 Subject: Set an environment variable In-Reply-To: <4358d112$0$187$edfadb0f@dread16.news.tele.dk> References: <43573022$0$155$edfadb0f@dread16.news.tele.dk> <1129798724.366618.194650@g44g2000cwa.googlegroups.com> <43589205$0$125$edfadb0f@dread16.news.tele.dk> <4358d112$0$187$edfadb0f@dread16.news.tele.dk> Message-ID: Christian wrote: > Steve Holden wrote: > > >>:::::::::::::: >>one.py >>:::::::::::::: >>import os >>os.environ['STEVE'] = "You are the man" >>os.system("python two.py") >>print "Ran one" >>:::::::::::::: >>two.py >>:::::::::::::: >>import os >>print "STEVE is", os.environ['STEVE'] >>print "Ran two" >>[sholden at headrat tmp]$ python one.py >>STEVE is You are the man >>Ran two >>Ran one >>[sholden at headrat tmp]$ >> >>Hope this helps. >> >>regards >> Steve > > > Thanks Steve, you're quite right, you are the man. And thanks to all the > rest of you for your kind help and patient understanding. I have learned > quite a lot and is about to consider my self advanced to the status of > Python newbie. > > So here is my final question: > Do I call the .sh script with a .py script like this: > > os.system("/path/to/the/script/startupscript.sh") Time you answered your own questions by trying things at the interactive interpreter prompt! regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From gsakkis at rutgers.edu Fri Oct 14 14:32:38 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: 14 Oct 2005 11:32:38 -0700 Subject: Searching files in directories References: <1129311080.579292.112990@g47g2000cwa.googlegroups.com> <434FF2C4.3040307@websafe.com> Message-ID: <1129314758.810705.101200@g14g2000cwa.googlegroups.com> "Larry Bates" wrote: > Not tested but should be close: > > import os > import shutil > > files = ['file1.txt'] > source_directory = '/tmp/source/' > destination_directory = '/tmp/destination/' > > for file in files: > src=os.path.join(source_directory, file > dst=os.path.join(destination_directory, file > if os.path.exists(os.path.join(source_directory, file): > shutil.copy(src, dst) Or more succinctly using the path module: from path import path files = ['file1.txt'] src_dir = path('/tmp/source/') dest_dir = path('/tmp/destination/') for filename in files: srcfile = src_dir / filename if srcfile.exists(): srcfile.copy(dest_dir) George From peterm at resmed.com.au Mon Oct 10 00:53:11 2005 From: peterm at resmed.com.au (Peter Milliken) Date: Mon, 10 Oct 2005 14:53:11 +1000 Subject: Python on the Power PC Message-ID: Hi, I (think I have :-)) installed Python on my Pocket PC (obtained from http://fore.validus.com/~kashtan/). There were Tkinter binaries with it so I installed those as well. When I attempt to run the most simplistic of python programs using Tkinter, I get an error message stating that Python can't find any tkinter module. Any ideas what I have done wrong anybody? Thanks Peter import Tkinter if __name__ == '__main__': root = Tkinter.Tk() root.title('Hello World?') root.mainloop() From tim at tt1lock.org Mon Oct 17 08:37:04 2005 From: tim at tt1lock.org (Tim Tyler) Date: Mon, 17 Oct 2005 12:37:04 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: Tim Roberts wrote or quoted: [Microsoft] > Part of their behavior really escape me. The whole thing about browser > wars confuses me. Web browsers represent a zero billion dollar a year > market. Why would you risk anything to own it? Power. Minshare. Controlling the planet's gateway to the internet. That sort of thing. -- __________ |im |yler http://timtyler.org/ tim at tt1lock.org Remove lock to reply. From deets at nospam.web.de Sun Oct 16 11:23:33 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 16 Oct 2005 17:23:33 +0200 Subject: wxPython & Cygwin In-Reply-To: References: <434e8dbf$0$452$7a628cd7@news.club-internet.fr> <3r8bo1Fi9etjU1@uni-berlin.de> <3rf6f4Fj4tqhU1@uni-berlin.de> Message-ID: <3rf9jlFj8e4kU1@uni-berlin.de> > I'm sure the Cygwin world would be grateful if you or someone else were > to establish the correct build procedure. For Qt? I found it on the Qt free edition site, and followed the instructionbs. Not much to do there. But make sure you have _plenty_ of time. It took me _days_ to compile Qt. No idea why MinGW is so darn slow. Diez From xah at xahlee.org Mon Oct 17 17:33:30 2005 From: xah at xahlee.org (Xah Lee) Date: 17 Oct 2005 14:33:30 -0700 Subject: Perl-Python-a-Day: split a file full path In-Reply-To: References: <1129514458.420045.75670@g44g2000cwa.googlegroups.com> Message-ID: <1129584810.302636.181380@g44g2000cwa.googlegroups.com> Xah Lee wrote: > > In Perl, spliting a full path into parts is done like this: Dr.Ruud wrote: > And then follows Perl-code that only works with an optional .html > "extension", Thanks for the note. I've corrected it here: http://xahlee.org/perl-python/split_fullpath.html namely: Note: the second argument to fileparse() is a list of regex. In particular, you need to escape the dot. Normally, one gives it a value such as ('\.html', '\.HTML', '\.jpg', '\.JPG'). Yes, it is case sensitive. If you want to match any extension (that is, the string after the last dot), use ('\.[^.]+$'). Xah xah at xahlee.org ? http://xahlee.org/ From wenshengwang at gmail.com Mon Oct 3 15:20:24 2005 From: wenshengwang at gmail.com (Wensheng) Date: 3 Oct 2005 12:20:24 -0700 Subject: simple AJAX with JSON Message-ID: <1128367224.695459.31910@z14g2000cwz.googlegroups.com> I just post a cookbook recipe on simple ajax. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440637 Hope someone find it's useful. Wensheng Wang From spe.stani.be at gmail.com Thu Oct 20 16:52:30 2005 From: spe.stani.be at gmail.com (SPE - Stani's Python Editor) Date: 20 Oct 2005 13:52:30 -0700 Subject: Popularity of blogging tools used by python programmers References: Message-ID: <1129841550.519444.141030@z14g2000cwz.googlegroups.com> Well, Python, Zope & Plone hosting are quite popular. However python based blog software isn't as sexy as let's say blogger. For SPE I first used a combination of PyDS&pycs.net. It is free for everyone, but unfortunately not stable enough to my standards. Luckily I got sponsored by zettai.net, who offer me excellent Zope hosting. There I use CoreBlog as I wanted consciously to use a python product. As a rule of thumb: when you are totally happy with the templates of prepacked blogs like blogger, then stick with that. But... even though they look slick, they all look the same. It's a bit the same problem of flash. So if you really want to modify your blog, you better take a product which is written in a language you understand. That's the reason why I like to work with Zope, Plone and CoreBlog. But I guess a python programmer using other blog systems is not as bad as a microsoft worker googling for the newest ipod. I'm sure a lot Perl or Ruby programmers also use mailman for their mailing lists. Stani http://pythonide.stani.be http://pythonide.stani.be/blog http://pythonide.stani.be/manual/html/manual.html From mwm at mired.org Mon Oct 10 20:33:59 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 10 Oct 2005 20:33:59 -0400 Subject: convert char to byte representation References: <434AB205.8000304@websafe.com> <11kld1jrulcri13@corp.supernews.com> Message-ID: <86br1w28p4.fsf@bhuda.mired.org> [Format recovered from top posting.] Larry Bates writes: > Grant Edwards wrote: >> On 2005-10-10, Larry Bates wrote: >>>>I am trying to xor the byte representation of every char in a string with >>>>its predecessor. But I don't know how to convert a char into its byte >>>>representation. This is to calculate the nmea checksum for gps data. >> >>>ord(c) gives you decimal representation of a character. >> >> While ord(c) is what the OP needs, it doesn't give a decimal >> represention -- which I guess would be a string like "65" for >> the ASCII characer "A". What ord() gives you is an integer >> object with the value of the character [which the hardware >> stores in binary on all of the platforms I'm aware of]. > > I've always read it written that the number that is returned by > ord(c) is the "decimal" (not hex, not octal) representation of > the ASCII/UNICODE character that is stored in memory location > pointed to by variable c. While the result is an integer (as > it couldn't really be anything else), I believe that most > character charts list the number that ord() returns as the > "decimal representation" of that character (as they normally > also show the octal and hex values as well). The value returned by ord is a *number*. That number has a decimal representation. It also has a hex representation and an octal representation. These are all strings, and they all represent the same number. You can't print a number - you can only print characters. So Python (indeed, most languages) translate the number into a string of characters that represent the number, using the decimal representation. You can use the hex and oct builtins to ask for the hex and octal representations of that number and print those strings if you want. > Probably an "old school" answer on my part. The decimal representation of ' ' is '32'. Python doesn't think that that's what ord(' ') returns: >>> ord(' ') == '32' False So I'd say it was "wrong" rather than old school. On the other hand, if you check ord(' ') against numbers, it doeesn't care what representation you use, so long as they represent the same number: >>> ord(' ') == 0x20 True >>> ord(' ') == 040 True >>> ord(' ') == 32 True Of course you can't read a number any more than you can write one, so Python kindly translates strings representing numbers into numbers when itt reads them. This process is often referred to as "reading a number", but what's actually read is characters. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From *firstname*nlsnews at georgea*lastname*.com Mon Oct 3 17:25:37 2005 From: *firstname*nlsnews at georgea*lastname*.com (Tony Nelson) Date: Mon, 03 Oct 2005 21:25:37 GMT Subject: Unicode charmap decoders slow References: <*firstname*nlsnews-69AACB.23331402102005@news.verizon.net> <43410f1b$0$7019$9b622d9e@news.freenet.de> <*firstname*nlsnews-BBA4DA.12405103102005@news.verizon.net> <43419076$0$25143$9b622d9e@news.freenet.de> Message-ID: <*firstname*nlsnews-506059.17254703102005@news.verizon.net> In article <43419076$0$25143$9b622d9e at news.freenet.de>, "Martin v. L?wis" wrote: > Tony Nelson wrote: > > I had seen iconv. Even if my system supports it and it is faster than > > Python's charmap decoder, it might not be available on other systems. > > Requiring something unusual in order to do a trivial LUT task isn't an > > acceptable solution. If I write a charmap decoder as an extension > > module in Pyrex I can include it with the program. I would prefer a > > solution that doesn't even need that, preferably in pure Python. Since > > Python does all the hard wark so fast it certainly could do it, and it > > can almost do it with "".translate(). > > Well, did you try a pure-Python version yourself? > > table = [chr(i).decode("mac-roman","replace") for i in range(256)] > > def decode_mac_roman(s): > result = [table[ord(c)] for c in s] > return u"".join(result) > > How much faster than the standard codec is that? It's .18x faster. ________________________________________________________________________ TonyN.:' *firstname*nlsnews at georgea*lastname*.com ' From ajikoe at gmail.com Thu Oct 13 02:08:37 2005 From: ajikoe at gmail.com (ajikoe at gmail.com) Date: 12 Oct 2005 23:08:37 -0700 Subject: how to make this code faster Message-ID: <1129183717.183243.100540@g49g2000cwa.googlegroups.com> def f(x,y): return math.sin(x*y) + 8 * x I have code like this: def main(): n = 2000 a = zeros((n,n), Float) xcoor = arange(0,1,1/float(n)) ycoor = arange(0,1,1/float(n)) for i in range(n): for j in range(n): a[i,j] = f(xcoor[i], ycoor[j]) # f(x,y) = sin(x*y) + 8*x print a[1000,1000] pass if __name__ == '__main__': main() I try to make this run faster even using psyco, but I found this still slow, I tried using java and found it around 8x faster... public class s1 { /** * @param args */ public static int n = 2000; public static double[][] a = new double[n][n]; public static double [] xcoor = new double[n]; public static double [] ycoor = new double[n]; public static void main(String[] args) { // TODO Auto-generated method stub for (int i=0; i References: <1129081494.725521.198920@g43g2000cwa.googlegroups.com> Message-ID: <434c701c$1_1@newspeer2.tds.net> black wrote: > hi all~ > > i wrote some functions for copying and moving files caz' i didnt find > concret functions within the doc. but i think these operations are > simple and important so there may be some internal ones i didnt know. > anyone could figure me out ? See the os, os.path and shutil modules for many file operations including copy and move. Kent From samrobertsmith at gmail.com Mon Oct 24 06:57:21 2005 From: samrobertsmith at gmail.com (Shi Mu) Date: Mon, 24 Oct 2005 03:57:21 -0700 Subject: ABOUT FIND Message-ID: <1d987df30510240357r7a557822h9af6d5720da2c8b@mail.gmail.com> I got confused by the following information from the help for "FIND": find(s, *args) find(s, sub [,start [,end]]) -> in what does *args mean (especially the '*')? also, in the sub, why put a comma before start? what does 'in' mean? From fccoelho at gmail.com Wed Oct 5 12:33:34 2005 From: fccoelho at gmail.com (Flavio) Date: 5 Oct 2005 09:33:34 -0700 Subject: updating local() Message-ID: <1128530014.323801.290360@g47g2000cwa.googlegroups.com> Hi, I heard time and again that you are not _supposed_ to update the locals dictionary. Can anyone tell me why, if the following code works, I should not do this? # # Extending Local namespace # def fun(a=1,b=2,**args): print 'locals:',locals() locals().update(args) print locals() e = {'s':3,'e':4} fun(k=10,v=32,**e) thanks, Fl?vio From aleaxit at yahoo.com Tue Oct 25 10:54:55 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 25 Oct 2005 07:54:55 -0700 Subject: Tricky Areas in Python References: <1130097286.772836.94930@g44g2000cwa.googlegroups.com> <1h4wbvb.1dblc4317zeuw2N%aleaxit@yahoo.com> <435CA1DE.2060101@REMOVEMEcyber.com.au> <1h4xfdx.azxzrkhr5xukN%aleaxit@yahoo.com> Message-ID: <1h4z96t.12ttsrfais6hnN%aleaxit@yahoo.com> Fredrik Lundh wrote: > Alex Martelli wrote: > > >> > class Sic: > >> > def getFoo(self): ... > >> > def setFoo(self): ... > >> > foo = property(getFoo, setFoo) > > > > Sorry for skipping the 2nd argument to setFoo, that was accidental in my > > post. The problem here is: class Sic is "classic" ("legacy", > > "old-style") so property won't really work for it (the setter will NOT > > trigger when you assign to s.foo and s is an instance of Sic). > > what's slightly confusing is that the getter works, at least until you attempt > to use the setter: Oh yes, that IS definitely contributing to the confusion -- which is part of why I think it makes sense to claim this is a "tricky area". > (a "setter isn't part of an new-style object hierarchy" exception would have > been nice, I think...) Agreed. Alas, a bit too late now, I fear (until 3.0 when old-style goes away) -- somebody might be (unwisely but "it-sort-of-works" style) relying on this behavior. Hmmm, maybe a WARNING could be given... Alex From mcfletch at rogers.com Mon Oct 24 03:06:48 2005 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Mon, 24 Oct 2005 03:06:48 -0400 Subject: System tray Icon In-Reply-To: References: Message-ID: <435C8808.2000407@rogers.com> I have a sample up here: http://blog.vrplumber.com/scripts/recordingdevices.py using wxPython. The sample application is Linux-specific, but it should give you a fairly good idea of how to use the system tray icon control in wxPython. HTH, Mike Mike Pippin wrote: > How would I have an app run with just a system tray Icon??? any help > would be greatly appreciated. I have no clue where to start. -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From apardon at forel.vub.ac.be Tue Oct 4 03:28:02 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 4 Oct 2005 07:28:02 GMT Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> Message-ID: Op 2005-10-03, Steven D'Aprano schreef : > On Mon, 03 Oct 2005 13:58:33 +0000, Antoon Pardon wrote: > >> Op 2005-10-03, Duncan Booth schreef : >>> Antoon Pardon wrote: >>> >>>> A language where variable have to be declared before use, would allow >>>> to give all misspelled (undeclared) variables in on go, instead of >>>> just crashing each time one is encounterd. >>> >>> Wrong. It would catch at compile-time those misspellings which do not >>> happen to coincide with another declared variable. >> >> Fine, it is still better than python which will crash each time >> one of these is encountered. > > Python doesn't crash when it meets an undeclared variable. It raises an > exception. Your nit-picking. For the sake of finding misspelled variables the difference is irrelevant. >>> Moreover, it adds a burden on the programmer who has to write all those >>> declarations, >> >> So? He has to write all those lines of code too. >> >> People often promote unittesting here. Writing all those unittest is >> an added burden too. But people think this burden is worth it. > > Yes, but there is no evidence that pre-declaration of variables is a > burden worth carrying. It doesn't catch any errors that your testing > wouldn't catch anyway. Maybe not, but it may catch them earlier and may make them easier to recognize. Declarations also allow easier writable closures. Since the declaration happens at a certain scope, the run time can easily find the correct scope when a variable is rebound. They also relieve a burden from the run-time, since all variables are declared, the runtime doesn't has to check whether or not a variable is accesible, it knows it is. And if you provide type information with the declaration, more efficient code can be produced. >> I think writing declaration is also worth it. The gain is not as >> much as with unittesting but neither is the burden, so that >> balances out IMO > > Speaking as somebody who spent a long time programming in Pascal, I got > heartedly sick and tired of having to jump backwards and forwards from > where I was coding to the start of the function to define variables. I have programmed a lot in Pascal too and Modula II and other languages. I never found declarations that much a burden. That you got heartedly sick of having to use declarations says very little about declarations and says more about you. I think language matters shouldn't be setlled by personal preferences. > It got to the stage that sometimes I'd pre-define variables I thought I > might need, intending to go back afterwards and delete the ones I didn't > need. When the programmer is having to to jump through hoops to satisfy > the compiler, there is something wrong. Maybe it was your way of working. I never thought I had to go through hoops to satisfy the compiler. You have to satisfy that compilor anyway, for the moment I have more problems with colons that have to be put after an "if", "else" etc than I ever had with declarations. >>> and worse it adds a burden on everyone reading the code who >>> has more lines to read before understanding the code. >> >> Well maybe we should remove all those comments from code too, >> because all it does is add more lines for people to read. > > Well-written comments should give the reader information which is not in > the code. If the comment gives you nothing that wasn't obvious from the > code, it is pointless and should be removed. > > Variable declarations give the reader nothing that isn't in the code. If I > write x = 15, then both I and the compiler knows that there is a variable > called x. It is blindingly obvious. Why do I need to say "define x" first? Because it isn't at all obvious at which scope that x is. Sure you can define your language that rebinding is always at local scope, but that you need to define it so, means it isn't that obvious. Also the question is not whether or not there is a variable x, the quesntions whether or not there should be a variable x. That is not at all that obvious when you write x = 15. > Pre-defining x protects me from one class of error, where I typed x > instead of (say) n. That's fine as far as it goes, but that's not > necessarily an _error_. If the typo causes an error, e.g.: > def spam(n): > return "spam " * x # oops, typo > > then testing will catch it, and many other errors as well. Declaring the > variable doesn't get me anything I wouldn't already get. Yes it would have caught this error even before you had to begin testing. > But if it doesn't cause an error, e.g.: > > def spam(n): > if n: > return "spam " * n > else: > x = 0 # oops, typo > return "spam " * n > > This may never cause a failure, since n is always an integer. Since my > other testing guarantees that n is always an integer, This is naive. Testing doesn't guarantee anything. If this is what you think about testing, then testing gives you a false impression of security. Maybe we should drop testing. > it doesn't matter > that I've created a variable x that doesn't get used. Yes, it would be > nice for the compiler to flag this, but if the cost of that niceness is to > have to define every single variable, I can live without it. But we should decide what language features are usefull and which are not by what some individual can or can't live without. >>> Also there is >>> increased overhead when maintaining the code as all those declarations have >>> to be kept in line as the code changes over time. >> >> Which is good. Just as you have to keep the unittests in line as code >> changes over time. > > That is not the same at all. Changing variable declarations needs to be > done every time you modify the internal implementation of a function. Well now I'll nitpick too. No you don't. You only have to do so if this modification needs other variables. > Changing the unittests, or any other testing for that matter, only needs > to be done when you change the interface. Which will be often enough. > In principle, if you have an interface designed up front before you write > any code, you could write all your tests at the start of the project and > never change them again. You can't do that with variable declarations, > since every time you change the implementation you have to change the > declarations. This argument has very little value since all you are saying is that if you were smart enought to choose the right interface to begin with, you won't have to change interface related stuff like unittests, while if you were not that smart in choosing your implementation, you will have to change implemantation related stuff like declarations. -- Antoon Pardon From kbk at shore.net Thu Oct 27 13:35:30 2005 From: kbk at shore.net (Kurt B. Kaiser) Date: Thu, 27 Oct 2005 13:35:30 -0400 (EDT) Subject: Weekly Python Patch/Bug Summary Message-ID: <200510271735.j9RHZUHG005080@bayview.thirdcreek.com> Patch / Bug Summary ___________________ Patches : 360 open (+16) / 2956 closed ( +1) / 3316 total (+17) Bugs : 893 open (+10) / 5353 closed (+12) / 6246 total (+22) RFE : 199 open ( -2) / 189 closed ( +2) / 388 total ( +0) New / Reopened Patches ______________________ Patch for (Doc) #1255218 (2005-10-17) http://python.org/sf/1328526 opened by Peter van Kampen Patch for (Doc) #1261659 (2005-10-17) http://python.org/sf/1328566 opened by Peter van Kampen pclose raises spurious exception on win32 (2005-10-17) http://python.org/sf/1328851 opened by Guido van Rossum datetime/xmlrpclib.DateTime comparison (2005-10-18) http://python.org/sf/1330538 opened by Skip Montanaro tarfile.py: fix for 1330039 (2005-10-19) CLOSED http://python.org/sf/1331635 opened by Lars Gust?bel Allow use of non-latin1 chars in interactive shell (2005-10-21) http://python.org/sf/1333679 opened by Noam Raphael Fix for int(string, base) wrong answers (2005-10-22) http://python.org/sf/1334979 opened by Adam Olsen Patch to implement PEP 351 (2005-10-23) http://python.org/sf/1335812 opened by Barry A. Warsaw Fix for int(string, base) wrong answers (take 2) (2005-10-24) http://python.org/sf/1335972 opened by Alan McIntyre remove 4 ints from PyFrameObject (2005-10-24) http://python.org/sf/1337051 opened by Neal Norwitz Elemental Security contribution - parsexml.py (2005-10-25) http://python.org/sf/1337648 opened by Guido van Rossum Elemental Security contribution - pgen2 package (2005-10-25) http://python.org/sf/1337696 opened by Guido van Rossum fileinput patch for bug #1336582 (2005-10-25) http://python.org/sf/1337756 opened by A. Murat EREN Inconsistent use of buffer interface in string and unicode (2005-10-25) http://python.org/sf/1337876 opened by Phil Thompson tarfile.py: fix for bug #1336623 (2005-10-26) http://python.org/sf/1338314 opened by Lars Gust?bel cross compile and mingw support (2005-10-27) http://python.org/sf/1339673 opened by Jan Nieuwenhuizen Patches Closed ______________ tarfile.py: fix for 1330039 (2005-10-19) http://python.org/sf/1331635 closed by nnorwitz New / Reopened Bugs ___________________ HTTPResponse instance has no attribute 'fileno' (2005-10-16) http://python.org/sf/1327971 opened by Kevin Dwyer __getslice__ taking priority over __getitem__ (2005-10-17) http://python.org/sf/1328278 opened by Josh Marshall os-process.html (2005-10-17) CLOSED http://python.org/sf/1328915 opened by Noah Spurrier Empty Generator doesn't evaluate as False (2005-10-17) CLOSED http://python.org/sf/1328959 opened by Christian H?ltje tarfile.add() produces hard links instead of normal files (2005-10-18) CLOSED http://python.org/sf/1330039 opened by Martin Pitt utf 7 codec broken (2005-10-19) CLOSED http://python.org/sf/1331062 opened by Ralf Schmitt string_subscript doesn't check for failed PyMem_Malloc (2005-10-19) CLOSED http://python.org/sf/1331563 opened by Adam Olsen Incorrect use of -L/usr/lib/termcap (2005-10-19) http://python.org/sf/1332732 opened by Robert M. Zigweid Inaccurate footnote 1 in Lib ref, sect 2.3.6.4 (2005-10-20) CLOSED http://python.org/sf/1332780 opened by Andy BSD DB test failures for BSD DB 3.2 (2005-10-19) http://python.org/sf/1332852 opened by Neal Norwitz Fatal Python error: Interpreter not initialized (2005-10-20) http://python.org/sf/1332869 opened by Andrew Mitchell BSD DB test failures for BSD DB 4.1 (2005-10-19) http://python.org/sf/1332873 opened by Neal Norwitz Bugs of the new AST compiler (2005-10-21) http://python.org/sf/1333982 opened by Armin Rigo int(string, base) wrong answers (2005-10-22) http://python.org/sf/1334662 opened by Tim Peters Python 2.4.2 doesn't build with "--without-threads" (2005-10-22) http://python.org/sf/1335054 opened by Gunter Ohrner fileinput device or resource busy error (2005-10-24) http://python.org/sf/1336582 opened by A. Murat EREN tarfile can't extract some tar archives.. (2005-10-24) http://python.org/sf/1336623 opened by A. Murat EREN Python.h should include system headers properly [POSIX] (2005-10-25) http://python.org/sf/1337400 opened by Dimitri Papadopoulos IDLE, F5 ? wrong external file content on error. (2005-10-26) http://python.org/sf/1337987 opened by MvGulik doctest mishandles exceptions raised within generators (2005-10-26) http://python.org/sf/1337990 opened by Tim Wegener Memory keeping (2005-10-26) http://python.org/sf/1338264 opened by sin CVS webbrowser.py (1.40) bugs (2005-10-26) http://python.org/sf/1338995 opened by Greg Couch shelve.Shelf.__del__ throws exceptions (2005-10-26) http://python.org/sf/1339007 opened by Geoffrey T. Dairiki Threading misbehavior with lambdas (2005-10-27) CLOSED http://python.org/sf/1339045 opened by Maciek Fijalkowski Bugs Closed ___________ wrong TypeError traceback in generator expressions (2005-10-14) http://python.org/sf/1327110 closed by mwh os-process.html (2005-10-17) http://python.org/sf/1328915 closed by nnorwitz Empty Generator doesn't evaluate as False (2005-10-17) http://python.org/sf/1328959 closed by rhettinger tarfile.add() produces hard links instead of normal files (2005-10-18) http://python.org/sf/1330039 closed by nnorwitz utf 7 codec broken (2005-10-19) http://python.org/sf/1331062 closed by lemburg string_subscript doesn't check for failed PyMem_Malloc (2005-10-19) http://python.org/sf/1331563 closed by nnorwitz Inaccurate footnote 1 in Lib ref, sect 2.3.6.4 (2005-10-20) http://python.org/sf/1332780 closed by birkenfeld Argument genexp corner case (2005-03-21) http://python.org/sf/1167751 closed by nnorwitz Encodings iso8859_1 and latin_1 are redundant (2005-08-12) http://python.org/sf/1257525 closed by lemburg ISO8859-9 broken (2005-10-11) http://python.org/sf/1324237 closed by lemburg mac_roman codec missing "apple" codepoint (2005-10-04) http://python.org/sf/1313051 closed by lemburg line numbers off by 1 in dis (2005-07-28) http://python.org/sf/1246473 closed by nascheme Threading misbehavior with lambdas (2005-10-27) http://python.org/sf/1339045 deleted by fijal RFE Closed __________ python scratchpad (IDLE) (2005-10-14) http://python.org/sf/1326830 closed by kbk datetime.replace could take a dict (2005-09-20) http://python.org/sf/1296581 closed by birkenfeld From dan at wolf.com Sat Oct 29 12:27:30 2005 From: dan at wolf.com (Dan M) Date: Sat, 29 Oct 2005 09:27:30 -0700 Subject: Building 2.4.2 on OpenBSD 3.8 Message-ID: I've been working with python 2.2.3 for the last couple of weeks, but would like to move up to 2.4. I grabbed the 2.4.2 tarball and attempted to install, but I get: gcc -pthread -c -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. -I./Include -DPy_BUILD_CORE -o Modules/python.o Modules/python.c In file included from /usr/include/sys/select.h:38, from Include/pyport.h:116, from Include/Python.h:55, from Modules/python.c:3: /usr/include/sys/event.h:53: error: syntax error before "u_int" /usr/include/sys/event.h:55: error: syntax error before "u_short" *** Error code 1 Stop in /usr/local/src/Python-2.4.2. immediately upon running "make". I took at look at event.h to see if I could find and fix the problem, but the error isn't immediately apparent to me. Has anyone successfully built 2.4.2 on OpenBSD? If so, how did you do it? From steve at REMOVETHIScyber.com.au Sat Oct 1 02:32:18 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sat, 01 Oct 2005 16:32:18 +1000 Subject: Will python never intend to support private, protected and public? References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xd5mstqab.fsf@ruckus.brouhaha.com> <7xzmpwuxd0.fsf@ruckus.brouhaha.com> <20050930075313.67b9b676.jk@ospaz.ru> <7xbr2a6dlz.fsf@ruckus.brouhaha.com> <7xk6gyoibc.fsf@ruckus.brouhaha.com> Message-ID: A cautionary tale of what happens when religious wars enter programming debates. For all I know, Paul Rubin is intelligent, gentle, kind to animals and small children, generous, charitable and modest. But touch his religious belief in the necessity of "truly" private variables, and boy oh boy does he lose the plot. First he compares using Python to being raped, earning (perhaps unfairly) at least one plonking, and then he shows that no matter how intelligent one might be, sense goes out the window when religion enters the door. See below. On Fri, 30 Sep 2005 05:23:35 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> > It's not easy if the base classes change after you check your code in. >> > You shouldn't need to know about that if it happens. Modularity, remember? >> >> Yes. And if you are relying on a public method in a class, and somebody >> dynamically modifies that public method, your code will stop working too. > > I'm not talking about dynamic anything. I'm talking about a normal > software project where there are multiple people working on the code. Paul misses the point: in a language like Python that allows the dynamic modification of public methods (as well as private ones) you can't be sure with absolute 100% mathematical certainty that your public interface is the same at runtime as it was when you did your last code audit. Paul worries about the possibility that some calling function will clobber a private variable that must not be clobbered. Why is this threat more worrisome than some calling function clobbering a public variable that must not clobbered? Logically, it is not -- if a function stuffs garbage into Klass.public_variable and breaks your entire program, that is no better or no worse than a function stuffing garbage into Klass._private_variable. There may be languages that make it impossible for the caller to clobber the public interface. But Python is not one of those languages. Since you can't prevent people from clobbering your public interface (by accident or design), and must instead (1) rely on the convention "don't break my code!" and (2) test to be sure that people haven't broken your code. Why worry MORE that people might clobber your private implementation? You deal with that problem the same way that you deal with the first: by convention ("attributes starting with an underscore are private, don't clobber them or rely on them being there!") and by testing. > You write a class and carefully make sure that none of its private > variables collide with superclasses in modules that it imports. You > check in your code and go do something else. Then the person > maintaining the superclasses goes and changes how they use their > private variables. He doesn't look at your code since his modules > don't import yours. But now both your code and his are broken. I'm surprised that for somebody who is so worried about bugs, Paul is satisfied with the "I didn't change anything that anyone can see, so the code must still be working" school of testing. (Otherwise known as the "I never changed anything" bug.) If your development team uses test-driven development, you will catch this breakage immediately you check the code in. If you don't, you've got lots more bugs that you don't know about, so one more is no big deal. Problem solved. Next? >> perhaps that mathematical certainty is appropriate for >> your ICBM control system or nuclear reactor, but it is a needless >> affectation for (say) a word processor. > > Why on earth would you want to unnecessarily introduce random bugs > into a word processor or anything else? Paul puts words into my mouth: I never suggested that it was good to introduce bugs, unnecessarily or otherwise. What I said was that aiming for 100% mathematical certainty that there are no bugs in a word processor is pointless. No lives are at stake. The fate of nations doesn't rest on your ability to make sure that PyWord is 100% bug free. Relax dude, the world won't end if there is a bug or two in your code. Of course, if Paul had been paying attention, he would have realised that 100% certainty is not possible in general no matter what style of development you use. Perhaps folks have heard of the halting problem? In programs which are small enough for you to trace through every possible program path, you might be able to get that 100% certainty, but for the rest, nope, no way. (The halting problem doesn't say that no program can check the correctness of *any* program, only than no program can check the correctness of *all* programs.) You can reduce the probability of bugs by using best practices, but never reduce it to zero. How small do you need? Is it really shocking to suggest that while a one in a billion billion chance of a bug might be needed for a nuclear reactor, we might be satisfied with just one in a million for a word processor? > And what happened to the > marketing claims that Python was good for critical applications? Paul makes the mistake of thinking that the truth of a claim depends on what those consequences are. Paul is wrong to suggest that Python being a dynamic language means that Python is not suited for critical applications, but even if he were right, that would not effect the truth of my statement. You can write broken or malicious C code that passes both visual inspection and even the best of automated testing (see, for example, the Underhanded C Contest http://www.brainhz.com/underhanded/ and the Obfuscated C Contest http://www.ioccc.org/). Should we decide that C is not suitable for critical applications? Well, perhaps we should -- but we don't. And neither should we jump to that conclusion about Python. It is true that your critical application in Python can be broken by a piece of code that modifies your class' public interfaces. So? Your C application might write directly to memory, clobbering its entire internal structure, and erase your hard disk to boot just to be sure. What's important is not whether or not such a thing is possible, but whether or not your application actually does it. In any case, there is a difference between mission-critical applications (such as, perhaps, a word processor) and what are generally called "real time" critical systems such as those controlling nuclear power stations and the like. I doubt that Python runs on any real-time operating systems suitable for such critical systems, but perhaps I'm wrong. -- Steven. From fredrik at pythonware.com Sun Oct 2 05:33:56 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 2 Oct 2005 11:33:56 +0200 Subject: Problems posting with urlencode References: <5HN%e.61089$mb4.14795@tornado.rdc-kc.rr.com> Message-ID: Joseph Chase wrote: > When I go and view the inserted record, the record exists, but the field > values are null. It is my thinking that the backend needs the "id" value > for each input value; how do I add that data to the urlencode() call? since the id isn't part of the form data set: http://www.w3.org/TR/REC-html40/interact/forms.html#form-data-set that's a bit unlikely. printing the params string might help you figure out what's missing. From steve at REMOVEMEcyber.com.au Tue Oct 4 04:34:50 2005 From: steve at REMOVEMEcyber.com.au (Steven D'Aprano) Date: Tue, 04 Oct 2005 18:34:50 +1000 Subject: Reply-To header References: <2ECA6FE9-3C8F-4C60-9E89-70CC078B14EF@gmail.com> <7rc0f.11261$Un.585792@phobos.telenet-ops.be> <86oe66jpfj.fsf@bhuda.mired.org> Message-ID: <43423EAA.9060600@REMOVEMEcyber.com.au> Mike Meyer wrote: > When I notice that a list is broken (RFC 2822 says that > reply-to is for the *author* of the message; anyone else setting it is > doing so in violation of the RFC, and hence broken, no matter how > useful it may be), Since when did obeying the RFC become important in and of itself? If there was a RFC that said that passwords should be limited to one alphanumeric character, would we slavishly follow it? I have been known to change the reply-to address from the address I am sending from (me at work for example) to the address I want the reply to go to (me at home). There are many times I'm emailing people I know can't cope with the complicated task of changing the To address of their reply, so I change the reply-to header so that their reply goes where I want it to go to (which might be another email address of mine, or a different person, or a mailing list). That's what reply to means, surely? What is the point of a reply-to header that must be the sender, since you already have a header that gives you the sender. If the RFC says that the reply-to header doesn't actually mean the address the reply should go to, but only the sender, then the RFC is broken. "Where the reply goes to" is a *human* decision, not a technical one. If I send you an email saying "Please reply to president at whitehouse.gov" then your mailer should honour that (although, since we are all adults, you should have the freedom to ignore my request and make a nuisance of yourself by emailing your reply to a different address). Likewise, if I set the reply address to the list, then your mailer should reply to the list. Perhaps you can argue that *my decision* to have replies go to the list is a bad one, but that's a social issue, not a technical one. > I tell my mailer to ignore reply-to on mail from > that list. Similarly, I no longer try and explain to people how long > lines violate RFCs and are a pain to read in well-behave mail readers, By "well-behaved", do you mean "can't cope with long lines"? How curious -- that's precisely the opposite definition of well-behaved I use. > or why mail readers that wrap text/plain content are broken. Curiouser and curiouser. Again that's the exact opposite of my definition of broken. -- Steven. From fredrik at pythonware.com Thu Oct 27 05:57:34 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 27 Oct 2005 11:57:34 +0200 Subject: Missing modules '_ssl', 'ext.IsDOMString', 'ext.SplitQName' References: <1130003715.743391.237890@f14g2000cwb.googlegroups.com><1130230864.068474.118500@g43g2000cwa.googlegroups.com><1130311678.936969.302020@g43g2000cwa.googlegroups.com> <1130406274.356454.141040@o13g2000cwo.googlegroups.com> Message-ID: uid09012_ti at collinsrealtime.com wrote: > xml.sax._exceptions.SAXReaderNotAvailable: No parsers found http://starship.python.net/crew/theller/moin.cgi/Py2exeAndPyXML > I checked out what Ron suggested, but I've no files where the names > could clash with python modules. next time you get stuck, make sure to check this page http://starship.python.net/crew/theller/moin.cgi/Py2Exe From elicriffield at gmail.com Thu Oct 20 16:53:46 2005 From: elicriffield at gmail.com (Eli Criffield) Date: 20 Oct 2005 13:53:46 -0700 Subject: nested escape chars in a shell command In-Reply-To: References: <1129666159.791998.134880@g49g2000cwa.googlegroups.com> Message-ID: <1129841626.103053.104800@g47g2000cwa.googlegroups.com> I can't seem to get that to work either. child = pexpect.spawn('/bin/sh',args=['-c','/usr/bin/ssh','-t','-o','StrictHostKeyChecking no',host,command,'|','awk','{print %s:$0}'%host], timeout=30) Complains its getting the wrong arguments to ssh. Eli From salvatore.didio at wanadoo.fr Thu Oct 13 17:13:43 2005 From: salvatore.didio at wanadoo.fr (Salvatore) Date: 13 Oct 2005 14:13:43 -0700 Subject: Nufox hosted. Message-ID: <1129238023.306428.145030@g47g2000cwa.googlegroups.com> Hello, I've been kindly authorized to host Nufox examples for free on : http://bsd.miki.eu.org:9090/ Regards From no at spam Tue Oct 4 10:13:41 2005 From: no at spam (D H) Date: Tue, 04 Oct 2005 09:13:41 -0500 Subject: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please! In-Reply-To: <1128432576.708995.19060@f14g2000cwb.googlegroups.com> References: <1128428885.390019.304730@g43g2000cwa.googlegroups.com> <1128432576.708995.19060@f14g2000cwb.googlegroups.com> Message-ID: Istvan Albert wrote: > Disclaimer: this is not a flame against Boo. > > It just boggles my mind that a language that describes itself as > "python inspired syntax" keeps being touted as: > > >>Luis M. Gonzalez wrote: >>Boo (which could be considered almost an static version of Python for .NET) > > > Boo is *nothing* like a static version of Python. Stop perpetuating > this nonsense. There is no static version of python, only a proposal[1] which was quickly stomped on and revised to be about slower runtime type-checking: def gcd(a: int, b: int) -> int: while a: a, b = b%a, a return b The boo equivalent is: (http://boo.codehaus.org/) def gcd(a as int, b as int) as int: while a: a, b = b%a, a return b Looks "nearly identical" to me. (Istvan has been a long spewer of anti-boo FUD on this list) [1] http://www.artima.com/weblogs/viewpost.jsp?thread=85551 From skromta at gmail.com Fri Oct 14 11:38:16 2005 From: skromta at gmail.com (Kalle Anke) Date: Fri, 14 Oct 2005 17:38:16 +0200 Subject: getting the path in a cgi script Message-ID: <0001HW.BF759D88004280C3F0284550@news.individual.de> I know I've done this once before ... I think ... but now I can't figure out how to do it I've set my web server to use an alias similar to this ScriptAlias /xx/ "/Library/WebServer/CGI-Executables/xxx.cgi/" which makes it possible for me to write http://127.0.0.1/xx/some/kind/of/path my problem is that I don't know how to get the 'some/kind/of/path' part of the URL in my script. I know that I can do like this in perl $documentRoot.path_info(); but how do I do it in python? From johnnyandfiona at hotmail.com Tue Oct 18 01:24:01 2005 From: johnnyandfiona at hotmail.com (Johnny Lee) Date: 17 Oct 2005 22:24:01 -0700 Subject: Question on class member in python In-Reply-To: References: <1129537638.714752.120290@g49g2000cwa.googlegroups.com> Message-ID: <1129613041.473285.84800@g44g2000cwa.googlegroups.com> Peter Otten ??? > Johnny Lee wrote: > > > Class A: > > def __init__(self): > > self.member = 1 > > > > def getMember(self): > > return self.member > > > > a = A() > > > > So, is there any difference between a.member and a.getMember? thanks > > for your help. :) > > Yes. accessor methods for simple attributes are a Javaism that should be > avoided in Python. You can always turn an attribute into a property if the > need arises to do some calculations behind the scene > > >>> class A(object): > ... def getMember(self): > ... return self.a * self.b > ... member = property(getMember) > ... def __init__(self): > ... self.a = self.b = 42 > ... > >>> A().member > 1764 > > I. e. you are not trapped once you expose a simple attribute. > > Peter Thanks for your help, maybe I should learn how to turn an attibute into a property first. From jmdeschamps at gmail.com Thu Oct 20 17:07:30 2005 From: jmdeschamps at gmail.com (jmdeschamps at gmail.com) Date: 20 Oct 2005 14:07:30 -0700 Subject: Set operations for lists: pythonic hints please! In-Reply-To: <1129842342.308921.201270@f14g2000cwb.googlegroups.com> References: <1129842342.308921.201270@f14g2000cwb.googlegroups.com> Message-ID: <1129842450.405250.210620@f14g2000cwb.googlegroups.com> Ouppsss! the title should have read:Set operation for tuples... (sigh!) From jeremy at emperorlinux.com Thu Oct 6 00:18:11 2005 From: jeremy at emperorlinux.com (Jeremy Moles) Date: Thu, 06 Oct 2005 00:18:11 -0400 Subject: Absolultely confused... In-Reply-To: <1128563928.3513.8.camel@localhost.localdomain> References: <1128563928.3513.8.camel@localhost.localdomain> Message-ID: <1128572291.3513.27.camel@localhost.localdomain> WELL, I figured it out--thanks to everyone's help. There were instances of the object and I am a total moron. Thanks again to everyone who helped me stomp this out. :) On Wed, 2005-10-05 at 21:58 -0400, Jeremy Moles wrote: > So, here is my relevant code: > > PyArg_ParseTuple(args, "O!", &PyType_vector3d, &arg1) > > And here ismy error message: > > argument 1 must be pylf.core.vector3d, not pylf.core.vector3d > > I know PyType_vector3d "works" (as I can use them in the interpreter all > day long), and I know I'm passing a pylf.core.vector3d (well, apparently > not...) > > I've spent hours and hours on this and I'm finally just giving up and > asking. I've tried everything to get my program to verify that arg1 is > really a PyType_vector3d, but to no avail. > > If I take out the "!" in the format string and just use "O", I can at > least get past PyArg_ParseTuple. Then I try something like... > > PyObject_TypeCheck(arg1, &PyType_vector3d) > > Which also fails, but I know for a fact that arg1's PyObject_Repr is > what it should be. (pylf.core.vector3d) > > I guess my question is: what in the world could be causing this to fail? > It seems like I'm just not able to use ParseType or BuildValue to create > objects of my own type. > > I know I haven't provided a lot of information, but does anyone have any > ideas or where I should start looking? > From gagenellina at softlab.com.ar Wed Oct 26 09:15:35 2005 From: gagenellina at softlab.com.ar (Gabriel Genellina) Date: 26 Oct 2005 06:15:35 -0700 Subject: Pickle to source code In-Reply-To: <1130315056.793178.232760@g14g2000cwa.googlegroups.com> References: <1130315056.793178.232760@g14g2000cwa.googlegroups.com> Message-ID: <1130332534.999358.152530@g49g2000cwa.googlegroups.com> > I want to convert from pickle format to python source code. That is, > given an existing pickle, I want to produce a textual representation > which, when evaluated, yields the original object (as if I had > unpickled the pickle). > I know of some transformations pickle/xml (Zope comes with one such > tool, gnosis xml is another) so I believe I could build something based > on them. > But I dont want to reinvent the wheel, I wonder if anyone knows of a > library which could do what I want? An example to make things clear: class MyClass: def __init__(self,a,b): self.a=a self.b=b def foo(self): self.done=1 # construct an instance and work with it obj = MyClass(1,2) obj.foo() # save into file pickle.dump(obj,file('test.dat','wb')) Then, later, another day, using another process, I read the file and want to print a block of python code equivalent to the pickle saved in the file. That is, I want to *generate* a block of code like this: xxx = new.instance(MyClass) xxx.a = 1 xxx.b = 2 xxx.done = 1 Or perhaps: xxx = new.instance(MyClass, {'a':1,'b':2,'done':1}) In other words, I need a *string* which, being sent to eval(), would return the original object state saved in the pickle. As has been pointed, repr() would do that for simple types. But I need a more general solution. The real case is a bit more complicated because there may be references to other objects, involving the persistent_id mechanism of pickles, but I think it should not be too difficult. In this example, if xxx.z points to another external instance for which persistent_id returns '1234', would suffice to output another line like: xxx.z = external_reference('1234') I hope its more clear now. Thanks, Gabriel Genellina Softlab SRL From iainking at gmail.com Tue Oct 25 09:30:35 2005 From: iainking at gmail.com (Iain King) Date: 25 Oct 2005 06:30:35 -0700 Subject: more than 100 capturing groups in a regex In-Reply-To: References: <1130160675.270886.208420@z14g2000cwz.googlegroups.com> <1130225565.592108.197670@z14g2000cwz.googlegroups.com> <1130242672.024469.324530@g47g2000cwa.googlegroups.com> Message-ID: <1130247035.969150.281910@g43g2000cwa.googlegroups.com> Steven D'Aprano wrote: > On Tue, 25 Oct 2005 05:17:52 -0700, Iain King wrote: > > > > > Fredrik Lundh wrote: > >> Joerg Schuster wrote: > >> > >> > I just want to use more than 100 capturing groups. > >> > >> define "more" (101, 200, 1000, 100000, ... ?) > >> > >> > > > > The Zero-One-Infinity Rule: > > > > http://www.catb.org/~esr/jargon/html/Z/Zero-One-Infinity-Rule.html > > > Nice in principle, not always practical. Sometimes the choice is, "do you > want it today with arbitrary limits, or six months from now with bugs > but no limits?" > > If assigning arbitrary limits prevents worse problems, well, then go for > the limit. For instance, anyone who has fought browser pops ups ("close > one window, and ten more open") may have wished that the browser > implemented an arbitrary limit of, say, ten pop ups. Or even zero :-) > Well, exactly. Why limit to ten? The user is either going to want to see pop-ups, or not. So either limit to 0, or to infinity (and indeed, this is what most browsers do). Note the jargon entry defines infinity in this case to me the largest possible amount given whatever ram/disk space/processing power you have available. Also: These arbitrary limits tend to stem from languages which predominantly use fixed size arrays - DIM in basic, or malloc in C. The native python component is the list, which doesn't have a max size, so these problems should be encountered less in python code; by it's nature, python steers you away from this mistake. Iain From no.mail.here.at.here at gmail.com Sun Oct 16 22:39:13 2005 From: no.mail.here.at.here at gmail.com (mike) Date: 16 Oct 2005 19:39:13 -0700 Subject: os.access with wildcards In-Reply-To: <1128795458.655247.166620@o13g2000cwo.googlegroups.com> References: <1128665933.923295.95580@f14g2000cwb.googlegroups.com> <1128732066.947274.206270@o13g2000cwo.googlegroups.com> <1128795458.655247.166620@o13g2000cwo.googlegroups.com> Message-ID: <1129516753.679356.209100@g49g2000cwa.googlegroups.com> ######################## ######################## ######################## ######################## ######################## os.path.exists() ######################## ######################## ######################## ######################## ######################## From jstroud at mbi.ucla.edu Tue Oct 25 18:01:58 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Tue, 25 Oct 2005 15:01:58 -0700 Subject: Top-quoting defined [was: namespace dictionaries ok?] In-Reply-To: <86ll0h2so4.fsf@bhuda.mired.org> References: <86ll0h2so4.fsf@bhuda.mired.org> Message-ID: <200510251501.58135.jstroud@mbi.ucla.edu> On Tuesday 25 October 2005 14:27, Mike Meyer wrote: > That's your right. Be aware that people will ignore, correct and/or > complain about you doing so. If I may be a complete ass: That should be "correct and/or complain about *your* doing so." James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From kent37 at tds.net Tue Oct 11 22:08:58 2005 From: kent37 at tds.net (Kent Johnson) Date: Tue, 11 Oct 2005 22:08:58 -0400 Subject: Nicer way of strip and replace? In-Reply-To: References: Message-ID: <434c6e64_3@newspeer2.tds.net> Markus Rosenstihl wrote: > Hi, > I wonder if i can make this nicer: > > euro=euro + float(string.replace(string.strip(rechnung[element][10], > '"'), ',' , '.')) You can use the str methods instead of functions from the string module: euro=euro + float(rechnung[element][10].strip('"').replace(',' , '.')) Kent From sjmaster at gmail.com Fri Oct 7 15:18:28 2005 From: sjmaster at gmail.com (Steve M) Date: 7 Oct 2005 12:18:28 -0700 Subject: Bug in COM Makepy utility? (ActivePython 2.4) In-Reply-To: <1128636487.225741.266930@g43g2000cwa.googlegroups.com> References: <1128636487.225741.266930@g43g2000cwa.googlegroups.com> Message-ID: <1128712708.794417.142350@g49g2000cwa.googlegroups.com> After exploring the bug database I discovered that this bug has been reported since March, and appears to derive from a bug in Python itself. http://bugs.activestate.com/show_bug.cgi?id=38052 It apparently only happens when the code generated by Makepy is really big (which it is for Word or Excel). So my options are to downgrade from Python 2.4.1 to 2.3.5 or to use Late Binding instead of Early Binding (as described in Hammond and Robinson, Ch. 12). The easiest path will be to use Early Binding, because as far as I can tell the only significant changes to code will be that I have to use integer literals instead of named constants. In my case this means replacing 'win32com.client.constants.wdSendToNewDocument' with '0' (zero). From twic at urchin.earth.li Tue Oct 4 20:18:14 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Wed, 5 Oct 2005 01:18:14 +0100 Subject: dictionary interface In-Reply-To: References: Message-ID: On Tue, 4 Oct 2005, Robert Kern wrote: > Antoon Pardon wrote: > >> class Tree: >> >> def __lt__(self, term): >> return set(self.iteritems()) < set(term.iteritems()) >> >> def __eq__(self, term): >> return set(self.iteritems()) == set(term.iteritems()) >> >> Would this be a correct definition of the desired behaviour? > > No. > > In [1]: {1:2} < {3:4} > Out[1]: True > > In [2]: set({1:2}.iteritems()) < set({3:4}.iteritems()) > Out[2]: False > >> Anyone a reference? > > The function dict_compare in dictobject.c . Well there's a really helpful answer. I'm intrigued, Robert - since you know the real answer to this question, why did you choose to tell the Antoon that he was wrong, not tell him in what way he was wrong, certainly not tell him how to be right, but just tell him to read the source, rather than simply telling him what you knew? Still, at least you told him which file to look in. And if he knows python but not C, or gets lost in the byzantine workings of the interpreter, well, that's his own fault, i guess. So, Antoon, firstly, your implementation of __eq__ is, i believe, correct. Your implementation of __lt__ is, sadly, not. While sets take "<" to mean "is a proper subset of", for dicts, it's a more conventional comparison operation, which constitutes a total ordering over all dicts (so you can sort with it, for example). However, since dicts don't really have a natural total ordering, it is ever so slightly arbitrary. The rules for ordering on dicts are, AFAICT: - If one dict has fewer elements than the other, it's the lesser - If not, find the smallest key for which the two dicts have different values (counting 'not present' as a value) -- If there is no such key, the dicts are equal -- If the key is present in one dict but not the other, the dict in which it is present is the lesser -- Otherwise, the dict in which the value is lesser is itself the lesser In code: def dict_cmp(a, b): diff = cmp(len(a), len(b)) if (diff != 0): return diff for key in sorted(set(a.keys() + b.keys())): if (key not in a): return 1 if (key not in b): return -1 diff = cmp(a[key], b[key]) if (diff != 0): return diff return 0 I assume your tree has its items sorted by key value; that means there's an efficient implementation of this using lockstep iteration over the two trees being compared. Another way of looking at it is in terms of list comparisons: comparing two dicts is the same as comparing the sorted list of keys in each dict, breaking ties by looking at the list of values, in order of their keys. There's a quirk, in that a shorter dict is always less than a longer dict, regardless of the elements. In code: def dict_cmp_alternative(a, b): diff = cmp(len(a), len(b)) if (diff != 0): return diff ka = sorted(a.keys()) kb = sorted(b.keys()) diff = cmp(ka, kb) if (diff != 0): return diff va = [a[k] for k in ka] vb = [b[k] for k in kb] return cmp(va, vb) Hope this helps. tom PS In case it's of any use to you, here's the code i used to test these: import random def rnd(n): return random.randint(0, n) def randomdict(maxlen=20, range=100): return dict((rnd(range), rnd(range)) for x in xrange(rnd(maxlen))) def test(cmp2, n=1000): for i in xrange(n): a = randomdict() b = randomdict() if ((cmp(a, b)) != (cmp2(a, b))): raise AssertionError, (a, b) -- What we learn about is not nature itself, but nature exposed to our methods of questioning. -- Werner Heisenberg From maksim.kasimov at gmail.com Wed Oct 5 03:01:42 2005 From: maksim.kasimov at gmail.com (Maksim Kasimov) Date: Wed, 05 Oct 2005 10:01:42 +0300 Subject: how to debug when "Segmentation fault" In-Reply-To: <4342bb72$0$6128$636a15ce@news.free.fr> References: <4342bb72$0$6128$636a15ce@news.free.fr> Message-ID: yes, to generete core dump is the best way, but the command "$ ulimit -c 500000" don't make python to generete core dump in the time of crush. I would like to know how to run python script so if it crushes than core dump will be genereted. Thanks Pierre Barbier de Reuille wrote: > Maksim Kasimov a ?crit : > >>Hello, >> >>my programm sometime gives "Segmentation fault" message (no matter how >>long the programm had run (1 day or 2 weeks). And there is nothing in >>log-files that can points the problem. >>My question is how it possible to find out where is the problem in the >>code? Thanks for any help. >> >>Python 2.2.3 >>FreeBSD >> > > > Well, your best bet is to generate a core file ! > To do so, in the shell launching the program, you need to accept core > files. The command is : > > $ ulimit -c > > For example: > $ ulimit -c 500000 > > For a 500MB max file. > > Then, if your program crash, you should see a file named "core.XXXX" > where XXXX is the PID of the process. You can know exactly where the > program crashed using gbd : > > $ gdb --core=core.XXXX > > Then, depending on the debug information you have in your executables > you may (or may not) be able to know what happened :) > > Pierre -- Best regards, Maksim Kasimov mailto: maksim.kasimov at gmail.com From mwm at mired.org Wed Oct 19 23:48:25 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 19 Oct 2005 23:48:25 -0400 Subject: Some more odd behaviour from the Regexp library References: <1129777843.892280.302490@g44g2000cwa.googlegroups.com> Message-ID: <86wtk8vofq.fsf@bhuda.mired.org> "David Veerasingam" writes: > Can anyone explain why it won't give me my captured group? > > In [1]: a = 'exit: gkdfjgfjdfsgdjglkghdfgkd' > In [2]: import re > In [3]: b = re.search(r'exit: (.*?)', a) > In [4]: b.group(0) > Out[4]: 'exit: ' > > In [5]: b.group(1) > Out[5]: '' > > In [6]: b.group(2) > IndexError: no such group It is giving you your captured group. While the * operator matches as long a string as possible, the *? operator matches as *short* a string as possible. Since '' matches .*?, that's all it's ever going to capture. So b.group(1) is '', which is what it's giving you. >>> a = 'exit: gkdfjgfjdfsgdjglkghdfgkd' >>> import re >>> b = re.search(r'exit: (.*)', a) >>> b.group(0) 'exit: gkdfjgfjdfsgdjglkghdfgkd' >>> b.group(1) 'gkdfjgfjdfsgdjglkghdfgkd' >>> which I suspect is what you actually want. Of course, being the founder of SPARE, I have to point out that a.split(': ') will get you the same two strings as the re I used above. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From jason at pengale.com Thu Oct 20 10:52:45 2005 From: jason at pengale.com (Jason Stitt) Date: Thu, 20 Oct 2005 09:52:45 -0500 Subject: sqlstring -- a library to build a SELECT statement In-Reply-To: <1129784130.596225.174860@z14g2000cwz.googlegroups.com> References: <1129774730.887128.314960@z14g2000cwz.googlegroups.com> <1129784130.596225.174860@z14g2000cwz.googlegroups.com> Message-ID: <0FC33E2A-CBF5-44DB-B037-6EAA4C8B2DCE@pengale.com> On Oct 19, 2005, at 11:55 PM, grunar at gmail.com wrote: > > Jason Stitt wrote: > >> >> Using // for 'in' looks really weird, too. It's too bad you can't >> overload Python's 'in' operator. (Can you? It seems to be hard-coded >> to iterate through an iterable and look for the value, rather than >> calling a private method like some other builtins do.) >> > > // was a bit of a stretch. I'd initially thought it for the "where" > clause, becuase it's lower precedence than ** (I think), and really > late at night // kind of looks like a W. I decided against it because > it looks to close to a comment in some other languages. > > Python "in" clause doesn't seem exploitable in any way--probably a > good > thing. I did add a "in_" method (name is arguable), which does the > same thing, also a not_in. What about modifying the overloaded == to produce 'in' if the right- hand side is a list? Then you can more easily generate statements dynamically: def makeCond(name): return someOtherCond & (model.table.name == name) makeCond("foo") makeCond(["foo", "bar"]) And it doesn't require two different functions. As long as there is no case where you might actually want to test if a column value equals a list, it should work. Is there? Some DBs support an Array type, but in general that might be better handled with an Array class, anyway. - Jason, fingers crossed that all this black magic doesn't affect one's chances in the afterlife ;) From axel at white-eagle.invalid.uk Mon Oct 24 16:33:03 2005 From: axel at white-eagle.invalid.uk (axel at white-eagle.invalid.uk) Date: Mon, 24 Oct 2005 20:33:03 GMT Subject: Microsoft Hatred FAQ References: <86k6g59ke6.fsf@bhuda.mired.org> <5y47f.174197$RW.59989@fe2.news.blueyonder.co.uk> <8qnpl11s9ie8s2pstqja5k5aeikn6tgtu7@4ax.com> Message-ID: <3yb7f.175669$RW.140991@fe2.news.blueyonder.co.uk> In comp.lang.perl.misc Roedy Green wrote: > On Mon, 24 Oct 2005 12:35:13 GMT, axel at white-eagle.invalid.uk wrote, > quoted or indirectly quoted someone who said : >>I see that you cannot make a reasoned argument against the fact that >>property in the form of houses is taxed in America. > And what has his inability to do that to your satisfaction got to do > with the price of eggs? Not that I care much since eggs bring on a rather strong reaction within me, but his arguments were totally false. Axel From strombrg at dcs.nac.uci.edu Mon Oct 10 16:31:46 2005 From: strombrg at dcs.nac.uci.edu (Dan Stromberg) Date: Mon, 10 Oct 2005 20:31:46 GMT Subject: Send password over TCP connection References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> Message-ID: On Mon, 10 Oct 2005 08:06:27 -0700, dcrespo wrote: > Hi all, > > I have a program that serves client programs. The server has a login > password, which has to be used by each client for logging in. So, when > the client connects, it sends a string with a password, which is then > validated on the server side. The problem is obvious: anyone can get > the password just sniffing the network. > > How can I solve this? > > Daniel What I've been doing for this, is to: 1) Store two copies of a (symmetric), one on the client host, one on the server host. 2) When the client wants to connect to the server, have the server generate a random string of bits, hash the client's password with the string, and then the random string to the client 3) The client then hashes its copy of the same password with that random string, and sends the result back to the server 4) The server, upon receiving the correct hash result, provides service There are a lot of collisions being found in hash algorithms these days. I haven't heard about any in the RIPEMD family of hash algorithms yet. Another possibility is to just use Diffie-Helman key exchange (pretty simple to code the base algorithm in python - I have an implementation in pure python for you if you want - but I hear that some numbers are more prone to attack than others, which my code does not attempt to take into account) to get a shared encryption key on both ends of the communication, and then encrypt everything with that. From aleax at mail.comcast.net Tue Oct 11 12:27:00 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Tue, 11 Oct 2005 18:27:00 +0200 Subject: Python's garbage collection was Re: Python reliability References: <7xr7au1hr5.fsf@ruckus.brouhaha.com> <7xwtkl21hn.fsf@ruckus.brouhaha.com> <7xll11twc2.fsf@ruckus.brouhaha.com> Message-ID: <1h4a5l4.13vx8k7etyxy1N%aleax@mail.comcast.net> Tom Anderson wrote: ... > Has anyone looked into using a real GC for python? I realise it would be a If you mean mark-and-sweep, with generational twists, that's what gc uses for cyclic garbage. > lot more complexity in the interpreter itself, but it would be faster, > more reliable, and would reduce the complexity of extensions. ??? It adds no complexity (it's already there), it's slower, it is, if anything, LESS reliable than reference counting (which is way simpler!), and (if generalized to deal with ALL garbage) it might make it almost impossible to write some kinds of extensions (ones which need to interface existing C libraries that don't cooperate with whatever GC collection you choose). Are we talking about the same thing?! > So python doesn't use the old SmallTalk 80 SmallInteger hack, or similar? > Fair enough - the performance gain is nice, but the extra complexity would > be a huge pain, i imagine. CPython currently is implemented on a strict "minimize all tricks" strategy. There are several other implementations of the Python language, which may target different virtual machines -- Jython for JVM, IronPython for MS-CLR, and (less mature) stuff for the Parrot VM, and others yet from the pypy project. Each implementation may use whatever strategy is most appropriate for the VM it targets, of course -- this is the reason behind Python's refusal to strictly specify GC semantics (exactly WHEN some given garbage gets collected)... allow such multiple implementations leeway in optimizing behavior for the target VM(s). Alex From usgog at yahoo.com Tue Oct 25 14:27:39 2005 From: usgog at yahoo.com (usgog at yahoo.com) Date: 25 Oct 2005 11:27:39 -0700 Subject: Newbie question: string replace In-Reply-To: <3s7620FlqdmnU1@uni-berlin.de> References: <1130258229.662596.228630@g49g2000cwa.googlegroups.com> <3s7620FlqdmnU1@uni-berlin.de> Message-ID: <1130264859.869054.291760@g14g2000cwa.googlegroups.com> So how to overwrite the config file directly in script.py instead of running script.py with two params? A XML file or ConfigParser is appealing but this is part of a legacy system...:( From trasno-bounces at ceu.fi.udc.es Thu Oct 13 10:41:07 2005 From: trasno-bounces at ceu.fi.udc.es (trasno-bounces at ceu.fi.udc.es) Date: Thu, 13 Oct 2005 16:41:07 +0200 Subject: Your message to Trasno awaits moderator approval Message-ID: Your mail to 'Trasno' with the subject Re: Your letter Is being held until the list moderator can review it for approval. The reason it is being held: SpamAssassin identified this message as possible spam (score 3) Either the message will get posted to the list, or you will receive notification of the moderator's decision. If you would like to cancel this posting, please visit the following URL: http://ceu.fi.udc.es/cgi-bin/mailman/confirm/trasno/dd18e8bb5cc9d685d0ef2dedb7b539562d988d39 From steve at REMOVETHIScyber.com.au Sun Oct 9 11:18:37 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 10 Oct 2005 01:18:37 +1000 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <868xx3m2ve.fsf@bhuda.mired.org> Message-ID: On Sun, 09 Oct 2005 13:36:26 +0000, Tim Tyler wrote: > Since - in Roedy's essay - messages are digitally signed, authority > to advise about any email address updates would presumably be confined > to those people with access to the sender's private key. If I have the sender's private key, then I can pretend to be him. That would mean that when you received an email from the sender, you couldn't be sure if it actually came from him or not, thus defeating the purpose of having a private key. > Even /without/ any form of authentication, a standard change-of-address > message - which is understood by mail readers - is a fine and sensible > idea. So any random person -- or bot -- could send an email to my business associates, telling them that my email address had changed to industrial_espionage at spyware.com, please send all your confidential information directly there thank you very much. Yeah. Fine *and* sensible. -- Steven. From bonono at gmail.com Sat Oct 22 01:21:01 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 21 Oct 2005 22:21:01 -0700 Subject: access dictionary with preferred order ? In-Reply-To: References: <1129954732.769162.62150@g43g2000cwa.googlegroups.com> Message-ID: <1129958461.424475.229750@o13g2000cwo.googlegroups.com> thanks. But I do quite understand how to specific my order(which could be arbitary). It seems to have a move method so I need to first loop through my order list and match then move things around ? James Stroud wrote: > This is an "ordered dict": > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/438823 > > On Friday 21 October 2005 21:18, bonono at gmail.com wrote: > > Hi, > > > > I am wondering if there is a dictionary data type that allows me to > > define the order of access when iterating it using items/keys etc. ? > > > > An example: > > > > a=dict(a=dict(), c=dict(), h=dict()) > > prefer=['e','h', 'a'] > > > > for x in a.values: print x > > > > would give me > > {h:dict()}, {a:dict()}, then the rest which I don't care about the > > order ? > > -- > James Stroud > UCLA-DOE Institute for Genomics and Proteomics > Box 951570 > Los Angeles, CA 90095 > > http://www.jamesstroud.com/ From belred at gmail.com Sun Oct 16 16:04:48 2005 From: belred at gmail.com (Bryan) Date: Sun, 16 Oct 2005 13:04:48 -0700 Subject: tuple versus list In-Reply-To: <1129475300.537237.131090@f14g2000cwb.googlegroups.com> References: <1129460775.484350.209520@g44g2000cwa.googlegroups.com> <1129475300.537237.131090@f14g2000cwb.googlegroups.com> Message-ID: bonono at gmail.com wrote: > In this particular case, it seems that (width,height) looks nicer. But > I think otherwise, list constuct is easier to read, even though it is > supposed to be slower. > > With list you can : > [a] + [ x for x in something ] > > With tuple it looks like this : > (a,) + tuple(x for x in something) > > I think the list looks cleaner. And since you cannot concat tuple with > list, I think unless it looks obvious and natural(as in your case), use > list. > i always use the structure analogy. if you view (width, height) as a structure, use a tuple. if you view it a sequence, use a list. in this example, i view it as a stucture, so i would use (width, height) as a tuple. bryan From dek at bosshog.lbl.gov Mon Oct 31 12:48:36 2005 From: dek at bosshog.lbl.gov (David E. Konerding DSD staff) Date: Mon, 31 Oct 2005 17:48:36 +0000 (UTC) Subject: Using graphviz to visualize trace.py output, anybody? References: <1130710534.618559.40680@g43g2000cwa.googlegroups.com> Message-ID: In article <1130710534.618559.40680 at g43g2000cwa.googlegroups.com>, svenn.are at bjerkem.de wrote: > Hi, > > has anybody thought of / already used graphviz to convert the output of > trace.py into a graph? I looked at PyUMLGraph, but 1. PyUMLGraph does > not successfully create a dot file, and 2. I don't really want a UML > representation but a compact representation of program execution. > > Maybe there is some other tool that I am not aware of which can create > this kind of trace. I use eclipse with pydev plugin on MacOS 10.3.9 > > Regards, > Svenn > Take a look at: http://dkbza.org/pydot.html It's a python interface which can produce dot format files (based on its internal graph API) and run graphviz for you. I'm not sure which trace.py you're referring to, but I assume it dumps some output file. You have a couple of obvious ways to get what you want: 1) modify trace.py to create a pydot graph structure then write to file 2) make a script that parses the trace.py output to create a pydot graph structure then write to file Dave From free.condiments at gmail.com Fri Oct 28 17:06:27 2005 From: free.condiments at gmail.com (Sam Pointon) Date: 28 Oct 2005 14:06:27 -0700 Subject: How do I sort these? In-Reply-To: <7x8xwdid3e.fsf@ruckus.brouhaha.com> References: <1130524906.918612.38540@g49g2000cwa.googlegroups.com> <1130531874.710810.39050@g43g2000cwa.googlegroups.com> <7x8xwdid3e.fsf@ruckus.brouhaha.com> Message-ID: <1130533587.452875.167870@z14g2000cwz.googlegroups.com> > unzip doesn't seem to work for me... It's not a part of the standard Python distribution, but this is a naive implementation (it doesn't react well to the list's contents having different lengths). def unzip(seq): result = [[] for i in range(len(seq[0]))] for item in seq: for index in range(len(item)): result[index].append(item[index]) return result >>> unzip(zip(range(5), 'abcde')) [[0, 1, 2, 3, 4], ['a', 'b', 'c', 'd', 'e']] From claudio.grondi at freenet.de Tue Oct 11 09:47:12 2005 From: claudio.grondi at freenet.de (Claudio Grondi) Date: Tue, 11 Oct 2005 13:47:12 -0000 Subject: Wanted: Python module allowing direct access to raw sectors ofharddrives (MFT, boot sector, etc.) in MS Windows References: <3r04p5Fh4lshU1@individual.net> <3r09niFh717sU1@individual.net> <1128986917.703980.35230@z14g2000cwz.googlegroups.com> Message-ID: <3r1n2sFha01oU1@individual.net> Thank you for your reply, even if currently not that interesting for me because after the first CD writer for IDE were available I stopped to use SCSI and didn't come back to it since then. Does the Python open() command not work the same way for SCSI drives as for IDE or USB drives (I can't try it myself, because of above)? Claudio P.S. for those who are interested I have uploaded a Python script I wrote for myself to have a reference to this subject to: http://people.freenet.de/AiTI-IT/Python/HowTo_AccessRawSectorsOfPhysicalDrives.py :-) "sam" schrieb im Newsbeitrag news:1128986917.703980.35230 at z14g2000cwz.googlegroups.com... > The following site contains my routines to access information from the > Microsoft SCSIPASSTHROUGH layer under windows. These routines allow you > to access the storage devices mounted under windows using SCSI > commands. The dll that I provide will work with Python 2.3 > > http://starship.python.net/crew/samschul/ > > Sam Schulenburg > > Claudio Grondi wrote: > > Thank you Jeff very much for your quick reply. > > It saved me really much time of digging in the wrong direction. > > > > wrote in > > news:... > > >> I took the advice from this web page: > > >> http://support.microsoft.com/kb/q100027/ > > Ok, I had found this page myself during Googling, but I have missed just > > to try to use the described way of addressing physical devices with file > > opening in Python. > > It works as expected with harddrives so you are right that you are getting > > the MBR with the proposed code. > > > > After some not always happy end adventures with Python > > scripting I am impressed by the power of the concept behind > > the language once again. > > > > Claudio > > > > >>(I don't know how this extends to floppies, and the 9x family of OSes > > isn't > > >>listed in "applies to", so this may not help your case) > > >>Here, I open "physical drive 0" and see that the magic number indicates a > > valid > > >>boot record. I believe it is the MBR. > > >>>>> f = open('\\\\.\\PhysicalDrive0', 'rb') > > >>>>> f.read(512)[-2:] > > >>'U\xaa' # that is, hex 55 AA > > >>I don't know much about low-level filesystem or partition details--I got > > the > > >>tidbit about the 55 AA magic number from > > >>http://www-uxsup.csx.cam.ac.uk/pub/doc/suse/sles9/adminguide-sles9/ch08.ht > > ml > > >>Jeff > > >> schrieb im Newsbeitrag > > news:mailman.1864.1128983425.509.python-list at python.org... > From meatpodeye at yahoo.com Thu Oct 27 03:00:34 2005 From: meatpodeye at yahoo.com (Gorlon the Impossible) Date: Thu, 27 Oct 2005 07:00:34 GMT Subject: loop help Message-ID: Hello. I am using Python 2.3.5 with IDLE 1.0.5 on a Windows98 PC. I have some programming experience but mostly I am still learning. I am having some trouble understanding the behaviour of a piece of code I have written. It plots points using PIL. Here is my loop: triangle = [(320,27),(172,323),(468,323)] currentpoint = (randint(0,640),randint(0,350)) t = 0 while t < 10: ct = choice(triangle) mp = (currentpoint[0] + ct[0])/2, (currentpoint[1] + ct[1])/2 draw.point(mp,(0,0,0)) currentpoint = mp t = t + 1 This works fine. But, if I try to divide by a floating point number in the calculation of mp, instead of mp being overwritten each time thru the loop, it starts accumulating, leading to overflow errors for large values of t. Why is this? From davids at webmaster.com Sun Oct 23 14:50:03 2005 From: davids at webmaster.com (David Schwartz) Date: Sun, 23 Oct 2005 11:50:03 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <86k6g59ke6.fsf@bhuda.mired.org> <863bmsakgp.fsf@bhuda.mired.org> Message-ID: "Mike Meyer" wrote in message news:863bmsakgp.fsf at bhuda.mired.org... >>>> I am not saying Microsoft did not know the law. I am saying that no >>>> rational person could have expected the law to be applied to Microsoft >>>> that >>>> way it was. The law *must* put a person on notice of precisely what >>>> conduct >>>> it prohibits. However, in this case, the law's applicability was >>>> conditioned >>>> on an abritrary and irrational choice of what the relevant market was. >>> MS has a long history of dancing with the DOJ, and has been repeatedly >>> warned about the legality - or lack thereof - of their behavior. No >>> rational person who knew of that history could expect the law to be >>> applied to MS in any way other than the way it was. >> Since when does the DOJ get to make the law? (George Bush's claims to >> the contrary not withstanding.) The issue is whether the *LAW* put >> Microsoft >> on notice. A just law must itself put people on notice as to precisely >> what >> conduct constitutes a violation of that law. > In that case, we hav an *awful* lot of unjust laws, because laws > seldom disallow "precise" behavior. That is true. A law *must* put a reasonable person on notice of precisely what conduct it prohibits and what it does not. At the "fringes", the tie goes to the runner, that is, the conduct is not illegal. The law is not supposed to care about things that are trivial. (Except in genuine private entity versus private entity non-criminal cases, where the law really is about the slightest tip of the scales and there is no presumption for either party.) >Which is the only rational way for > a system of laws to work. Requiring that the law predict *everything* > that someone might do to harm others and explicitly listing all those > cases is silly. That's not what I'm asking for. I'm asking that the law *clearly* put people on notice of what conduct is prohibited. That's very easy in legitimate laws, because we all know what it means to punch someone or to rob them. It becomes very difficult in illegitimate laws, because there is no reasonable test to decide whether something is a 'monopoly' or not. This burden makes it harder for the government to pass unjust laws, and that is a good thing. > Instead, you outline a class of actions and tag them > all as illegal. That's why we have laws against assault and battery > and unsafe driving. And laws against exercising monopoly power in an > unfair manner. Interesting how you, again, equate a gun and an argument. It is very important to you to justify responding to arguments with guns. However, I reject that premise at its roots, not just in your application of it. DS From bokr at oz.net Sat Oct 15 23:59:28 2005 From: bokr at oz.net (Bengt Richter) Date: Sun, 16 Oct 2005 03:59:28 GMT Subject: Why asci-only symbols? References: <86vf04zx0k.fsf@bhuda.mired.org> <434ccfcd$0$28021$9b622d9e@news.freenet.de> Message-ID: <4351cef6.112238340@news.oz.net> On Wed, 12 Oct 2005 10:56:44 +0200, =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= wrote: >Mike Meyer wrote: >> Out of random curiosity, is there a PEP/thread/? that explains why >> Python symbols are restricted to 7-bit ascii? > >No PEP yet; I meant to write one for several years now. > >The principles would be >- sources must use encoding declarations >- valid identifiers would follow the Unicode consortium guidelines, > in particular: identifiers would be normalized in NFKC (I think), > adjusted in the ASCII range for backward compatibility (i.e. > not introducing any additional ASCII characters as legal identifier > characters) >- __dict__ will contain Unicode keys >- all objects should support Unicode getattr/setattr (potentially > raising AttributeError, of course) >- open issue: what to do on the C API (perhaps nothing, perhaps > allowing UTF-8) Perhaps string equivalence in keys will be treated like numeric equivalence? I.e., a key/name representation is established by the initial key/name binding, but values can be retrieved by "equivalent" key/names with different representations like unicode vs ascii or latin-1 etc.? Regards, Bengt Richter From uche.ogbuji at gmail.com Thu Oct 27 23:25:44 2005 From: uche.ogbuji at gmail.com (uche.ogbuji at gmail.com) Date: 27 Oct 2005 20:25:44 -0700 Subject: XML Tree Discovery (script, tool, __?) In-Reply-To: <1130350833.334697.60490@g47g2000cwa.googlegroups.com> References: <1130183060.195730.178330@g47g2000cwa.googlegroups.com> <1130189785.358171.307700@o13g2000cwo.googlegroups.com> <1130350833.334697.60490@g47g2000cwa.googlegroups.com> Message-ID: <1130469944.901132.312500@g43g2000cwa.googlegroups.com> > - don't use SAX unless your document is huge > - don't use DOM unless someone is putting a gun to your head What I say is: use what works for you. I think SAX would be fine for this task, but, hey, I personally would use Amara ( http://uche.ogbuji.net/tech/4suite/amara/ ), of course. The following does the trick: import sets import amara from amara import binderytools #element_skeleton_rule suppresses char data from the resulting binding #tree. If you have a large document and only care about element/attr #structure and not text, this saves a lot of memory rules = [binderytools.element_skeleton_rule()] #XML can be a file path, URI, string, or even an open-file-like object doc = amara.parse(XML, rules=rules) elems = {} for e in doc.xml_xpath('//*'): paths = elems.setdefault((e.namespaceURI, e.localName), sets.Set()) path = u'/'.join([n.nodeName for n in e.xml_xpath(u'ancestor::*')]) paths.add(u'/' + path) #Pretty-print output for name in elems: print name, '\n\t\t\t', '\n\t\t\t'.join(elems[name]) -- Uche Ogbuji Fourthought, Inc. http://uche.ogbuji.net http://fourthought.com http://copia.ogbuji.net http://4Suite.org Articles: http://uche.ogbuji.net/tech/publications/ From http Fri Oct 7 10:21:33 2005 From: http (Paul Rubin) Date: 07 Oct 2005 07:21:33 -0700 Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86u0fxi7gf.fsf@bhuda.mired.org> <434545b7$0$662$626a14ce@news.free.fr> <86mzlmpo5r.fsf@bhuda.mired.org> <43458fc7$0$660$626a14ce@news.free.fr> <86br22pbgb.fsf@bhuda.mired.org> Message-ID: <7xbr21tnki.fsf@ruckus.brouhaha.com> Mike Meyer writes: > > When you want local variable in lisp you do : > > > > (let ((a 3)) (+ a 1)) > > Excep that's not a decleration, that's a binding. That's identical to > the Python fragment: > > a = 3 > return a + 1 > > except for the creation of the new scope. Not a variable decleration > in site. Really not though, the scope is what makes it a declaration. In Python you can say: for i in 1,2: if i == 2: print x # x is unbound the first time through the loop x = 9 # but bound the second time and the print doesn't raise an error. Further, 'x' is still in scope even after the loop exits. Scheme lets you say something like (define (counter) (let ((k 0)) (define (f) (set! k (+ 1 k)) k) f)) Yeah, I know you'd write it a bit more concisely in Scheme, but I wanted to make it look like the Python equivalent: def counter(): k = 0 def f(): k += 1 return k return f The trouble is, in f, k is neither local nor global, so Python throws up its hands and raises an error. There's no way to tell it where to find k. This could be solved with a declaration, if Python understood it. From davids at webmaster.com Wed Oct 26 22:50:40 2005 From: davids at webmaster.com (David Schwartz) Date: Wed, 26 Oct 2005 19:50:40 -0700 Subject: Microsoft Hatred FAQ References: <11lsopl4qpg9gc2@corp.supernews.com> <5970m1tfp5qoh9qpr6cbiki6n7b7ajbi3b@4ax.com> Message-ID: Roedy Green wrote: > On 26 Oct 2005 18:05:45 +0200, Tor Iver Wilhelmsen > wrote, quoted or indirectly quoted someone > who said : >>> IBM seems to have had a history of squeezing out competition in the >>> same way Microsoft has, if I recall correctly. >> ... and were told not to by a court. Which is the whole reason for >> the existence of IBM clones, whether PCs or mainframes. > Back in the early days, IBM was just as bad as MS. Competition and > some smackdown by the DOJ, have made them much better behaved. And opened the door for Microsoft. DS From steve at holdenweb.com Thu Oct 13 06:48:43 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 13 Oct 2005 11:48:43 +0100 Subject: Python's garbage collection was Re: Python reliability In-Reply-To: <7xvf0168nq.fsf@ruckus.brouhaha.com> References: <3r6i0uFi3qb8U2@uni-berlin.de> <7xfyr5kfgm.fsf@ruckus.brouhaha.com> <3r6osdFhsfjgU1@uni-berlin.de> <7xvf0168nq.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > "Diez B. Roggisch" writes: > >>That particular implementation used 3 or 4 tag-bits. Of course you are >>right that nowadays python won't notice the difference, as larger nums >>get implicitely converted to a suitable representation. But then the >>efficiency goes away... Basically I think that trying to come up with >>all sorts of optimizations for rather marginal problems (number >>crunching should be - if a python domain at all - done using Numarray) > > > I don't think it's necessarily marginal. Tagged ints can be kept in > registers, which means that even the simplest code that does stuff > with small integers becomes a lot more streamlined, easing the load on > both the Python GC and the cpu's memory cache. Right now with the > bytecode interpreter, it probably doesn't matter, but with Pypy > generating native machine code, this kind of thing can make a real > difference. Until someone does the experiment this stuff is bound to be speculation (what's that saying about "premature optimization"?). But I can foresee that there'd be problems at the outer edges of the language: for example, sys.maxint would have to be reduced, and this in turn would lead to reduction in, for example, the theoretical maximum length of sequences. Even if it reduced the average execution time of the "average" program, this will involve trade-offs which can only be fully appreciated in the light of practical experience. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From my_email_is_posted_on_my_website at munged.invalid Wed Oct 12 17:44:22 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 12 Oct 2005 21:44:22 GMT Subject: Jargons of Info Tech industry References: <1124804082_1011@spool6-east.superfeed.net> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <5hrik11q3p5ugcjm4hmmgqgq20o8fdrhr9@4ax.com> <7x4q7q2yer.fsf@ruckus.brouhaha.com> Message-ID: <8q0rk1tiktr86ksdu55mgsqffpkf2uus1c@4ax.com> On 09 Oct 2005 14:06:20 -0700, Paul Rubin wrote or quoted : >That's the worst of all. I certainly don't want my mail reader >opening network connections to arbitrary places when I read my mail. >I have no willingness at all to reveal my mail reading habits or IP >address to everyone who sends me email. Obviously you can't trust anything code-like that arrives from strangers. It is an extension of the law Mommy laid down not to take candy from strangers. However, formatted text is not code. Pictures are not code. It is unfair to tar them with the brush of JavaScript or the goofy things Outlook does with enclosures. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From steve at holdenweb.com Thu Oct 6 09:19:29 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 06 Oct 2005 14:19:29 +0100 Subject: Help with chaos math extensions. In-Reply-To: <4343BC8E.1060702@yahoo.com> References: <43433982.8080008@yahoo.com> <4343BC8E.1060702@yahoo.com> Message-ID: Brandon K wrote: > In case you missed it, I said I have windows XP. Windows XP > pre-compiled python binaries are built on VS .NET 2003. In order to > build extensions, you need the compiler the interpreter was built on, or > at least that is what is reported to me by calling setup.py. If I was > using linux, which I currently am not, it'd be a different story. > Additionally, GCC isn't available for windows XP, only MinGW, the port, > and I don't know that much about it to use it running on a Windows > platform. Furthermore, I was asking for help on an extension, not an > economical question about my programming environment. > > Thanks > >> >>On Oct 4, 2005, at 10:25 PM, Brandon Keown wrote: >> >>> I have programmed a fractal generator (Julia Set/Mandelbrot Set) >>>in python in the past, and have had good success, but it would run so >>>slowly because of the overhead involved with the calculation. I >>>recently purchased VS .NET 2003 (Win XP, precomp binary of python >>>2.4.2rc1) to make my own extensions. >> >>Why did you need to purchase anything when gcc is available for free? >> Since gcc isn't an option, the logical way to proceed would be to do what others have done and install the Microsoft Toolkit compiler, available from their web site for the outrageous price of nothing. I can vouch that it really does compile extensions for Python 2.4 on Windows, having done that myself. See http://www.vrplumber.com/programming/mstoolkit/ regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From tim at tt1lock.org Mon Oct 17 08:45:45 2005 From: tim at tt1lock.org (Tim Tyler) Date: Mon, 17 Oct 2005 12:45:45 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: In comp.lang.java.programmer Roedy Green wrote or quoted: > MS has held BACK computer evolution by tying their OS so heavily to > the Pentium architecture. The chip architecture has nowhere near > enough registers. MS refused to believe the Internet was more than a > passing fad. They are still frantically patching security holes in > their OS over a decade later. Another big problem appears to be sitting on their customers and milking them - rather than working on improving things. There has been some progress with their OS - but it seems to be going very slowly. -- __________ |im |yler http://timtyler.org/ tim at tt1lock.org Remove lock to reply. From hancock at anansispaceworks.com Mon Oct 17 20:07:20 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Mon, 17 Oct 2005 19:07:20 -0500 Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> Message-ID: <200510171907.20938.hancock@anansispaceworks.com> On Monday 17 October 2005 05:27 pm, Roel Schroeven wrote: > John Bokma wrote: > > Or do you really consider the Linux desktop (any of them) quality? > > Actually yes. Are they better than MS's desktop? Depends on one's needs. > If I didn't need MS for my job, there's a very big chance I would only > use Linux. Or MacOS X. Duh. Yeah of course they're better than Windows' desktop. Trying to get anything done with an XP box is somewhere between the frustration level of dealing with the IRS and trying to work your way out of a well while hanging upside down from the bucket by your feet with your arms tied behind your back. For example, on Linux I don't have: * pop-up ads * applications that only do half the job, then offer to sell me the other half * the "zero click" interface -- there is NOTHING more frustrating than having the desktop constantly second guessing you, and pushing buttons because it thinks you waited too long (i.e. you actually stopped to read the dialog text). but I do have: * multiple virtual desktops * one click pasting between windows Now, I'm sure, that under some theoretical, fully-tricked-out Windows platform, with all the possible bells and whistles installed, and all the stupid OEM modifications removed (including all that adware), this might not be so. But frankly, I've never SEEN a Windows box like that, much less used one. What I have seen is a factory-direct Dell laptop with a pre-installed Windows XP which had all of the problems I described above. OTOH, the Linux environment I describe is run-of-the-mill Debian Sarge with KDE. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From rubencharles at gmail.com Mon Oct 31 07:34:10 2005 From: rubencharles at gmail.com (Ruben Charles) Date: Mon, 31 Oct 2005 08:34:10 -0400 Subject: Need Python Pro for Help!! Plzz In-Reply-To: <5uSdnSSK7vYrTfneRVn-pQ@giganews.com> References: <5uSdnSSK7vYrTfneRVn-pQ@giganews.com> Message-ID: A stranger from the land of Woot came to Master Foo as he was eating the morning meal with his students. "I hear y00 are very l33t," he said. "Pl33z teach m3 all y00 know." Master Foo's students looked at each other, confused by the stranger's barbarous language. Master Foo just smiled and replied: "You wish to learn the Way of Unix?" "I want to b3 a wizard hax0r," the stranger replied, "and 0wn ever3one's b0xen." "I do not teach that Way," replied Master Foo. http://www.catb.org/~esr//writings/unix-koans/script-kiddie.html On 10/30/05, blah at blah.blah wrote: > Need python Pro at newtopython at googlegroups.com , if u wanna help, plz > reply to that address. We are python beginners. need a real good > Python Programmer for Help. TIA!! > -- > * Posted with NewsLeecher v3.0 Beta 7 > * http://www.newsleecher.com/?usenet > -- > http://mail.python.org/mailman/listinfo/python-list > From hancock at anansispaceworks.com Mon Oct 10 17:42:34 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Mon, 10 Oct 2005 16:42:34 -0500 Subject: [Info] PEP 308 accepted - new conditional expressions In-Reply-To: References: <3q4ro9Fd770nU3@individual.net> Message-ID: <200510101642.34288.hancock@anansispaceworks.com> On Sunday 09 October 2005 07:50 am, phil hunt wrote: > On Fri, 7 Oct 2005 01:05:12 -0500, Terry Hancock wrote: > >GvR's syntax has the advantage of making grammatical sense in English (i.e. > >reading it as written pretty much makes sense). > > I know, let's re-write Python to make it more like COBOL! That's > bound to be a winner! Whereas the "natural order" of "condition affirmative negative" is natural for what reason? That it is so in C? I don't find that so compelling either, frankly. Why should it really matter in the end? I've always found C's order (and punctuation) confusing, I have to look it up practically everytime I use it or have to read it (which correlates to it being used very rarely, with causality in both directions). Given that situation, choosing a form which is easy to read is surely an advantage, and, since it is the way that Python has handled logic in the past, it makes sense to continue doing so. No doubt, ANY choice of ternary operator for Python will be criticized, and no doubt, ANY choice would nevertheless be usable. OTOH, I think this choice is consistent with the rest of Python's design. The general choice to use keyword operators for LOGIC and symbolic operators for MATH is retained, and so long as we're describing the logic in words, it makes sense for the wording to sound natural. Consistency certainly does make it easier for me to remember. Python's main advantage over other languages, for me, is that it makes me run to the manual a lot less, and I generally don't get confused trying to follow other people's code. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From __peter__ at web.de Sun Oct 30 03:53:09 2005 From: __peter__ at web.de (Peter Otten) Date: Sun, 30 Oct 2005 09:53:09 +0100 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <1130614532.765771.288960@g43g2000cwa.googlegroups.com> <4363f91d$0$2089$edfadb0f@dtext02.news.tele.dk> Message-ID: David Rasmussen wrote: > None of the solutions presented in this thread is nearly as fast as the > > print file("filename", "rb").read().count("\x00\x00\x01\x00") Have you already timed Scott David Daniels' approach with a /large/ blocksize? It looks promising. Peter From james at colannino.org Mon Oct 24 01:27:05 2005 From: james at colannino.org (James Colannino) Date: Sun, 23 Oct 2005 22:27:05 -0700 Subject: output from external commands In-Reply-To: <86hdb77b4f.fsf@bhuda.mired.org> References: <86hdb77b4f.fsf@bhuda.mired.org> Message-ID: <435C70A9.6040404@colannino.org> Mike Meyer wrote: >This is a scripting language feature. Python doesn't have direct >support for it, any more than C++ does. To get that functionality, you >want to use either the os.popen function, or - preferable, but only >available in newer Pythons - the subprocess module. > > Thanks. James -- My blog: http://www.crazydrclaw.com/ My homepage: http://james.colannino.org/ From robin at reportlab.com Wed Oct 19 05:16:42 2005 From: robin at reportlab.com (Robin Becker) Date: Wed, 19 Oct 2005 10:16:42 +0100 Subject: override a property In-Reply-To: References: <43542065$0$21621$636a15ce@news.free.fr> <4354ABB3.1030203@jessikat.fsnet.co.uk> <4354b324$0$21023$636a55ce@news.free.fr> Message-ID: <43560EFA.5030108@chamonix.reportlab.co.uk> Steven Bethard wrote: > Robin Becker wrote: > ....... > > Can you add the object to be observed as another parameter to the add > method? > > py> class ObservableProperty(property): > ... def __init__(self, *args, **kwargs): ...... > py> A.x.add(b, obs2) > py> b.x = 7 > obs2: 7 > > Probably "self._observers" should use some sort of weakref dict instead > of a regular dict, but hopefully the idea is clear. > > STeVe yes I think this is what Alex is proposing. It probably means abandoning the class based observers entirely otherwise there would have to be a decision on whether the instance observers take priority and some argument convention on whether the class or the instance was being added to. -- Robin Becker From tengo at DELETEMEecc.lu Sun Oct 9 06:25:54 2005 From: tengo at DELETEMEecc.lu (Stefaan A Eeckels) Date: Sun, 9 Oct 2005 12:25:54 +0200 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> Message-ID: <20051009122554.6237bh04.tengo@DELETEMEecc.lu> On Sat, 08 Oct 2005 22:39:38 GMT Roedy Green wrote: > So from an aesthetic point of view, once people learn how it works, > CSS lets sender and receiver compromise on what the message looks > like. No other medium gives ANY control to the receiver about how a > message is formatted. My mail reader renders HTML as text. Usually, that gets the message through without the impediments the sender included. Of course one can render anything in one's computer exactly the way one wants, given comptence and time. Mutual agreement on a CSS is possible, but for widespread usage it needs to be a standardised CSS, and then we're back in the featuritis spiral. > One of the most important changes in the ability to select special > fonts for the those without prefect vision and larger fonts. That's exactly why I don't want people to muck with the presentation of an email. I've set up my machine to render standard ASCII emails execatly the way I want, with the font that I can read, in a size that optimises ease and visible text. I don't care that someone would like to inline a 5000x3000 JPEG from their 15 megapixel camera, or render text in white on black, or any other silly format. If they want me to see a document in _exactly_ the way they prepared it, let them use PDF. It's there, and it works well. > There is also the philosophical question. When my nephew sends me a > message, do I have a right to warp his intent even if I don't like the > aesthetics? That is part of his message. That question is answered above - if your nephew wants you to see exactly what he produced, let him use the format specifically designed for the purpose. And yes, philosophically speaking the recipient can do anything they like with the message, including not reading it at all. Anything else would be preposterous. > Should my email reader fix the spelling mistakes in the emails sent me > by angry US soldiers? Or is that part of the message? If you want it to do that, yes. Wheter including the corrected message in the reply is a good idea is another question (mostly related to how the relation is, how it should be, and how big the soldier in question is). > There are three different issues getting muddled together: > > 1. avoiding spam Which happens to use HTML to obfuscate the message and avoid getting caught by filters. > 2. making mail from well meaning but inept friends more readable. Who happen to use HTML because they don't have a clue. > 3. what constitutes a good general style for general correspondence. > How should you use rich text appropriately. Which happens to be largely superfluous as far as conveying intent is concerned. Email works well without rich text, especially when combined with attachments that use a format sender and recipient have agreed to. We don't need more, and we shouldn't assume that more complex technology equates to an improvement. Example: it's not because we can use a gazillion typefaces in pastel colours that documents that we should do so. Take care, -- Stefaan -- As complexity rises, precise statements lose meaning, and meaningful statements lose precision. -- Lotfi Zadeh From aleax at mail.comcast.net Sat Oct 8 12:30:31 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Sat, 8 Oct 2005 09:30:31 -0700 Subject: Python for search engine development References: <1128288465.580210.35460@g49g2000cwa.googlegroups.com> <1128291039.914526.68840@o13g2000cwo.googlegroups.com> Message-ID: <1h43whh.1bln89vje62izN%aleax@mail.comcast.net> wittempj at hotmail.com wrote: > Well, Google applies some Python in their implementation, see > http://www-db.stanford.edu/~backrub/google.html "Some" is correct. As for writing a search engine in Python _only_, hmmm -- I honestly don't know. You could surely develop a working implementation, but then, to make it perform well, you'd most likely want to profile it and retune some CPU-intensive parts using pyrex, or C. So, if during your program development process you can find good open-source C or C++ libraries offering a fast implementation of some of the CPU-bound stuff you know you'll need, you would probably be better off by wrapping those libraries (again using pyrex, or maybe SWIG, or Boost Python for C++, ...) rather than redoing them from scratch in Python (and probably later having to do some tuning on those parts). One notably strong point of Python is that it "plays well with others", and I would advise you to leverage this fact. Alex From haraldarminmassa at gmail.com Tue Oct 25 04:39:33 2005 From: haraldarminmassa at gmail.com (Harald Armin Massa) Date: 25 Oct 2005 01:39:33 -0700 Subject: migrate from ZODB 3.3.1 --- to where, and how? Message-ID: <1130229573.350936.223760@z14g2000cwz.googlegroups.com> Hello, I am using ZODB "standalone" in version 3.3.1 within some application. Now I learn that the 3.3.x branch of ZODB is "retired". No problem so far, everything is running fine. BUT... "retired" gives me the hint that nothing GREAT will be done to this branch anymore :) Now I am questioning myself: to which branch should I migrate? Is 3.5 a sure bet, or are uneven subversions a bad sign, making retirement likely? As much as my diggings showed me, the "special sign" of 3.3 was import ZODB from persistent import Persistent from persistent.list import PersistentList from persistent.mapping import PersistentMapping that PersistentList and PersistenMapping reside within persistent., while in the 3.2 branch they reside somewhere else in the namespace. I learned it the hard way that 3.3 filestores not get converted magically or easy to 3.2 :) ... So, my questions: - where should I migrate to? - how is migration done best (especially taking care of "old" filestores Harald From sjmaster at gmail.com Mon Oct 17 18:11:10 2005 From: sjmaster at gmail.com (Steve M) Date: 17 Oct 2005 15:11:10 -0700 Subject: Problem Pythoncard tutorial References: <1129563565.327047.327000@o13g2000cwo.googlegroups.com> Message-ID: <1129587070.176237.316450@o13g2000cwo.googlegroups.com> I'd say that the tutorial text (by Dan Shafer) and the file starter1.py are not in sync. The word 'self' doesn't appear in the source file, it isn't a keyword (just a convention) or a literal, and it isn't imported by wildcard or some other trickery. So just by inspection you can tell that the name isn't defined at the point you are trying to use it, and so using the name anywhere other than as the target of an assignment (is that called an 'lvalue' ?) will cause a NameError. I think the problem begins around where the tutorial says: ----- Here's the important part to focus on: def on_menuFileExit_select(self, event): pass ----- Based on the indentation and other clues, that was probably supposed to be a method of the Minimal class, but it doesn't exist in the starter1.py file. Just stick it in (as a method of that class) and things should work. FYI here is the version of starter1.py from my installed PythonCard 0.8.1: #!/usr/bin/python """ __version__ = "$Revision: 1.6 $" __date__ = "$Date: 2004/05/05 16:53:23 $" """ from PythonCard import model class Minimal(model.Background): pass if __name__ == '__main__': app = model.Application(Minimal) app.MainLoop() From davids at webmaster.com Thu Oct 27 07:11:11 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 04:11:11 -0700 Subject: Microsoft Hatred FAQ References: <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <3sbohtFmqs4eU1@news.dfncis.de> Message-ID: Sibylle Koczian wrote: > David Schwartz schrieb: >> When you are not in the majority, you are going to face >> inconveniences. You'd face the same inconvenience if you wanted to >> buy a new car without seats. Most people wants cars with seats, so >> that's the way they're packaged. >> > What a stupid comparison! A computer without Windows is a computer > with another operating system. It isn't even comparable to a car with > specially expensive non standard seats. It is comparable in the only sense in which I used a comparison. More people want a computer with Windows preinstalled than want it any other way. Similarly, more people want a car with standard seats preinstalled than want it any other way. Who said anything about 'specially expensive'? Are you pretending I said that just so you can refute it? It kind of reminds me of a scene from Futurama, which went roughly like this: Leela: We need to get some money. Fry: Well how are we going to do that? A daring daylight robbery of Fort Knox on elephant back? That's the dumbest idea I ever heard! DS From jeremy at emperorlinux.com Fri Oct 28 14:02:29 2005 From: jeremy at emperorlinux.com (Jeremy Moles) Date: Fri, 28 Oct 2005 14:02:29 -0400 Subject: Why doesn't this work? :) Message-ID: <1130522549.4095.19.camel@localhost.localdomain> Jumping right into the code (which should speak for itself): # ----------------------------------- try: # this will fail and be caught # below, weeee import foobar except ImportError, error: class foobar: @staticmethod def __getattr__(*args, **kargs): return None print foobar.bg # ----------------------------------- This doesn't work and I'm just curious as to why? I can, of course, make __getattr__ non-static, instantiate a foolbar object, and everything works; but, the "idea" above seems cleaner and whatnot. :) Am I misunderstanding something fundamental about the builtin __* functions? Can they not be "static?" No rush on this, just curious. I'm using the following in a more general way, and it works fine for now... :) # ----------------------------------- try: import foobar except ImportError, error: class Foobar: def __getattr__(*args, **kargs): return None foobar = Foobar() print foobar.bg # ----------------------------------- From aleaxit at yahoo.com Mon Oct 24 10:52:40 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 24 Oct 2005 07:52:40 -0700 Subject: High Order Messages in Python References: <1130015536.273136.295800@g43g2000cwa.googlegroups.com> <435bb315$0$15040$ed2619ec@ptn-nntp-reader02.plus.net> <1130118446.643842.178950@g47g2000cwa.googlegroups.com> <1130122476.079450.216280@g47g2000cwa.googlegroups.com> <1h4wiqv.m4hrpogqt6tvN%aleaxit@yahoo.com> <1130127914.446263.222800@z14g2000cwz.googlegroups.com> <435cb299$1_3@newspeer2.tds.net> Message-ID: <1h4xep9.1qqp5prje5wb1N%aleaxit@yahoo.com> Kent Johnson wrote: ... > For example to open a file and read from it uses two closures, one to wrap > a block with the file open/close, one to iterate lines (from the pickaxe > book): > > File.open("testfile") do |file| > file.each_line { |line| puts line } > end Good example -- Ruby blocks are used both for iteration, and for non-iterative wrapping of a single action with "try-finally" semantics. Python's generators, up to 2.4, don't really support the non-iterative part of this well, and have other limitations (they can get values "out" with yield, but can't easily or naturally get results back "in"...). In the forthcoming 2.5, Python generators will be enriched with enough functionality for these purposes, and a new statement "with" to clearly indicate the non-iterative case (while "for" indicates iteration). So, in Python 2.5, the above snippet may become, in Python: with opening("testfile") as my_file: for line in my_file: print line, The fact that 2.5 will acquire extra functionality to "round out" generators &c to the power of Ruby blocks may be taken as a clear indication that, right now (Ruby 1.8.* vs Python 2.4.*), Ruby's blocks are somewhat more powerful. As for the differences in style that will remain when Python 2.5 is born, we'll be back to "personal taste" level issues, it appears to me. Alex From noahbedford at gmail.com Sat Oct 22 19:51:26 2005 From: noahbedford at gmail.com (noah bedford) Date: Sat, 22 Oct 2005 19:51:26 -0400 Subject: Jargons of Info Tech industry References: <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <41hhk195gcipfarnqu85ggs606aqi89ea1@4ax.com> <2dadnfArEfWwvdTeRVnzvA@telenor.com> <0trik1ldrtvuhsdvoai4a7h34q7la1pehl@4ax.com> <8v0rk1hjh0k6q2estgqc19i0da59fgurse@4ax.com> Message-ID: <20051022195126.586c645f@localhost.localdomain> On Wed, 12 Oct 2005 21:50:22 GMT Roedy Green wrote: >It is almost like providing ladders and setting out cookies and milk >for the burglars. Fire escapes at christmas. From steve at holdenweb.com Sun Oct 9 06:26:23 2005 From: steve at holdenweb.com (Steve Holden) Date: Sun, 09 Oct 2005 11:26:23 +0100 Subject: What about letting x.( ... ? ... ) be equivalent to ( ... x ... ) In-Reply-To: <4348e72f$0$11133$626a14ce@news.free.fr> References: <4348e72f$0$11133$626a14ce@news.free.fr> Message-ID: al wrote: > Fredrik Lundh a ?crit : > >>if you have a fear of introducing new local variables, you have problems >>that cannot be solved by syntax. > > > Dear Fredrik, > > I have read the original messages on fr.comp.lang.python, and I don't > understand your answer. > > It is not about a fear of introducing new local variables, but for me it > is an elegant solution to a common problem, to avoid creation of useless > variables (what in french we call "variables muettes", like indexes in > loops who are just there because some langages level is too low). > > It also avoid the increase of parenthesis depth, and so the readability > is enhanced. > > And it solve a problem that in all object oriented langages, a method > that process 2 or more different classes of objets belongs just to one > of those classes. > > All this kind of problems appears often to me (and in different > langages), and contrarily to you, I'm very impressed by the compacity > and elegance of the solution. I think it would be nice if implemented in > different langages (because it breaks nothing), and firstly Python. > > Best regards, > Al > > PS : sorry for my approximative english, but my natural langage is french. It seems to me that what you proposed was a "solution", that seems obvious only to you, to a problem perceived only by you. I am afraid you would have to work rather harder to persuade me that there is a problem, let alone that you have found the solution to it. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From kent37 at tds.net Fri Oct 21 22:43:23 2005 From: kent37 at tds.net (Kent Johnson) Date: Fri, 21 Oct 2005 22:43:23 -0400 Subject: Python vs Ruby In-Reply-To: References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> <4358d9f6$0$19694$626a14ce@news.free.fr> <3nc*FXJ1q@news.chiark.greenend.org.uk> <11lin723i0e3k80@corp.supernews.com> Message-ID: <4359a541$1_3@newspeer2.tds.net> Bryan wrote: > i would not say sion's ratio of 5:1 is dubious. for what it's worth, > i've written i pretty complex program in jython over the last year. > jython compiles to java source code and the number of generated java > lines to the jython lines is 4:1. Ugh. The code generated by jythonc is *nothing like* the code you would write by hand to do the same thing. This is a meaningless comparison. Kent From apardon at forel.vub.ac.be Wed Oct 5 04:51:57 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 5 Oct 2005 08:51:57 GMT Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> <434245F5.6060500@REMOVEMEcyber.com.au> <7xr7b14lk0.fsf@ruckus.brouhaha.com> <7xu0fx9l7y.fsf@ruckus.brouhaha.com> Message-ID: Op 2005-10-05, Duncan Booth schreef : > Paul Rubin wrote: > >> Brian Quinlan writes: >>> Have those of you who think that the lack of required declarations in >>> Python is a huge weakness given any thought to the impact that adding >>> them would have on the rest of the language? I can't imagine how any >>> language with required declarations could even remotely resemble >>> Python. >> >> What's the big deal? Perl has an option for flagging undeclared >> variables with warnings ("perl -w") or errors ("use strict") and Perl >> docs I've seen advise using at least "perl -w" routinely. Those >> didn't have much impact. Python already has a "global" declaration; >> how does it de-Pythonize the language if there's also a "local" >> declaration and an option to flag any variable that's not declared as >> one or the other? > > The difference is that perl actually needs 'use strict' to be useful for > anything more than trivial scripts. Without 'use strict' you can reference > any variable name without getting an error. Python takes a stricter > approach to begin with by throwing an exception if you reference an > undefined variable. > > This only leaves the 'assigning to a different name than the one we > intended' problem which seems to worry some people here, and as has been > explained in great detail it incurs a cost to anyone reading the code for > what most Python users consider to be a very small benefit. It also is one possibility to implement writable closures. One could for instace have a 'declare' have the effect that if on a more inner scope such a declared variable is (re)bound it will rebind the declared variable instead of binding a local name. -- Antoon Pardon From maxm at mxm.dk Tue Oct 4 05:32:46 2005 From: maxm at mxm.dk (Max M) Date: Tue, 04 Oct 2005 11:32:46 +0200 Subject: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please! In-Reply-To: References: Message-ID: <43424bee$0$38666$edfadb0f@dread12.news.tele.dk> spiffo wrote: > The Main Issue in a nutshell > > I am a corporate developer, working for a single company. Got a new project > coming up and wondering if I should stay with Python for this new, fairly > large project, are jump back on the 'safe' M$ bandwagon using a dot net > language? Hehe ... I can run my very first Python program right now in the current version of Python. I cannot even find a platform to run my .asp code from that same timeframe ... So much for 'safe'! -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science From davids at webmaster.com Wed Oct 19 06:15:03 2005 From: davids at webmaster.com (David Schwartz) Date: Wed, 19 Oct 2005 03:15:03 -0700 Subject: Microsoft Hatred FAQ References: <867jcbzdw9.fsf@bhuda.mired.org> <4vcbl1dkek9kr86embmgrj70vk945t99ho@4ax.com> <35jbl1dprs4v1o87i0tapc2husjqiqm6fi@4ax.com> <4355ea72$1_3@news.melbourne.pipenetworks.com> Message-ID: "Roedy Green" wrote in message news:vm6cl19r7j3r6b4o73d5m3ab2bmih2v3j6 at 4ax.com... > On Wed, 19 Oct 2005 01:54:14 -0700, "David Schwartz" > wrote or quoted : >> They have obligations to their clients because (and only because) >>failure to provide the services they contract to provide will result in >>lawsuits and harm to the shareholders. All other obligations come from the >>harm these failures will do to the shareholders. > That's the view of Republican, but it is not the only view. Some > might say the law trumps that. It does not matter if breaking the law > would be more profitable, you still don't do it. Did I say their obligation was to secure their shareholders as much profit as possible? I said their obligation was to their shareholders. I am only continuing this off-topic thread on newsgroups that probably don't want it because it is a basic principle of fairness that a false or distorted comment deserves an rebuttal anywhere that false or distorted comment appears. However, it doesn't deserve a full debate anywhere except where it's on-topic. DS From david at jotax.com Wed Oct 26 12:03:15 2005 From: david at jotax.com (David Poundall) Date: 26 Oct 2005 09:03:15 -0700 Subject: How best to reference parameters. In-Reply-To: <4SM7f.4313$Zd.1145@tornado.tampabay.rr.com> References: <1130274796.584531.229340@g43g2000cwa.googlegroups.com> <4SM7f.4313$Zd.1145@tornado.tampabay.rr.com> Message-ID: <1130342595.533405.191920@g43g2000cwa.googlegroups.com> Sadly Ron, c_y can only see index and showall in your example. From paul at boddie.org.uk Tue Oct 18 13:32:28 2005 From: paul at boddie.org.uk (Paul Boddie) Date: 18 Oct 2005 10:32:28 -0700 Subject: html parser? References: Message-ID: <1129656748.638138.237120@g49g2000cwa.googlegroups.com> Thorsten Kampe wrote: > For simple things like that "BeautifulSoup" might be overkill. [HTMLParser example] I've used SGMLParser with some success before, although the SAX-style processing is objectionable to many people. One alternative is to use libxml2dom [1] and to parse documents as HTML: import libxml2dom, urllib url = 'http://www.python.org' doc = libxml2dom.parse(urllib.urlopen(url), html=1) anchors = doc.xpath("//a") Currently, the parseURI function in libxml2dom doesn't do HTML parsing, mostly because I haven't yet figured out what combination of parsing options have to be set to make it happen, but a combination of urllib and libxml2dom should perform adequately. In the above example, you'd process the nodes in the anchors list to get the desired results. Paul [1] http://www.python.org/pypi/libxml2dom From mwm at mired.org Tue Oct 4 12:28:38 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 04 Oct 2005 12:28:38 -0400 Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> <434245F5.6060500@REMOVEMEcyber.com.au> Message-ID: <86psqli6vd.fsf@bhuda.mired.org> Steven D'Aprano writes: >> My gut reaction is that it's a wash. The time taken to declare >> variables in well-written code in a well-designed language - meaning >> the declarations and use will be close together - isn't all that >> great, but neither are the savings. > You've gone from thinking about the implementation of the algorithm to > thinking about how to satisfy the requirements of the compiler. As > context switches go, it isn't as big as the edit-compile-make-run > method of testing, but it is still a context switch. I'm making context switches all the time when programming. I go from thinking about the problem in terms of the problem, to thinking about in terms of programming language objects, to thinking about the syntax for expressing those objects. Adding another one does have a cost - but it's no big deal. > I don't know whether there are languages that will check everything in > that way. If there aren't, then perhaps there should be. But Python > shouldn't be one of them. Right. You're doing different things when you program in a language like Python, vs. Eiffel (which is where I drew most of my checks from). Each does what it does well - but they don't do the same things. > Specifying every last detail about the objects making up the space > shuttle is one of the reasons why it costs umpty-bazillion dollars > to build one, and almost as much to maintain it -- and it still has > a safety record worse than most $10,000 cars. As if a something that's designed to literally blow you off the face of the earth could reasonably be compared with an internal combustion engine that never leaves the ground for safety. The shuttle has one of the best safety records around for vehicles that share it's purpose. It's doing something that's inherently very dangerous, that we are still learning how to do. Overengineering is the only way to get any measure of safety. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From twic at urchin.earth.li Fri Oct 21 13:51:19 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Fri, 21 Oct 2005 18:51:19 +0100 Subject: Binding a variable? In-Reply-To: References: Message-ID: On Fri, 21 Oct 2005, Paul Dale wrote: > Is it possible to bind a list member or variable to a variable such that > > temp = 5 > list = [ temp ] > temp == 6 > list > > would show > > list = [ 6 ] As you know by now, no. Like any problem in programming, this can be solved with a layer of abstraction: you need an object which behaves a bit like a variable, so that you can have multiple references to it. The simplest solution is to use a single-element list: >>> temp = [None] # set up the list >>> temp[0] = 5 >>> list = [temp] >>> temp[0] = 6 >>> list [[6]] I think this is a bit ugly - the point of a list is to hold a sequence of things, so doing this strikes me as a bit of an abuse. An alternative would be a class: class var: def __init__(self, value=None): self.value = value def __str__(self): # not necessary, but handy return "<<" + str(self.val) + ">>" >>> temp = var() >>> temp.value = 5 >>> list = [temp] >>> temp.value = 6 >>> list [<<6>>] This is more heavyweight, in terms of both code and execution resources, but it makes your intent clearer, which might make it worthwhile. tom -- Transform your language. From michele.simionato at gmail.com Sat Oct 1 01:59:03 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 30 Sep 2005 22:59:03 -0700 Subject: PEP 308 accepted - new conditional expressions In-Reply-To: References: <3q4ro9Fd770nU3@individual.net><0qh%e.20023$Ix4.15230@okepread03> Message-ID: <1128146343.001242.66990@z14g2000cwz.googlegroups.com> Terry Reedy ha scritto: > "Dave Benjamin" > > > Hooray! After years of arguing over which syntax to use, and finally > > giving up since nobody could agree, > > I understand that this has become the local 'politically correct' view, but > as a participant in the discussion, I know it not true and actively > deceptive. The community was prevented from coming to a decision. There > was a 'primary' vote with an incumbent, 15 challengers, and several > write-ins. But there was no runoff. FWIW, I think Terry's recollection is pretty close to the "historical truth". Guido could have decided two years ago, sparing us the PEP 308 ordalia. So, I am happy that at the end we will have a conditional operator, but I am not happy of how the process worked out. It was just an enormous waste of resources that could have been employed much better :-( Michele Simionato From maravilloso at gmail.com Wed Oct 26 05:49:13 2005 From: maravilloso at gmail.com (Maravilloso) Date: 26 Oct 2005 02:49:13 -0700 Subject: Printing a document in the default network printer under Windows In-Reply-To: References: Message-ID: <1130320153.342542.81580@g43g2000cwa.googlegroups.com> Perfect, thanks! I owe you now some PyBeers :-) From onurb at xiludom.gro Mon Oct 24 04:49:01 2005 From: onurb at xiludom.gro (bruno modulix) Date: Mon, 24 Oct 2005 10:49:01 +0200 Subject: Tricky Areas in Python In-Reply-To: <1130104962.547011.277540@g47g2000cwa.googlegroups.com> References: <1130097286.772836.94930@g44g2000cwa.googlegroups.com> <1130104962.547011.277540@g47g2000cwa.googlegroups.com> Message-ID: <435c9ffe$0$664$626a14ce@news.free.fr> PyPK wrote: > hmm Thats one thing. Also I was thinking of something like benefites of > python over other languages. That's fairly context-dependant *and* subjective. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From fergdeff at gmail.com Tue Oct 25 10:54:19 2005 From: fergdeff at gmail.com (ferg) Date: 25 Oct 2005 07:54:19 -0700 Subject: MoinMoin - Can't create new pages Message-ID: <1130252059.474472.102670@g14g2000cwa.googlegroups.com> I've checked all the FAQs and help - spent a couple of hours on this now and it's really bugging me. I've got Moin 1.3.5 installed on IIS 5.0. I can view and edit pages without any problems, but cannot create new pages - either trough the GUI, or by creating a new WikiName and clicking on it. I'm stumped as to whether this is a Moin ACL problem (played around a lot with this, but to no avail) or perhaps an IIS config problem (though the Web Account has full control to the data directory). The Wiki is an internal intranet one for our development group, so I don't really care if everyone is an admin, I just need to be able to create new pages anyway. Here is my wikiconfig.py >>>> FILE START >>>> # -*- coding: iso-8859-1 -*- # IMPORTANT! This encoding (charset) setting MUST be correct! If you live in a # western country and you don't know that you use utf-8, you probably want to # use iso-8859-1 (or some other iso charset). If you use utf-8 (a Unicode # encoding) you MUST use: coding: utf-8 # That setting must match the encoding your editor uses when you modify the # settings below. If it does not, special non-ASCII chars will be wrong. """ MoinMoin - Configuration for a single wiki If you run a single wiki only, you can omit the farmconfig.py config file and just use wikiconfig.py - it will be used for every request we get in that case. Note that there are more config options than you'll find in the version of this file that is installed by default; see the module MoinMoin.multiconfig for a full list of names and their default values. Also, the URL http://moinmoin.wikiwikiweb.de/HelpOnConfiguration has a list of config options. @copyright: 2000-2005 by Juergen Hermann @license: GNU GPL, see COPYING for details. """ from MoinMoin.multiconfig import DefaultConfig class Config(DefaultConfig): # Wiki identity ---------------------------------------------------- # Site name, used by default for wiki name-logo [Unicode] sitename = u'ISS Wiki' # Wiki logo. You can use an image, text or both. [Unicode] # Example: u'My WikiMy Wiki' # For no logo or text, use '' logo_string = sitename # The interwiki name used in interwiki links interwikiname = None # Critical setup --------------------------------------------------- # Misconfiguration here will render your wiki unusable. Check that # all directories are accessible by the web server or moin server. # If you encounter problems, try to set data_dir and data_underlay_dir # to absolute paths. # Where your mutable wiki pages are. You want to make regular # backups of this directory. data_dir = './data/' # Where read-only system and help page are. You might want to share # this directory between several wikis. When you update MoinMoin, # you can safely replace the underlay directory with a new one. This # directory is part of MoinMoin distribution, you don't have to # backup it. data_underlay_dir = './underlay/' # This must be '/wiki' for twisted and standalone. For CGI, it should # match your Apache Alias setting. url_prefix = '/wiki' # Security ---------------------------------------------------------- # Security critical actions (disabled by default) # Uncomment to enable options you like. #allowed_actions = ['DeletePage', 'AttachFile', 'RenamePage'] # Enable acl (0 to disable) acl_enabled = 1 # IMPORTANT: grant yourself admin rights! replace YourName with # your user name. See HelpOnAccessControlLists for more help. # All acl_rights_xxx options must use unicode [Unicode] acl_rights_before = u"arkprod\it_32564:read,write,delete,revert,admin" # Link spam protection for public wikis (Uncomment to enable) # Needs a reliable internet connection. #from MoinMoin.util.antispam import SecurityPolicy # Mail -------------------------------------------------------------- # Configure to enable subscribing to pages (disabled by default) # or sending forgotten passwords. # SMTP server, e.g. "mail.provider.com" (empty or None to disable mail) mail_smarthost = "" # The return address, e.g "My Wiki " mail_from = "" # "user pwd" if you need to use SMTP AUTH mail_login = "" # User interface ---------------------------------------------------- # Add your wikis important pages at the end. It is not recommended to # remove the default links. Leave room for user links - don't use # more than 6 short items. # You MUST use Unicode strings here, but you need not use localized # page names for system and help pages, those will be used automatically # according to the user selected language. [Unicode] navi_bar = [ # Will use page_front_page, (default FrontPage) u'%(page_front_page)s', u'RecentChanges', u'FindPage', u'HelpContents', ] # The default theme anonymous or new users get theme_default = 'modern' # Language options -------------------------------------------------- # See http://moinmoin.wikiwikiweb.de/ConfigMarket for configuration in # YOUR language that other people contributed. # The main wiki language, set the direction of the wiki pages default_lang = 'en' # You must use Unicode strings here [Unicode] page_category_regex = u'^Category[A-Z]' page_dict_regex = u'[a-z]Dict$' page_form_regex = u'[a-z]Form$' page_group_regex = u'[a-z]Group$' page_template_regex = u'[a-z]Template$' # Content options --------------------------------------------------- # Show users hostnames in RecentChanges show_hosts = 1 # Enumerate headlines? show_section_numbers = 0 # Charts size, require gdchart (Set to None to disable). chart_options = {'width': 600, 'height': 300} >>>>> FILE END >>>>>> From scott.daniels at acm.org Fri Oct 21 14:36:02 2005 From: scott.daniels at acm.org (Scott David Daniels) Date: Fri, 21 Oct 2005 11:36:02 -0700 Subject: Python vs Ruby In-Reply-To: <4358d9f6$0$19694$626a14ce@news.free.fr> References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> <4358d9f6$0$19694$626a14ce@news.free.fr> Message-ID: <43593468$1@nntp0.pdx.net> bruno modulix wrote: > ... Another language that failed to make it to the mainstream but is > worth giving a try is Smalltalk - the father of OOPLs (Simula being the > GrandFather). I would say Simula is the forefather of modern OOPLs, and Smalltalk is the toofather. --Scott David Daniels scott.daniels at acm.org From steve at holdenweb.com Wed Oct 5 12:40:49 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 05 Oct 2005 17:40:49 +0100 Subject: updating local() In-Reply-To: <1128530014.323801.290360@g47g2000cwa.googlegroups.com> References: <1128530014.323801.290360@g47g2000cwa.googlegroups.com> Message-ID: Flavio wrote: > Hi, > > I heard time and again that you are not _supposed_ to update the > locals dictionary. > > Can anyone tell me why, if the following code works, I should not do > this? > > # > # Extending Local namespace > # > > def fun(a=1,b=2,**args): > > print 'locals:',locals() > locals().update(args) > print locals() > > e = {'s':3,'e':4} > fun(k=10,v=32,**e) > Because it depends on the current implementation and isn't guaranteeed to work in the future. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From my_email_is_posted_on_my_website at munged.invalid Tue Oct 18 00:59:10 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Tue, 18 Oct 2005 04:59:10 GMT Subject: Microsoft Hatred FAQ References: <86h8l15n3odeetug7j231fi9rb3jrauo7h@4ax.com> Message-ID: <7809l15uqvhvmleds067rj7af6acpot47v@4ax.com> On Mon, 17 Oct 2005 19:43:16 -0700, "David Schwartz" wrote or quoted : > I understand why the argument is invalid. I'm presenting it as an >example of a similar invalid argument. Not every post is meant to contradict or inform the OP. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From kevin.bell at slcgov.com Wed Oct 5 12:33:27 2005 From: kevin.bell at slcgov.com (Bell, Kevin) Date: Wed, 5 Oct 2005 10:33:27 -0600 Subject: change a value to NULL? Message-ID: <2387F0EED10A4545A840B231BBAAC722607F0F@slcimail1.slcgov.com> Thanks, being new to this, I wasn't sure if I should use None, Null, Nope, Nada, or Nil! I'm going to be loading a list into an MS Access db. Do you know if I load None into an Access field if Access will recognize that as blank/null? I suppose I'll just go test it out. Thanks again... Kevin Bell -----Original Message----- From: Laszlo Zsolt Nagy [mailto:gandalf at designaproduct.biz] Sent: Wednesday, October 05, 2005 10:18 AM To: Bell, Kevin; python-list at python.org Subject: Re: change a value to NULL? Bell, Kevin wrote: >I'm pulling a list of numbers from MS Excel, but occasionally if there >is no data from excel, the value is an asterisk, but I need to make it >null. > >What is the best way to do that? Thus far, I'm using: > > >for value in myRange: > try: > intV = int(value) > print intV > except: > print "its an asterisk" > > I'm affraid I did not understand what is your real problem. Here is an answer, anyway. When converting a string intoto an int, you should use TypeError to trap type errors only: try: intV = int(value) except TypeError: intV = None print intV # It will be None if 'value' is not an int Best, Les From fccoelho at gmail.com Thu Oct 6 10:04:08 2005 From: fccoelho at gmail.com (Flavio) Date: 6 Oct 2005 07:04:08 -0700 Subject: updating local() In-Reply-To: <3qkmjcFfbem9U1@uni-berlin.de> References: <1128530014.323801.290360@g47g2000cwa.googlegroups.com> <1128603314.197733.119160@g47g2000cwa.googlegroups.com> <3qkmjcFfbem9U1@uni-berlin.de> Message-ID: <1128607448.235410.152590@o13g2000cwo.googlegroups.com> Ok, its not thousands, but more like dozens of variables... I am reading a large form from the web which returns a lot of values. (I am Using cherrypy) I know I could pass these variables around as: def some_function(**variables): ... some_function(**variables) but its a pain in the neck to have to refer to them as variables['whatever']... dont you think? Flavio From digitalsuicide at gmail.com Wed Oct 12 10:18:30 2005 From: digitalsuicide at gmail.com (dataw0lf) Date: Wed, 12 Oct 2005 08:18:30 -0600 Subject: A Tree class, my $0.02 contribution to the python community. In-Reply-To: References: Message-ID: <434D1B36.4040407@gmail.com> Steve Holden wrote: > Does this type bear any relationship at all to what most people call a > tree, which is a bifurcated data structure? Or do you call it a tree for > some other reason? I'd think that the 'avl' part would answer that question. !google avl tree -- Joshua Simpson -- dataw0lf.org Lead Network Administrator/Engineer Aero-Graphics Inc. jsimpson at aero-graphics.com From dinamo99 at lycos.com Sun Oct 23 01:56:54 2005 From: dinamo99 at lycos.com (Joe) Date: Sun, 23 Oct 2005 05:56:54 GMT Subject: IDE recommendation please References: <1h4usyj.1ndvf691bu0zvuN%aleaxit@yahoo.com> <1130044581.644967.254230@g49g2000cwa.googlegroups.com> Message-ID: SPE is great I suggest you take a look at it http://www.stani.be/python/spe/ bonono at gmail.com wrote: >> On the Mac, I think the XCode integration you get with PyObjC is >> probably best. I know there are plugins for Eclipse but haven't tried >> any personally, so it's hard to make suggestions (I'm a dinosaur, and I >> prefer to develop with GVim + a command-line tool, such as Python's own >> interactive mode...). I'm not sure if BlackAdder (simplest and fastest >> to learn) and WingIDE (probably THE one most powerful Python IDE) work >> on the Mac (shame on me, as a Python AND Mac enthusiast, for not having >> tried them...), but they're surely worth investigating. Ditto for >> ActiveState's Komodo tool... >> >> >> Alex From axel at white-eagle.invalid.uk Thu Oct 13 04:23:06 2005 From: axel at white-eagle.invalid.uk (axel at white-eagle.invalid.uk) Date: Thu, 13 Oct 2005 08:23:06 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <868xx3m2ve.fsf@bhuda.mired.org> <86irw6l1mc.fsf@bhuda.mired.org> <86vf02uhae.fsf@bhuda.mired.org> Message-ID: In comp.lang.perl.misc Roedy Green wrote: > On Thu, 13 Oct 2005 01:17:45 -0400, Mike Meyer wrote >>No, that's what makes email a vector for infection. What makes using >>the address book - for whatever purpose - possible for viruses is >>having an API that allows arbitrary code to access it. But you have to >>have that API - your customers are going to insist that they be able >>to use their address book from third party applications. > An automated change of address is possible today. It would be LESS > easy to pull off under the scheme I proposed that requires digital > signatures. How? I keep my address book on my Palm as I send mail from different computers? I suspect many other people do as well. Axel From grante at visi.com Tue Oct 4 17:07:58 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 04 Oct 2005 21:07:58 -0000 Subject: Call C functions from Python References: <1128454231.381256.297280@g47g2000cwa.googlegroups.com> <11k5mpg999eos1f@corp.supernews.com> <1128457689.105158.24700@g44g2000cwa.googlegroups.com> Message-ID: <11k5rpekldqd29e@corp.supernews.com> On 2005-10-04, Java and Swing wrote: > ok i got ctypes...now i try > >>> from ctypes import * >>> myApp = CDLL("C:\\myapp.dll") I've never seen that sort of usage before. I don't know what CDLL does, and I can't find it in the docs anywhere. Based on my reading of the tutorial, I would have tried eitehr myApp = cdll.myapp or myApp = cdll.LoadLibrary("C:/myapp.dll") > ..now how can I call functions on in myapp.dll? From the > tutorial I am not sure.. Assuming CDLL did something equivalent to cdll.LoadLibrary(), I'd try: myApp.FuncName() I've always done it the way it's done in the tutorial: mylib = windll.Lib_Name mylib.myFuncName() > i try, dir(cdll.myApp) and dir(myApp)..but don't see my > functions listed. I don't think dir() works on dll's like that. I certainly don't see it mentioned in the tutorial. What happened when you tried calling the function the way the tutorial does? myapp = cdll.myapp myapp.MyFunc() -- Grant Edwards grante Yow! Yow! Is my fallout at shelter termite proof? visi.com From aleaxit at yahoo.com Sun Oct 23 12:36:33 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 23 Oct 2005 09:36:33 -0700 Subject: Python vs Ruby References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> <1129883505.814349.306860@g44g2000cwa.googlegroups.com> <86fyqt9j9x.fsf@bhuda.mired.org> <1h4ukde.1gc4cgu1a252ggN%aleaxit@yahoo.com> <86y84k95c5.fsf@bhuda.mired.org> Message-ID: <1h4vl5j.1sg46l1irzgfmN%aleaxit@yahoo.com> Mike Meyer wrote: ... > > Of course, these results only apply where the "complexity" (e.g., number > > of operators, for example) in a single line of code is constant. > > I'm not sure what you're trying to say here. The tests ranged over > things from PL/I to assembler. Are you saying that those two languages > have the same "complexity in a single line"? Not necessarily, since PL/I, for example, is quite capable of usages at extremes of operator density per line. So, it doesn't even have "the same complexity as itself", if used in widely different layout styles. If the studies imply otherwise, then I'm reminded of the fact that both Galileo and Newton published alleged experimental data which can be shown to be "too good to be true" (fits the theories too well, according to chi-square tests etc)... > > for item in sequence: blaap(item) > > > > or > > > > for item in sequence: > > blaap(item) > > > > are EXACTLY as easy (or hard) to write, maintain, and document -- it's > > totally irrelevant that the number of lines of code has "doubled" in the > > second (more standard) layout of the code!-) > > The studies didn't deal with maintenance. They only dealt with > documentation in so far as code was commented. > > On the other hand, studies of reading comprehension have shown that > people can read and comprehend faster if the line lengths fall within > certain ranges. While it's a stretch to assume those studies apply to > code, I'd personally be hesitant to assume they don't apply without > some reseach. If they do apply, then your claims about the difficulty > of maintaining and documenting being independent of the textual line > lengths are wrong. And since writing code inevitable involves > debugging it - and the studies specified debugged lines - then the > line length could affect how hard the code is to write as well. If time to code depends on textual line lengths, then it cannot solely depend on number of lines at the same time. If, as you say, the studies "prove" that speed of delivering debugged code depends strictly on the LOCs in the delivered code, then those studies would also be showing that the textual length of the lines is irrelevant to that speed (since, depending on coding styles, in most languages one can trade off textually longer lines for fewer lines). OTOH, the following "mental experiment" shows that the purported deterministic connection of coding time to LOC can't really hold: say that two programmers, Able and Baker, are given exactly the same task to accomplish in (say) language C, and end up with exactly the same correct source code for the resulting function; Baker, being a honest toiling artisan, codes and debugs his code in "expansive" style, with lots of line breaks (as lots of programming shops practice), so, given the final code looks like: while (foo()) { bar(); baz(); } (etc), he's coding 5 lines for each such loop; Able, being able, codes and debugs extremely crammed code, so the same final code looks, when Able is working on it, like: while (foo()) { bar(); baz(); } so, Able is coding 1 line for each such loop, 5 times less than Baker (thus, by hypothesis, Able must be done 5 times faster); when Able's done coding and debugging, he runs a "code beautifier" utility which runs in negligible time (compared to the time it takes to code and debug the program) and easily produces the same "expansively" laid-out code as Baker worked with all the time. So, Able is 5 times faster than Baker yet delivers identical final code, based, please note, not on any substantial difference in skill, but strictly on a trivial trick hinging on a popular and widely used kind of code-reformatting utility. Real-life observation suggests that working with extremely crammed code (to minimize number of lines) and beautifying it at the end is in fact not a sensible coding strategy and cannot deliver such huge increases in coding (and debugging) speed. Thus, either those studies or your reading of them must be fatally flawed in this respect (most likely, some "putting hands forward" footnote about coding styles and tools in use was omitted from the summaries, or neglected in the reading). Such misunderstandings have seriously damaged the practice of programming (and managements of programming) in the past. For example, shops evaluating coders' productivity in terms of lines of code have convinced their coders to distort their style to emit more lines of code in order to be measured as more productive -- it's generally trivial to do so, of course, in many cases, e.g. for i in range(100): a[i] = i*i can easily become 100 lines "a[0] = 0" and so on (easily produced by copy and paste or editor macros, or other similarly trivial means). At the other extreme, some coders (particularly in languages suitable for extreme density, such as Perl) delight in producing "one-liner" (unreadable) ``very clever'' equivalents of straightforward loops that would take up a few lines if written in the obvious way instead. The textual measure of lines of code is extremely easy to obtain, and pretty easy to adjust to account for some obvious first-order effects (e.g., ignoring comments and whitespace, counting logical lines rather than physical ones, etc), and that, no doubt, accounts for its undying popularity -- but it IS really a terrible measurement for "actual program size and complexity". Moreover, even if you normalized "program size" by suitable language specific factors (number of operators, decision points, cyclomatic complexity, etc), the correlation between program size and time to code it would still only hold within broadly defined areas, not across the board. I believe "The mythical man-month" was the first widely read work to point out how much harder it is to debug programs that use unrestrained concurrency (in today's terms, think of multithreading without any of the modern theory and helpers for it), which Brooks called "system programs", compared to "ordinary" sequential code (which Brooks called "application programs" -- the terminology is quite dated, but the deep distinction remains valid). Also: one huge monolithic program using global variables for everything is going to have complexity (and time to delivery of debugged code) that grows way more than linearly with program size; to keep a relation that's close to linear (though in no case can exact linearity be repeatably achieved for sufficiently large programming systems, I fear), we employ a huge variety of techniques to make our software systems more modular. It IS important to realize that higher level languages, by making programs of equivalent functionality (and with comparable intrinsic difficulty, modularity, etc) "textually smaller" (and thereby "conceptually" smaller), raises program productivity. But using "lines of code", without all the appropriate qualifications, for these measurements, is not appropriate. Even the definition of a language's level in terms of LOCs per function point is too "rough and ready" and thus suffers from this issue (function points as a language-independent measure of a coding task's "size" have their own issues, but much smaller ones than LOCs as a measure of a delivered code's size). Consider the analogy of measuring a writing task (in, say, English) by number of delivered words -- a very popular measure, too. No doubt, all other things being equal, it may take a writer about twice as much to deliver 2000 copy-edited words than to deliver 1000. But... all other things are rarely equal. To me, for example, it often comes most natural to take about 500 words to explain and illustrate one concept; but when I need to be concise, I will then take a lot of time to edit and re-edit that text until just about all of the same issues are put across in 200 words or less. It may take me twice as long to rewrite the original 500 words into 200, as it took to put down the 500 words in the first place -- which helps explains why many of my posts are so long, as I don't take all the time to re-edit them, and why it taks so long to write a "Nutshell" series book, where conciseness is crucial. Nor it is only my own issue... remember Pascal's "Lettres Provinciales", and the famous apology about "I am sorry that this letter is so long, but I did not have the time to write a shorter one"!-) Alex From my_email_is_posted_on_my_website at munged.invalid Tue Oct 18 22:51:06 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 19 Oct 2005 02:51:06 GMT Subject: Microsoft Hatred FAQ References: <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <867jcbzdw9.fsf@bhuda.mired.org> Message-ID: On Tue, 18 Oct 2005 11:53:29 -0700, "David Schwartz" wrote or quoted : >>> >>> Wrong. The only obligation Microsoft has is to their shareholders. >> >> If you genuinely believe that, you are a psychopath. > > That's almost as convincing as "that's what you think". If your only obligation is to a group of person, that makes you a sort of slave. What about obligations to family, community, yourself? -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From mde at micah.elliott.name Mon Oct 17 12:57:49 2005 From: mde at micah.elliott.name (Micah Elliott) Date: Mon, 17 Oct 2005 09:57:49 -0700 Subject: Run process with timeout In-Reply-To: <1h4kw2y.1r4xzk31tnakucN%aleaxit@yahoo.com> References: <1129547240.998935.126970@g14g2000cwa.googlegroups.com> <1h4kw2y.1r4xzk31tnakucN%aleaxit@yahoo.com> Message-ID: <20051017165749.GF5267@kitchen.client.attbi.com> On Oct 17, Alex Martelli wrote: > Natan wrote: > > I have a python script under linux where I poll many hundreds of > > interfaces with mrtg every 5 minutes. Today I create some threads and > > use os.system(command) to run the process, but some of them just hang. > > I would like to terminate the process after 15 seconds if it doesn't > > finish, but os.system() doesn't have any timeout parameter. > > Use the subprocess module. With a subprocess.Popen object, you can > ... kill it (use its .pid attribute). The problem I've run into with this approach is the inability to kill the pid's children. Most often I'm not so fortunate to be able to depend on the process to not be doing its own forking. So here's a simplified use case: $ cat sleep10.sh #! /bin/bash sleep 10 # does not get killed $ $ cat to3.py #! /usr/bin/env python from subprocess import Popen from time import sleep from os import kill from signal import SIGTERM p = Popen(['./sleep10.sh']) sleep(3) kill(p.pid, SIGTERM) # Oops, won't kill p.pid's children. ##kill(-p.pid, SIGTERM) # Won't work since not group leader, # and I'd rather avoid fork/dup/exec. $ $ ./to3.py $ # to3.py finished but sleep 10 still running If you try this you will see that sleep10.sh gets killed, but its "sleep 10" subprocess does not, and runs for an additional 7 seconds. I presently rely on an ugly script to do this properly. It uses low level calls such as pipe, close, dup2, fork, exec, setpgrp, etc. I won't post that here for brevity's sake (unless requested). For this case it would fork/exec sleep10.sh, make it a group leader, and the parent would kill its group. Is there any way to enable Python's subprocess module to do (implicit?) group setup to ease killing of all children? If not, is it a reasonable RFE? -- Micah Elliott From lard at tardis.ed.ac.molar.uk Mon Oct 31 06:40:32 2005 From: lard at tardis.ed.ac.molar.uk (Alex Hunsley) Date: Mon, 31 Oct 2005 11:40:32 GMT Subject: data hiding/namespace pollution In-Reply-To: <87zmopnco7.fsf@linux.site> References: <4365f743$0$9485$636a15ce@news.free.fr> <87zmopnco7.fsf@linux.site> Message-ID: Jorge Godoy wrote: > Alex Hunsley writes: > > >>Sorry, I wasn't being clear. What I should have said is that I don't like the >>idea of a typo in an assignment causing the assigning of the wrong thing. >>e.g. imagine a simple value-holding class: >> >>class Values: >> pass >> >>v = Values() >> >>v.conductoin = 10 >> >> >>... I meant to type 'conduction' in the source but spelt it wrong. >>My value won't be there when elsewhere I refer to the correct attribute: >>"conduction". > > > Recently there was a big thread where that was raised again (yep, you're not > the first, nor the second, nor the third...). You should write unittests, use > tools like pychecker, pylint, etc. Btw, can you recall the subject line of the thread? I'd like to google groups for it and have a read of that thread... ta! alex > From bretthoerner at gmail.com Mon Oct 10 21:51:02 2005 From: bretthoerner at gmail.com (Brett Hoerner) Date: 10 Oct 2005 18:51:02 -0700 Subject: Newbie needs help. Setting PYTHONDOCS to read HTML. In-Reply-To: References: Message-ID: <1128995462.893750.155420@o13g2000cwo.googlegroups.com> You can use Python regardless of the docs... of course. Not sure what you mean there. As far as setting an Environment Variable, though: (1) Right-Click My Computer, go to Properties (2) Go to the Advanced tab (3) Click Environment Variables (bottom middle-ish) (4) Under "User Variables" click New, (5) Variable name: PYTHONDOCS Variable value: C:\Python24 Of course, the value needs to be the correct folder that you said you dropped the HTML docs into. From johnnyandfiona at hotmail.com Tue Oct 11 05:57:22 2005 From: johnnyandfiona at hotmail.com (Johnny Lee) Date: 11 Oct 2005 02:57:22 -0700 Subject: A problem while using urllib Message-ID: <1129024641.113182.74420@g49g2000cwa.googlegroups.com> Hi, I was using urllib to grab urls from web. here is the work flow of my program: 1. Get base url and max number of urls from user 2. Call filter to validate the base url 3. Read the source of the base url and grab all the urls from "href" property of "a" tag 4. Call filter to validate every url grabbed 5. Continue 3-4 until the number of url grabbed gets the limit In filter there is a method like this: -------------------------------------------------- # check whether the url can be connected def filteredByConnection(self, url): assert url try: webPage = urllib2.urlopen(url) except urllib2.URLError: self.logGenerator.log("Error: " + url + " ") return False except urllib2.HTTPError: self.logGenerator.log("Error: " + url + " not found") return False self.logGenerator.log("Connecting " + url + " successed") webPage.close() return True ---------------------------------------------------- But every time when I ran to the 70 to 75 urls (that means 70-75 urls have been tested via this way), the program will crash and all the urls left will raise urllib2.URLError until the program exits. I tried many ways to work it out, using urllib, set a sleep(1) in the filter (I thought it was the massive urls crashed the program). But none works. BTW, if I set the url from which the program crashed to base url, the program will still crashed at the 70-75 url. How can I solve this problem? thanks for your help Regards, Johnny From steve at holdenweb.com Fri Oct 7 08:56:14 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 07 Oct 2005 13:56:14 +0100 Subject: "no variable or argument declarations are necessary." In-Reply-To: <43465736$0$11160$626a14ce@news.free.fr> References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net><1128306351.13c600edac4bfa99f9f10238681bf68f@teranews><3qi8erFf252rU1@uni-berlin.de><3qkdbrFfgga9U1@uni-berlin.de><3qkn7qFffkl6U1@uni-berlin.de><3qkr1hFfgj5uU1@uni-berlin.de><7xr7ax690j.fsf@ruckus.brouhaha.com><1128676408.129888.297840@g <434651f4$0$11145$626a14ce@news.free.fr <43465736$0$11160$626a14ce@news.free.fr> Message-ID: Christophe wrote: > Fredrik Lundh a ?crit : > >>"Christophe" wrote: >> >> >> >>>It's more of a "Nearly too late" type checking I would say. Not that I >>>complain but it would be great if there were also some automatic type >>>checking to catch a few errors as soon as possible. >> >> >>use assert as the soonest possible point. implementing "type gates" is >>trivial, if you think you need them. > > > Still, it would be great if there were also some automatic type checking > in place. Using assert is hardly automatic and non intrusive. > > I mean, why not ? Why does the compiler let me do that when you know > perfectly that that code is incorrect : > def f(): > return "a" + 5 > > Of course the system can't be perfect but it doesn't need to be. It > doesn't need to constrain us in any way but if it can detect some errors > early, then it is worth it. While this is a perfectly acceptable feature request, we should remember that Python is developed and maintained by a volunteer team. Do we *really* want them spending their time adding "features" like this? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From christian at spam.not Fri Oct 21 07:29:18 2005 From: christian at spam.not (Christian) Date: Fri, 21 Oct 2005 13:29:18 +0200 Subject: Set an environment variable In-Reply-To: References: <43573022$0$155$edfadb0f@dread16.news.tele.dk> <1129798724.366618.194650@g44g2000cwa.googlegroups.com> <43589205$0$125$edfadb0f@dread16.news.tele.dk> Message-ID: <4358d112$0$187$edfadb0f@dread16.news.tele.dk> Steve Holden wrote: > :::::::::::::: > one.py > :::::::::::::: > import os > os.environ['STEVE'] = "You are the man" > os.system("python two.py") > print "Ran one" > :::::::::::::: > two.py > :::::::::::::: > import os > print "STEVE is", os.environ['STEVE'] > print "Ran two" > [sholden at headrat tmp]$ python one.py > STEVE is You are the man > Ran two > Ran one > [sholden at headrat tmp]$ > > Hope this helps. > > regards > Steve Thanks Steve, you're quite right, you are the man. And thanks to all the rest of you for your kind help and patient understanding. I have learned quite a lot and is about to consider my self advanced to the status of Python newbie. So here is my final question: Do I call the .sh script with a .py script like this: os.system("/path/to/the/script/startupscript.sh") From mystilleef at gmail.com Tue Oct 11 06:30:23 2005 From: mystilleef at gmail.com (Mystilleef) Date: 11 Oct 2005 03:30:23 -0700 Subject: Let My Terminal Go References: <1129010288.251817.147690@z14g2000cwz.googlegroups.com> <1129012665.29863.2.camel@blackwidow> Message-ID: <1129026623.319531.97420@g43g2000cwa.googlegroups.com> Hello, Thank you. That's all I needed. For some reason, I had always assumed forking was an expensive process. I guess I was ill-informed. From dudufigueiredo at gmail.com Mon Oct 31 13:52:27 2005 From: dudufigueiredo at gmail.com (dudufigueiredo at gmail.com) Date: 31 Oct 2005 10:52:27 -0800 Subject: Rename files with numbers In-Reply-To: References: <1130776390.085587.116270@g43g2000cwa.googlegroups.com> Message-ID: <1130784747.373637.108040@g14g2000cwa.googlegroups.com> Ok, so the function simplifyed without loops: def renamer(folder, band): archive = #file to transform rest = archive[3:] print band + " -",rest.capitalize() obs: the file names came this way(with spaces or apostrophes) from the cd i imported. From jepler at unpythonic.net Fri Oct 7 15:01:44 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Fri, 7 Oct 2005 14:01:44 -0500 Subject: 2d array slicing problem In-Reply-To: <1128704653.953332.218930@g47g2000cwa.googlegroups.com> References: <1128704653.953332.218930@g47g2000cwa.googlegroups.com> Message-ID: <20051007190144.GA19288@unpythonic.net> Do you have a simple program that demonstrates the problem? I have an x86 machine with Python 2.3, and an x86_64 machine with Python 2.4 available. I wrote a simple test program which performs a slice operation, but it behaves the same on both platforms. Here's the program: #------------------------------------------------------------------------ import numarray, sys, os print "python: ", sys.version_info print "numarray:", numarray.__version__ print "CPU: ", os.uname()[-1] n = numarray.arange(10) o = numarray.outerproduct(n,n) p = o[3:7,6:10].copy() q = numarray.outerproduct([3,4,5,6], [6,7,8,9]) print "Success: ", numarray.alltrue(p.ravel() == q.ravel()) #------------------------------------------------------------------------ Here are the two results I gathered: python: (2, 4, 1, 'final', 0) numarray: 1.3.3 CPU: x86_64 Success: True python: (2, 3, 2, 'final', 0) numarray: 0.9 CPU: i686 Success: 1 Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From pink at odahoda.de Fri Oct 28 06:08:20 2005 From: pink at odahoda.de (Benjamin Niemann) Date: Fri, 28 Oct 2005 12:08:20 +0200 Subject: How to translate python into C References: <1130491053.787273.201650@g44g2000cwa.googlegroups.com> Message-ID: Johnny Lee wrote: > Hi, > First, I want to know whether the python interpreter translate the > code directly into machine code, or translate it into C then into > machine code? Neither this nor that. The interpreter first compiles the code into python 'byte code' - something similar to machine code, but not it is not targeted at the CPU of your system, but for a portable virtual machine. This virtual machine will then execute the byte code, just like a CPU would execute machine code. > Second, if the codes are translated directly into machine codes, how > can I translate the codes into C COMPLETELY the same? if the codes are > translated first into C, where can I get the C source? You may have a look at PyPy. I do not know what it exactly can do, but this might be interesting for you: http://codespeak.net/pypy/dist/pypy/doc/faq.html#how-do-i-compile-my-own-programs -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ From fredrik at pythonware.com Tue Oct 25 03:53:53 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 25 Oct 2005 09:53:53 +0200 Subject: pickle References: <1130223861.28336.6.camel@blackwidow> <1d987df30510250023u5d679c9co4cd6f960df6edf1b@mail.gmail.com> Message-ID: Shi Mu wrote: > what does the following code mean? > > y = pickle.load(file("cnumber.pickle", "r")) open the file "cnumber.pickle" for reading, pass the file handle to the pickle.load function, and store the result in the "y" variable. > also, I can not understand "f" in pickle.dump(x, f) the second argument to pickle is a file handle, opened for writing. pickle.dump will save the "pickled data" to that file. From steve at holdenweb.com Thu Oct 13 03:04:04 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 13 Oct 2005 08:04:04 +0100 Subject: Adding a __filename__ predefined attribute to 2.5? In-Reply-To: <1129154738.455062.140750@f14g2000cwb.googlegroups.com> References: <1129098667.336115.303060@g47g2000cwa.googlegroups.com> <1129103007.870187.101790@g44g2000cwa.googlegroups.com> <1129150883.303899.259570@g43g2000cwa.googlegroups.com> <1h4ce9x.v65tbpm7xivfN%aleax@mail.comcast.net> <1129154738.455062.140750@f14g2000cwb.googlegroups.com> Message-ID: <434E06E4.8090609@holdenweb.com> Rune Strand wrote: > Ok, Alex. I know a good explanation when I see one. Thanks! > Make that "...when someone beats me over the head with it" ;-) Glad you have the explanation you needed, anyway. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From steve at rueb.com Sun Oct 2 14:43:16 2005 From: steve at rueb.com (Steve Bergman) Date: Sun, 02 Oct 2005 13:43:16 -0500 Subject: Distributing programs In-Reply-To: <43402562.284351435@news.xs4all.nl> References: <43402562.284351435@news.xs4all.nl> Message-ID: <43402A44.6070501@rueb.com> Wouter van Ooijen (www.voti.nl) wrote: >Yes, and you must also include a blank sheet, signed by you in blood. > > I thought you only had to do that if you were submitting a patch to MySQL, Qt, OpenOffice, or OpenSolaris. ;-) -Steve Bergman From gregpinero at gmail.com Wed Oct 12 12:04:08 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Wed, 12 Oct 2005 12:04:08 -0400 Subject: Windows memory pointers in Python? Message-ID: <312cfe2b0510120904v6bb0d008ub32a00659efd6699@mail.gmail.com> Hi guys, I'm really lost of on this one. How can I turn this (VB?) code into Python? Basically I call a function exposed from a dll and it returns me what I believe is a pointer to a location in memory? Now I need to read that area to get the string I need. This link has the solution but it is written in VB: http://www.contactreview.com/mb/showflat.php/Cat/0/Number/15670/an/0/page/14(it's the third post down) I have to think Python would have something similiar. Below is my relevant source code just in case you need that too. I really appriciate any help anyone might have. -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com ) #---My code: (testing the GOLDMINE API) from ctypes import * windll.LoadLibrary('GM6S32.dll') windll.GM6S32.GMW_LoadBDE('J:\\','J:\\GMBase\\',r'J:\\Common\\','user','pw') windll.GM6S32.GMW_NV_SetValue(container,"AccountNo", "(310)555-1212") #finally, I call a function to see what I stored: windll.GM6S32.GMW_NV_GetValue(container, "AccountNo", "'(none)'") #it returns 16236360 #Now I need to access the string related to this somewhere ... -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVETHIScyber.com.au Sat Oct 15 15:22:51 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 16 Oct 2005 05:22:51 +1000 Subject: Comparing lists References: <1128930699.799657.146210@g47g2000cwa.googlegroups.com> <1128952417.0544cc73190bbbd4e683448c137969c8@teranews> <434ba977@nntp0.pdx.net> <1129216693.445956.155490@g47g2000cwa.googlegroups.com> Message-ID: On Sat, 15 Oct 2005 18:17:36 +0200, Christian Stapfer wrote: >>> I'd prefer a (however) rough characterization >>> of computational complexity in terms of Big-Oh >>> (or Big-whatever) *anytime* to marketing-type >>> characterizations like this one... >> >> Oh how naive. > > Why is it that even computer science undergrads > are required to learn the basics of Big-Oh and > all that? So that they know how to correctly interpret what Big O notation means, instead of misinterpreting it. Big O notation doesn't tell you everything you need to know to predict the behaviour of an algorithm. It doesn't even tell you most of what you need to know about its behaviour. Only actual *measurement* will tell you what you need to know. Perhaps you should actually sit down and look at the assumptions, simplifications, short-cuts and trade-offs that computer scientists make when they estimate an algorithm's Big O behaviour. It might shock you out of your faith that Big O is the be all and end all of algorithm planning. For all but the simplest algorithm, it is impractical to actually count all the operations -- and even if you did, the knowledge wouldn't help you, because you don't know how long each operation takes to get executed. That is platform specific. So you simplify. You pretend that paging never happens. That memory allocations take zero time. That set up and removal of data structures take insignificant time. That if there is an N**2 term, it always swamps an N term. You assume that code performance is independent of the CPUs. You assume that some operations (e.g. comparisons) take no time, and others (e.g. moving data) are expensive. Those assumptions sometimes are wildly wrong. I've been seriously bitten following text book algorithms written for C and Pascal: they assume that comparisons are cheap and swapping elements are expensive. But in Python, swapping elements is cheap and comparisons are expensive, because of all the heavy object-oriented machinery used. Your classic text book algorithm is not guaranteed to survive contact with the real world: you have to try it and see. Given all the assumptions, it is a wonder that Big O estimates are ever useful, not that they sometimes are misleading. [snip] >> The marketing department says: "It's O(N), so it is blindingly fast." > > I might as well interpret "blindingly fast" as meaning O(1). - Why not? > Surely marketing might also have reasoned like > this: "It's O(1), so its blindingly fast". But I *want*, nay, I *must* > know whether it is O(N) or O(1). You might _want_, but you don't _need_ to know which it is, not in every case. In general, there are many circumstances where it makes no sense to worry about Big O behaviour. What's your expected data look like? If your data never gets above N=2, then who cares whether it is O(1)=1, O(N)=2, O(N**2)=4 or O(2**N)=2? They are all about as fast. Even bubble sort will sort a three element list fast enough -- and probably faster than more complicated sorts. Why spend all the time setting up the machinery for a merge sort for three elements? [snip] >> Big O notation is practically useless for judging how fast a single >> algorithm will be, or how one algorithm compares to another. > > That's why Knuth liked it so much? > That's why Aho, Hopcroft and Ullman liked it so much? That's why Gonnet > and Baeza-Yates liked it so much? Two reasons: it is useful for telling you how a single algorithm will scale as the input increases, just as I said. And, unlike more accurate ways of calculating the speed of an algorithm from first principles, it is actually possible to do Big O calculations. No doubt the state of the art of algorithm measurements has advanced since I was an undergraduate, but certain fundamental facts remain: in order to calculate that Big O, you have to close your eyes to all the realities of practical code execution, and only consider an idealised calculation. Even when your calculation gives you constants of proportionality and other coefficients, Big O notation demands you throw that information away. But by doing so, you lose valuable information. An O(N**2) algorithm that scales like 1e-6 * N**2 will be faster than an O(N) algorithm that scales as 1e6 * N, until N reaches one million million. By tossing away those coefficients, you wrongly expect the first algorithm to be slower than the second, and choose the wrong algorithm. >> It is only useful for telling you how a single algorithm will scale as >> the input increases. > > And that's really very useful information indeed. Yes it is. Did I ever say it wasn't? > Since, given such > information for the basic data types and operations, as implemented by > the language and its standard libraries, I stand a real chance of being > able to determine the computational complexity of the > *particular*combination* of data types and algorithms of my own small > utility or of a critical piece of my wonderful and large application, on > which the future of my company depends, with some confidence and > accuracy. Yes, zero is a real chance. [snip] >> As for sets, they are based on dicts, which are effectively hash >> tables. Hash tables are O(1), unless there are collisions, > > Depending on the "load factor" of the hash tables. So we would want to > ask, if we have very large lists indeed, how much space needs to be > invested to keep the load factor so low that we can say that the > membership test is O(1). And knowing that hash tables are O(1) will not tell you that, will it? There is only one practical way of telling: do the experiment. Keep loading up that hash table until you start getting lots of collisions. > Do A-B and A&B have to walk the entire hash > table (which must be larger than the sets, because of a load factor < > 1)? Also: the conversion of lists to sets needs the insertion of N > elements into those hash tables. That alone already makes the overall > algorithm *at*least* O(N). So forget about O(log N). Yes, inserting N items into a hash table takes at least N inserts. But if those inserts are fast enough, you won't even notice the time it takes to do it, compared to the rest of your algorithm. In many algorithms, you don't even care about the time it takes to put items in your hash table, because that isn't part of the problem you are trying to solve. So in real, practical sense, it may be that your algorithm gets dominated by the O(log N) term even though there is technically an O(N) term in there. Are Python dicts like that? I have no idea. But I know how to find out: choose a problem domain I care about ("dicts with less than one million items") and do the experiment. >> in which case the more >> common algorithms degenerate to O(N). > > So here, indeed, we have the kind of reasoning that one ought to be able > to deliver, based on what's in the Python documentation. Luckily, you > have that kind the knowledge of both, how sets are implemented and what > Big-Oh attaches to the hash table operation of "look up". > In order to *enable* SUCH reasoning for *everyone*, > starting from the module interface documentation only, one clearly needs > something along the lines that I was suggesting... I don't object to having that Big O information available, except insofar as it can be misleading, but I take issue with your position that such information is necessary. [snip] >> Now run the test code: >> >> py> test_Order() >> N = 1 0.000219106674194 >> N = 10 0.000135183334351 > > Curious: N=10 takes less time than N=1? Yes, funny how real-world results aren't as clean and neat as they are in theory. There are those awkward assumptions coming to bite you again. I've done two additional tests, and get: N = 1 0.000085043907166 N = 10 0.000106656551361 N = 1 0.000497949123383 N = 10 0.000124049186707 Remember, these results are averaged over twenty trials. So why it is quicker to do work with sets of size 10 than sets of size 1? Big O notation will never tell you, because it ignores the implementation details that really make a difference. >> N = 100 0.000481128692627 > > Why do we have such a comparatively large jump here, from N=100 to > N=1000? Did hash tables overflow during conversion or something like > that? Who knows? Maybe Python was doing some garbage collection the first time I run it. I've modified my code to print a scale factor, and here is another run: N = 1 0.00113509893417 N = 10 0.000106143951416 (x 0.093511) N = 100 0.00265134572983 (x 24.978774) N = 1000 0.0057701587677 (x 2.176313) N = 10000 0.0551437973976 (x 9.556721) N = 100000 0.668345856667 (x 12.120055) N = 1000000 8.6285964489 (x 12.910376) An increase from N=1 to 1000000 (that's a factor of one million) leads to an increase in execution time of about 7600. You will notice that the individual numbers vary significantly from trial to trial, but the over-all pattern is surprisingly consistent. >> N = 1000 0.0173740386963 >> N = 10000 0.103679180145 >> N = 100000 0.655336141586 >> N = 1000000 8.12827801704 > > Doesn't look quite O(n). Not yet... No it doesn't. > >> In my humble opinion, that's not bad behaviour. It looks O(log N) to >> me, That's a mistake -- it is nowhere near O(log N). My bad. Closer to O(sqrt N), if anything. > How could that be? *Every* element of A and B must touched, if only to > be copied: that can't make it O(log(N)). And, no doubt, if you had *really enormous* lists, oh, I don't know, maybe a trillion items, you would see that O(N) behaviour. But until then, the overall performance is dominated by the smaller-order terms with larger coefficients. > Also, the conversion of lists > to sets must be at least O(N). And N isn't the right measure anyway. It > would probably have to be in terms of |A| and |B|. For example, if |A| > is very small, as compared to |B|, then A-B and A & B can be determined > rather quickly by only considering elements of A. Both lists have the same number of elements, so double N. [snip] > You must distinguish questions of principle and questions of muddling > through like this testing bit you've done. Your "question of principle" gives you completely misleading answers. Remember, you were the one who predicted that lists would have to be faster than sets. Your prediction failed miserably. > It would take me some time to > even be *sure* how to interpret the result. What's to interpret? I know exactly how fast the function will run, on average, on my hardware. I can even extrapolate to larger sizes of N, although I would be very careful to not extrapolate too far. (I predict less than 10 minutes to work on a pair of 10,000,000 element lists, and less than two hours to work on 100,000,000 element lists.) > I would never want to say > "it looks O(log N) to me", as you do, and leave it at that. Rather, I > might say, as you do, "it looks O(log N) to me", *but* then try to > figure out, given my knowledge of the implementation (performance wise, > based on information that is sadly missing in the Python documentation), > *why* that might be. Fine. You have the source code, knock yourself out. > Then, if my experiments says "it looks like O(log > N)" AND if my basic knowledge of the implementation of set and list > primitives says "it should be O(log N)" as well, I would venture, with > some *confidence*, to claim: "it actually IS O(log N)".... > > You do not compare the convert-it-to-sets-approach > to the single list-walk either. No I did not, because I didn't have a function to do it. You've got my source code. Knock yourself out to use it to test any function you like. > Supposing the OP had actually sorted > lists to begin with, then a single, simultaneous walk of the lists would > be about as fast as it can get. Very, very likely *faster* than > conversion to sets would be... Please let us know how you go with that. It should be really interesting to see how well your prediction copes with the real world. (Hint: another of those awkward little implementation details... how much work is being done in C code, and how much in pure Python? Just something for you to think about. And remember, an O(N) algorithm in Python will be faster than an O(N**2) algorithm in C... or is that slower?) -- Steven. From aleaxit at yahoo.com Mon Oct 24 11:09:13 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 24 Oct 2005 08:09:13 -0700 Subject: Python vs Ruby References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> <1129883505.814349.306860@g44g2000cwa.googlegroups.com> <86fyqt9j9x.fsf@bhuda.mired.org> <1h4ukde.1gc4cgu1a252ggN%aleaxit@yahoo.com> <86y84k95c5.fsf@bhuda.mired.org> <1h4vl5j.1sg46l1irzgfmN%aleaxit@yahoo.com> <1130154629.382286.33090@g43g2000cwa.googlegroups.com> Message-ID: <1h4xfpb.1oh4ntjwcvubfN%aleaxit@yahoo.com> Michele Simionato wrote: > Alex Martelli wrote: > > ... remember Pascal's "Lettres Provinciales", > > and the famous apology about "I am sorry that this letter is so long, > > but I did not have the time to write a shorter one"!-) > > This observation applies to code too. I usually spend most of my time > in making short programs > that would have been long. This means: Absolutely true. > cutting off non-essential features (and you can discover that a feature > is non essential only after having implemented it) This one is difficult if you have RELEASED the program with the feature you now want to remove, sigh. You end up with lots of "deprecated"s... somebody at Euro OSCON was saying that this was why they had dropped Java, many years ago -- each time they upgraded their Java SDK they found out that half their code used now-deprecated features. Still, I agree that (once in a while) accepting backwards incompatibility by removing features IS a good thing (and I look forwards a lot to Python 3.0!-). But -- the "dream" solution would be to work closely with customers from the start, XP-style, so features go into the code in descending order of urgence and importance and it's hardly ever necessary to remove them. > and/or > > rethinking the problem to a superior level of abstraction (only > possible after you have implented > the lower level of abstraction). Yep, this one is truly crucial. But if I had do nominate ONE use case for "making code smaller" it would be: "Once, And Only Once" (aka "Don't Repeat Yourself"). Scan your code ceaselessly mercilessly looking for duplications and refactor just as mercilessly when you find them, "abstracting the up" into functions, base classes, etc... Alex From inyeol.lee at siliconimage.com Tue Oct 4 14:18:38 2005 From: inyeol.lee at siliconimage.com (Inyeol Lee) Date: Tue, 4 Oct 2005 11:18:38 -0700 Subject: [OT] Re: how to debug when "Segmentation fault" In-Reply-To: <200510041122.25067.mekstran@scl.ameslab.gov> References: <200510041122.25067.mekstran@scl.ameslab.gov> Message-ID: <20051004181838.GC480@siliconimage.com> On Tue, Oct 04, 2005 at 11:22:24AM -0500, Michael Ekstrand wrote: [...] > I've never seen "stock" Python (stable release w/ only included modules) > segfault, but did see a segfault with an extension module I was using > the other week (lxml IIRC, but I'm not sure). > > - Michael So far, this is the simplest way to crash stock python, at least in Unix/Linux; $ python < /bin If you redirect directory instead of file, python crashes. I think this bug was introduced around 2.1 or 2.2, and not yet fixed as of 2.4.1. - Inyeol From peter at engcorp.com Sun Oct 16 08:33:18 2005 From: peter at engcorp.com (Peter Hansen) Date: Sun, 16 Oct 2005 08:33:18 -0400 Subject: How to get a raised exception from other thread In-Reply-To: <1129438147.182266.196790@g44g2000cwa.googlegroups.com> References: <1129326320.914350.171460@o13g2000cwo.googlegroups.com> <1129434185.879062.61600@o13g2000cwo.googlegroups.com> <1129434873.307336.112030@g47g2000cwa.googlegroups.com> <1129438147.182266.196790@g44g2000cwa.googlegroups.com> Message-ID: themightydoyle at gmail.com wrote: > Nevermind. I found a better solution. I used shared memory to create > a keep-alive flag. I then use the select function with a specified > timeout, and recheck the keep-alive flag after each timeout. As Dennis points out, your original attempt was destined to fail because you were calling the method from the main thread, not the one you wanted to kill. Threads don't magically execute any methods that are attached to the Thread instance just because they're attached. You have to actually call those methods *from* the thread, which means from the run() method or from any of the routines it calls (whether they are methods on that Thread or not), but it must be done in the context of the thread you want to raise exceptions in or it won't work. More importantly, you've now described your use case (and I hope that of the OP as well, since he hasn't replied yet): killing threads. This is an oft-discussed topic here, and searching the archives will probably give you lots more answers, but the short answer is you cannot kill a thread in Python (except by exiting the entire process). Instead, as you've discovered, you must ask it nicely to exit. The nearly canonical approach to doing that is as follows: class MyThread(threading.Thread): def __init__(self, *args, **kwargs): threading.Thread.__init__(self, *args, **kwargs) self._keepRunning = True def stop(self, timeout=None): self._keepRunning = False # optional: wait for thread to exit self.join(timeout=timeout) def run(self): while self._keepRunning: # do stuff here Now you can do things like this: thread = MyThread() thread.start() # other stuff... thread.stop() # block here until the thread exits I hope that clarifies things a little more... -Peter From steve at holdenweb.com Wed Oct 12 09:35:32 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 12 Oct 2005 14:35:32 +0100 Subject: A problem while using urllib In-Reply-To: <1129114426.017651.123560@g44g2000cwa.googlegroups.com> References: <1129024641.113182.74420@g49g2000cwa.googlegroups.com> <1h49slu.1gaj0nnmdk5ghN%aleax@mail.comcast.net> <1129089078.852454.153800@f14g2000cwb.googlegroups.com> <1129102671.990994.43590@f14g2000cwb.googlegroups.com> <434CC861.2080805@holdenweb.com> <1129114426.017651.123560@g44g2000cwa.googlegroups.com> Message-ID: Johnny Lee wrote: > Steve Holden wrote: > >>Steve Holden wrote: >> >>>Johnny Lee wrote: [...] >> >>So my conclusion is that there's something in the Cygwin socket module >>that causes problems not seen under other platforms. >> >>I couldn't find any obviously-related error in the Python bug tracker, >>and I have copied this message to the Cygwin list in case someone there >>knows what the problem is. >> >>Before making any kind of bug submission you should really see if you >>can build a program shorter that the existing 220+ lines to demonstrate >>the bug, but it does look to me like your program should work (as indeed >>it does on other platforms). >> [...] > > > But if you change urllib2 to urllib, it works under cygwin. Are they > using different mechanism to connect to the page? > I haven't looked into it that deeply. Perhaps you can take a look at the library code to see what the differences are? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From donbro at mac.com Mon Oct 31 19:02:50 2005 From: donbro at mac.com (donbro) Date: 31 Oct 2005 16:02:50 -0800 Subject: MacOS Extension Carbon.File.FSCatalogInfo file sizes should be UInt64? References: <1130736502.902026.91020@g43g2000cwa.googlegroups.com> Message-ID: <1130803369.983549.156170@o13g2000cwo.googlegroups.com> Kevin, Thanks for the tip. I'll post this to the pythonmac-sig mailing list. Don From xah at xahlee.org Mon Oct 10 02:24:47 2005 From: xah at xahlee.org (Xah Lee) Date: 9 Oct 2005 23:24:47 -0700 Subject: Pythot doc problem: lambda keyword... Message-ID: <1128925487.783702.198410@f14g2000cwb.googlegroups.com> i'm trying to lookup on the detail of language Python's ?lambda? function feature. I've seen it before, but today i need to read about it again since i'm writing. I quickly went to the index page: http://python.org/doc/2.4.1/lib/genindex.html but all i got is a LambdaType. i'm thinking, maybe built-in functions are not listed there. Lo, but map() and friends are there. O, maybe i'm confused and ?lambda? is actually a keyword by this particular language's feelings, but Lo, ?while? is certainly a keyword but it is there. Fuck the Python liers and ignorant fuckheads. Motherfucking don't know shit and yet lying thru their teeth with fanfare. (for the technical context and justification of this message, please see the essays at the bottom of: http://xahlee.org/perl-python/python.html ) Xah xah at xahlee.org ? http://xahlee.org/ From vvoipio at kosh.hut.fi Tue Oct 11 01:50:30 2005 From: vvoipio at kosh.hut.fi (Ville Voipio) Date: Tue, 11 Oct 2005 08:50:30 +0300 (EEST) Subject: Python reliability References: <434A2F31.6010507@REMOVEMEcyber.com.au> Message-ID: In article , Peter Hansen wrote: > Other than that, we had no real issues and definitely felt the choice of > Python was completely justified. I have no hesitation recommending it, > other than to caution (as I believe Paul R did) that use of new features > is "dangerous" in that they won't have as wide usage and shouldn't > always be considered "proven" in long-term field use, by definition. Thank you for this information. Of course, we try to be as conservative as possible. The application fortunately allows for this, cyclic references and new features can most probably be avoided. > Also test heavily. We were using test-driven development and had > effectively thousands of hours of run-time by the time the first system > shipped, so we had great confidence in it. Yes, it is usually much nicer to debug the software in the quiet, air-conditioned lab than somewhere in a jungle on the other side of the globe with an extremely angry customer next to you... - Ville -- Ville Voipio, Dr.Tech., M.Sc. (EE) From fairwinds at eastlink.ca Mon Oct 17 13:30:42 2005 From: fairwinds at eastlink.ca (David Pratt) Date: Mon, 17 Oct 2005 14:30:42 -0300 Subject: Stripping ASCII codes when parsing In-Reply-To: Message-ID: Hi Steve. My plan is to parse the data removing the control characters and validate to data as records are being added to a dictionary. I am going to Unicode after this step but before it gets into storage (in which case I think the translate method could work well). The encoding itself is not explicit for this data except to say that it is ASCII and that besides not using chars 0-30, ASCII 128-254 is permitted. I am not certain whether I should assume cp1252 or ISO-8859-1. I can't say that everyone is using Windows although likely vast majority for sure. Would you think it safe to unicode before or after seeking out control characters and validating stage? My validations are relatively simple but to ensure that if I am expecting a date, integer, string etc the data is what it is supposed to be, (since next stage is database), unify whitespace, remove control characters, and check for SQL strings in the data to prevent any stupid things from happening if someone wanted to be malicious. Regards, David On Monday, October 17, 2005, at 12:49 PM, Steve Holden wrote: > David Pratt wrote: > [about ord(), chr() and stripping control characters] >> Many thanks Steve. This is good information. I think this should work >> fine. I was doing a string.replace in a cleanData() method with the >> following characters but don't know if that would have done it. This >> contains all the control characters that I really know about in normal >> use. ord(c) < 32 sounds like a much better way to go and >> comprehensive. >> So I guess instead of string.replace, I should do a ... for char >> in ... and check evaluate each character, correct? - or is there a >> better way of eliminating these other that reading a string in >> character by character. >> >> '\a','\b','\e','\f','\n','\r','\t','\v','|' >> > > There are a number of different things you might want to try. One is > translate() which, given a string and a translate table, will perform > the translation all in one go. For example: > >>>> delchars = "".join(chr(i) for i in range(32)) + "|" >>>> print repr(delchars) > '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12 > \x13\x14\ > x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f|' >>>> nultxfrm = "".join(chr(i) for i in range(256)) >>>> > > So delchars is a list of characters you want to remove, and nultxfrm is > a 256-character string where the nultxfrm[n] == chr(n) - this performs > no translation at all. So then > > s = s.translate(nultxfrm, delchars) > > will remove all the "illegal" characters from s. > > Note that I am sort-of cheating here, as this is only going to work for > 8-bit characters. Once Unicode enters the picture all bets are off. > > regards > Steve > -- > Steve Holden +44 150 684 7255 +1 800 494 3119 > Holden Web LLC www.holdenweb.com > PyCon TX 2006 www.python.org/pycon/ > > -- > http://mail.python.org/mailman/listinfo/python-list > From richie at entrian.com Tue Oct 18 04:02:47 2005 From: richie at entrian.com (Richie Hindle) Date: Tue, 18 Oct 2005 09:02:47 +0100 Subject: UI toolkits for Python In-Reply-To: References: <7xslv56ud1.fsf@ruckus.brouhaha.com> <3ras6oFit2djU1@individual.net> <4350dd34$0$6774$9b4e6d93@newsread4.arcor-online.net> <863bn12k6i.fsf@bhuda.mired.org> Message-ID: [Ken] > Web interfaces are missing a lot more than this. Here are just a few > things that cannot be done with web-based interfaces (correct me > where I'm wrong): > > 1) A real word processor. http://www.writely.com/ http://www.goffice.com/ > 2) Keybindings in a web application http://rememberthemilk.com/ Google Keys (but what happened to it? It's disappeared!) > 3) Drag and drop http://www.walterzorn.com/dragdrop/dragdrop_e.htm http://qooxdoo.oss.schlund.de/demo/release/public/test/user/Index.html (pick "Drag and Drop N" from the dropdown on the right hand side of the top bar) > 4) Resizable windows (i.e. not the browser window) within the > application. http://qooxdoo.oss.schlund.de/demo/release/public/test/user/Index.html (pick "Window N" from the dropdown on the right hand side of the top bar) http://www.bindows.net/ (click "Click for a quick DEMO") > 5) Anything other than absolutely trivial graphical programs. Not sure what you mean by this... Google maps? > web interfaces are still basically forms that can contain > buttons, checkboxes, text fields, and a few other basic controls. I > wish it were otherwise. It *is* otherwise. You should follow the Ajaxian weblog here: http://www.ajaxian.com/ -- Richie Hindle richie at entrian.com From davids at webmaster.com Wed Oct 19 04:57:32 2005 From: davids at webmaster.com (David Schwartz) Date: Wed, 19 Oct 2005 01:57:32 -0700 Subject: Microsoft Hatred FAQ References: <867jcbzdw9.fsf@bhuda.mired.org> <48jbl1honbc8ccfnkuo0bjatmqi5bqfks4@4ax.com> Message-ID: "Roedy Green" wrote in message news:io1cl1tv54gs7epehprk566spfs2bln3if at 4ax.com... > On Tue, 18 Oct 2005 23:18:31 -0700, "David Schwartz" > wrote or quoted : >> Perhaps you aren't following the thread, but I was talking about the >>obligations a company has, not the obligations any individual has. And I >>was >>talking about obligations *to* individuals. > To me that makes no sense. Microsoft is an abstraction. It can't do > anything. It can't make decisions. Only the individuals to work for it > or on the board can, though they may do it in Microsoft's name. If > you want to talk about moral action, obligation etc. you can't divorce > that from the people who do the actions. If anything that makes the objection even less meaningful. The objection was: > Why should loyalty to company trump all other loyalties -- family, > law, species, community, country, religion ... ? And the answer is that I'm not talking about "loyalty to company" but loyalty to shareholders, which are people. Of course, a person is never required to do anything that actually conflicts with their conscience, although in some cases this may require you to quit. DS From john at castleamber.com Sat Oct 15 18:47:45 2005 From: john at castleamber.com (John Bokma) Date: 15 Oct 2005 22:47:45 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: Tim Roberts wrote: > Part of their behavior really escape me. The whole thing about > browser wars confuses me. Web browsers represent a zero billion > dollar a year market. Why would you risk anything to own it? Opera seems to be making money with it. Also, Firefox gets money from Google kickback. Maybe MS had a similar idea in mind, but it failed (remember how they wanted to add ads to keywords in webpages?) -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From rutt at bmi.osu.edu Tue Oct 11 15:57:09 2005 From: rutt at bmi.osu.edu (Benjamin Rutt) Date: Tue, 11 Oct 2005 15:57:09 -0400 Subject: disable Pmw.Counter? Message-ID: <5vll0zvnca.fsf@akron.bmi.ohio-state.edu> Does anyone know how to disable a Pmw.Counter? (make it so it cannot be changed, but you can still call the get() function to see its current value?) Thanks, -- Benjamin Rutt From john at castleamber.com Sat Oct 15 14:06:01 2005 From: john at castleamber.com (John Bokma) Date: 15 Oct 2005 18:06:01 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <4350b0ee$0$11061$e4fe514c@news.xs4all.nl> Message-ID: "Martin P. Hellwig" wrote: > Jeroen Wenting wrote: > >> >> Without Microsoft 90% of us would never have seen a computer more >> powerful than a ZX-81 and 90% of the rest of us would never have used >> only dumb mainframe terminals. > > At the time you "PC" guys where hacking around monochrome green and a > bit lighter green screens I was doing multi-media editing on my Amiga > 600. So perhaps we should state that we would have been a lot further > if not an incredible amount of cool technologies where bought by MS > and then simply put in the freezer to protect their future market > share. You mean like the lamp that keeps burning forever, like Philips has? > Although Commodore where never serious competitors, Because there programming skills were as worse as MS? I mean, their BASIC had only 2 instuctions: PEEK and POKE? > they had > some "intern" difficulties, too bad but life goes on. Yup, same for Acorn. Their RISC work station was the fastest computer available for home users at that moment. > To go on, stable version of truly free unix likes where released > around 1994 that was in the same time MS was working on their super > stable released windows 95 and a slightly better NT 3.5 and let me not > forget OS/2 warp 3.0 . > > I'm not a MS basher, Yet you call NT slightly better compared to Windows 95. So you have no clue what you're talking about. > hey I make money of them administrating them, > however to state that if we didn't had MS we would been in the IT > stone ages is blatantly wrong, Now there is truth. > I think we would have been a lot > further No, since companies are just companies, not little gods like some want them to be. > then where we are now. Perhaps we even had a other mainstream > architecture like sparcs and powerpc's. But "crippled" like Intel. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From heuer at semagia.com Sat Oct 1 12:20:27 2005 From: heuer at semagia.com (Lars Heuer) Date: Sat, 1 Oct 2005 18:20:27 +0200 Subject: Nufox : Xul + Python In-Reply-To: <1128182754.232912.9980@z14g2000cwz.googlegroups.com> References: <1128163366.631178.74800@o13g2000cwo.googlegroups.com> <1128182754.232912.9980@z14g2000cwz.googlegroups.com> Message-ID: <1333220536.20051001182027@semagia.com> Hi, > Oops: > http://artyprog.noip.org:8080 Again Oops: :)) http://artyprog.no-ip.org:8080 Best regards, Lars -- http://semagia.com From http Tue Oct 4 14:43:29 2005 From: http (Paul Rubin) Date: 04 Oct 2005 11:43:29 -0700 Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> <434245F5.6060500@REMOVEMEcyber.com.au> <7xr7b14lk0.fsf@ruckus.brouhaha.com> Message-ID: <7xu0fx9l7y.fsf@ruckus.brouhaha.com> Brian Quinlan writes: > Have those of you who think that the lack of required declarations in > Python is a huge weakness given any thought to the impact that adding > them would have on the rest of the language? I can't imagine how any > language with required declarations could even remotely resemble > Python. What's the big deal? Perl has an option for flagging undeclared variables with warnings ("perl -w") or errors ("use strict") and Perl docs I've seen advise using at least "perl -w" routinely. Those didn't have much impact. Python already has a "global" declaration; how does it de-Pythonize the language if there's also a "local" declaration and an option to flag any variable that's not declared as one or the other? There's been a proposal from none other than GvR to add optional static declarations to Python: http://www.artima.com/weblogs/viewpost.jsp?thread=85551 From vishnuvyas at gmail.com Sat Oct 29 09:04:04 2005 From: vishnuvyas at gmail.com (vishnuvyas) Date: 29 Oct 2005 06:04:04 -0700 Subject: tool for syntax coloring in html In-Reply-To: <1130330426.059794.282450@g49g2000cwa.googlegroups.com> References: <1130330426.059794.282450@g49g2000cwa.googlegroups.com> Message-ID: <1130591044.737746.232800@g47g2000cwa.googlegroups.com> I use htmlize for that. you can try that. http://fly.srk.fer.hr/~hniksic/emacs/htmlize.el From davids at webmaster.com Wed Oct 19 06:19:04 2005 From: davids at webmaster.com (David Schwartz) Date: Wed, 19 Oct 2005 03:19:04 -0700 Subject: Microsoft Hatred FAQ References: <86ll0vs1sw.fsf@bhuda.mired.org> <867jcbzdw9.fsf@bhuda.mired.org> <4vcbl1dkek9kr86embmgrj70vk945t99ho@4ax.com> <35jbl1dprs4v1o87i0tapc2husjqiqm6fi@4ax.com> <4355ea72$1_3@news.melbourne.pipenetworks.com> Message-ID: "Antoon Pardon" wrote in message news:slrndlc55k.9v5.apardon at rcpc42.vub.ac.be... > A company figures out something is wrong with one of their new models. > They have two options. They can repair the problem or they can leave > it as is and brace the laswsuits that will likely follow. An analysis > shows that the first option is likely to cost more than the second. > > As far as I understand you, the company should ship the faulty model. It is impossible to respond to this with anything shorter than many pages. Google for "prudent predator" if you want all sides to this question. The short answer is "maybe". To the people who think that you obviously shouldn't, ask them the following hypothetical: You have a million pounds of grain. Destroying it will probably cost at least ten lives due to starvation. The grain, however, is contaminated, and selling it will likely make ten people sick, of which three will probably die. Should you destroy the grain? You do have an obligation to the shareholders not to commit fraud in their name. DS From john at castleamber.com Wed Oct 12 20:36:14 2005 From: john at castleamber.com (John Bokma) Date: 13 Oct 2005 00:36:14 GMT Subject: Jargons of Info Tech industry References: <1124804082_1011@spool6-east.superfeed.net> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <86y853mzmr.fsf@bhuda.mired.org> <86mzlil269.fsf@bhuda.mired.org> Message-ID: Roedy Green wrote: > On 12 Oct 2005 01:43:32 GMT, John Bokma wrote > or quoted : > >>> So let's say I decide to send an email to Donald Knuth. >> >>:-) > > I did write him, snail mail, and he responded giving us permission to > rewrite any of the algorithms in his famous set of books in to Java. Like I quoted, he does even get (some) email (printed out that is) :-). But I think snail mail is better. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From david.rasmussen at gmx.net Mon Oct 31 02:26:04 2005 From: david.rasmussen at gmx.net (David Rasmussen) Date: Mon, 31 Oct 2005 08:26:04 +0100 Subject: Scanning a file In-Reply-To: <4363fdd4$0$2107$edfadb0f@dtext02.news.tele.dk> References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <4363fdd4$0$2107$edfadb0f@dtext02.news.tele.dk> Message-ID: <4365c6f9$0$2085$edfadb0f@dtext02.news.tele.dk> No comments to this post? /David From piet at cs.uu.nl Sun Oct 30 09:23:59 2005 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sun, 30 Oct 2005 15:23:59 +0100 Subject: popen2 References: <1130524659.070912.256550@o13g2000cwo.googlegroups.com> <11m6tj5q9rskma1@corp.supernews.com> <11m7na4je921j89@corp.supernews.com> Message-ID: >>>>> Grant Edwards (GE) wrote: >GE> On 2005-10-29, Piet van Oostrum wrote: >GE> That would require that the application know about the named >GE> pipe and open it. I don't think there is any way to swap a >GE> pipe in for stdin/stdout once a process is running. >>> >>> Sure. 'myprogram' should be designed to communicate through a >>> named pipe, or be called with named pipe(s) as stdin/stdout. >GE> That's all well and good, but it's got nothing to do with the >GE> OP's problem: he's got a program that's already running and he >GE> wants to write a Python program that can "attach" pipes to that >GE> already running program's stdin/stdout. He didn't state that he has no control over that program. I.e. if it is a program that he has source code of, he could change its behaviour to use a named pipe. -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From deets at web.de Wed Oct 12 11:18:19 2005 From: deets at web.de (Diez B. Roggisch) Date: 12 Oct 2005 08:18:19 -0700 Subject: Adding a __filename__ predefined attribute to 2.5? In-Reply-To: <1129108543.596435.200600@g47g2000cwa.googlegroups.com> References: <1129098667.336115.303060@g47g2000cwa.googlegroups.com> <1129103007.870187.101790@g44g2000cwa.googlegroups.com> <3r3u8kFhhsqmU1@uni-berlin.de> <1129108543.596435.200600@g47g2000cwa.googlegroups.com> Message-ID: <1129130299.270571.113250@z14g2000cwz.googlegroups.com> Rune Strand wrote: > Excuse me, do you suffer from a bad hair-day? I didn't say it is > platform independant. It's ok for my use on Linux and Windows. If you > cannot imagine any other usecase for a __filename__ attribute, that's > your problem, not mine. I think you are the one who wants __filename__, not me. So I don't have to have any usecase for it. And requesting random features built into the interpreter without even specifying a usecase - as remote as it may be - isn't very likely happen, don't you think? Which I wanted to express with my apparently misunderstood solve_my_problem()-example. And if your solution isn't platform-independent and one (several people actually) provides you with one that is short and concise and no overhead at all - well, that _could_ trigger a "cool, didn't know about that"-reaction. But obviously, it hasn't. Diez From irmen.NOSPAM at xs4all.nl Tue Oct 4 13:31:23 2005 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Tue, 04 Oct 2005 19:31:23 +0200 Subject: tcp socket programming In-Reply-To: References: Message-ID: <4342bc6d$0$11074$e4fe514c@news.xs4all.nl> Mohammed Smadi wrote: > hi; > If i have a tcp connection with a remote server, what is a good way to > read all the data into a buffer before starting to process the data? > I know that the data recieved will be 3 lines with CRLF between them. > However if I can sock.recv(1024) the output is not consistent all the > time, sometime i get one line and sometimes i get two. So I figures I > should read all the data first then work on it and I used the following > code: > result = [] > while True: > got=s.recv(1024) > print got > if not got: break > result.append(got) > got = [] # i tried also taking this out > s.close() > > but this code just hangs in the loop and never quits ... because it doesn't 'know' when to stop reading. The socket recv() returns anything from 0 to 1024 bytes depending on the amount of data that is available at that time. You have to design your wire protocol a bit differently if you want to do this in a consistent, reliable way. For instance, you can decide on sending *one* byte first that signifies the amount of bytes to read after that. (limiting the size to 255 ofcourse). Or you will have to change your read-loop to read until it encountered the third CRLF occurrence (and no more!) The latter is actually quite easily done by not reading directly from the socket object, but first converting it to a file-like object: s=socket.socket(....) s.connect(...) fs=s.makefile() fs.readline() fs.readline() fs.readline() --Irmen. From none at no.chance Tue Oct 4 08:42:38 2005 From: none at no.chance (Peter Tillotson) Date: Tue, 04 Oct 2005 13:42:38 +0100 Subject: Python profiler In-Reply-To: References: Message-ID: look in the gc module ... Celine & Dave wrote: > Hello All, > > I am trying to find a profiler that can measure the > memory usage in a Python program. I would like to > gather some statistics about object usages. For > example, I would like to be able to see how much time > it takes to search for an item in a dict object, how > many times it has to access the symbol table to > retrieve a specific item, and things like that. > > Thanks, > > Dave > > > > __________________________________ > Yahoo! Mail - PC Magazine Editors' Choice 2005 > http://mail.yahoo.com From steve at holdenweb.com Fri Oct 7 11:55:56 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 07 Oct 2005 16:55:56 +0100 Subject: When someone from Britain speaks, Americans hear a "British accent"... In-Reply-To: <11kd19ajdtkoi6f@corp.supernews.com> References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kbgj7421kd560@corp.supernews.com> <4h5ck1hkqq0ls83pq0lodkb51tsda4053k@4ax.com> <11kd19ajdtkoi6f@corp.supernews.com> Message-ID: Grant Edwards wrote: > On 2005-10-07, Steve Holden wrote: [...] >>Then again, what can you expect from a country whose leader >>pronounces "nuclear" as though it were spelled "nucular"? > > > Don't get me started on _that_ one. I found it particularly > horrifying that Jimmy Carter pronounced it "nucular" -- he had > studied nuclear engineering at the naval acadamy, and should at > least be able pronounce the word. > > >>I suppose it's only a matter of time before they change the >>spelling just like they did with "aluminium". > > > :) > One can only hope that Bush has been control of the nuclear weapons rather than the nuclear ones. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From apgwoz at gmail.com Tue Oct 4 07:12:18 2005 From: apgwoz at gmail.com (Andrew Gwozdziewycz) Date: Tue, 4 Oct 2005 07:12:18 -0400 Subject: semi-newbie module namespace confusion In-Reply-To: <3qev4iFash6dU1@news.dfncis.de> References: <1128404572.837225.41870@g47g2000cwa.googlegroups.com> <3qer81FeldcmU1@news.dfncis.de> <3qev4iFash6dU1@news.dfncis.de> Message-ID: <24FDFC64-F509-4A8D-B0EA-479C55054EC5@gmail.com> >> > well, in my opinion python is not trying hard enough. to me it is > immediately obvious that the main module gets evaluated twice and > i am rather sure that one could introduce some magic of the kind > "oh, i reevaluate the main script here, the module does not get filled > the usual way but uses the existing objects instead". this would have > to happen on a very low level (when the file i just read from is > known) > but i think it would be possible. whether the effort to do so is worth > it, is a different question... There is an easy fix to this situation, and it's called creating a new script that imports the modules. If it's truely a module (which I guess really everything in python is), it probably should only be run by itself for testing purposes only. >>> Now i wonder how difficult it would be to "correct" the behavior? >>> >> >> there's no way to "fix" it without introducing a huge number of >> inconsistencies. Plus, it's not broken to begin with. --- Andrew Gwozdziewycz apgwoz at gmail.com http://ihadagreatview.org http://plasticandroid.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From scott.daniels at acm.org Sat Oct 29 17:13:15 2005 From: scott.daniels at acm.org (Scott David Daniels) Date: Sat, 29 Oct 2005 14:13:15 -0700 Subject: Scanning a file In-Reply-To: <3sg8hiFmvbo7U1@individual.net> References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <3sf070Fo0klqU1@individual.net> <3sg8hiFmvbo7U1@individual.net> Message-ID: <4363e506$1@nntp0.pdx.net> Paul Watson wrote: > Here is a better one that counts, and not just detects, the substring. This > is -much- faster than using mmap; especially for a large file that may cause > paging to start. Using mmap can be -very- slow. > > > ... > b = fp.read(blocksize) > count = 0 > while len(b) > be: > count += b.count(ss) > b = b[-be:] + fp.read(blocksize) > ... In cases where that one wins and blocksize is big, this should do even better: ... block = fp.read(blocksize) count = 0 while len(block) > be: count += block.count(ss) lead = block[-be :] block = fp.read(blocksize) count += (lead + block[: be]).count(ss) ... -- -Scott David Daniels scott.daniels at acm.org From __peter__ at web.de Mon Oct 17 04:36:34 2005 From: __peter__ at web.de (Peter Otten) Date: Mon, 17 Oct 2005 10:36:34 +0200 Subject: Question on class member in python References: <1129537638.714752.120290@g49g2000cwa.googlegroups.com> Message-ID: Johnny Lee wrote: > Class A: > def __init__(self): > self.member = 1 > > def getMember(self): > return self.member > > a = A() > > So, is there any difference between a.member and a.getMember? thanks > for your help. :) Yes. accessor methods for simple attributes are a Javaism that should be avoided in Python. You can always turn an attribute into a property if the need arises to do some calculations behind the scene >>> class A(object): ... def getMember(self): ... return self.a * self.b ... member = property(getMember) ... def __init__(self): ... self.a = self.b = 42 ... >>> A().member 1764 I. e. you are not trapped once you expose a simple attribute. Peter From http Thu Oct 27 16:57:29 2005 From: http (Paul Rubin) Date: 27 Oct 2005 13:57:29 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <66u633-etj.ln1@news.it.uc3m.es> <7xbr1aewtq.fsf@ruckus.brouhaha.com> <86acgulv5z.fsf@localhost.localdomain> Message-ID: <7xvezi8ypy.fsf@ruckus.brouhaha.com> "David Schwartz" writes: > Sorry to be pedantic, but I think it's an important point that no court > ever found that Microsoft illegally acquired a monopoly. So to characterize > the monopoly itself as "illegal" is simply erroneous. Who is paying you to tell these ridiculous crap? The monopoly is illegal if maintained by anticompetitive means regardless of how it was acquired. >From http://cyber.law.harvard.edu/msdoj/conclusions-l.html: Section 2 of the Sherman Act declares that it is unlawful for a person or firm to "monopolize . . . any part of the trade or commerce among the several States, or with foreign nations . . . ." 15 U.S.C. ? 2. This language operates to limit the means by which a firm may lawfully either acquire or perpetuate monopoly power. Specifically, a firm violates sec. 2 if it attains or preserves monopoly power through anticompetitive acts. The threshold element of a sec 2 monopolization offense being "the possession of monopoly power in the relevant market... David Schwartz, I have a direct question for you: are you on Microsoft's payroll? From news at NOwillmcguganSPAM.com Sat Oct 8 05:04:42 2005 From: news at NOwillmcguganSPAM.com (Will McGugan) Date: Sat, 08 Oct 2005 10:04:42 +0100 Subject: Contest snub? In-Reply-To: References: Message-ID: <43478bab$0$525$da0feed9@news.zen.co.uk> maxx at easynews.com wrote: > Notice anything strange here? The Python entry seems to have edged the PHP > entries, but is not declared the victor. Source is missing as well (the archive > is empty.) > > http://www.apress.com/promo/fractal/seesource.html > > Hmmmm... an irrational fear of snakes perhaps? Its not irrational if you are a gator! Will McGugan -- http://www.willmcgugan.com "".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in "jvyy*jvyyzpthtna^pbz") From gandalf at designaproduct.biz Thu Oct 6 05:00:54 2005 From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy) Date: Thu, 06 Oct 2005 11:00:54 +0200 Subject: Help-log in to a web page In-Reply-To: References: Message-ID: <4344E7C6.5060900@designaproduct.biz> Murugesh wrote: >Hi all, >I'm a newbie to python.I need to login to a webpage after supplying >usename and password. > >import urllib >sock = urllib.urlopen("http://xop-pc.main.com") >htmlSource = sock.read() >sock.close() >print htmlSource > >In the above code how can i supply username and password to that URL. >Thanks for you time. > > xop-pc.main.com is not an existing site. Can you tell me what kind of authentication method it is using? If that is the "basic authentication" (defined the standard HTTP protocol) then you need to read this: http://docs.python.org/lib/urlopener-objs.html Basically, you need to subclass URLopener or FancyURLopener, and overwrite its "prompt_user_passwd" method. That method will be then called whenever the server needs authentication. Here is a template for you (untested): from urllib import FancyURLOpener class MyOpener(FancyURLOpener): def prompt_user_passwd(host,realm): return ('myusername','mypassword') opener = MyOpener({}) f = opener.open("http://xop-pc.main.com") try: html_source = f.read() finally: f.close() Best, Les From lasse at vkarlsen.no Sat Oct 8 11:10:48 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Sat, 08 Oct 2005 17:10:48 +0200 Subject: Function decorator that caches function results In-Reply-To: <1128783738.588723.200130@g43g2000cwa.googlegroups.com> References: <1128783738.588723.200130@g43g2000cwa.googlegroups.com> Message-ID: Sam Pointon wrote: > What about not storing args at all? Something like this: > > def cache_function(func, args_list): > cache = {} > def cached_result(*args, **kwargs): > kwargs.update(dict(zip(args_list, args))) > if kwargs in cache: > return cache[kwargs] > result = func(**kwargs) > cache[kwargs] = result > return result > return cached_result > > args_list is a list of all the argument names, so that they can be > converted into keyword arguments. > I'll take a look at the zip function, didn't know about that one, but your example also has the problem that dictionaries can't be used as dictionary keys, but that can be easily solved. I think I can simplify my solution with some of yours. The parameter names can be gotten by doing a inspect.getargspec(fn)[0] so that can be done by the decorator function. -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From chris.cavalaria at free.fr Fri Oct 14 06:37:25 2005 From: chris.cavalaria at free.fr (Christophe) Date: Fri, 14 Oct 2005 12:37:25 +0200 Subject: Yes, this is a python question, and a serious one at that (moving to Win XP) In-Reply-To: References: Message-ID: <434f8a54$0$16641$626a14ce@news.free.fr> Kenneth McDonald a ?crit : > For unfortunate reasons, I'm considering switching back to Win XP (from > OS X) as my "main" system. Windows has so many annoyances that I can > only compare it to driving in the Bay Area at rush hour (OS X is like > driving in Portland at rush hour--not as bad, but getting there), but > there are really only a couple of things that are really, absolutely > preventing me from making the switch. Number one is the lack of a > decent command line and command-line environment, and I'm wondering > (hoping) if perhaps someone has written a "Python shell"-- something > that will look like a regular shell, let users type in commands, maybe > have some of the nice features of bash etc. like tab completion, etc, > and will then execute an underlying python script when the command is > entered. I'm not thinking of IDLE, but something that is really aimed > more at being a system terminal, not a Python- specific terminal. > > Yes, I know that Cygwin is out there, but last I looked, they still > went through the Win command-line window, which imposes a lot of > restrictions. > > More generally, has anyone written any python programs to administer > various Win settings for which one must otherwise delve deep into mazes > of twisty little dialogs, all alike? Or to help out with other > annoyances? I know there are a lot of general utilities, but if they're > in Python, I can also use them as a starting base for my own needs. > > Finally, a significant incentive in doing this is that I could avoid a > lot of installation hassle, since virtually everything has at least a > decent installation package for Win. (I'd hoped this would happen for > OS X, but it never has). Can anyone think of important python- related > packages (release level, not cutting edge alphas) for which this might > not be the case? > > Many thanks, > Ken Last time I checked, you could install a native win32gui version of rxvt with cygwin. This would give you a better terminal window than that crappy thing you get in XP. From peter at engcorp.com Mon Oct 10 22:28:28 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 10 Oct 2005 22:28:28 -0400 Subject: Why asci-only symbols? In-Reply-To: <86vf04zx0k.fsf@bhuda.mired.org> References: <86vf04zx0k.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > Out of random curiosity, is there a PEP/thread/? that explains why > Python symbols are restricted to 7-bit ascii? And of equally random curiosity :-), what alternative(s) can you suggest would have been appropriate? (I note that Unicode, for example, dates from around the time Python was first released. And I can't really imagine a non-ugly alternative, which probably reveals something bad about my imagination.) -Peter From mwm at mired.org Sun Oct 9 20:06:34 2005 From: mwm at mired.org (Mike Meyer) Date: Sun, 09 Oct 2005 20:06:34 -0400 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <868xx3m2ve.fsf@bhuda.mired.org> Message-ID: <86achikzg5.fsf@bhuda.mired.org> Roedy Green writes: > On Sun, 09 Oct 2005 05:55:01 -0400, Mike Meyer wrote > or quoted : >>Virus writers will love the ability to >>change peoples address books remotely. > Since this is just a broad brush view, I find it odd you can predict > just what bugs there will be in the early implementations. I'm not predicting bugs in the implementations. I'm predicting how people are going to abuse *features* of the implementations. > You sound almost as if you were the author of the current system and > feel personally attacked by others looking for ways to improve it. Nah, I've just know people who spend a lot of time - and money - dealing with spam, and we've discussed these issues at great length. You haven't proposed anything that hasn't been proposed before, and rejected for various reasons. > In my scheme, every message is digitally signed, even a change of > address message. Yup, I assumed that. > Surely for a virus to send out a digitally signed change of address > message is more difficult than sending out an unsigned one, which they > can do today. Maybe yes, maybe no. They can use existing APIs to send mail now. If there's an API to sign a message - and there just about has to be, otherwise changing mail readers will require sending out a change of address form to change the public key - what prevents the virus from simply using that to send out an encrpyted message? Yes, it's more difficult, just like it's more difficult to send out mail with an attachment than one that's just plain text. But the difference is just more work, not something fundamentally different. > You have two problems you want to avoid: > > 1. the practical problem: failure to inform your correspondents, not > just your address list, of your new address (at least the ones you > don't consider spam or pests). > > 2. the potential problem: rogue software sending out fake change of > address notices. > > In my scheme, The receiver of the change of address message ignores > it unless it is properly signed. Surely that is a more secure system > than we have today and that handles (1) without effort. At worst, a > very clever virus could change the one address book entry, the one for > this computer, in other's machines. It could not generally corrupt > other machines. Depends on how convenient you make things. The problems aren't technical, they're social. For instance, people will want their address book to automatically send out change of address notices to every non-pest if their address is changed. A virus can exploit this by changing the address in the address book. No need for it to send out mail - the users mail agent does it all for them. Fixing this requires convincing the users that they should do a lot of work to achieve point 1 - which sort of defeats your purpose. Personally, I don't believe that you'll convince people to take do more work to get more security. So you've got to convince all the authors who deploy mail readers - and/or key security systems - to not allow that. Since such a feature will be requested by users, and will make their software more popular, that's not going to be easy either. To be really secure, you store the private key encrypted, and ask the user for a passphrase to decrypt it every time you want to sign a message. So you make your interface do that, and it asks the user for a key every time a message is signed. For true security, you have to include the recipient address in the signatture, otherwise you're liable to replay attacks sent different addresses, so changing your address will involve providing your pass phrase once for everyone you notify. Someone else will decide that's to inconvenient, and provide an interface that stores the passphrase to reuse for some user-specified length of time. Existing systems do this, and get lots of use even thought they are less secure than doing it right. Then you'll get a interface that ask for the key once a session. Then you'll get one that asks once, and just keeps it forever. We've seen this happen with access to web site passwords. Guess which one users are going to prefer. Guess which one makes it simple for viruses to hijack they system to send out mail that "you" have signed. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From high-commander at todds-world.net Wed Oct 26 20:17:54 2005 From: high-commander at todds-world.net (Todd Beauchemin) Date: Thu, 27 Oct 2005 00:17:54 GMT Subject: RPM Modules Message-ID: Is there any documentation that shows how to use the RPM API for Python. I have found one example but it's dated 2000 and I haven't been able to get it to work :(. Thanks ~Todd From aleaxit at yahoo.com Sun Oct 30 19:15:01 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 30 Oct 2005 17:15:01 -0700 Subject: Controlling output using print with format string References: <3sl7mnFordm3U1@individual.net> Message-ID: <1h5994n.1l0ku535g7z39N%aleaxit@yahoo.com> Paul Watson wrote: > It is clear that just using 'print' with variable names is relatively > uncontrollable. However, I thought that using a format string would > reign the problem in and give the desired output. > > Must I resort to sys.stdout.write() to control output? In general, yes, because print tries hard to separate with spaces the things it is separately printing. You can fight that by resetting sys.stdout.softspace after each and every print, but that's harder than just using sys.stdout.write. So, you should use the right tool for the job: print for simple output, often diagnostic in nature, where you don't mind the spaces and/or newlines that implies; sys.stdout.write when you do want to really control every aspect of the output. Alex From codecraig at gmail.com Fri Oct 7 15:47:58 2005 From: codecraig at gmail.com (Java and Swing) Date: 7 Oct 2005 12:47:58 -0700 Subject: Help creating extension for C function Message-ID: <1128714478.552412.135950@g47g2000cwa.googlegroups.com> I need to write an extension for a C function so that I can call it from python. C code (myapp.c) ====== typedef unsigned long MY_LONG; char *DoStuff(char *input, MY_LONG *x) { ... } so you pass in a string and an array of MY_LONGS...such as MY_LONGS vals[10] = {....}; char *input = "this is my input"; char *result; result = DoStuff(input, vals); ...I need to create an extension so that I can call this from Python such as... >> import myapp >> vals = [1,2,3,4,5,6,7,8,9,10] >> input = "this is my input" >> result = myapp.DoStuff(input, vals) >> print result ideally the result would be a String, vals would be a list and input would be a string. I was hoping to follow along with how to write an extension, as shown here http://docs.python.org/ext/contents.html. ...but a better example would help. Thanks. From iainking at gmail.com Thu Oct 27 08:55:40 2005 From: iainking at gmail.com (Iain King) Date: 27 Oct 2005 05:55:40 -0700 Subject: Microsoft Hatred FAQ In-Reply-To: References: <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> <20i1m19cup3s8hb4ikqti1monvtf9nb3dv@4ax.com> Message-ID: <1130417740.645004.151310@z14g2000cwz.googlegroups.com> David Schwartz wrote: > Roedy Green wrote: > > > The particular way MS threatened to put me out of business was by > > threatening to arm twist all wholesalers to refuse to sell MS product > > to me, which any retailer needed to survive in those days. > > Right, I get that. You owed your entire business to Microsoft. Without > their products, you would have had nothing, by your own admission. The way > you repay them is by trying to screw them -- attract people who come in only > because you offer Windows and then say "here's an OS that's better and > cheaper". Oh right. You're actually just a troll. Oh well. *plonk* Iain From onurb at xiludom.gro Wed Oct 5 07:46:16 2005 From: onurb at xiludom.gro (bruno modulix) Date: Wed, 05 Oct 2005 13:46:16 +0200 Subject: "no variable or argument declarations are necessary." In-Reply-To: <86u0fxi7gf.fsf@bhuda.mired.org> References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86u0fxi7gf.fsf@bhuda.mired.org> Message-ID: <4343bd0a$0$8938$626a14ce@news.free.fr> Mike Meyer wrote: (snip) > Antoon, at a guess I'd say that Python is the first time you've > encountered a dynamnic language. Being "horrified" at not having > variable declarations, Mike, "being horrified" by the (perceived as...) lack of variable declaration was the OP's reaction, not Antoon's. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From hancock at anansispaceworks.com Fri Oct 7 01:55:25 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Fri, 7 Oct 2005 00:55:25 -0500 Subject: Where to find python c-sources In-Reply-To: References: <433e7898$0$49766$ed2e19e4@ptn-nntp-reader04.plus.net> Message-ID: <200510070055.25502.hancock@anansispaceworks.com> On Monday 03 October 2005 12:26 pm, John J. Lee wrote: > [Tor Erik S?nvisen] > > socketmodule.c, but I can't locate this file... Where should I look? > > [John, finding 'socketmodule.c' responds well to "I'm Feeling Lucky"] > > Does google vary in its results across the globe? > > [Michael] > > The search terms might be obvious to you, but it simply means your google-fu > > is strong, and the strong should help the weak. (or not attack them at > > least...) > > You believe that Tor is dumb enough not to think of searching for > "socketmodule.c" when, um, searching for socketmodule.c? No, ironically, the problem is that Tor is too *smart* to search for "socketmodule.c" -- it requires *unlearning* the experience from searching physical libraries where subject catalogs and librarians are the "search engine". They don't respond to the same type of search terms as machines do. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From fredrik at pythonware.com Tue Oct 11 06:50:05 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 11 Oct 2005 12:50:05 +0200 Subject: strange import error with Python-2.4.1 References: <434B8EDF.3060905@chamonix.reportlab.co.uk> <434B9602.9070001@holdenweb.com> Message-ID: Steve Holden wrote: > Can I ask if you are specifying a source encoding in your file with a > pragma (?) like > > # -*- coding: iso-8859-15 -*- > > I've noticed what appear to be spurious syntax errors from time to time > on such files, and have been attempting to debug the problem for some > time without any apparent success. http://www.python.org/sf/1175396 From steve at REMOVETHIScyber.com.au Sun Oct 9 06:36:09 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 09 Oct 2005 20:36:09 +1000 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> Message-ID: Oh, and another point... On Sun, 09 Oct 2005 00:03:05 +0200, Lasse V?gs?ther Karlsen wrote: > But trying to keep your email world into a pure text-based > no-formatting-whatsoever world, that's a fantasy bubble that is bound to > burst, sooner rather than later. Nonsense. I can easily set up a filter to dump non-plain text email straight into the trash. If I choose, I never need see a HTML mail. Ever. In fact, since the single strongest predictor of spam is the use of HTML, I predict that a lot more people than you think have HTML emails either deleted or dumped in a spam folder. -- Steven. From mwm at mired.org Sun Oct 16 18:23:16 2005 From: mwm at mired.org (Mike Meyer) Date: Sun, 16 Oct 2005 18:23:16 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <11l369039d6ppe0@corp.supernews.com> Message-ID: <86psq514q3.fsf@bhuda.mired.org> Greymaus writes: > Mike Meyer wrote: >> You clearly weren't paying attention to what the rest >> of the microcomputer industry was doing while Gates was selling IBM >> non-existent software. While IBM was introducing 16-bit processors and >> DOS was doing a flat file system, Tandy was selliig systems - for a >> fraction of the price of any MS-DOS based system - that were >> multitasking, multiuser, had an optional windowing system that came >> with a complete (for the time) office suite. Of course, that was while >> Tandy still thought they could sell computers by selling better >> computers than you could get running MS software. > Was that the Color Computer III running OS9 Level II for an operating > system, that you're talking about? Motorola 6809 processor? HELLUVA > little computer! OS9 was a bit quirky, though, even for a UNIX clone. Yup. OS9 wasn't really a Unix clone - it was designed as an embedded OS for instruments, and last time I looked was still around, though they had moved on to newer processors. And if you think the Coco was a helluva little computer, you should have seen what the Japanese weren't exporting. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From thorsten at thorstenkampe.de Tue Oct 18 12:08:54 2005 From: thorsten at thorstenkampe.de (Thorsten Kampe) Date: Tue, 18 Oct 2005 17:08:54 +0100 Subject: html parser? References: Message-ID: * Christoph S?llner (2005-10-18 12:20 +0100) > right, that's what I was looking for. Thanks very much. For simple things like that "BeautifulSoup" might be overkill. import formatter, \ htmllib, \ urllib url = 'http://python.org' htmlp = htmllib.HTMLParser(formatter.NullFormatter()) htmlp.feed(urllib.urlopen(url).read()) htmlp.close() print htmlp.anchorlist and then use urlparse to parse the links/urls... From mwm at mired.org Mon Oct 10 21:02:19 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 10 Oct 2005 21:02:19 -0400 Subject: Why asci-only symbols? Message-ID: <86vf04zx0k.fsf@bhuda.mired.org> Out of random curiosity, is there a PEP/thread/? that explains why Python symbols are restricted to 7-bit ascii? http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From theller at python.net Thu Oct 6 10:11:08 2005 From: theller at python.net (Thomas Heller) Date: Thu, 06 Oct 2005 16:11:08 +0200 Subject: py2exe has a new maintainer References: Message-ID: "Jimmy Retzlaff" writes: > I am taking over the maintenance and support of py2exe from Thomas > Heller. As he announced a few weeks ago he is looking to focus on other > things. py2exe has been very useful to me over the years and I look > forward to keeping it every bit as useful in the future. Jimmy, I'm very happy that you take over the py2exe package maintainace and wish you all good luck with it. Open source how it should work! Thanks again, Thomas From gene.tani at gmail.com Wed Oct 12 23:35:32 2005 From: gene.tani at gmail.com (gene tani) Date: 12 Oct 2005 20:35:32 -0700 Subject: Looking for a Python mentor In-Reply-To: <1129167866.253155.157850@g43g2000cwa.googlegroups.com> References: <1129167866.253155.157850@g43g2000cwa.googlegroups.com> Message-ID: <1129174532.546206.11810@o13g2000cwo.googlegroups.com> is this it:? http://mail.python.org/mailman/listinfo/tutor LenS wrote: > Hello > > Was wandering if there is any place where some one could go to get > mentoring on python coding. I have started coding in python but I am > the only one in the shop using it. So there is no one around to look > over my code give suggestions on improvement, in style, logic, easier > ways of doing things etc. I am not really looking for hand holding as > much mentoring. I have purchased about every python book out and have > a list a mile long on my internet bookmarks. I believe I have a good > grasp of the fundamentals procedurally and I am fighting my way through > OOP. I am more at the stage of trying to pull things together into > programs that perform real world tasks. At one point I thought I saw > some place on one of the web site that did this kind of thing but I > can't find it now. > > Any help or suggestions welcomed > Len Sumnler From uche.ogbuji at gmail.com Mon Oct 24 17:36:25 2005 From: uche.ogbuji at gmail.com (uche.ogbuji at gmail.com) Date: 24 Oct 2005 14:36:25 -0700 Subject: XML Tree Discovery (script, tool, __?) In-Reply-To: <1130183060.195730.178330@g47g2000cwa.googlegroups.com> References: <1130183060.195730.178330@g47g2000cwa.googlegroups.com> Message-ID: <1130189785.358171.307700@o13g2000cwo.googlegroups.com> "inally diving into XML programmatically. Does anyone have a best practice recommendation for programmatically discovering the structure of an arbitrary XML document via Python?" You can do this with DOM or SAX, or any of the many more friendly XML processing libraries out there. You might want to be more specific. What sort of output do you want from this discovery? -- Uche Ogbuji Fourthought, Inc. http://uche.ogbuji.net http://fourthought.com http://copia.ogbuji.net http://4Suite.org Articles: http://uche.ogbuji.net/tech/publications/ From gerrit at nl.linux.org Mon Oct 17 16:39:51 2005 From: gerrit at nl.linux.org (Gerrit Holl) Date: Mon, 17 Oct 2005 22:39:51 +0200 Subject: your mail In-Reply-To: <20051017152141.80D211E4069@bag.python.org> References: <20051017152141.80D211E4069@bag.python.org> Message-ID: <20051017203951.GA29069@topjaklont.student.utwente.nl> Finn Waldrip wrote: > X-Spambayes-Classification: unsure; 0.242 > > > 404 Not Found > >

Not Found

> The requested URL was not found on this server.

>


>
Apache/1.3.31
> How can my poor Spambayes ever make sense of this? Gerrit. -- Temperature in Lule?, Norrbotten, Sweden: | Current temperature 05-10-17 22:29:59 9.6 degrees Celsius ( 49.2F) | -- Det finns inte d?ligt v?der, bara d?liga kl?der. From pierre.barbier at cirad.fr Thu Oct 6 11:44:03 2005 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Thu, 06 Oct 2005 17:44:03 +0200 Subject: "no variable or argument declarations are necessary." In-Reply-To: <86u0fxi7gf.fsf@bhuda.mired.org> References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86u0fxi7gf.fsf@bhuda.mired.org> Message-ID: <434545b7$0$662$626a14ce@news.free.fr> Mike Meyer a ?crit : > Antoon Pardon writes: > >>Op 2005-10-03, Steven D'Aprano schreef : >> >>>On Mon, 03 Oct 2005 13:58:33 +0000, Antoon Pardon wrote: >> >>Declarations also allow easier writable closures. Since the declaration >>happens at a certain scope, the run time can easily find the correct >>scope when a variable is rebound. > > > If it happens at runtime, then you can do it without declarations: > they're gone by then. Come to think of it, most functional languages - > which are the languages that make the heaviest use of closures - don't > require variable declarations. Well, can you give a single example of such language ? Because all the functionnal language I know but one do need variable declaration : lisp, scheme, ocaml, haskell do need variable declaration ! Erlang do not ... > > [...] > > > Only in a few cases. Type inferencing is a well-understood > technology, and will produce code as efficient as a statically type > language in most cases. > Type inferencing only works for statically typed languages AFAIK ! In a dynamically typed languages, typing a variable is simply impossible as any function may return a value of any type ! > >>I think language matters shouldn't be setlled by personal preferences. > > > I have to agree with that. For whether or not a feature should be > included, there should either be a solid reason dealing with the > functionality of the language - meaning you should have a set of use > cases showing what a feature enables in the language that couldn't be > done at all, or could only be done clumsily, without the feature. Wrong argument ... with that kind of things, you would just stick with plain Turing machine ... every single computation can be done with it ! > > Except declarations don't add functionality to the language. They > effect the programing process. And we have conflicting claims about > whether that's a good effect or not, all apparently based on nothing > solider than personal experience. Which means the arguments are just > personal preferences. > Well, so why not *allow* for variable declaration ? Languages like Perl does that successfully ... you don't like : you don't do ! you like : you do ! A simple option at the beginning of the file tell the compilor if variable declaration is mandatory or not ! > Until someone does the research to provide hard evidence one way or > another, that's all we've got to work with. Which means that languages > should exist both with and with those features, and if one sides > experiences generalize to the population at large, they alternative > languages will die out. Which hasn't happened yet. > > >>But we should decide what language features are usefull and which are >>not by what some individual can or can't live without. > > > Um - that's just personal preference (though I may have misparsed your > sentence). What one person can't live without, another may not be able > to live with. All that means is that they aren't likely to be happy > with the same programming language. Which is fine - just as no > programming language can do everything, no programming language can > please everyone. > > Antoon, at a guess I'd say that Python is the first time you've > encountered a dynamnic language. Being "horrified" at not having > variable declarations, which is a standard feature of such languages > dating back to the 1950s, is one such indication. Dynamic language and variable declaration are non-related issues ! You can have statically-typed language without variable declaration (i.e. BASIC) and dynamically-typed language with (i.e. Lisp) ! Please, when you says something about languages, at least give 1 name of language asserting what you're saying ! > Dynamic languages tend to express a much wider range of programming > paradigms than languages that are designed to be statically > compiled. Some of these paradigms do away with - or relegate to the > level of "ugly performance hack" - features that someone only > experienced with something like Pascal would consider > essential. Assignment statements are a good example of that. Well, could you be more specific once more ? I can't that many paradigm only available on dynamically typed languages ... beside duck-typing (which is basically a synonym for dynamically-typed) > Given these kinds of differences, prior experience is *not* a valid > reason for thinking that some difference must be wrong. Until you have > experience with the language in question, you can't really decide that > some feature being missing is intolerable. You're in the same position > as the guy who told me that a language without a goto would be > unusable based on his experience with old BASIC, FORTRAN IV and > assembler. After more than two years of Python programming, I still fill the need for variable declarations. It would remove tons of bugs for little works and would also clarify the scope of any single variable. > Pick one of the many languages that don't require declarations. Try > writing a code in them, and see how much of a problem it really is in > practice, rather than trying to predict that without any > information. Be warned that there are *lots* of variations on how > undeclared variables are treated when referenced. Python raises > exceptions. Rexx gives them their print name as a value. Other > languages do other things. > > References: <1130616373.235379.140630@g49g2000cwa.googlegroups.com> Message-ID: <1f7befae0510311239h7f32761fu29bb001322af8b8@mail.gmail.com> [Talin] > I've been using generators to implement backtracking search for a while > now. Unfortunately, my code is large and complex enough (doing > unification on math expressions) that its hard to post a simple > example. So I decided to look for a simpler problem that could be used > to demonstrate the technique that I am talking about. > > I noticed that PEP 255 (Simple Generators) refers to an implementation > of the "8 Queens" problem in the lib/test directory. Looking at the > code, I see that while it does use generators, it doesn't use them > recursively. In context, the N-Queens and MxN Knight's Tour solvers in test_generators.py are exercising the conjoin() generators in that file. That's a different approach to backtracking search, with some nice features too: (1) it uses heap space instead of stack space; and, (2) it's easy to run entirely different code at different levels of the search. #2 isn't well-illustrated by the N-Queens solver because the problem is so symmetric, although it is used to give the code for each row its own local table of the board lines used by the squares in that row. That in turn is a major efficiency win. The Knight's Tour solver makes more obvious use of #2, by, e.g., running different code for "the first" square than for "the second" square than for "the last" square than for "all the other" squares. That doesn't require any runtime test-and-branch'ing in the search code, it's set up once at the start in the list of M*N generators passed to conjoin() (each square gets its own generator, which can be customized in arbitrary ways, in advance, for that square). > As an alternative, I'd like to present the following implementation. If > you compare this one with the one in lib/test/test_generator.py you > will agree (I hope) that by using recursive generators to implement > backtracking, the resulting code is a little more straightforward and > intuitive: Since "straightfoward and intuitive" weren't the goals of the test_generators.py implementations, that's not too surprising ;-) > ... From mwm at mired.org Fri Oct 21 15:41:39 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 21 Oct 2005 15:41:39 -0400 Subject: Set an environment variable References: <43573022$0$155$edfadb0f@dread16.news.tele.dk> <1129798724.366618.194650@g44g2000cwa.googlegroups.com> <43589205$0$125$edfadb0f@dread16.news.tele.dk> <11lhv31li8sgm0c@corp.supernews.com> <86ll0mu6px.fsf@bhuda.mired.org> <11lifp8r4kipi5c@corp.supernews.com> Message-ID: <868xwmu07g.fsf@bhuda.mired.org> Grant Edwards writes: > My point: the OP wanted to know how to export an environment > variable to a child process. Either of the lines of code above > will do that, so what's with all the shellular shenanigans? Actually, the OP didn't say he wanted to export a variable to a child process. He said he wanted to know how to do the equivalent of "export SYMBOL=value", which got intreprted as "setting a variable in the parent shell." http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From tim at tt1lock.org Sun Oct 9 09:20:14 2005 From: tim at tt1lock.org (Tim Tyler) Date: Sun, 9 Oct 2005 13:20:14 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <86y853mzmr.fsf@bhuda.mired.org> Message-ID: In comp.lang.java.programmer Mike Meyer wrote or quoted: > The technial problems have been solved for over a decade. NeXT shipped > systems that used text/richtext, which has none of the problems that > HTML has. The problems are *social* - you've got to arrange for > people to use mail/news readers that understand a rich text format > that isn't a vector for viruses. It's not HTML that has problems, it's Microsoft's crappy software. Writing virus-free HTML renderers is not hard - but of course Microsoft can still screw it up. Don't blame HTML for viruses - *every* document format Microsoft has anything to do with becomes a vector for viruses. They *even* managed to get virulent spreadsheets and word processor documents! -- __________ |im |yler http://timtyler.org/ tim at tt1lock.org Remove lock to reply. From steve at holdenweb.com Mon Oct 24 07:49:06 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 24 Oct 2005 12:49:06 +0100 Subject: New User In-Reply-To: References: Message-ID: thatchmatic wrote: > I just downloaded and I think installed python. I am not sure if I > did cause it does'nt respond to the commands that the read me file > told me to use. Also can someone suggest a trial program I can maybe > write for fun? > > Thanks. > > > 1: http://www.python.org/doc/faq/windows.html 2: Depends on your definition of fun, of course :-) How about a program to print the average of a set of numbers you type in? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From mwm at mired.org Mon Oct 3 05:02:54 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 03 Oct 2005 05:02:54 -0400 Subject: Will python never intend to support private, protected and public? References: <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xll1gvk7w.fsf@ruckus.brouhaha.com> <1128001308.905398.321670@g44g2000cwa.googlegroups.com> <311b5ce105092908332c12164c@mail.gmail.com> <7xbr2btv84.fsf@ruckus.brouhaha.com> <7xy85fvxny.fsf@ruckus.brouhaha.com> <86vf0inlt3.fsf@bhuda.mired.org> <7xd5mq9ir9.fsf@ruckus.brouhaha.com> <86wtkym33t.fsf@bhuda.mired.org> <7xll1d7l2c.fsf@ruckus.brouhaha.com> <86slvlmdnv.fsf@bhuda.mired.org> <7xr7b3spri.fsf@ruckus.brouhaha.com> <86br27mztp.fsf@bhuda.mired.org> <7x8xxbidtp.fsf@ruckus.brouhaha.com> <86ll1bkz99.fsf@bhuda.mired.org> <7xpsqn6wpx.fsf@ruckus.brouhaha.com> <8664sfkwol.fsf@bhuda.mired.org> <7x4q7zp36t.fsf@ruckus.brouhaha.com> Message-ID: <861x33km69.fsf@bhuda.mired.org> Paul Rubin writes: > Mike Meyer writes: >> > Privilege separation is considered a good coding practice. How does >> > Python help it? >> With conventions and name mangling. Which are only slightly less >> effective than the C++/Java technic for doing the same thing. > That's not what privilege separation means. It means that the > privileged objects stay secure even when the unprivileged part of the > program is completely controlled by an attacker. In which case, what's "private" got to do with this? The examples I've seen of it don't give you privilege seperation any more than python does. Of course, while we're adding things to Python to support what people consider good coding practices, let's not forget: Design by contract. Covariant method specialization. Class invariants. Avoiding variable aliasing. Hungarian Notation. The Law of Demeter. Loop invariants. Avoiding mixed mode arithmetic. The telephone test. Procedure/function sepration. Type discipline. Contravariant method specialization. and so on. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From dcrespo at gmail.com Tue Oct 25 10:51:20 2005 From: dcrespo at gmail.com (dcrespo) Date: 25 Oct 2005 07:51:20 -0700 Subject: What is Transport parameter in xmlrpclib.Server used for? Message-ID: <1130251880.798052.278410@z14g2000cwz.googlegroups.com> Hello all... Someone can tell me what is the parameter 'transport' used for? I think it can be used for encrypt the data... If so, how can I use it? Thanks From chris.cavalaria at free.fr Mon Oct 3 11:42:02 2005 From: chris.cavalaria at free.fr (Christophe) Date: Mon, 03 Oct 2005 17:42:02 +0200 Subject: "no variable or argument declarations are necessary." In-Reply-To: References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> Message-ID: <43414f82$0$21209$626a54ce@news.free.fr> Steven D'Aprano a ?crit : > On Mon, 03 Oct 2005 06:59:04 +0000, Antoon Pardon wrote: > > >>Well I'm a bit getting sick of those references to standard idioms. >>There are moments those standard idioms don't work, while the >>gist of the OP's remark still stands like: >> >> egold = 0: >> while egold < 10: >> if test(): >> ego1d = egold + 1 > > > for item in [x for x in xrange(10) if test()]: > > But it isn't about the idioms. It is about the trade-offs. Python allows > you to do things that you can't do in other languages because you > have much more flexibility than is possible with languages that > require you to declare variables before using them. The cost is, some > tiny subset of possible errors will not be caught by the compiler. But > since the compiler can't catch all errors anyway, you need to test for > errors and not rely on the compiler. No compiler will catch this error: > > x = 12.0 # feet > # three pages of code > y = 15.0 # metres > # three more pages of code > distance = x + y > if distance < 27: > fire_retro_rockets() > > And lo, one multi-billion dollar Mars lander starts braking either too > early or too late. Result: a new crater on Mars, named after the NASA > employee who thought the compiler would catch errors. > > > Declared variables have considerable labour costs, and only marginal > gains. Since the steps you take to protect against other errors will also > protect against mistyping variables, declarations of variables is of > little practical benefit. As a matter of fact, doing that one on a HP48 calculator with unit anotated values would have worked perfectly, except for the distance < 27 check which would have raised one error. From antonyliu2002 at yahoo.com Sat Oct 15 00:52:07 2005 From: antonyliu2002 at yahoo.com (Anthony Liu) Date: Fri, 14 Oct 2005 21:52:07 -0700 (PDT) Subject: Problem splitting a string Message-ID: <20051015045208.28476.qmail@web35811.mail.mud.yahoo.com> I have this simple string: mystr = 'this_NP is_VL funny_JJ' I want to split it and give me a list as ['this', 'NP', 'is', 'VL', 'funny', 'JJ'] 1. I tried mystr.split('_| '), but this gave me: ['this_NP is_VL funny_JJ'] It is not splitted at all. 2. I tried mystr.split('_'), and this gave me: ['this', 'NP is', 'VL funny', 'JJ'] in which, space is not used as a delimiter. 3. I tried mystr.split(' '), and this gave me: ['this_NP', 'is_VL', 'funny_JJ'] in which, '_' is not used as delimiter. I think the documentation does say that the separator/delimiter can be a string representing all delimiters we want to use. I do I split the string by using both ' ' and '_' as the delimiters at once? Thanks. __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com From sharidas at zeomega.com Wed Oct 5 06:56:08 2005 From: sharidas at zeomega.com (Satchidanand Haridas) Date: Wed, 05 Oct 2005 16:26:08 +0530 Subject: Quick help needed: how to format an integer ? In-Reply-To: <4343A2FC.6060106@mailpont.hu> References: <4343A2FC.6060106@mailpont.hu> Message-ID: <4343B148.6010303@zeomega.com> One possible solution. Don't know how efficient it is though. :-) >>> def put_decimal(s): ... return ''.join( [ [s[i], '.%s' % s[i]][(len(s)-i)%3 == 0] for i in range(0, len(s))]) ... >>> put_decimal("10001234") '10.001.234' >>> put_decimal("12622") '12.622' thanks, Satchit durumdara at mailpont.hu wrote: >Hi ! > >I need to convert some integer values. > >"1622" ->"1 622" > >or > >"10001234" -> ""10.001.234"" > >So I need thousand separators. > >Can anyone helps me with a simply solution (like %xxx) ? > >Thanx for it: dd > >Ps: >Now I use this proc: > >def toths(i): > s=str(i) > l=[] > ls=len(s) > for i in range(ls): > c=s[ls-i-1] > if i%3==0 and i<>0: > c=c+"." > l.append(c) > l.reverse() > return "".join(l) > > > > > From bobrien18 at yahoo.com Wed Oct 19 21:16:24 2005 From: bobrien18 at yahoo.com (KraftDiner) Date: 19 Oct 2005 18:16:24 -0700 Subject: Having trouble deleting objects from a list... Message-ID: <1129770984.225558.284260@g49g2000cwa.googlegroups.com> I have a list, and within it, objects are marked for deletion. However when I iterate through the list to remove objects not all the marked objects are deleted.. here is a code portion: i = 0 for obj in self.objList: if obj.mouseHit: print 'delete + ' + `i` self.objList.pop(i) flag = True else: i = i + 1 print `i` I can't see what I'm doing wrong! It seems like the last selected object is the one that is not deleted... From Tomasik at 2kop.mil.pl Tue Oct 18 09:32:23 2005 From: Tomasik at 2kop.mil.pl (Robert) Date: Tue, 18 Oct 2005 15:32:23 +0200 Subject: wxPython + pyPlot References: Message-ID: Maebe, does anyone have some examples with wxPython and pyplot? Thanks again, Robert From nicopernetty at nowhere.fr Sat Oct 8 17:31:40 2005 From: nicopernetty at nowhere.fr (Nicolas Pernetty) Date: Sat, 8 Oct 2005 23:31:40 +0200 Subject: Continuous system simulation in Python References: <20051007011222.1aeab426@linuxcestcomplique.fr> <1128708054.819697.232950@o13g2000cwo.googlegroups.com> <20051007224533.08bde751@linuxcestcomplique.fr> <1128794785.152776.116370@g47g2000cwa.googlegroups.com> Message-ID: <20051008233140.77ad2c2e@linuxcestcomplique.fr> Simulink is well fitted for small simulators, but when you run into big projects, I find many shortcomings appears which made the whole thing next to unusable for our kind of projects. That's why I'm interested in Python by the way, it is not a simple clone like Scilab/Scicos. It is a real language which bring its own advantages, and its own shortcomings, which I find well suited for our activity. If you want, I can send you a paper I wrote last year, detailing all Simulink shortcomings. I doubt that this mailing list is interested in such things...(and it's in French...). Concerning Scilab/Scicos, I'm not really interested in a technology primarily developed (INRIA and ENSPC) and used by France. Python and all its libraries and communities are so much more dynamic ! And also I've heard that Scilab was developed in Fortran in a way which make it rigid and that the sources are poorly documented, not a good sign for an open source software (and Scilab isn't 'Free' for the FSF). Regards, *********** REPLY SEPARATOR *********** On 8 Oct 2005 11:06:25 -0700, "S?bastien Boisg?rault" wrote : > > Simulink is a framework widely used by the control engineers ... > It is not *perfect* but the ODEs piece is probably the best > part of the simulator. Why were you not convinced ? > > You may also have a look at Scicos and Ptolemy II. These > simulators are open-source ... but not based on Python. > > Cheers, > > SB > > > > > > Nicolas Pernetty a ?crit : > > > Hello Phil, > > > > Yes I have considered Octave. In fact I'm already using Matlab and > > decided to 'reject' it for Python + Numeric/numarray + SciPy because > > I think you could do more in Python and in more simple ways. > > > > Problem is that neither Octave, Matlab and Python offer today a > > framework to build continuous system simulator (in fact Matlab with > > Simulink and SimMechanics, do propose, but I was not convinced at > > all). > > > > Regards, > > > > *********** REPLY SEPARATOR *********** > > > > On 7 Oct 2005 11:00:54 -0700, phil_nospam_schmidt at yahoo.com wrote : > > > > > Nicholas, > > > > > > Have you looked at Octave? It is not Python, but I believe it can > > > talk to Python. > > > Octave is comparable to Matlab for many things, including having > > > ODE solvers. I have successfully used it to model and simulate > > > simple systems. Complex system would be easy to model as well, > > > provided that you model your dynamic elements with (systems of) > > > differential equations. > > > > From aleaxit at yahoo.com Sun Oct 30 19:08:04 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 30 Oct 2005 17:08:04 -0700 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <87ek65kbw5.fsf@lucien.dreaming> <1h5760l.1e2eatkurdeo7N%aleaxit@yahoo.com> <3siakvFohl3aU1@individual.net> <1h57cij.16dkc141lds4s4N%aleaxit@yahoo.com> Message-ID: <1h597yx.wjk2a71spyjhyN%aleaxit@yahoo.com> John J. Lee wrote: > aleaxit at yahoo.com (Alex Martelli) writes: > [...] > > If you're trying to test your code to ensure it explicitly closes all > > files, you could (from within your tests) rebind built-ins 'file' and > > 'open' to be a class wrapping the real thing, and adding a flag to > > remember if the file is open; at __del__ time it would warn if the file > > had not been explicitly closed. E.g. (untested code): > [...] > > In general __del__ methods interfere with garbage collection, don't Yes, cyclic gc only. > they? I guess in the case of file objects this is unlikely to be > problematic (because unlikely to be any reference cycles), but I > thought it might be worth warning people that in general this > debugging strategy might get rather confusing since the __del__ could > actually change the operation of the program by preventing garbage > collection of the objects whose lifetime you're trying to > investigate... Yeah, but you'll find them all listed in gc.garbage for your perusal -- they DO get collected, but they get put in gc.garbage rather than FREED, that's all. E.g.: >>> class a(object): ... def __del__(self): print 'del', self.__class__.__name__ ... >>> class b(a): pass ... >>> x=a(); y=b(); x.y=y; y.x=x >>> del x, y >>> gc.collect() 4 >>> gc.garbage [<__main__.a object at 0x64cf0>, <__main__.b object at 0x58510>] So, no big deal -- run a gc.collect() and parse through gc.garbage for any instances of your "wrapper of file" class, and you'll find ones that were forgotten as part of a cyclic garbage loop and you can check whether they were explicitly closed or not. Alex From smadim2 at grads.ece.mcmaster.ca Tue Oct 4 14:33:09 2005 From: smadim2 at grads.ece.mcmaster.ca (Mohammed Smadi) Date: Tue, 4 Oct 2005 14:33:09 -0400 (EDT) Subject: how to get any available port Message-ID: hi; if am using s.bind for a tcp socket. On the client side i dont really care which socket i use as long as i get an available socket. Is there a funciton or a way to get an available socket? thanks smadi From apardon at forel.vub.ac.be Thu Oct 27 04:27:53 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 27 Oct 2005 08:27:53 GMT Subject: Would there be support for a more general cmp/__cmp__ References: Message-ID: Op 2005-10-26, Christopher Subich schreef : > Antoon Pardon wrote: >> Op 2005-10-25, Christopher Subich schreef : >>> >>>My biggest complaint here is about returning None or IncomparableValue; >>>if that happens, then all code that relies on cmp returning a numeric >>>result will have to be rewritten. >> >> >> I don't know. There are two possibilities. >> >> 1) The user is working with a total order. In that case the None >> or IncomparableValues won't be returned anyway so nothing about >> his code has to change. >> >> 2) The user is working with a partial order. In that case cmp >> doesn't provide consistent results so the use of cmp in this >> case was a bug anyway. > > Case 3) The user is working with an unknown class, using duck typing, > and expects a total order. If cmp suddenly returned Incomparable or > None, the code would break in Unexpected Ways, with Undefined Behavior. This is case 2. Under the current circumstances working with cmp with a partial order will give inconsistent behaviour. So your code is already broken for relying on cmp to give consistent results in circumstances it can't. > This is a classic "exception versus error code" argument; in this case, > returning None would be the error flag. It's almost always better to > just throw the exception, because then this allows error-checking at a > more natural level. If you prefer a raised exception, I could live with that. >>>As for saying that cmp should return some times and raise an exception >>>other times, I just find it squicky. >> >> >> But cmp already behaves this way. The only difference would be that >> the decision would be made based on the values of the objects instead >> of only their class. >> >> >>>Admittedly, this is entirely up to >>>the class designer, and your proposed guideline wouldn't change cmp's >>>behavior for clases that /are/ totally ordered. >>> >>>Then again, sets excepted, your guideline doesn't seem very applicable >>>in standard library code. >> >> >> Well AFAIAC this isn't specific about library code. > > A change that cmp return a 4th possible "value" (None or Incomparable) > is a fundamental language change. Because this would break large > amounts of existing code, it's a bad idea. I have always included the option that cmp would raise an exception instead of returning a fourth value. -- Antoon Pardon From hancock at anansispaceworks.com Mon Oct 24 11:38:01 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Mon, 24 Oct 2005 10:38:01 -0500 Subject: Microsoft Hatred FAQ In-Reply-To: <8qnpl11s9ie8s2pstqja5k5aeikn6tgtu7@4ax.com> References: <5y47f.174197$RW.59989@fe2.news.blueyonder.co.uk> <8qnpl11s9ie8s2pstqja5k5aeikn6tgtu7@4ax.com> Message-ID: <200510241038.01363.hancock@anansispaceworks.com> On Monday 24 October 2005 08:19 am, Roedy Green wrote: > On Mon, 24 Oct 2005 12:35:13 GMT, axel at white-eagle.invalid.uk wrote, > quoted or indirectly quoted someone who said : > > >I see that you cannot make a reasoned argument against the fact that > >property in the form of houses is taxed in America. > > And what has his inability to do that to your satisfaction got to do > with the price of eggs? Funny you should ask that. Taxation, mostly in the form of income tax supports a system of farm subsidies in the United States, that pays farmers for surplus product, thus artificially elevating the price of several farm products, including milk, cheese, and (you guessed it) eggs. The purpose of this (ostensibly anyway) is to keep family farmers in business, because that is viewed as a social benefit in itself (I happen to agree with this statement, even if it does mean I pay more for eggs -- though the price is still one of the lowest globally, because the US has such a large natural surplus of agricultural products owing to arable land and mostly good weather). Of course it does produce one of the most notorious examples of wastage -- much of that surplus is allowed to rot (or at least this *was* true at one time, I haven't fact-checked that in over a decade). It has been proposed that most of that food should instead go to foreign aid, or to programs within the US for eliminating poverty. Certainly some of it does, I have no idea what the current balance is, though. The ability to do this, moreover represents the philosophical point that the government "owns" the economy, in that it has the right, representing the interests of the people, to pursue public good by manipulating the economy. In other words, we do not believe in the formal concept of a laissez faire economy, nor in the idea of "anarchic libertarianism". People who do support the latter kind of idea frequently say that a company should be "allowed to do anything to pursue profit, as long as it isn't illegal". But of course, they usually turn around and say that "there is no natural law". The combination of the two philosophies is nonsensical -- if law consists only of artificial constraints, then there is no natural basis for arguing what the law "should" allow. Hence, only the will of the people matters, which means any form of monopoly restriction is entirely within the powers of a democratic government to pursue. Since this includes ANY economic system from "laissez faire capitalism" to "pure communism", it has no persuasive power whatsoever, and should be dropped. If on the other hand, you believe (as I do), that State law is an embodiment, backed up by State power, to implement the best approximation we can manage of "natural law" (i.e. law as evident to at least a consensus of human minds, albeit through transcendental rather than empirical derivation), then there IS a basis for arguing what laws "should" be. But you can't make arguments about what law "should" be if you don't acknowledge that law is measured against some external standard. This is of course, another result of the Human tendency to confuse "NULL" with "ZERO". The absence of an external system of evaluating law, does not mean that all laws must be negated. It equates to having no basis for prefering them to exist or not, and thus abdicating all right to change them. People who believe this really need, therefore, to shut up. ;-D -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From larry.bates at websafe.com Tue Oct 18 15:53:43 2005 From: larry.bates at websafe.com (Larry Bates) Date: Tue, 18 Oct 2005 14:53:43 -0500 Subject: example of using urllib2 with https urls In-Reply-To: <1129650132.645135.155030@g44g2000cwa.googlegroups.com> References: <1129650132.645135.155030@g44g2000cwa.googlegroups.com> Message-ID: <435552C7.1000601@websafe.com> import httplib import base64 import sys import random # # Get the length of the file from os.stat # username='' password='' file='' size=os.stat(file)[6] # # file contains the entire path, split off the name # WebSafe. # name=os.path.basename(file) url='https://www.somedomain.com' auth_string = base64.encodestring('%s:%s' % (username, password)) rid = '%02x' % random.uniform(0, sys.maxint-1) conn = httplib.HTTP(url) conn.putrequest('PUT', '%s/%s' % (path, rid)) conn.putheader('Content-Type', 'text/plain') conn.putheader('Content-Length', str(size)) conn.putheader('Authorization', 'Basic %s' % auth_string) conn.endheaders() # # Open file in binary mode for reading # fp=open(file, 'rb') # # Loop over all the file's blocks and send them sequentially # blocknum=0 while 1: bodypart=fp.read(blocksize) blocknum+=1 if blocknum % 10 == 0: print "upload-sending blocknum=", blocknum if not bodypart: break conn.send(bodypart) fp.close() reply, msg, headers = conn.getreply() print "upload-PUT reply=", reply, " msg=", msg, "headers=", headers This is for Basic Authentication (if your https site is using something different, method would be different). May not be what you need. Hope this helps. Larry Bates Michele Simionato wrote: > Can somebody provide an example of how to retrieve a https url, given > username and password? I don't find it in the standard documentation. > TIA, > > Michele Simionato > From eurleif at ecritters.biz Wed Oct 5 03:52:15 2005 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Wed, 05 Oct 2005 07:52:15 GMT Subject: 2 class with same name in different module In-Reply-To: References: Message-ID: Iyer, Prasad C wrote: > I have a class in a module which is getting imported in main module. > How do you differentiate between the 2 class import foo import bar foo.TheClass().dostuff() bar.TheClass().dostuff() From steve at REMOVETHIScyber.com.au Wed Oct 5 10:59:38 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Thu, 06 Oct 2005 00:59:38 +1000 Subject: question about output References: <1128522271.424943.204030@o13g2000cwo.googlegroups.com> Message-ID: On Wed, 05 Oct 2005 07:24:31 -0700, Java and Swing wrote: > i have printed out some numbers and they look like > > 10944800e > 10952560d They don't look like numbers to me. They have letters at the end. What are they? What does the letter mean? > ...if i want to later assign this type of number to variable how can i > do it? > > for example i can't do... > >>> x = 10944800e > > ..since it says "invalid token" on the "e". How did you get the "numbers"? If you just typed them in by hand, then leave the "e" off and you have a number. If they are supposed to be hex numbers, then you can use: x = int("10944800e", 16) # note the quote marks print x -> 4450451470 If you don't care about the numeric value, then you just put quote marks around the number+letter: x = "10944800e" but then x will be a string, not a number. If none of these answers is what you need, you will need to explain your problem a little better. -- Steven. From spe.stani.be at gmail.com Thu Oct 27 12:20:43 2005 From: spe.stani.be at gmail.com (SPE - Stani's Python Editor) Date: 27 Oct 2005 09:20:43 -0700 Subject: ANN: SPE 0.7.5.d released! References: <1130421938.507881.207330@z14g2000cwz.googlegroups.com> Message-ID: <1130430043.080669.35810@g47g2000cwa.googlegroups.com> I forgot to include a sample of an exported Uml diagram, so here it is as a pdf: http://www.stani.be/python/spe/images/smdi.pdf Previous announcement: I'm currently packaging the new SPE. The release is a matter of minutes. Next releases (0.8.*) will focus on the Mac in honour of the fund raising for the purchase of a Mac. Read more on the homepage. New features: * UML export to bitmap (bmp, gif, jpg, pcx, png, pnm, tif, xbm, xpm), to vector drawing (eps) or to printer (pdf). * Dialog box for passing arguments and options to debugger. * Unicode support (specify encoding in source file) You can read more on the SPE news blog. It would be nice if some (experienced) Mac users would subscribe to the developers mailing list to speed up the Mac port for SPE. I expect my new Mac any moment. Stani -- http://pythonide.stani.be http://pythonide.stani.be/manual/html/manual.html From codecraig at gmail.com Tue Oct 4 15:30:31 2005 From: codecraig at gmail.com (Java and Swing) Date: 4 Oct 2005 12:30:31 -0700 Subject: Call C functions from Python Message-ID: <1128454231.381256.297280@g47g2000cwa.googlegroups.com> Is there some other way, besides SWIG, which will allow me to call functions inside an Ansi C DLL? Example (C): defs.h ------- typedef unsigned long MY_DIGIT; myapp.c ----------------- #include "defs.h" char *DoSomeStuff(char *input, MY_DIGIT *digits) { ... } ..thats an example of something I would like to call from Python. From fredrik at pythonware.com Mon Oct 24 06:02:17 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 24 Oct 2005 12:02:17 +0200 Subject: Setting a Limit to the Maximum Size of an Upload References: <1130147553.883353.141410@g14g2000cwa.googlegroups.com> Message-ID: "Joey C." wrote: > thefile = params["upfile.file"] > if os.path.getsize(thefile) <= conf["upmax"]: > print "File Size Okay." #Add Functions Later... > else: > print "File Too Large." #Here, too. > > CGItb reported the following error: > TypeError: coercing to Unicode: need string or buffer, instance found > args = ('coercing to Unicode: need string or buffer, instance > found',) cgitb probably also reported what line you got that error for, and the values of the variables involved. can you perhaps post that information too? From dcrespo at gmail.com Fri Oct 28 08:59:16 2005 From: dcrespo at gmail.com (dcrespo) Date: 28 Oct 2005 05:59:16 -0700 Subject: How to replace all None values with the string "Null" in a dictionary In-Reply-To: References: <1130444785.353905.85380@g47g2000cwa.googlegroups.com> Message-ID: <1130504356.062998.237450@g47g2000cwa.googlegroups.com> Thanks... I did it right that way, but asked it without telling how I did it just to see what are the occurences of others. I thing there's no better/faster solution. Many thanks Daniel From apardon at forel.vub.ac.be Mon Oct 3 07:05:18 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 3 Oct 2005 11:05:18 GMT Subject: Problem with slices. Message-ID: I'm for the moment writing two classes. A table, which is like a list, but can start at any integer. A tree which is like a dictionary, but will iterate over the keys in sorted order. The problem is that I would like to implemet slices but, that seems to be impossible with how slices are implemented now. I wrote the following class to test things out. class Tst: def __getitem__(self, key): print key then I called the interpreter and got this: >>> from tst import Tst >>> t=Tst() >>> t[:] slice(0, 2147483647, None) >>> t[:9] slice(0, 9, None) >>> t[:'ok'] slice(None, 'ok', None) >>> t['ok':] slice('ok', None, None) >>> t[6:] slice(6, 2147483647, None) >>> t[1,2] (1, 2) >>> t[1,2:] (1, slice(2, None, None)) >>> t[(1,2):] slice((1, 2), None, None) Now suppose tab is a table with indexes from -5 to 12. tab[:4] would have to make a table ranging from -5 to 4 tab[0:4] would have to make a table ranging from 0 to 4. But each time I would be given the same argument, being slice(0, 4, None). So I would be unable to distinghuish between the two. I don't think it very likely but I could have a table with indexes from 2147483647 to 2147483700, so having 2147483647 as value that indicated till the end of the sequence is a bit awkward. The same problems occur when I have a tree with integer key values. But even if I don't use integers as keys I have a problem with what is returned since None is a valid key and thus it shouldn't be used this way. -- Antoon Pardon From wolfgang.keller.nospam at gmx.de Sun Oct 23 14:21:19 2005 From: wolfgang.keller.nospam at gmx.de (Wolfgang Keller) Date: Sun, 23 Oct 2005 20:21:19 +0200 Subject: IDE recommendation please References: Message-ID: > I'm new to Python but am wondering what IDE Python developers use? > I use Mac OS X 10.4.2. Just look in the archives of the Pythonmac mailinglist. We have discussed this very subject intensively recently, with a pretty extensive review of the different IDEs available. I'll get a copy of WingIDE as soon as I get my new PowerMac. > Suggestions for plugins for Eclipse would also be nice. Err, Eclipse (imho) is a H-O-G. Sincerely, Wolfgang From michaelschneider at fuse.net Fri Oct 14 12:43:10 2005 From: michaelschneider at fuse.net (Michael Schneider) Date: Fri, 14 Oct 2005 12:43:10 -0400 Subject: Problems with properties In-Reply-To: References: Message-ID: <434FE01E.9070907@fuse.net> Thanks to all, I added the object as a subclass (should this be required for 2.4.1 ???) I also switched to the decorator with the @property syntax Thank you very much for the help for adding @property to the language. what a great language :-) Mike Michael Schneider wrote: > Hello All, > > I have been working on learning how to use python properties. > > The get property access is working, but the the set > property is not working. > > Rather then dispatching the property assignment to setNothing, the > property object is being replaced with a string. > > I must be doing something very stupid here. > > Could someone please point out my error, I have dents in my forehead > for this one. > > Thanks, > Mike > > > > ------------------------------------------------------------------ > > from unittest import TestCase > import unittest > > > class Task: > def __init__(self,command): > self._command = command > > def setNothing(self, value): > raise AttributeError > > def getCommand(self): > return self._command > > command=property(getCommand, setNothing) > > > class taskTest(TestCase): > > def testTask(self): > t = Task("dir c:") > c = t.command > self.assertEquals("dir c:", c) > > # should fail, but doesn't > t.command = "foo Bar" > > self.assertEquals("dir c:", t.command) > > > > if __name__ == "__main__": > unittest.main() -- The greatest performance improvement occurs on the transition of from the non-working state to the working state. From claird at lairds.us Tue Oct 4 19:08:03 2005 From: claird at lairds.us (Cameron Laird) Date: Tue, 04 Oct 2005 23:08:03 GMT Subject: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please! References: Message-ID: In article , spiffo wrote: . . . >I am a corporate developer, working for a single company. Got a new project >coming up and wondering if I should stay with Python for this new, fairly >large project, are jump back on the 'safe' M$ bandwagon using a dot net >language? Cross platform is NOT an issue, but COMPLETE control/compatability . . . While I know others in this thread have already mentioned the fact somewhat obliquely, I'll make it explicit: Python IS "a dot net language" . From g.tagliarettiNO at SPAMparafernalia.org Sun Oct 23 08:14:23 2005 From: g.tagliarettiNO at SPAMparafernalia.org (Gian Mario Tagliaretti) Date: Sun, 23 Oct 2005 14:14:23 +0200 Subject: IDE recommendation please References: Message-ID: <435b627c$0$20493$4fafbaef@reader4.news.tin.it> microsnot wrote: > I'm new to Python but am wondering what IDE Python developers use? I use > Mac OS X 10.4.2. I have PythonIDE which comes with MacPython but I don't > think that has even rudimentary "intellisense". Xcode and Eclipse don't > seem to support Python out of the box. Suggestions for plugins for Eclipse > would also be nice. I use wingIDE and as Alex said before is the best python IDE ever... cheers -- Gian Mario Tagliaretti PyGTK GUI programming http://www.parafernalia.org/pygtk/ From jepler at unpythonic.net Tue Oct 4 17:05:07 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Tue, 4 Oct 2005 16:05:07 -0500 Subject: how to debug when "Segmentation fault" In-Reply-To: <20051004190827.3914.1498135555.divmod.quotient.23977@ohm> References: <200510041122.25067.mekstran@scl.ameslab.gov> <20051004190827.3914.1498135555.divmod.quotient.23977@ohm> Message-ID: <20051004210507.GB29124@unpythonic.net> I've rewritten your middle example to be clearer. $ python2.4 Python 2.4.1 (#1, May 16 2005, 15:15:14) [GCC 4.0.0 20050512 (Red Hat 4.0.0-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> type("Y", (type,), {"mro": lambda x: [float]})("X", (), {}) and here's another one for you to enjoy: >>> import marshal >>> f = lambda: None >>> code = marshal.loads(marshal.dumps(f.func_code).replace('d\0\0S','d\xff\xffS')) >>> f.func_code = code >>> f() Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From mwm at mired.org Thu Oct 27 16:46:32 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 27 Oct 2005 16:46:32 -0400 Subject: How to replace all None values with the string "Null" in a dictionary References: <1130444785.353905.85380@g47g2000cwa.googlegroups.com> Message-ID: <867jbyit7b.fsf@bhuda.mired.org> "dcrespo" writes: > Hi all, > > How can I replace all None values with the string 'Null' in a > dictionary? Iterate over everything in the dictionary: for key, item in mydict.items(): if item is None: mydict[key] = 'Null' http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From pauloneves at gmail.com Tue Oct 18 13:25:50 2005 From: pauloneves at gmail.com (Paulo Eduardo Neves) Date: 18 Oct 2005 10:25:50 -0700 Subject: Well written open source Python apps In-Reply-To: <1129214592.342917.100090@g43g2000cwa.googlegroups.com> References: <1129214592.342917.100090@g43g2000cwa.googlegroups.com> Message-ID: <1129656350.052690.188500@g14g2000cwa.googlegroups.com> This is an old thread in this subject that I bookmarked: http://groups.google.com/group/comp.lang.python/browse_thread/thread/984262217c1b3727/8793a0b7722bb32f From apardon at forel.vub.ac.be Wed Oct 26 04:18:58 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 26 Oct 2005 08:18:58 GMT Subject: Would there be support for a more general cmp/__cmp__ References: Message-ID: Op 2005-10-25, Christopher Subich schreef : > Antoon Pardon wrote: > >> I also think there is the problem that people aren't used to partial >> ordering. There is an ordering over sets, it is just not a total >> ordering. But that some pairs are uncomparable (meaning that neither >> one is smaller or greater) doesn't imply that comparing them is >> ill defined. > > It depends on your definition of "comparison." Admittedly, <, =, !=, > and > can be defined for a partial ordering, but classical mathematics, > as understood by most people (even programmers), assumes that unless a >== b, a > b or a < b. > > The comparisons, as defined this way, are done on a totally ordered set, > yes. But since most comparisons ever done -are- done on a totally > ordered set (namely the integers or reals), it's entirely fair to say > that "a programmer's expectation" is that comparisons should work more > or less like a totally ordered list. > > > With that caevat in mind, comparison on a partially ordered domain /is/ > ill-defined; it can give inconsistent results from the "a < b or a > b > or a == b" rule. Against people expectations is not the same as inconsistent. >> >> Well it is a wrong assumption is general. There is nothing impure about >> partial ordering. > > Impure? Probably not. Useless from many perspective when "comparisons" > are needed, to the point where it's probably safer to throw an exception > than define results. > >> That is IMO irrelevant. The subset relationship is an ordering and as >> such has all characteristics of other orderings like "less than", >> except that the subset relationship is partial and the less than >> relationship is total. How it is called "subset" vs "less than" is >> IMO irrelevant. It is about mathematical characteristics. > > Still accident. < wouldn't be used for sets if we had a subset symbol > on the standard keyboard, APL fans notwithstanding. That is only because people usualy work with numbers and sets at the same time and using different symbols helps making the distinction. But using <= for subset is mathematical completely correct. If you want to go purely formal, numbers are just a particular family of sets where the less than or equal relation of numbers coincides with the subset relation of sets in that family. People use the multiplication symbol for multiplying matrices although matrix multiplication is something different from number multiplication. If the multiplications of matrices is enough like the multiplication of numbers to use the same symbol, I see nothing wrong in using the same symbol for the (strict) subset relation as is used for the less than (or equal) relation on numbers. > Simce programmers > familiar with Python understand that < on sets isn't a "real" comparison > (i.e. provide a total order), they don't expect unique, consistent > results from something like sort (or a tree, for that matter). >> >>>By analogy, one can ask, "is the cat inside the box?" and get the answer >>>"No", but this does not imply that therefore the box must be inside the >>>cat. >> >> >> Bad analogy, this doesn't define a mathematical ordering, the subset >> relationship does. > > Yes, it does. Consider "in" as a mathematical operator: My appologies, I though you were going in the "I can in my coat, my coat can in the box" kind of direction. > For the set (box, cat-in-box) > > box in box: False > box in cat-in-box: False > cat-in-box in box: True > cat-in-box in cat-in-box: False > > For the set (box, smart-cat) # cat's too smart to get in the box > > box in box: False > box in smart-cat: False > smart-cat in box: False > smart-cat in smart-cat: False > > In both these cases, the "in" operator is irreflexive, asymmetric, and > transitive (extend to mouse-in-cat if you really care about transitive), > so "in" is a partial order sans equality. A useless one, but a partial > order nonetheless. I don't know if it is useless. This kind of relationship seems very common in political geography. This village is in this county, this county is in this state, this state is in this nation. Also magizines that test certain equipment to give advice on the best buy, usualy work with methods that result in partial orderings. >>>Notice that L1 and L2 contain the same elements, just in different orders. >>>Sorting those two lists should give the same order, correct? >> >> >> No. Since we don't have a total ordering, sorting doesn't has to give >> the same result. For as far as sorting is defined on this kind of >> object, the only thing I would expect is that after a sort the >> following condition holds. >> >> for all i,j if i < j then not L[i] > L[j] > > Highly formal, aren't you? I like the precision it provides. > Again, common programming allows for "not a > b" > == "a <= b", so your condition becomes the more familiar: > > for all i,j in len(list), if i < j then L[i] <= L[j] So, should we limit our programming to the common cases or should a language also provide help for the uncommon case. > This condition is also assumed implicitly by many other assumed "rules" > of sorted lists, namely their uniqueness: > > "If L is a list of unique keys, then sort(L) is a unique list of keys in > sorted order." > > Yes, this assumes that L has a total order. Big whoop -- this is a > matter of programming practiciality rather than mathematical purity. I don't find it so practical if the language limits the programmer to the common cases. I can understand that implementation issues impose limits on what can pratically realised and often enough that is the more common practice. So in this case it is about programming practiciality. But you seem to think it is programming practiciality if you limit yourself to the common case from the beginning, even if implementing for a more general case wouldn't be much harder then implementing only the common case. -- Antoon Pardon From hancock at anansispaceworks.com Mon Oct 10 18:06:23 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Mon, 10 Oct 2005 17:06:23 -0500 Subject: Learning Python In-Reply-To: <7e6dnQAA36FTBtfeRVn-rg@rogers.com> References: <7e6dnQAA36FTBtfeRVn-rg@rogers.com> Message-ID: <200510101706.23267.hancock@anansispaceworks.com> On Monday 10 October 2005 11:50 am, Paul DiRezze wrote: > I'm spending the next two weeks off and I'm looking to take a crack at > learning how to program in Python. [...] > > I'm looking for additional resources (links, names of books, > whatever...) that you think may help me out. > > I'm a hobby programmer using mostly BASIC(s) and some Java. I learned from "Learning Python" from O'Reilly. There's a new edition out that covers a somewhat more recent version of Python (2.3, I think). I learned BASIC as a teen -- Fortran, Pascal, C, and a bit of C++ later, so I think you probably have a similar PoV to what I had. Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From mwm at mired.org Sun Oct 9 19:19:39 2005 From: mwm at mired.org (Mike Meyer) Date: Sun, 09 Oct 2005 19:19:39 -0400 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <868xx3m2ve.fsf@bhuda.mired.org> Message-ID: <86irw6l1mc.fsf@bhuda.mired.org> Tim Tyler writes: > In comp.lang.java.programmer Mike Meyer wrote or quoted: >> Roedy Green writes: >> > Read my essay. >> > http://mindprod.com/projects.html/mailreadernewsreader.html >> > >> > I talk around those problems. >> >> Actually, you present a design that forces a solution that makes them >> do what you want down their throats, never mind what they want, or >> what they've been doing. It shows an amazing ignorance about the >> internet and how people behave on it. Like most antispam proposals, it >> won't actually stop spam, just force spammers to concentrate on >> different channels. You seem to have randomly broken quoting for >> people who download mail and read it offline, and for any medium >> that's unreliable or doesn't reliably deliver messages "in order" - >> which includes mail and news. Virus writers will love the ability to >> change peoples address books remotely. > > Since - in Roedy's essay - messages are digitally signed, authority > to advise about any email address updates would presumably be confined > to those people with access to the sender's private key. It's not confined to just people - software can do this as well. In particular, you should expect that the users mail agent will have to have access to the key, so it can automatically send out the change of address notice when the user changes their address (it actually needs it to send any mail). Viruses regularly make users mail agents do thing. "Change my address" becomes much more entertaining when that triggers sending out change of addresses notices to everyone in the address book. More likely, though, there'll be an API for getting the key so that users can change mail agents without invalidating the public key that everyone they correspond with has for them, and the virus will just use that API. This is also why his plan doesn't stop spam. Most spam comes from zombies already. This will just cause them to masquerade as the owner of the owned machine rather than somebody the author has a beef with. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From fredrik at pythonware.com Wed Oct 26 02:43:54 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 26 Oct 2005 08:43:54 +0200 Subject: more than 100 capturing groups in a regex References: <1130160675.270886.208420@z14g2000cwz.googlegroups.com><1130225565.592108.197670@z14g2000cwz.googlegroups.com><1130242672.024469.324530@g47g2000cwa.googlegroups.com><1130247035.969150.281910@g43g2000cwa.googlegroups.com> <1130253162.790086.59130@o13g2000cwo.googlegroups.com> Message-ID: Iain King wrote: > Anyway, back to the OP: in this specific case, the cap of 100 groups in > a RE seems random to me, so I think the rule applies. perhaps in the "indistinguishable from magic" sense. if you want to know why 100 is a reasonable and non-random choice, I suggest checking the RE documentation for "99 groups" and the special meaning of group 0. From codecraig at gmail.com Mon Oct 24 09:06:34 2005 From: codecraig at gmail.com (jas) Date: 24 Oct 2005 06:06:34 -0700 Subject: Redirect os.system output In-Reply-To: <1130157195.954433.131650@g49g2000cwa.googlegroups.com> References: <1129927486.854143.169670@g49g2000cwa.googlegroups.com> <43596c70$1_3@newspeer2.tds.net> <1130154552.795209.25830@g43g2000cwa.googlegroups.com> <435cd10c$1_2@newspeer2.tds.net> <1130157195.954433.131650@g49g2000cwa.googlegroups.com> Message-ID: <1130159194.833666.250820@g47g2000cwa.googlegroups.com> Ok, I tried this... C:\>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 subprocess as sp >>> p = sp.Popen("cmd", stdout=sp.PIPE) >>> >>> result = p.communicate("ipconfig") 'result' is not recognized as an internal or external command, operable program or batch file. >>> basically I was opening to send the "ipconfig" command to cmd.exe and store the result in the "result" variable. But you can see there was an error with result. Ideas? jas wrote: > I see that, although I don't totall grasp the code. However, I am > looking to basically emulate a command prompt. i.e. everything u see > in the windows command prompt should be displayed back in python. > > How can I do it without files? > > Kent Johnson wrote: > > jas wrote: > > > Any other ideas? or examples of using subprocess to do what I was > > > asking? > > > > Actually I thought I was giving an example of what you were asking: > > - on windows > > - send a series of commands to a command process > > - capture the result to a variable > > > > The example I referenced sends a series of HELP commands to cmd.exe, captures the output of the commands and saves it to a file. > > > > What did I miss? > > > > Kent > > > > > > > > > > > Kent Johnson wrote: > > > > > >>jas wrote: > > >> > > >>>I would like to redirect the output from os.system to a variable, but > > >>>am having trouble. I tried using os.popen(..).read() ...but that > > >>>doesn't give me exactly what i want. > > >> > > >>Here is an example using subprocess: > > >>http://groups.google.com/group/comp.lang.python/msg/9fa3a3c287e8e2a3?hl=en& > > >> > > >>Kent > > >> > > >> > > >>>..this is windows by the way. > > >>> > > >>>For example: > > >>>tmp = os.popen("hostname").read() > > >>> > > >>>...works as expected. > > >>> > > >>>however, > > >>> > > >>>tmp = os.popen("cmd").read() > > >>>...i would like to have access to the cmd process...i.e. enter commands > > >>>like a normal command line. os.system() allows this, but i dont want > > >>>output to the screen..i wanna store it to a variable. then send > > >>>content of variable elsewhere, receive more input and submit it. > > >>>almost emulate the windows command prompt. > > >>> > > >>>any ideas? > > >>> > > > > > > From http Fri Oct 7 12:17:53 2005 From: http (Paul Rubin) Date: 07 Oct 2005 09:17:53 -0700 Subject: socketServer questions References: <1128699247.9040.15.camel@athop1.ath.vt.edu> Message-ID: <7xll15paha.fsf@ruckus.brouhaha.com> rbt writes: > 1. Do I need to use threads to handle requests, if so, how would I > incorporate them? The clients are light and fast never sending more > than 270 bytes of data and never connecting for more than 10 seconds > at a time. There are currently 500 clients and potentially there > could be a few thousand... how high does the current version scale? The way it's written now, the server reads a single request, writes some stuff to the log, and closes the connection. It can't handle multiple requests simultaneously, but that's ok, no connection stays open for very long. If you want to have longer-running connections open simultaneously, you need some type of concurrency such as threads. But then you have to write the code differently, to serialize the log recording. You probably should get a copy of "Python Cookbook" which explains the basics of multi-threaded programming, if you have to ask a question > like that. > 2. What's the proper way to handle server exceptions (server stops, > fails to run at boot, etc.)? > 3. How do I keep people from tampering with the server? The clients > send strings of data to the server. All the strings start with x and > end with y and have z in the middle. Is requiring x at the front and > y at the back and z someplace in the middle enough to keep people > out? I'm open to suggestions. It only keeps them out if they don't know to use that x..y..z pattern and maybe not even then. Get a copy of "Security Engineering" by Ross Anderson to have an idea of what you're dealing with, especially if your server controls something valuable. From smitty_one_each at bigfoot.com Thu Oct 13 17:35:59 2005 From: smitty_one_each at bigfoot.com (Chris Smith) Date: Thu, 13 Oct 2005 17:35:59 -0400 Subject: [Info] PEP 308 accepted - new conditional expressions References: <3q4ro9Fd770nU3@individual.net> <87irw3l0qb.fsf@bigfoot.com> Message-ID: <8764s185hc.fsf@bigfoot.com> >>>>> "Duncan" == Duncan Booth writes: Duncan> Chris Smith wrote: >> What I really want to do is take four lines of conditional, and >> put them into one, as well as blow off dealing with a 'filler' >> variable: >> >> return "the answer is " + "yes" if X==0 else "no" >> >> >> Or whatever the final release syntax is. Duncan> The syntax is fine, but the semantics might not be what Duncan> you expected. If I understand it correctly you need: Duncan> return "the answer is " + ("yes" if X==0 else "no") Duncan> Guido's pronouncement said: >> In general, 'if' and 'else' bind less tight than everything >> except lambda. I say, with the utmost arrogance, that I won't neglect the parens more than, say, 50 times. ;) -Chris From albalmer at att.net Mon Oct 10 12:35:58 2005 From: albalmer at att.net (Alan Balmer) Date: Mon, 10 Oct 2005 09:35:58 -0700 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> Message-ID: <036lk15rkocgpjjlbdl11vsr82tkrc4bmn@4ax.com> On Sat, 08 Oct 2005 20:43:12 GMT, Roedy Green wrote: >On Tue, 04 Oct 2005 17:57:13 -0000, gordonb.u09l7 at burditt.org (Gordon >Burditt) wrote or quoted : > >>HTML enables a heck of a lot of problems: "web bugs" in email, >>links to fake sites that appear as real ones in what shows up >>on the screen, Javascript viruses, denial-of-service attacks >>(pages that open two windows when you close one), etc. >> >>>That is like hating all choirs because televangelists use them. >> >>I liken it more to hating all viruses because some of them >>install keyloggers. > > I take it then you avoid browsers or use Lynx? No you FIX the >problems rather than wear a hair shirt. Same for email. Why should >rich expressions only be permitted to those with websites. > >Some people use email PRIMARILY for sharing photos. And they don't know about attachments? -- Al Balmer Balmer Consulting removebalmerconsultingthis at att.net From http Sun Oct 9 05:49:38 2005 From: http (Paul Rubin) Date: 09 Oct 2005 02:49:38 -0700 Subject: Function decorator that caches function results References: Message-ID: <7x4q7rt3yl.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > > def cache_function(fn): > > cache = {} > > def cached_result(*args, **kwargs): > > if args in cache: > > return cache[args] > > result = fn(*args, **kwargs) > > cache[args] = result > > return result > > return cached_result > > I'm curious... where does cache live after you use cache_function to > memoize some function? It doesn't appear to be an attribute of the newly > memoized function, nor does it look like a global variable. It's in the closure returned by cache_function. cached_result doesn't change the value of 'cache' (it only changes the boxed content), cached_result finds it in the outer scope, so you can get away with that in Python. You couldn't do something like: def counter(): n = 0 def k(): n += 1 # rebinds n, so Python thinks n is local, oops return n return k Since k changes the value of n, Python thinks n is local to k, and you get a NameError when you try to increment it the first time. That you can't set the value of a closure variable is something of a Python wart and is one of the things that makes me want a "local" declaration in Python. Closures are a Scheme idiom and Pythonistas tend to use class instances instead, but both techniques are useful. From leszczynscyATnospam.yahoo.com.nospam Wed Oct 26 23:36:10 2005 From: leszczynscyATnospam.yahoo.com.nospam (Andy Leszczynski) Date: Wed, 26 Oct 2005 22:36:10 -0500 Subject: Python vs Ruby In-Reply-To: References: Message-ID: Amol Vaidya wrote: > Hi. I am interested in learning a new programming language, and have been > debating whether to learn Ruby or Python. How do these compare and contrast > with one another, and what advantages does one language provide over the > other? I would like to consider as many opinions as I can on this matter > before I start studying either language in depth. Any help/comments are > greatly appreciated. Thanks in advance for your help. How Ruby solves the problem of global interpreter lock? A. From gandalf at designaproduct.biz Tue Oct 11 03:23:27 2005 From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy) Date: Tue, 11 Oct 2005 09:23:27 +0200 Subject: Send password over TCP connection In-Reply-To: <7xd5md76kd.fsf@ruckus.brouhaha.com> References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> <7xd5md76kd.fsf@ruckus.brouhaha.com> Message-ID: <434B686F.10903@designaproduct.biz> >If you really want to do it right, use SRP, . > > This is a bit offtopic here. I read the RFC and I do not see why SRP is not vulnerable to dictionary attacks. If I have a working client software then I can use it to reveal passwords. Isn't it a dictionary attack? Can you please enlighten me? Les From mwm at mired.org Fri Oct 28 19:59:56 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 28 Oct 2005 19:59:56 -0400 Subject: Automatic binding of **kwargs to variables References: <1130539752.667045.183460@g14g2000cwa.googlegroups.com> Message-ID: <86d5lpdwg3.fsf@bhuda.mired.org> "lbolognini at gmail.com" writes: > I have a very long list of parameters coming from a web form to my > method foo(self, **kwargs) > > I would like to avoid manually binding the variables to the values > coming through the **kwargs dictionary, just to keep the code cleaner, > I'd like to bind them automatically > > I was adviced against doing it by adding stuff to locals such as: > > locals()["x"] = 5 > > since the Python Docs say: > > Warning: The contents of this dictionary should not be modified; > changes may not affect the values of local variables used by the > interpreter. > > Is there a way to do this? Maybe object.__setattr__() or something that > involves metaclasses? .__setattr__() will modify the instance variables, not the local variables. > As I might go touching something that I shouldn't (like locals()) I'd > like some advice from you before deciding which way to go. Reference the keyword arguments through the dictionary. Looking up values by name is what dictionaries are for. Trying to move the names from a dictionary into the local (or global) namespace is usually a bad idea. If you don't know all the names in advance, you risk collisions between the items in the dictionary and the legitimate inhabitants of the namespace. If you do know all the names in advance, you need to make sure the keys in the dictionary are in the list of values you expect, so you need an explicit list. That said, the most straightforward way to do this that I can think of is with exec: for name, value in kwargs.items(): if name in ('a', 'list', 'of', 'valid', 'keywords'): exec "%s = %s" % (name, value) else: raise ValueError, "Unrecognized keyword " + name Others will probably tell you that you really shouldn't be using exec. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From jepler at unpythonic.net Wed Oct 12 19:50:49 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Wed, 12 Oct 2005 18:50:49 -0500 Subject: Python's garbage collection was Re: Python reliability In-Reply-To: References: <7xr7au1hr5.fsf@ruckus.brouhaha.com> <7xwtkl21hn.fsf@ruckus.brouhaha.com> <7xll11twc2.fsf@ruckus.brouhaha.com> Message-ID: <20051012235048.GA8826@unpythonic.net> On Mon, Oct 10, 2005 at 08:37:03PM +0100, Tom Anderson wrote: > So python doesn't use the old SmallTalk 80 SmallInteger hack, or similar? > Fair enough - the performance gain is nice, but the extra complexity would > be a huge pain, i imagine. I tried to implement this once. There was not a performance gain for general code, and I also made the interpreter buggy in the process. I wrote in 2002: | Many Lisp interpreters use 'tagged types' to, among other things, let | small ints reside directly in the machine registers. | | Python might wish to take advantage of this by designating pointers to odd | addresses stand for integers according to the following relationship: | p = (i<<1) | 1 | i = (p>>1) | (due to alignment requirements on all common machines, all valid | pointers-to-struct have 0 in their low bit) This means that all integers | which fit in 31 bits can be stored without actually allocating or deallocating | anything. | | I modified a Python interpreter to the point where it could run simple | programs. The changes are unfortunately very invasive, because they | make any C code which simply executes | o->ob_type | or otherwise dereferences a PyObject* invalid when presented with a | small int. This would obviously affect a huge amount of existing code in | extensions, and is probably enough to stop this from being implemented | before Python 3000. | | This also introduces another conditional branch in many pieces of code, such | as any call to PyObject_TypeCheck(). | | Performance results are mixed. A small program designed to test the | speed of all-integer arithmetic comes out faster by 14% (3.38 vs 2.90 | "user" time on my machine) but pystone comes out 5% slower (14124 vs 13358 | "pystones/second"). | | I don't know if anybody's barked up this tree before, but I think | these results show that it's almost certainly not worth the effort to | incorporate this "performance" hack in Python. I'll keep my tree around | for awhile, in case anybody else wants to see it, but beware that it | still has serious issues even in the core: | >>> 0+0j | Traceback (most recent call last): | File "", line 1, in ? | TypeError: unsupported operand types for +: 'int' and 'complex' | >>> (0).__class__ | Segmentation fault | | http://mail.python.org/pipermail/python-dev/2002-August/027685.html Note that the tree where I worked on this is long since lost. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From aleax at mail.comcast.net Mon Oct 10 04:27:49 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Mon, 10 Oct 2005 10:27:49 +0200 Subject: Question about parsing a string References: Message-ID: <1h47os6.237r7a1srkiyaN%aleax@mail.comcast.net> Nico Grubert wrote: > Hi there, > > I would like to parse a string in Python. > > If the string is e.g. '[url=http://www.whatever.org][/url]' I would like > to generate this string: > 'http://www.whatever.org' > > If the string is e.g. '[url=http://www.whatever.org]My link[/url]' I > would like to generate this string: > 'My link' > > Any idea how I can do this? Maybe with regular expressions? If you know the string always starts with '[url=' and ends with '[/url]' (or, any string not thus starting/ending are to be skipped, etc), REs are a bit of an overkill (they'll work, but you can do it more simply). If your actual needs are different, you'll have to express them more explicitly. But assuming the "given starting and ending" scenario: _start = '[url=' _startlen = len(_start) _end = '[/url]' _endlen = len(_end) def doit(s): if s[:_startlen] != _start: raise ValueError if s[-_endlen:] != _end: raise ValueError where_closebracket = s.index(']') url = s[_startlen:where_closebracket] txt = s[where_closebracket+1:-_endlen] if not txt: txt = url return '%s' % (url, txt) I've just typed in this code without trying it out, but roughly it should be what you want. Alex From lasse at vkarlsen.no Fri Oct 28 04:51:40 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Fri, 28 Oct 2005 10:51:40 +0200 Subject: how to associate files with application In-Reply-To: <1130439184.801178.280190@g14g2000cwa.googlegroups.com> References: <1130439184.801178.280190@g14g2000cwa.googlegroups.com> Message-ID: Ashok wrote: > hi, > i want to know how to make a specific type of file open in an > application i developed in python when the user clicks on the file.(in > windows) for eg. a .txt file when clicked opens in notepad, a .doc file > when clicked opens in MS-word. In the same way i want to make a .xyz > file open in the application i developed when clicked. > thanks in advance for any advice. > You need to add several registry keys to do this, here's a short version of what you need to do: Example assumes you want to: 1. associate .ext with C:\Program Files\MyProgram\prog.exe 2. pass on any extra arguments to prog.exe (ie. test.ext 1 2 3 would send 1 2 3 as well to prog.exe) 3. associate the icon of prog.exe to any file with a .ext extension Ok, here's what you need to do: 1. Under HKEY_CLASSES_ROOT, add a key (folder) with the name .ext 2. Open that key, and set the (Default) value to MyProgramExtendedFile (this name is something you choose yourself and should be a "identifier" that identifies the file type. If your program supports several types of files, make up unique identifiers for each.) 3. Under HKEY_CLASSES_ROOT, add another key, this time with the same name you made up in 2. above, ie MyProgramExtendedFile 4. Open that key, and set the (Default) value to a textual description of the type of file. This is what will show up in explorer in the file type column. If you leave this empty, the description will be .EXT File 5. Inside MyProgramExtendedFile, add another key with the name shell (lower-case is typical, can probably be Shell or whatever) 6. Inside shell, create another key with the name open 7. Inside open, create another key with the name command 8. Inside command, Set the (Default) value to: "C:\Program Files\MyProgram\prog.exe" "%1" %* Note that you need the quotes as specified above, exactly like written 9. Go back to MyProgramExtendedFile and create another key with the name DefaultIcon 10. Inside DefaultIcon, set (Default) value to: "C:\Program Files\MyProgram\prog.exe", 0 This will pick the first icon in prog.exe resource to show for the files. Use 1 for second, etc. There are also other commands you can add. If you want to be able to right-click on the file and select a menu item to process the file in a specific way, for instance by passing along specific parameters to prog.exe, you can add more keys than "open" on the level open is created. The (Default) value inside the key is then the text of the menu item. To find examples, just find a file extension in Windows that behaves the way you want your own to behave and look through HKEY_CLASSES_ROOT\.ext to find the details you want. -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From matt.walsh at gmail.com Thu Oct 20 22:16:00 2005 From: matt.walsh at gmail.com (MBW) Date: 20 Oct 2005 19:16:00 -0700 Subject: TK question Message-ID: <1129860960.909273.68840@g43g2000cwa.googlegroups.com> I have a class that is a windows in a GUI the following is the code: class optWin: def __init__(self): return None def __call__(self): self.root = tk() self.root.title("My title") self.root.mainloop() return None 1)Why doesn't this work when I go to call optWin 2)What is a better way to do this Thanks in advance From theller at python.net Thu Oct 20 12:50:09 2005 From: theller at python.net (Thomas Heller) Date: Thu, 20 Oct 2005 18:50:09 +0200 Subject: __getattr__, __setattr__ References: <1129822629.250883.78570@g49g2000cwa.googlegroups.com> Message-ID: "wittempj at hotmail.com" writes: > for new style classes __getattribute__ is defined, see eg. > http://www.python.org/2.2.3/descrintro.html Steve Holden writes: > >>> object.__getattribute__ > > > Ring any bells? Yes, of course. Thanks ;-) Thomas From jepler at unpythonic.net Tue Oct 11 14:17:31 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Tue, 11 Oct 2005 13:17:31 -0500 Subject: dictionnaries and lookup tables In-Reply-To: <1129053992.141269.149840@z14g2000cwz.googlegroups.com> References: <1129053992.141269.149840@z14g2000cwz.googlegroups.com> Message-ID: <20051011181731.GD21569@unpythonic.net> On Tue, Oct 11, 2005 at 11:06:32AM -0700, m.barenco at gmail.com wrote: > Note that when I type: > >>>dir(D) [...] > the functions __ge__, __gt__, __lt__, __le__ seem to be non-implemented > but there is some __doc__ in them. Is there the intention to do > something similar as is described above or are they here for some > (future) dictionnary comparison purposes? Sure they're implemented. That's why I can compare dictionaries for equality or order. >>> d = {1: None} >>> e = {1: None} >>> f = {2: None} >>> d == e True >>> d == f False >>> d < f or f < e True If the operation you need to optimize is "find the largest element that is smaller than X", then perhaps you want to use the bisect module. This involves keeping your information in a sorted list of tuples, instead of in a dictionary. However, removing or inserting items has O(n) complexity instead of O(1). Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From mwm at mired.org Mon Oct 24 10:03:44 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 24 Oct 2005 10:03:44 -0400 Subject: output from external commands References: <435C6642.8020504@colannino.org> Message-ID: <868xwj6mgv.fsf@bhuda.mired.org> darren kirby writes: > If all you want is filenames this will work: >>>> import glob >>>> files = ["%s" % f for f in glob.glob("*")] What's the point of doing "%s" % f? How is this different from just file = [f for f in glob.glob("*")]? http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From jabel at plus.net Mon Oct 24 10:46:18 2005 From: jabel at plus.net (John Abel) Date: Mon, 24 Oct 2005 15:46:18 +0100 Subject: Python/Apache Oddness On OSX Message-ID: <435CF3BA.9050506@plus.net> Hi, I'm running Python 2.3.5/2.4.2 on OSX 10.4.2, and am trying to run CGI scripts using the builtin Apache. For ease, I've symlinked my custom modules into the /Library/Python/2.3/site-packages directory, and they import OK via command line python. However, when I perform the import from a cgi script, python fails to find the module. It is definately something to do with the symlink, as the CGI works OK if I copy the directory into site-packages. Is there some oddness with Python/Apache and symlink imports? Any pointers would be most useful. Thanks J From meatpodeye at yahoo.com Sat Oct 8 19:04:49 2005 From: meatpodeye at yahoo.com (Gorlon the Impossible) Date: Sat, 08 Oct 2005 23:04:49 GMT Subject: Pyzine article Python and MIDI Message-ID: ok, here's a long shot: would anyone here who subscribes to Pyzine be willing to send me the article on Python and MIDI from Issue #6? I would be eternally grateful as I am strapped for funds and cannot justify spending the money for a 1 yr subscription when i am only interested in this one article. Thanks. here's the link... http://www.pyzine.com/Issue006/index.html please? pretty please? with sugar on top? Bri meatpodeye at yahoo.com From larry.bates at websafe.com Thu Oct 20 10:17:38 2005 From: larry.bates at websafe.com (Larry Bates) Date: Thu, 20 Oct 2005 09:17:38 -0500 Subject: Accessing a dll from Python In-Reply-To: <1129814361.130127.255990@f14g2000cwb.googlegroups.com> References: <1129814361.130127.255990@f14g2000cwb.googlegroups.com> Message-ID: <4357A702.1040209@websafe.com> If you want you can also take a look at something I wrote a while ago (before ctypes was really well known). It has worked for me with .DLLS form Castelle and Expervision that both have extensive APIs. It is located here: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146847 Larry Bates dcrespo wrote: > Hi to all, > > Can someone give me lights on how can I deal with dlls from python? > > My main purpose is to get access to a Unitech PT600 Bar Code system. I > have the dll that works fine through Visual Basic. But I'm migrating to > Python, so I need a way to use the same dll, or a C library. > > I tried to access a dll created by myself on Visual Basic. The dll just > have one function. It works perfect when using it on a VB project just > including it in the references configuration. But I can't access it > from python. I tried the ctypes module. > > Thank you > > Daniel > From rupole at hotmail.com Wed Oct 26 20:32:09 2005 From: rupole at hotmail.com (Roger Upole) Date: Wed, 26 Oct 2005 20:32:09 -0400 Subject: Using Python to add thumbnails to Explorer References: <1130355747_658@spool6-east.superfeed.net> Message-ID: <1130373382_7@spool6-east.superfeed.net> Sorry, I didn't realize you meant per-file. However, Pythoncom supports both the interfaces (IExtractIcon and IPersistFile) specified on the page you referenced, so you ought to be able to implement an icon handler with the Pywin32 extensions. Roger "c d saunter" wrote in message news:djoqn3$s0d$1 at heffalump.dur.ac.uk... > Hi Roger, > Thanks for the info - I was actually interested in custom > per file thumbnails rather than icons, but your message sentt me > pouring through seemingly relevent parts of the registry - however > what I need isn't there. > > Turns out I need to use a .dll shell extension as per > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ > shellcc/platform/shell/programmersguide/shell_int/shell_int_extending/ > extensionhandlers/shell_ext.asp > > Not so simple, and not (directly) a job for Python. > > Thanks, > Chris > Roger Upole (rupole at hotmail.com) wrote: > : As you guessed, the icon locations are stored in the registry. > : There's a key under HKEY_CLASSES_ROOT for each > : registered file type, with a default value holding the class name. > : Under the class name, there's a DefaultIcon key that gives > : the path to the icon. Using python files an an example, you > : have HKCR\.py with Default=Python.File, and under > : HKCR\Python.File\DefaultIcon, you should have the > : path to py.ico. You can use the _winreg module to create > : your own entries. > > : hth > : Roger > > > > ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= East/West-Coast Server Farms - Total Privacy via Encryption =--- From shitizb at yahoo.com Fri Oct 14 20:35:31 2005 From: shitizb at yahoo.com (Shitiz Bansal) Date: Fri, 14 Oct 2005 17:35:31 -0700 (PDT) Subject: wierd threading behavior In-Reply-To: <1129332571.166816.209360@z14g2000cwz.googlegroups.com> Message-ID: <20051015003531.30516.qmail@web53809.mail.yahoo.com> seems that in the thread module, the stdout stream is captured by a single thread. Qun Cao wrote:Thanks Sam, That was a stupid typo ( yeah, I actually typed it in :), it should be (test,()). I am using python 2.4.1 in ubuntu. I do aware that threading.Thread is prefered, but I did not realize thread is deprecated. It is still a mysterious behavior anyhow. :) -- http://mail.python.org/mailman/listinfo/python-list --------------------------------- Yahoo! Music Unlimited - Access over 1 million songs. Try it free. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwm at mired.org Fri Oct 21 19:10:59 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 21 Oct 2005 19:10:59 -0400 Subject: Python cgi References: <1129930246.435616.291660@g44g2000cwa.googlegroups.com> Message-ID: <86r7aesby4.fsf@bhuda.mired.org> "jbrewer" writes: > Also, I need to run an external program with my CGI script using > something like os.system with flags from input forms, which is a major > security risk. Is it simply enough to test for flag.isalnum() or > should I do more to prevent random programs from being run? I should > also do some minimal DOS protection as well, so information on how to > do that simply would be appreciated as well. Map the input data through a dictionary: flags = dict(longflag = '-l', verboseflag = '-v', ...) comflags = [flags[flag] for flag in flags if form[flag].value] os.system(mycommand, *comflags) or words to that effect. The critical thing is that data from over the net never goes into the command, it's just used to look up values in the dictionary, which provides strings you know are safe to pass to the command. The downside is that the client can only use flags your code knows about. Of course, that's also an *upside*. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From fredrik at pythonware.com Thu Oct 13 11:25:49 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 13 Oct 2005 17:25:49 +0200 Subject: Pass a tuple (or list) to a C wrapper function References: <1129147560.524316.281110@g43g2000cwa.googlegroups.com><1129152455.3374.20.camel@localhost.localdomain> <1129207125.929288.77350@o13g2000cwo.googlegroups.com> Message-ID: "Java and Swing" wrote: > anyhow, for receiving an object from python..is it > > ok = PyArg_ParseTuple(args, "sO", &x, &y); > > ...is it "sO" or "s0" ....is it O (as in the letter) or 0 (as in the > number)? I would think "O" the letter..but it looks like a zero. eh? if you're not sure, what keeps you from cutting and pasting ? or comparing it visually with characters that you type in yourself ? (it's the letter O, for Object. the corresponding variable must be a pointer to a PyObject pointer. see the documentation for details: http://www.python.org/doc/current/api/arg-parsing.html ) From debl2_nospammy at verizon.net Sat Oct 22 00:11:51 2005 From: debl2_nospammy at verizon.net (David) Date: Sat, 22 Oct 2005 04:11:51 GMT Subject: Problem with py2exe Message-ID: I am unable to use py2exe to create an executable, even on the simple sample that comes with the package. There seems to be a problem when it is copying files. The ?build? and ?dist? directories are created and populated, but there is no executable created. The error message says: setup.py returned exit code: can?t copy c:\Python24\Lib\sit I am running on Windows XP with distribution 2.4.2 and executing the setup.py from Pythonwin Build 204 I downloaded py2exe from sourceforge the version of py2exe for Python 2.4 Can anyone suggest what may be wrong? Thanks in advance David From rrr at ronadam.com Mon Oct 24 22:53:00 2005 From: rrr at ronadam.com (Ron Adam) Date: Tue, 25 Oct 2005 02:53:00 GMT Subject: namespace dictionaries ok? In-Reply-To: References: Message-ID: James Stroud wrote: > Here it goes with a little less overhead: > > > py> class namespace: > ... def __init__(self, adict): > ... self.__dict__.update(adict) > ... > py> n = namespace({'bob':1, 'carol':2, 'ted':3, 'alice':4}) > py> n.bob > 1 > py> n.ted > 3 > > James But it's not a dictionary anymore so you can't use it in the same places you would use a dictionary. foo(**n) Would raise an error. So I couldn't do: def foo(**kwds): kwds = namespace(kwds) kwds.bob = 3 kwds.alice = 5 ... bar(**kwds) #<--- do something with changed items Ron > On Monday 24 October 2005 19:06, Ron Adam wrote: > >>Hi, I found the following to be a useful way to access arguments after >>they are passed to a function that collects them with **kwds. >> >> >> class namespace(dict): >> def __getattr__(self, name): >> return self.__getitem__(name) >> def __setattr__(self, name, value): >> self.__setitem__(name, value) >> def __delattr__(self, name): >> self.__delitem__(name) >> >> def foo(**kwds): >> kwds = namespace(kwds) >> print kwds.color, kwds.size, kwds.shape etc.... >> >> foo( color='red', size='large', shape='ball', .... etc..) >> >> >>It just seems awkward to have to use "string keys" in this situation. >>This is easy and still retains the dictionary so it can be modified and >>passed to another function or method as kwds again. >> >>Any thoughts? Any better way to do this? >> >>Cheers, Ron From gsakkis at rutgers.edu Fri Oct 14 17:42:29 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Fri, 14 Oct 2005 17:42:29 -0400 Subject: Function to execute only once References: <1129317118.937439.159550@g43g2000cwa.googlegroups.com> <1129322058.901077.90680@o13g2000cwo.googlegroups.com> Message-ID: <1129326153.90af6e69484850ae117b7a9245589d82@teranews> "snoe" wrote: > I've been seeing alot about decorators and closures lately and my > initial thought was that this would be a good place to use them instead > of wrapping it around a class. That was my initial thought :) What I > came up with was this: Apparently you're not the first to think of it: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/425445. George From pwatson at redlinepy.com Mon Oct 31 15:05:37 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Mon, 31 Oct 2005 14:05:37 -0600 Subject: Scanning a file In-Reply-To: References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <87ek65kbw5.fsf@lucien.dreaming> <1h5760l.1e2eatkurdeo7N%aleaxit@yahoo.com> <3siakvFohl3aU1@individual.net> <1h57cij.16dkc141lds4s4N%aleaxit@yahoo.com> <1h597yx.wjk2a71spyjhyN%aleaxit@yahoo.com> <3smn47FoolfbU1@individual.net> Message-ID: <3snboiFolt77U1@individual.net> Steve Holden wrote: >> Since everyone needs this, how about building it in such that files >> which are closed by the runtime, and not user code, are reported or >> queryable? Perhaps a command line switch to either invoke or suppress >> reporting them on exit. >> > This is a rather poor substitute from correct program design and > implementation. It also begs the question of exactly what constitutes a > "file". What about a network socket that the user has run makefile() on? > What about a pipe to another process? This suggestion is rather > ill-defined. > >> Is there any facility for another program to peer into the state of a >> Python program? Would this be a security problem? > > It would indeed be a security problem, and there are enough of those > already without adding more. > > regards > Steve All I am looking for is the runtime to tell me when it is doing things that are outside the language specification and that the developer should have coded. How "ill" will things be when large bodies of code cannot run successfully on a future version of Python or a non-CPython implementation which does not close files. Might as well put file closing on exit into the specification. The runtime knows it is doing it. Please allow the runtime to tell me what it knows it is doing. Thanks. From joe at invalid.address Tue Oct 25 12:00:58 2005 From: joe at invalid.address (joe at invalid.address) Date: 25 Oct 2005 11:00:58 -0500 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: Steven D'Aprano writes: > On Tue, 25 Oct 2005 09:56:28 -0500, joe wrote: > > > Yes, I know, they can do whatever they want, it's not a crime, > > etc. However when they use their market position to disallow > > competition, it sounds to me like they're worried about something, > > and trying to squelch it. > > But that's the whole point: they *can't* do whatever they want, They've been pretty much doing just that for a long time. The "it's not a crime etc" part was to deflect parenthetical arguments that confuse the issue. In other words, I was recognizing that a lot of people don't think what MS does is a crime, and until MS gets convicted of a crime, it's a matter of opinion. I was trying to say something else. > and certain behaviours *are* crimes. Just because Microsoft > executives wear business suits instead of torn jeans or dirty > sweatshirts doesn't make them beyond the law. Maybe, but good lawyers might :-) Joe -- Gort, klatu barada nikto From irmen.NOSPAM at xs4all.nl Thu Oct 6 20:17:53 2005 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Fri, 07 Oct 2005 02:17:53 +0200 Subject: ANN: Pyro 3.5 (remote objects) Message-ID: <4345beb1$0$11064$e4fe514c@news.xs4all.nl> I'm glad to announce the new version of Python's own powerful remote method invocation technology -- Pyro 3.5 (final)! You can get it via http://pyro.sourceforge.net, then go to the SF project homepage download area. It has many new features and improvements over Pyro 3.4, which was released mor than a year ago. Most important new stuff: - more efficient socket code, up to 20% performance gain - mobile code bug fixes - name server bug fixes - added a few interesting new examples - manual has been updated - various other minor fixes and improvements For the full list, see the change log in the manual: http://pyro.sourceforge.net/manual/12-changes.html#latest Have fun, and thanks for your interest, support, and feedback! --Irmen de Jong ---> What is Pyro? Pyro is an acronym for PYthon Remote Objects. Pyro is an advanced and powerful Distributed Object Technology system written entirely in Python, that is designed to be very easy to use. It is extremely easy to implement a distributed system with Pyro, because all network communication code is abstracted and hidden from your application. You just get a remote Python object and invoke methods on the object on the other machine. Pyro offers you a Name Server, an Event Service, mobile objects, remote exceptions, dynamic proxies, remote attribute access, automatic reconnection, a very good and detailed manual, and many examples to get you started right away. From aleaxit at yahoo.com Sat Oct 29 17:14:59 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 29 Oct 2005 14:14:59 -0700 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <87ek65kbw5.fsf@lucien.dreaming> Message-ID: <1h5760l.1e2eatkurdeo7N%aleaxit@yahoo.com> Tim Roberts wrote: ... > >> print file("filename", "rb").read().count("\x00\x00\x01\x00") > > > >Funny you should say that, because I can't stand unnecessary one-liners. > > > >In any case, you are assuming that Python will automagically close the > >file when you are done. > > Nonsense. This behavior is deterministic. At the end of that line, the > anonymous file object out of scope, the object is deleted, and the file is > closed. In today's implementations of Classic Python, yes. In other equally valid implementations of the language, such as Jython, IronPython, or, for all we know, some future implementation of Classic, that may well not be the case. Many, quite reasonably, dislike relying on a specific implementation's peculiarities, and prefer to write code that relies only on what the _language_ specs guarantee. Alex From ddelay at club-internet.fr Sun Oct 9 08:29:39 2005 From: ddelay at club-internet.fr (daniel delay) Date: Sun, 09 Oct 2005 14:29:39 +0200 Subject: What about letting x.( ... ? ... ) be equivalent to ( ... x ... ) In-Reply-To: References: Message-ID: <43490d16$0$6485$626a14ce@news.free.fr> Fredrik Lundh a ?crit : > ddelay at club-internet.fr wrote: > > >>These 3 intermediate variables used to improve readability >>can introduce bugs : you have to check that b, c and d are >>not used anywhere else in the code. > > > if you have a fear of introducing new local variables, you have problems > that cannot be solved by syntax. > > > There's something i don't understand : I've posted the original message you reply to yesterday, but I still cannot see it in comp.lang.python, while I can see your reply, and my reply to your reply. I tried with two different providers to get the messages, but with the same result. Is it possible that this msg could have been throwned away by moderators of this list ?? But in this case, you wouldn't have been able to read it... Daniel delay From hancock at anansispaceworks.com Fri Oct 7 16:28:24 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Fri, 7 Oct 2005 15:28:24 -0500 Subject: When someone from Britain speaks, Americans hear a "British accent"... In-Reply-To: References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <4h5ck1hkqq0ls83pq0lodkb51tsda4053k@4ax.com> Message-ID: <200510071528.25305.hancock@anansispaceworks.com> On Friday 07 October 2005 03:01 am, Steve Holden wrote: > OK, so how do you account for the execresence "That will give you a > savings of 20%", which usage is common in America? In America, anyway, "savings" is a collective abstract noun (like "physics" or "mechanics"), there's no such noun as "saving" (that's present participle of "to save" only). How did you expect that sentence to be rendered? Why is it an "execresence"? By the way, dict.org doesn't think "execresence" is a word, although I interpret the neologism as meaning something like "execrable utterance": dict.org said: > No definitions found for 'execresence'! Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From sweet_thiruvonam at yahoo.co.in Wed Oct 5 03:01:17 2005 From: sweet_thiruvonam at yahoo.co.in (sweet_thiruvonam at yahoo.co.in) Date: 5 Oct 2005 00:01:17 -0700 Subject: Turn $6 into $6.000 In-Reply-To: <1128476043.147955.40620@f14g2000cwb.googlegroups.com> References: <1128476043.147955.40620@f14g2000cwb.googlegroups.com> Message-ID: <1128493391.314202.293820@g43g2000cwa.googlegroups.com> Hello, Happy Harmony is the fastest growing matrimonial portal for Indians. You can email and IM other members without paying anything on this site. The amazing thing is that this site is totally free. Absolutely free. Cannot believe? Then click on this link to visit and register Happy Harmony. http://www.happyharmony.com/?idAff=14 Background check is the new facility they have added now. You can do a free background check including age, address, phone numbers, property owneship information etc of anybody in the US. Regards, Resh From grant.bodie at gmail.com Thu Oct 20 12:04:24 2005 From: grant.bodie at gmail.com (grant.bodie at gmail.com) Date: 20 Oct 2005 09:04:24 -0700 Subject: Ruby on Rails Agile role Message-ID: <1129824264.055233.186310@f14g2000cwb.googlegroups.com> I am looking for 2 Software Engineers with a Java / Python / Ruby background to work for a rapidly growing start-up using Ruby on Rails in an Agile environment. The role is paying between ?40 - ?45k and is based in central London. Please send your details to grant @ connectionsrecruit.co.uk or call 01189897601 From jhu at metrigenix.com Wed Oct 5 21:35:01 2005 From: jhu at metrigenix.com (James Hu) Date: Wed, 5 Oct 2005 21:35:01 -0400 Subject: return struct in ctypes Message-ID: <90DEA7ED93F71A4580CEDF76A02682EA04C273@torexch.metrigenix.com> hi, I need to use ctypes to call the API function like fun1(&list, listLen) //here list is struct { long id; long type; long isOpen;} ListItem; so I define class LIST_ITEM(Structure): _fields_ = [("Id", c_ulong), ("Type",c_ulong ), ("isOpen", c_ulong), ] list=LIST_ITEM() listLen=c_ulong(1) thedriver.fun1(byref(list),listLen) doesn't work, here the list is input param, not return info. if use list=c_char_p() thedriver.fun1(byref(list),listLen) how can I convert the list to LIST_ITEM? another Q is : how to use ctypes to implement this: struct1 mySettings; // here struct1 {long size; long params[32];} mySettings.size = sizeof(mySettings); Where can get ctypes good samples? the samples with the package seems very simple. and the ctypes tutorial doesn't handle these cases either. Thanks in advance James -------------- next part -------------- An HTML attachment was scrubbed... URL: From pmartin at snakecard.com Mon Oct 24 16:18:27 2005 From: pmartin at snakecard.com (Philippe C. Martin) Date: Mon, 24 Oct 2005 20:18:27 GMT Subject: python cgi script not understood as html References: <80b7f.6738$tV6.6215@newssvr27.news.prodigy.net> Message-ID: Many thanks !! Regards, Philippe Mitja Trampus wrote: > Philippe C. Martin wrote: >> Hi, >> >> The following code outputs the actual HTML text to the browser, not the >> interpreted text. >> >> Any idea ? >> >> html_ok = """ >> Content-Type: text/html\n > > > > ... > > """ > > Avoid the starting newline (before content-type). > Add at least TWO newlines after content-type. > > Or use a package to handle the HTTP stuff for you. From mekstran at scl.ameslab.gov Thu Oct 6 10:09:58 2005 From: mekstran at scl.ameslab.gov (Michael Ekstrand) Date: Thu, 6 Oct 2005 09:09:58 -0500 Subject: /usr/bin/env python, force a version In-Reply-To: <1128597929.636452.223890@o13g2000cwo.googlegroups.com> References: <1128597929.636452.223890@o13g2000cwo.googlegroups.com> Message-ID: <200510060909.58454.mekstran@scl.ameslab.gov> On Thursday 06 October 2005 06:25, manatlan at gmail.com wrote: > I hope you understand my needs. Is there a python/bash mechanism to > override the default python version of the system ... and run the > script with any version of python (but the most recent) ? > or can you explain me how to do that ? the simplest way ? This solution makes a few assumptions... but it should work in the majority of cases. The principle is that Python is, in my experience, *usually* installed as python2.4 or whatever - even ./configure && make && make install in the tarball makes python a symbolic link to a python2.4 executable. Assuming that this is the case, and that python2.4 will never be any other version of Python: #!/bin/sh APPPATH=/path/to/app PYTHON=`which python2.4` if [ $? != 0 ]; then echo "This program requires Python 2.4 to be installed." >/dev/stderr exit 1 fi "$PYTHON" "$APPATH" "$@" Problems: Requires Python 2.4 to be installed as python2.4, and doesn't have upward compatibility (i.e. 2.5). But it's at least as good as #!/usr/bin/env python2.4, and it gives a clean error message. -Michael From mtebeka at qualcomm.com Thu Oct 6 06:21:47 2005 From: mtebeka at qualcomm.com (Miki Tebeka) Date: Thu, 6 Oct 2005 13:21:47 +0300 Subject: Swig and pointers In-Reply-To: <1128541976.495441.46140@f14g2000cwb.googlegroups.com> References: <1128541976.495441.46140@f14g2000cwb.googlegroups.com> Message-ID: <20051006102147.GB8064@qualcomm.com> Hello Java, > ... > extern int doIt(char *a, MY_DIGIT **digit); > %include cpointer.i > %pointer_functions(MY_DIGIT, md_prt); Don't you mean md_ptr? > %typemap(in) (char *a, MY_DIGIT **argv) { > /* Check if is a list */ > if (PyList_Check($input)) { > int i; > $1 = PyList_Size($input); > $2 = (MY_DIGIT **) malloc(($1+1)*sizeof(long *)); > for (i = 0; i < $1; i++) { > PyObject *o = PyList_GetItem($input,i); > if (PyString_Check(o)) > $2[i] = PyString_AsString(PyList_GetItem($input,i)); > else { > PyErr_SetString(PyExc_TypeError,"list must contain strings"); > free($2); > return NULL; > } > } > $2[i] = 0; > } else { > PyErr_SetString(PyExc_TypeError,"not a list"); > return NULL; > } > } > > %typemap(freearg) (char *a, MY_DIGIT **argv) { > free((MY_DIGIT *) $2); > } > > > ..from Python I am trying > > >> ptr = [] > >> doIt("blah", ptr) > > I thought this was the correct approach as described here: > http://www.swig.org/Doc1.3/SWIGDocumentation.html#Python_nn59 > > However, python comes back and says "TypeError: argument number 2: a > 'MY_DIGIT **' is expected, 'list([])' is received" > > ..any ideas? Didn't check it but from http://www.swig.org/Doc1.3/Library.html it looks like you need to do: ptr = new_md_prt() HTH. -- ------------------------------------------------------------------------ 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 enas_khalil at yahoo.com Thu Oct 13 14:29:29 2005 From: enas_khalil at yahoo.com (enas khalil) Date: Thu, 13 Oct 2005 11:29:29 -0700 (PDT) Subject: IOError: brown is not installed In-Reply-To: Message-ID: <20051013182929.30858.qmail@web30514.mail.mud.yahoo.com> hello , when i run this code for unigramtagger : from nltk.tagger import * from nltk.corpus import brown # Tokenize ten texts from the Brown Corpus train_tokens = [] for item in brown.items()[:10]: train_tokens.append(brown.read(item)) # Initialise and train a unigram tagger mytagger = UnigramTagger(SUBTOKENS='WORDS') for tok in train_tokens: mytagger.train(tok) #Once a UnigramTagger has been trained, the tag() method can be used to tag new text: text_token = Token(TEXT="John saw the book on the table") WhitespaceTokenizer(SUBTOKENS='WORDS').tokenize(text_token) mytagger.tag(text_token) print text_token i got the following : Traceback (most recent call last): File "F:\MSC first Chapters\unigramgtag1.py", line 5, in -toplevel- for item in brown.items()[:10]: File "C:\Python24\Lib\site-packages\nltk\corpus\__init__.py", line 589, in items self._initialize() File "C:\Python24\Lib\site-packages\nltk\corpus\__init__.py", line 518, in _initialize raise IOError('%s is not installed' % self._name) IOError: brown is not installed although i have extracted the brown folder and put it in the NLTK path what should i do thanks in advance --------------------------------- Yahoo! Music Unlimited - Access over 1 million songs. Try it free. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVETHIScyber.com.au Sat Oct 22 06:48:29 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sat, 22 Oct 2005 20:48:29 +1000 Subject: A question about searching with multiple strings References: <1129927157.674735.13000@g44g2000cwa.googlegroups.com> Message-ID: On Fri, 21 Oct 2005 13:39:17 -0700, googleboy wrote: > Hi there. > > I have defined a class called Item with several (about 30 I think) > different attributes (is that the right word in this context?). Generally speaking, attributes shouldn't be used for storing arbitrary items in an object. That's what mapping objects like dicts are for. I would change your class so that it no longer mucked about with it's internal __dict__: class Item(): def __init__(self, height, length, function, **kwargs): # assumes that ALL items will have height, length, function # plus an arbitrary number (may be zero) of keyword args self.height = height self.length = length self.function = function self.data = kwargs # store custom data in an instance attribute, # NOT in the object __dict__ You would use it something like this: def create_items(): all_items = [] # WARNING WARNING WARNING # pseudo-code -- this doesn't work because I don't # know what your input file looks like open input file for record in input file: h = read height l = read length f = read function D = {} for any more items in record: D[item key] = item value newitem = Item(h, l, f, D) all_items.append(newitem) close input file return all_items Now you have processed your input file and have a list of Items. So let's search for some! Firstly, create a function that searches a single Item: def SearchOneOr(source, height=None, length=None, \ function=None, **kwargs): """Performs a short-circuit OR search for one or more search term.""" if height is not None: if source.height == height: return True if length is not None: if source.length == length: return True if function is not None: if source.function == function: return True for key, value in kwargs: if source.data.has_key(key) and source.data[key] == value: return True return False def SearchOneAnd(source, height=None, length=None, \ function=None, **kwargs): """Performs a short-circuit AND search for one or more search term.""" if height is not None: if source.height != height: return False if length is not None: if source.length != length: return False if function is not None: if source.function != function: return False for key, value in kwargs: if source.data.has_key(key) and source.data[key] != value: return False else: return False return True Now create a function that searches all items: def SearchAll(source_list, flag, height=None, length=None, \ function=None, **kwargs): found = [] if flag: search = SearchOneOr else: search = SearchOneAnd for source in source_list: if search(source, height, length, function, kwargs): found.append(source) return found Now pass all_items to SearchAll as the first argument, and it will search through them all and return a list of all the items which match your search terms. Hope this helps. -- Steven. From programmer.py at gmail.com Thu Oct 13 10:45:29 2005 From: programmer.py at gmail.com (Jaime Wyant) Date: Thu, 13 Oct 2005 09:45:29 -0500 Subject: How to call a script from another? In-Reply-To: <434e6f56$0$90426$edfadb0f@dread16.news.tele.dk> References: <434e6f56$0$90426$edfadb0f@dread16.news.tele.dk> Message-ID: I think this is the simplest way to do that: import sys sys.path.append('/path/to/directory/containg/script') import zopescript zopescript.main() The code above assumes: o that the path you use to append contains an __init__.py in it... o zopescript is the module you want to `run' o main is the method in zopescript that cranks up zope. I'm not sure of how to do it the hard way... jw On 10/13/05, Christian wrote: > From a not even newbie: > > Without knowing much about Python (yet) I'm trying to install the CMS > Zope via FTP (with the well documented changes to make it work on an > Apache server). > By birth Zope is started from a shell script. And not having the > permissions to execute such ones I'll try writing a .py script (with the > shebang that I allready knows will do the job) to call another .py > script like the original shell script does. > > So my question is: > How do I call a .py script from another .py script? > (Writing the rest - I hope - is piece of cake ;-) ). > > (And yes, I know that there are a lot of other problems but for starters > I just would like to try to call a .py script from another .py script.) > > > Thanks > > Chris > -- > http://mail.python.org/mailman/listinfo/python-list > From aleaxit at yahoo.com Tue Oct 18 04:50:08 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 18 Oct 2005 10:50:08 +0200 Subject: override a property References: <43542065$0$21621$636a15ce@news.free.fr> <4354ABB3.1030203@jessikat.fsnet.co.uk> Message-ID: <1h4mizj.17bo24b1k0idliN%aleaxit@yahoo.com> Robin Becker wrote: > Bruno Desthuilliers wrote: > > Robin Becker a ?crit : > > > >> Is there a way to override a data property in the instance? Do I need > >> to create another class with the property changed? > > > > Do you mean attributes or properties ? > > I mean property here. My aim was to create an ObserverProperty class > that would allow adding and subtracting of set/get observers. My current > implementation works fine for properties on the class, but when I need > to specialize an instance I find it's quite hard. A property is an 'overriding descriptor', AKA 'data descriptor', meaning it "captures" assignments ('setattr' kinds of operations), as well as accesses ('getattr' kinds), when used in a newstyle class. If for some reason you need an _instance_ to bypass the override, you'll need to set that instance's class to one which has no overriding descriptor for that attribute name. A better design might be to use, instead of the builtin type 'property', a different custom descriptor type that is specifically designed for your purpose -- e.g., one with a method that instances can call to add or remove themselves from the set of "instances overriding this ``property''" and a weak-key dictionary (from the weakref module) mapping such instances to get/set (or get/set/del, if you need to specialize "attribute deletion" too) tuples of callables. Alex From my_email_is_posted_on_my_website at munged.invalid Wed Oct 12 18:02:47 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 12 Oct 2005 22:02:47 GMT Subject: Jargons of Info Tech industry References: <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <41hhk195gcipfarnqu85ggs606aqi89ea1@4ax.com> Message-ID: <7t1rk1p8dihr8ajhrbcapcdoqnv8p3c0md@4ax.com> On Mon, 10 Oct 2005 08:49:32 +1000, Steven D'Aprano wrote or quoted : >Oh gosh, pictures of a new house. Why didn't you say so??? If you're >sending pictures named "my_new_house1.jpg" etc then OF COURSE they have >to be imbedded in a HTML email, otherwise how could anyone know what they >were? I suppose your subscribe to the shoebox theory of picture handling. Just dump them in a box. It is OBVIOUS what they are. Go back to them years later, and you would be surprised how baffling they can be, or if the next generation wants to understand them. You suggest there is something nefarious about wanting to caption and share images by email. Why NOT? -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From adelagon at gmail.com Thu Oct 20 04:15:19 2005 From: adelagon at gmail.com (Alvin A. Delagon) Date: Thu, 20 Oct 2005 16:15:19 +0800 Subject: Any SOAPpy users here? Message-ID: <43575217.8010108@gmail.com> Hello python programmers! I would like to add myself to the ever increasing number of python users. Here's my first question. I've written two SOAP clients using PERL and a PHP. I tried to wirte a new SOAP client using python but I'm having problems. First, I can't seem to find a good documentation of the SOAPpy module. Second, I found a code snippet of a python SOAP client but it was designed only to use the SOAPproxy function. How can I create a python SOAP client given these parameters: URI: urn:TESTWS HOST: https://hostname/cgi-bin/server.cgi Here's the PERL snippet that I'm trying to convert into a pythinic language: my $login = SOAP::Lite -> uri ($URL) -> proxy ($host) -> login($uname, $epwd); my $result = $login ->result; Help will be greatly appreciated. Thank you in advance and more power to python programmers! -------------- next part -------------- An HTML attachment was scrubbed... URL: From davids at webmaster.com Thu Oct 27 21:41:28 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 18:41:28 -0700 Subject: Microsoft Hatred FAQ References: <3s6l8mFmj3fjU1@individual.net> <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> <7rZ7f.6819$dO2.5775@newssvr29.news.prodigy.net> Message-ID: "Mike Schilling" wrote in message news:qHd8f.6518$BZ5.2214 at newssvr13.news.prodigy.com... >>> There's a huge difference to the non-techy consumer. One of the >>> buggest reasons Linux has had a reputation of being harder to use >>> than Windows was the fact that Linux had to be installed, while >>> Windows just booted up. >> Is that really true? I mean, I remember distributions of Linux that you >> could just stick in the CD, boot from CD, and you were up in minutes. >> Installing was as simple as pushing the 'install to hard drive' button. [snip] > But picture that, when this was less true, you wanted to buy a machine > with the newest-whizbang graphics card or disk controller. For Windows, > the manufacturer would make sure the proper drivers are installed and > configured. For Linux, you the consumer had to find a driver, install it, > configure it (the phrase "drive geometry" sticks in my head) and deal with > the lack of useful feedback if anything goes wrong. [snip] That's a really good point. DS From programmer.py at gmail.com Fri Oct 14 15:23:49 2005 From: programmer.py at gmail.com (Jaime Wyant) Date: Fri, 14 Oct 2005 14:23:49 -0500 Subject: Function to execute only once In-Reply-To: <1129317118.937439.159550@g43g2000cwa.googlegroups.com> References: <1129317118.937439.159550@g43g2000cwa.googlegroups.com> Message-ID: If I understand you correctly, you want `tmp' to be global... If so, declare it as so in execute -> def execute(): global tmp tmp = tmp+1 return tmp Otherwise, what happens is that you declare a variable local to execute, that is named tmp. When the assignment occurs it uses the global value of `tmp', which is 0, and adds it to the *local* tmp. I hope that is not too confusing. jw On 14 Oct 2005 12:11:58 -0700, PyPK wrote: > Hi if I have a function called > tmp=0 > def execute(): > tmp = tmp+1 > return tmp > > also I have > def func1(): > execute() > .... > and > def func2(): > execute() > .... > > now I want execute() function to get executed only once. That is the > first time it is accessed. > so taht when funcc2 access the execute fn it should have same values as > when it is called from func1. > > -- > http://mail.python.org/mailman/listinfo/python-list > From dwahler at gmail.com Mon Oct 31 21:52:15 2005 From: dwahler at gmail.com (David Wahler) Date: 31 Oct 2005 18:52:15 -0800 Subject: Reuse base-class implementation of classmethod? In-Reply-To: <9By9f.17396$65.522385@twister1.libero.it> References: <9By9f.17396$65.522385@twister1.libero.it> Message-ID: <1130813535.688189.181610@g44g2000cwa.googlegroups.com> Giovanni Bajo wrote: > Hello, > > what's the magic needed to reuse the base-class implementation of a > classmethod? > > class A(object): > @classmethod > def foo(cls, a,b): > # do something > pass > > class B(A): > @classmethod > def foo(cls, a, b): > A.foo(cls, a, b) # WRONG! > > I need to call the base-class classmethod to reuse its implementation, but I'd > like to pass the derived class as first argument. > -- > Giovanni Bajo See the super object. In your case, it can be used like this: class B(A): @classmethod def foo(cls, a, b): super(B, cls).foo(a, b) This all assumes you want to modify the behavior of foo in a subclass. If not, of course, you don't need to override it at all. -- David From joe at invalid.address Tue Oct 25 10:56:28 2005 From: joe at invalid.address (joe at invalid.address) Date: 25 Oct 2005 09:56:28 -0500 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: Not Bill Gates writes: > davids at webmaster.com wrote... > > > 1) There is no other operating system worth selling. In this > > case, you are right, you have no choice but to sell the Microsoft > > OS, but the deal they're offering you harms you in no way. (Unless > > you intended to sell PCs with no OS at all.) > > > > 2) There are other realistic competing operating systems. In > > this case, you were foolish to agree to Microsoft's deal. You lost > > out on the realistic competing markets. That is, unless Windows > > only really was a better deal, in which case you were wise to take > > the deal and have no reason to be upset. > > The flaw with this is that business owners don't get to decide what > the market wants. And the market wanted the Microsoft OS. Every > other OS in the market had bit player status, via the economic > principle called increasing returns. > > You either sell what the market wants, or you go out of business. I'm hesitant to get into this, but I keep wondering why, if there is no other competing OS, or not one worth worrying about, the MS business agreements are so draconian? Why would a company come up with such heavy handed agreements if it wasn't worried about competition? Yes, I know, they can do whatever they want, it's not a crime, etc. However when they use their market position to disallow competition, it sounds to me like they're worried about something, and trying to squelch it. Joe -- Gort, klatu barada nikto From grante at visi.com Thu Oct 6 23:01:02 2005 From: grante at visi.com (Grant Edwards) Date: Fri, 07 Oct 2005 03:01:02 -0000 Subject: When someone from Britain speaks, Americans hear a "British accent"... References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kbgj7421kd560@corp.supernews.com> <867jcqoxgk.fsf@bhuda.mired.org> Message-ID: <11kbp7eogjniq4c@corp.supernews.com> On 2005-10-07, Mike Meyer wrote: >>> Not just you. It always amuses me in trips to the US that >>> British voices (outside of the movies) are often subtitled, >>> while first-generation Americans whose English is. um, >>> limited, are not. >> >> What?!? I've never seen a British voice (inside or outside of >> the movies) subtitled -- with the exception of one of a >> nightclub scenes in one movie (I think it was Trainspotting) >> where the dialog was inaudible because of the music. > > Maybe they were dubbed? I don't think so. Where exactly did you see all these sub-titled British TV/movies? In all the British movies and TV shows I've seen in the US, the British actors sound the same as the do on British TV. I don't recall ever going to a theater in England, but I've seen plenty of TV in England. To me the dialog sounds the same as it does in the US. > I know America International dubbed the first version of "Mad > Max" that they imported into the US. Then again, American > International is well-know for their quality. That could be. -- Grant Edwards grante Yow! LIFE is a at never-ending INFORMERCIAL! visi.com From steve at holdenweb.com Wed Oct 12 04:25:05 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 12 Oct 2005 09:25:05 +0100 Subject: A problem while using urllib In-Reply-To: <1129102671.990994.43590@f14g2000cwb.googlegroups.com> References: <1129024641.113182.74420@g49g2000cwa.googlegroups.com> <1h49slu.1gaj0nnmdk5ghN%aleax@mail.comcast.net> <1129089078.852454.153800@f14g2000cwb.googlegroups.com> <1129102671.990994.43590@f14g2000cwb.googlegroups.com> Message-ID: <434CC861.2080805@holdenweb.com> Johnny Lee wrote: > Steve Holden wrote: > >>Johnny Lee wrote: >> >>>Alex Martelli wrote: >>> >>> >>>>Johnny Lee wrote: >>>> ... >>>> >>>> >>>>> try: >>>>> webPage = urllib2.urlopen(url) >>>>> except urllib2.URLError: >>>> >>>> ... >>>> >>>> >>>>> webPage.close() >>>>> return True >>>>>---------------------------------------------------- >>>>> >>>>> But every time when I ran to the 70 to 75 urls (that means 70-75 >>>>>urls have been tested via this way), the program will crash and all the >>>>>urls left will raise urllib2.URLError until the program exits. I tried >>>>>many ways to work it out, using urllib, set a sleep(1) in the filter (I >>>>>thought it was the massive urls crashed the program). But none works. >>>>>BTW, if I set the url from which the program crashed to base url, the >>>>>program will still crashed at the 70-75 url. How can I solve this >>>>>problem? thanks for your help >>>> >>>>Sure looks like a resource leak somewhere (probably leaving a file open >>>>until your program hits some wall of maximum simultaneously open files), >>>>but I can't reproduce it here (MacOSX, tried both Python 2.3.5 and >>>>2.4.1). What version of Python are you using, and on what platform? >>>>Maybe a simple Python upgrade might fix your problem... >>>> >>>> >>>>Alex >>> >>> >>>Thanks for the info you provided. I'm using 2.4.1 on cygwin of WinXP. >>>If you want to reproduce the problem, I can send the source to you. >>> >>>This morning I found that this is caused by urllib2. When I use urllib >>>instead of urllib2, it won't crash any more. But the matters is that I >>>want to catch the HTTP 404 Error which is handled by FancyURLopener in >>>urllib.open(). So I can't catch it. >>> >> >>I'm using exactly that configuration, so if you let me have that source >>I could take a look at it for you. >> [...] > > I've sent the source, thanks for your help. > [...] Preliminary result, in case this rings bells with people who use urllib2 quite a lot. I modified the error case to report the actual message returned with the exception and I'm seeing things like: http://www.holdenweb.com/./Python/webframeworks.html Message: Start process http://www.amazon.com/exec/obidos/ASIN/0596001886/steveholden-20 Error: IOError while parsing http://www.amazon.com/exec/obidos/ASIN/0596001886/steveholden-20 Message: . . . So at least we know now what the error is, and it looks like some sort of resource limit (though why only on Cygwin betas me) ... anyone, before I start some serious debugging? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From nyamatongwe+thunder at gmail.com Sun Oct 9 19:40:07 2005 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Sun, 09 Oct 2005 23:40:07 GMT Subject: non descriptive error In-Reply-To: References: <4346002C.3080504@open-networks.net> <200510070240.56350.hancock@anansispaceworks.com> <4349A55C.90203@open-networks.net> Message-ID: Timothy Smith: > FYI i have located where the problem was. in the first if statement > there was an unbalanced ). now since when does python not give a > descriptive error for that? I see this with the arrow pointing at the extra ')': >pythonw -u "xx.py" File "xx.py", line 3 if Decimal(self.parent.TillDetails[self.TillSelection.GetStringSelection()]['ChangeTinBalance'])) == Decimal('0'): ^ SyntaxError: invalid syntax Neil From john at castleamber.com Mon Oct 17 17:42:09 2005 From: john at castleamber.com (John Bokma) Date: 17 Oct 2005 21:42:09 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <1129491006.021102.43920@g14g2000cwa.googlegroups.com> <86zmp8zsjk.fsf@bhuda.mired.org> Message-ID: Steven D'Aprano wrote: > On Mon, 17 Oct 2005 00:17:03 -0400, Mike Meyer wrote: > >> Yup. When NS was the 800 lb gorilla > > When was this? When did Netscape have a monopoly in any market? > > Netscape was never the 800 lb gorilla. > >> on they acted like MS, > > When did Netscape executives perjure themselves in court? > > When did Netscape commit fraud? Astro-turfing? Patent infringement? Theft > of code? They got killed too soon. > that was then, this is now, and unlike IBM, Microsoft hasn't yet learnt > about karma. Which is a good thing, since MS is not a human being. It's a company, a thing to make money, so it can make more money. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From nospam at here.com Mon Oct 17 13:36:45 2005 From: nospam at here.com (Matt Feinstein) Date: Mon, 17 Oct 2005 13:36:45 -0400 Subject: Installing Python at Work References: <1129561955.452114.53290@g44g2000cwa.googlegroups.com> Message-ID: On 17 Oct 2005 08:12:35 -0700, "Nikola" wrote: >I'm currently learning Python for my own use. >I'm considering installing it on a work laptop, knowing that it is >non-licensed, distributable software. > >However, does it access communication ports? I know the company checks >their ports regularly for activity. > >I won't be doing anything very serious; I'm just trying out Python, >learning the basics from 'Learning Python' by O'Reilly. Python installations are pretty benign. Note, however, that when you install additional modules, you are trusting the module writer. For locality, you can do a completely local Python installation in Linux, and generally speaking, additional modules can be installed locally as well. Under win32, the standard binary installer makes a registry entry which is checked when additional (binary) modules are installed. I don't think there's any other 'non-local' behavior. Matt Feinstein -- There is no virtue in believing something that can be proved to be true. From sean at buildingonline.com Mon Oct 10 00:11:56 2005 From: sean at buildingonline.com (Sean Berry) Date: Sun, 9 Oct 2005 21:11:56 -0700 Subject: best Pythonic way to do this sort: Python newb Message-ID: Hello all I have build a list that contains data in the form below -- simplified for question -- myList = [[value1, value2, value3],[value1, value2, value3], ...] I have a function which takes value3 from the lists above and returns another value. I want to use this returned value to sort the lists. So, my resultant list would be ordered by the return value of the function with value3 as its argument. >From a relative Python newb, what is the best way to do this? Thanks for any help offered. From codecraig at gmail.com Tue Oct 11 15:14:11 2005 From: codecraig at gmail.com (Java and Swing) Date: 11 Oct 2005 12:14:11 -0700 Subject: Help creating extension for C function In-Reply-To: <1129056123.654224.18070@z14g2000cwz.googlegroups.com> References: <1128714478.552412.135950@g47g2000cwa.googlegroups.com> <1129049460.649101.96890@g47g2000cwa.googlegroups.com> <1129056123.654224.18070@z14g2000cwz.googlegroups.com> Message-ID: <1129058051.426314.28670@g43g2000cwa.googlegroups.com> ..ok I modified wrap_doStuff, so it just returns 0 instead of return PyBuildValue....this fixed the problems I had with compiling. however, when I try using it in Python..I get a SystemError: error return without exception set. Anyhow, I need PyBuildValue to work. One other note, the VC++ 6 compiler gives two warnings, one of which is... "warning C4013: 'PyBuildValue' undefined; assuming extern returning int" thanks. >> from DLLTester import * >> x = doStuff("1,2,3,4,5", ",") >> Java and Swing wrote: > Fredrik, > I now have this. > > myapp.c > -------- > #include > #include > #include "Python.h" > > int doStuff(const char *input, const char *d) { ... } > > static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { > // get the arguments from Python > int result; > char *input = 0; > char *d = 0; > int ok = PyArg_ParseTuple(args, "ss", &input, &d); > if (!ok) return 0; > > // make the function call > result = doStfuff(input, d); > > // return the result > return PyBuildValue("i", result); > } > > static PyMethodDef functions[] = > { > {"PyDoStuff", wrap_doStuff, METH_VARARGS, "some documentation"}, > {NULL, NULL} > }; > > extern PyMODINIT_FUNC initDLLTester(void) > { > Py_InitModule4( > "DLLTester", functions, "my doStfuff function", NULL, > PYTHON_API_VERSION > ); > > } > > ...when I try to compile in Visual C++ 6, I get > > Linking... > Creating library Release/DLLTester.lib and object > Release/DLLTester.exp > test.obj : error LNK2001: unresolved external symbol _PyBuildValue > Release/DLLTester.dll : fatal error LNK1120: 1 unresolved externals > Error executing link.exe. > > Any ideas what's happening here? > > DLLTester.dll - 2 error(s), 0 warning(s) > > Fredrik Lundh wrote: > > Java and Swing wrote: > > > > > So is "module.c" a new C file or do I add it to my existing, myapp.c? > > > > it's a complete module. if you want it to do something other than printing > > the arguments, replace the "do stuff" section with your own code. if you > > want to call it something else, rename it. if you want to change the API, > > change it. it's not that large; you should be able to figure out what it does > > and how it does it in no time at all. > > > > From bh at intevation.de Wed Oct 12 12:24:56 2005 From: bh at intevation.de (Bernhard Herzog) Date: Wed, 12 Oct 2005 18:24:56 +0200 Subject: C Wrapper Function, crashing Python? References: <1129122046.417746.100120@g47g2000cwa.googlegroups.com> <1129123866.536068.69520@g43g2000cwa.googlegroups.com> <1129133752.747652.246050@g49g2000cwa.googlegroups.com> Message-ID: "Java and Swing" writes: > thanks for the tip, however even when I do not free aString or bString, > i'm still crashing at the malloc in the c function, not the wrapper. Do you have any more places where you use free incorrectly? In my experience, calling free with invalid values can corrupt the data structures used by the memory allocator in such a way that subsequent malloc calls crash. Bernhard -- Intevation GmbH http://intevation.de/ Skencil http://skencil.org/ Thuban http://thuban.intevation.org/ From cfajohnson at gmail.com Sat Oct 15 14:08:12 2005 From: cfajohnson at gmail.com (Chris F.A. Johnson) Date: Sat, 15 Oct 2005 14:08:12 -0400 Subject: how to improve simple python shell script (to compile list of files) References: Message-ID: On 2005-10-15, Jari Aalto wrote: > > [Keep CC, thank you] > > Please suggest comments how can I make this script to work > from bash. Also how can I skip better the [0] argument from > command line without hte extra variable i? > > #!/bin/bash > > function compile () > { > python -c ' > import os, sys, py_compile; > i = 0; > for arg in sys.argv: > file = os.path.basename(arg); > dir = os.path.dirname(arg); > i += 1; > if i > 1 and os.path.exists(dir): > os.chdir(dir); > print "compiling %s\n" % (file); > py_compile.compile(file); > ' $* > } Don't indent: function compile () { python -c ' import os, sys, py_compile; i = 0; for arg in sys.argv: file = os.path.basename(arg); dir = os.path.dirname(arg); i += 1; if i > 1 and os.path.exists(dir): os.chdir(dir); print "compiling %s\n" % (file); py_compile.compile(file); ' $* } > compile $(find path/to -type f -name "*.py") > > # End of example > > The error message reads: > > File "", line 2 > import os, sys, py_compile; > ^ > SyntaxError: invalid syntax > > Jari > -- Chris F.A. Johnson ================================================================== Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress From fredrik at pythonware.com Sat Oct 15 07:38:22 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 15 Oct 2005 13:38:22 +0200 Subject: how to improve simple python shell script (to compile list of files) References: Message-ID: Jari Aalto wrote: > Please suggest comments how can I make this script to work > from bash. replace it with a call to the compileall module? $ python -mcompileall [directory...] ? $ python -mcompileall -h option -h not recognized usage: python compileall.py [-l] [-f] [-q] [-d destdir] [-x regexp] [directory ...] -l: don't recurse down -f: force rebuild even if timestamps are up-to-date -q: quiet operation -d destdir: purported directory name for error messages if no directory arguments, -l sys.path is assumed -x regexp: skip files matching the regular expression regexp the regexp is search for in the full path of the file From apardon at forel.vub.ac.be Fri Oct 7 02:50:33 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 7 Oct 2005 06:50:33 GMT Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <3qi8erFf252rU1@uni-berlin.de> <3qkdbrFfgga9U1@uni-berlin.de> <3qkn7qFffkl6U1@uni-berlin.de> <3qkr1hFfgj5uU1@uni-berlin.de> Message-ID: Op 2005-10-06, Diez B. Roggisch schreef : >> Suppose we have a typesystem which has the type ANY, which would mean >> such an object could be any type. You could then have homogenous lists >> in the sense that all elements should be of the same declared type and >> at the same time mix all kind of type in a particular list, just >> as python does. > > The you have JAVA Object or C void*. Which cause all kinds of runtime > troubles.... because they essentially circumvene the typechecking! Why do you call this a JAVA Object or C void*? Why don't you call it a PYTHON object. It is this kind of reaction that IMO tells most opponents can't think outside the typesystems they have already seen and project the problems with those type systems on what would happen with python should it acquire a type system. >> So how would this limit python. > > The limitation is that in static languages I must _know_ what type to > cast such an ANY, before calling anything on it. Otherwise its useless. > >>>even though ususally the contents of a list >>>share some common behaviour. And that exactly is the key point here: in >>>a statically typed world, that common behaviour must have been extracted >>>and made explicit. >> >> >> Would my suggestion be classified as a statically typed world? > > See above. Your answer tells more about you then about my suggestion. -- Antoon Pardon From steve at REMOVETHIScyber.com.au Sun Oct 16 12:01:43 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 17 Oct 2005 02:01:43 +1000 Subject: Comparing lists - somewhat OT, but still ... References: <1128930699.799657.146210@g47g2000cwa.googlegroups.com> <1128952417.0544cc73190bbbd4e683448c137969c8@teranews> <434ba977@nntp0.pdx.net> <1129216693.445956.155490@g47g2000cwa.googlegroups.com> Message-ID: On Sun, 16 Oct 2005 15:16:39 +0200, Christian Stapfer wrote: > Come to think of an experience that I shared > with a student who was one of those highly > creative experimentalists you seem to have > in mind. He had just bought a new PC and > wanted to check how fast its floating point > unit was as compared to our VAX. After > having done his wonderfully creative > experimenting, he was utterly dejected: "Our (old) > VAX is over 10'000 times faster than my new PC", > he told me, almost in despair. Which it was. It finished executing his code in almost 1/10,000th of the time his PC could do. > Whereupon I, > always the uncreative, dogmatic theoretician, > who does not believe that much in the decisiveness > of the outcome of mere experiments, told him > that this was *impossible*, that he *must* have > made a mistake... It wasn't a mistake and it did happen. The VAX finished the calculation 10,000 times faster than his PC. You have a strange concept of "impossible". > It turned out that the VAX compiler had been > clever enough to hoist his simple-minded test > code out of the driving loop. Optimizations have a tendency to make a complete mess of Big O calculations, usually for the better. How does this support your theory that Big O is a reliable predictor of program speed? For the record, the VAX 9000 can have up to four vector processors each running at up to 125 MFLOPS each, or 500 in total. A Pentium III runs at about 850 Mflops. Comparing MIPS or FLOPS from one system to another is very risky, for many reasons, but as a very rough and ready measure of comparison, a four processor VAX 9000 is somewhere about the performance of a P-II or P-III, give or take some fudge factor. So, depending on when your student did this experiment, it is entirely conceivable that the VAX might have been faster even without the optimization you describe. Of course, you haven't told us what model VAX, or how many processors, or what PC your student had, so this comparison might not be relevant. > In fact, our VAX > calculated the body of the loop only *once* > and thus *immediately* announced that it had finished > the whole test - the compiler on this student's > PC, on the other hand, had not been clever enough > for this type of optimization: hence the difference... Precisely. And all the Big O notation is the world will not tell you that. Only an experiment will. Now, perhaps in the simple case of a bare loop doing the same calculation over and over again, you might be able to predict ahead of time what optimisations the compiler will do. But for more complex algorithms, forget it. This is a clear case of experimentation leading to the discovery of practical results which could not be predicted from Big O calculations. I find it quite mind-boggling that you would use as if it was a triumph of abstract theoretical calculation when it was nothing of the sort. > I think this is really a cautionary tale for > experimentalists: don't *believe* in the decisiveness > of the outcomes your experiments, but try to *understand* > them instead (i.e. relate them to your theoretical grasp > of the situation)... Or, to put it another way: your student discovered something by running an experimental test of his code that he would never have learnt in a million years of analysis of his algorithm: the VAX compiler was very cleverly optimized. The fact that your student didn't understand the problem well enough to craft a good test of it is neither here nor there. -- Steven. From larry.bates at websafe.com Mon Oct 10 11:29:14 2005 From: larry.bates at websafe.com (Larry Bates) Date: Mon, 10 Oct 2005 10:29:14 -0500 Subject: Default argument to __init__ In-Reply-To: <1128955812.913224.150760@z14g2000cwz.googlegroups.com> References: <1128955812.913224.150760@z14g2000cwz.googlegroups.com> Message-ID: This comes up on the list about once a week on this list. See: http://www.nexedi.org/sections/education/python/tips_and_tricks/python_and_mutable_n/view -Larry Bates netvaibhav at gmail.com wrote: > Hi All: > > Here's a piece of Python code and it's output. The output that Python > shows is not as per my expectation. Hope someone can explain to me this > behaviour: > > [code] > class MyClass: > def __init__(self, myarr=[]): > self.myarr = myarr > > myobj1 = MyClass() > myobj2 = MyClass() > > myobj1.myarr += [1,2,3] > > myobj2.myarr += [4,5,6] > > print myobj1.myarr > print myobj2.myarr > [/code] > > The output is: > [1, 2, 3, 4, 5, 6] > [1, 2, 3, 4, 5, 6] > > Why do myobj1.myarr and myobj2.myarr point to the same list? The > default value to __init__ for the myarr argument is [], so I expect > that every time an object of MyClass is created, a new empty list is > created and assigned to myarr, but it seems that the same empty list > object is assigned to myarr on every invocation of MyClass.__init__ > > It this behaviour by design? If so, what is the reason, as the > behaviour I expect seems pretty logical. > > Thanks. > > Vaibhav > From what at yeahyou.com Mon Oct 10 09:26:27 2005 From: what at yeahyou.com (david) Date: Mon, 10 Oct 2005 13:26:27 GMT Subject: >> Unlimited Free Music Downloads ! << Message-ID: <7_t2f.75723$lI5.53435@tornado.ohiordc.rr.com> ALL COOL MUSIC -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwm at mired.org Tue Oct 18 15:16:17 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 18 Oct 2005 15:16:17 -0400 Subject: UI toolkits for Python References: <7xslv56ud1.fsf@ruckus.brouhaha.com> <3ras6oFit2djU1@individual.net> <4350dd34$0$6774$9b4e6d93@newsread4.arcor-online.net> <863bn12k6i.fsf@bhuda.mired.org> <7xslv02aoj.fsf@ruckus.brouhaha.com> <87psq39aur.fsf@wilson.rwth-aachen.de> <7xwtkbud5q.fsf@ruckus.brouhaha.com> <1h4mhm2.1rmv4fh1czi843N%aleaxit@yahoo.com> <86r7aiyg4g.fsf@bhuda.mired.org> <1h4n6ag.5uhq7a7xe1v4N%aleaxit@yahoo.com> Message-ID: <86ach6y6ta.fsf@bhuda.mired.org> aleaxit at yahoo.com (Alex Martelli) writes: > Mike Meyer wrote: >> What surprises me is that marketing types will accept turning away - >> what's the current internet user base? 200 million? - 10 million >> potential customers without a complaint. Or maybe they just don't get >> told that that's what's going on. > In firms where marketing has lots of power, they may indeed well decide > to pursue those "10 millions" by demanding an expenditure of effort > that's totally out of proportion What makes you think that the expenditure of effort is "totally out of proportion"? In my experience, that isn't the case - at least if you go into it planning on doing things that way. Retrofitting a site that was built without any thought but "make it work in my favoriter browser in my favorite configuration" can be a radically different thing. > Maybe that's part of the explanation for the > outstanding success of some enterprises founded by engineers, led by > engineers, and staffed overwhelmingly with engineers, competing with > other firms where marketing wield power...? You mean like google? Until recently, they're an outstanding example of doing things right, and providing functionality that degrades gracefully as the clients capabilities go down. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From samrobertsmith at gmail.com Tue Oct 25 05:33:30 2005 From: samrobertsmith at gmail.com (Shi Mu) Date: Tue, 25 Oct 2005 02:33:30 -0700 Subject: cell and row In-Reply-To: References: <1d987df30510250150mb4f0f97y79d6e93c0c0d66ff@mail.gmail.com> Message-ID: <1d987df30510250233x368c1bbfv914e76e7f79cbc26@mail.gmail.com> In the follwoing code, Why the result is "'defenestrate', 'window', 'defenestrate', " before the original list instead of 'defenestrate', 'window', ? >>> a = ['defenestrate', 'cat', 'window', 'defenestrate'] >>> for x in a[:]: ... if len(x) > 4: a.insert(0, x) ... >>> a ['defenestrate', 'window', 'defenestrate', 'defenestrate', 'cat', 'window', 'defenestrate'] On 10/25/05, Fredrik Lundh wrote: > Shi Mu wrote: > > >I can not understand the use of "cell" and "row" in the code: > > > > # convert the matrix to a 1D list > > matrix = [[13,2,3,4,5],[0,10,6,0,0],[7,0,0,0,9]] > > items = [cell for row in matrix for cell in row] > > print items > > working through the Python tutorial might be a good idea. here's the section > on list comprehensions: > > http://docs.python.org/tut/node7.html#SECTION007140000000000000000 > > and here's the section on for loops: > > http://docs.python.org/tut/node6.html#SECTION006200000000000000000 > > briefly: > > items = [cell for row in matrix for cell in row] > > or, slightly edited for clarity: > > items = [(cell) > for row in matrix > for cell in row] > > is the same thing as: > > items = [] > for row in matrix: > for cell in row: > items.append(cell) > > except that it's a bit shorter, and a bit more efficient. > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From gry at ll.mit.edu Tue Oct 11 14:42:32 2005 From: gry at ll.mit.edu (gry at ll.mit.edu) Date: 11 Oct 2005 11:42:32 -0700 Subject: dictionnaries and lookup tables In-Reply-To: <1129053992.141269.149840@z14g2000cwz.googlegroups.com> References: <1129053992.141269.149840@z14g2000cwz.googlegroups.com> Message-ID: <1129056152.562848.251690@g14g2000cwa.googlegroups.com> m.barenco at gmail.com wrote: > Hello, > > I am considering using dictionnaries as lookup tables e.g. > > >>>D={0.5:3.9,1.5:4.2,6.5:3} > > and I would like to have a dictionnary method returning the key and > item of the dictionnary whose key is smaller than the input of the > method (or <=,>,>=) but maximal (resp. maximal,minimal,minimal) eg.: > > >>>D.smaller(3.0) > (1.5,4.2) > >>>D.smaller(11.0) > (6.5,3) > >>>D.smaller(-1.0) > None (or some error message) > > Now, I know that dictionnaries are stored in a non-ordered fashion in > python but they are so efficient in recovering values (at least wrt > lists) that it suggests me that internally there is some ordering. I > might be totally wrong because I don't know how the hashing is really > done. Of course I would use such methods in much larger tables. So is > this possible or should I stick to my own class with O(log2(N)) > recovery time? ... I believe that to do this efficiently, you want some kind of tree, e.g. B-tree, RB-tree, AVL-tree. You could try the AVL tree from: ftp://squirl.nightmare.com/pub/python/python-ext/avl/avl-2.0.tar.gz From saint.infidel at gmail.com Thu Oct 20 11:37:37 2005 From: saint.infidel at gmail.com (infidel) Date: 20 Oct 2005 08:37:37 -0700 Subject: possible bug in cherrypy.lib.autoreload In-Reply-To: <1129759757.331157.177020@g47g2000cwa.googlegroups.com> References: <1129759757.331157.177020@g47g2000cwa.googlegroups.com> Message-ID: <1129822657.743578.163470@o13g2000cwo.googlegroups.com> Ok, so it turns out that the problem the cherrypy.lib.autoreload module is having, is that kid imports elementtree and on my machine the elementtree modules are inside a zip file (.egg). So the "path" to the elementtree __init__.py file is not a valid OS path because everything after the .egg file is inside the file. Is there a quick way of determining that a module was imported from a zip file, or that a module's __file__ attribute is a valid path as far as Python is concerned, even though it doesn't exist to the OS? From fergdeff at gmail.com Tue Oct 25 11:00:27 2005 From: fergdeff at gmail.com (ferg) Date: 25 Oct 2005 08:00:27 -0700 Subject: MoinMoin - Can't create new pages In-Reply-To: <1130252059.474472.102670@g14g2000cwa.googlegroups.com> References: <1130252059.474472.102670@g14g2000cwa.googlegroups.com> Message-ID: <1130252427.220729.312180@o13g2000cwo.googlegroups.com> I should have mentioned that the error message I keep getting is the ol HTTP 404 - "The page cannot be found" From gsakkis at rutgers.edu Sat Oct 8 00:26:41 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Sat, 8 Oct 2005 00:26:41 -0400 Subject: Objects with different data views References: Message-ID: <1128745619.cf80396cc7e4ebc9b4d5efa213ab0917@teranews> "Steven D'Aprano" wrote: > I'm not sure how to do this, or where to start looking for the right > information, so any advice would be appreciated. > > I want to implement a class with two (or more) different ways of looking > at its attributes. > > One example of this might be complex numbers, which can be written in > Cartesian form (x+yi) or polar form (r cis theta). > > (Yes, I know Python already has complex numbers. That was just an example.) > > Another might be 3D vectors, which can be written in Cartesian form > [x, y, z], polar form [r, theta, z] or spherical polar [r, theta, phi]. > > It is important that there are no privileged attributes, e.g. in the > above example, I can set any of x, y, z, r, theta or phi and all the > others will automatically reflect the changes. A concrete, if simple, > example will make it clear. > > Suppose I have a transformation (a,b) <-> (x,y) where: > > x = a+b > y = a+2*b > > I create an instance spam, and set a and b: > > spam.a = 1 > spam.b = 2 > > Now I should be able to read x and y: > > print spam.x, spam.y > # prints 3 5 > > If I set attribute y: > > spam.y = 0 > > a and b automatically change to match: > > print spam.a, spam.b > # prints 6, -3 > > > Anyone have any good ideas for how I should implement this? As others have replied, properties is the way to go. There have been a few recipes in the Cookbook that avoid cluttering the class namespace with temporary get/set/del methods, e.g. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/410698. HTH, George From steve at REMOVETHIScyber.com.au Sun Oct 9 06:54:32 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 09 Oct 2005 20:54:32 +1000 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <41hhk195gcipfarnqu85ggs606aqi89ea1@4ax.com> Message-ID: On Sun, 09 Oct 2005 07:19:29 +0000, Roedy Green wrote: > On Sat, 08 Oct 2005 23:33:13 GMT, Rich Teer > wrote or quoted : > >>WHat the hell has that got to do with HTML email? Sending photos >>is an example of what attachments are for. > > Normally you send photos to grandma with captions under each photo. No, normally YOU send photos to grandma with captions under each photo. My grandma doesn't put captions in her photo album, and she doesn't need captions on her photos in email. > That is far more convenient for the technopeasant receiver than > dealing with multiple attachments. Only if your photos are so obscure and confusing that they need captions. "Here's Johnny with the dog. Here is Johnny with the dog again. This one is Johnny on his own. Here is the dog. Oh look, it is Johnny with the dog again -- that's the dog on the left, in case it isn't clear. Just for a change, this is Johnny wearing a hat. It is blue with a feather in it, in case you couldn't tell from, oh I don't know, looking at the actual picture." -- Steven. From spiralx at gmail.com Tue Oct 11 08:02:12 2005 From: spiralx at gmail.com (James) Date: Tue, 11 Oct 2005 13:02:12 +0100 Subject: datetime and daylight savings problem Message-ID: <7ee3dcd80510110502j5ef8be6co1c746fa98c4d4cfc@mail.gmail.com> I need to import a bunch of data into our database for which there's a single entry each day which occurs at the same time every day in local time - so I need to convert this to UTC taking into account local daylight savings. However daylight savings just don't seem to be working at all... Python 2.3.5 (#2, May 4 2005, 08:51:39) [GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from pytz import timezone >>> from datetime import datetime >>> t=timezone("Europe/Paris") >>> utc=timezone("UTC") >>> d=datetime(2005,01,24,16,59,tzinfo=t) >>> d datetime.datetime(2005, 1, 24, 16, 59, tzinfo=) >>> d.astimezone(utc) datetime.datetime(2005, 1, 24, 16, 59, tzinfo=) >>> d2=datetime(2005,06,01,16,59,tzinfo=t) >>> d2 datetime.datetime(2005, 6, 1, 16, 59, tzinfo=) >>> d2.astimezone(utc) datetime.datetime(2005, 6, 1, 16, 59, tzinfo=) One of these should be in DST, the other shouldn't, I'm not sure why. Additional oddness here >>> d.astimezone(utc).astimezone(t) datetime.datetime(2005, 1, 24, 18, 59, tzinfo=) >>> d2.astimezone(utc).astimezone(t) datetime.datetime(2005, 6, 1, 17, 59, tzinfo=) I'm not sure if it's just something I'm doing completely wrong here... James From usenet at marduk.letterboxes.org Tue Oct 25 03:04:23 2005 From: usenet at marduk.letterboxes.org (marduk) Date: Tue, 25 Oct 2005 07:04:23 GMT Subject: pickle In-Reply-To: References: Message-ID: <1130223861.28336.6.camel@blackwidow> On Mon, 2005-10-24 at 23:55 -0700, Shi Mu wrote: > I got a sample code and tested it but really can not understand the > use of pickle and dump: > > >>> import pickle > >>> f = open("try.txt", "w") > >>> pickle.dump(3.14, f) > >>> pickle.dump([1,2,3,4], f) > >>> f.close() The pickle module "serializes" python objects. You can "dump" a python object that can later be loaded: >>> x = complex(2,3.5) >>> f = open("cnumber.pickle", "w") >>> import pickle >>> pickle.dump(x, f) >>> f.close() >>> y = pickle.load(file("cnumber.pickle", "r")) >>> y (2+3.5j) From codecraig at gmail.com Tue Oct 25 14:28:39 2005 From: codecraig at gmail.com (jas) Date: 25 Oct 2005 11:28:39 -0700 Subject: Read/Write from/to a process In-Reply-To: References: <1130163642.868252.148070@g44g2000cwa.googlegroups.com> <1130174259.472124.114790@f14g2000cwb.googlegroups.com> <1130242940.918480.65020@f14g2000cwb.googlegroups.com> Message-ID: <1130264919.181056.87730@g47g2000cwa.googlegroups.com> I have setup multiple threads and a queue...which is working pretty good. But I have one other issue...I have a new thread (since it is different issue) here: http://groups.google.com/group/comp.lang.python/browse_frm/thread/ec81d8982d1a0130 if you get chance, would you mind checking that out. Thanks! From hrvoje at despammed.com Tue Oct 4 17:21:08 2005 From: hrvoje at despammed.com (Hrvoje Blazevic) Date: Tue, 04 Oct 2005 23:21:08 +0200 Subject: Idle In-Reply-To: <08C0f.517$ht7.198@newssvr21.news.prodigy.com> References: <08C0f.517$ht7.198@newssvr21.news.prodigy.com> Message-ID: Philippe C. Martin wrote: > Hi, > > I remember having that when the wrong version of TCL/TK was installed on my > system. > And what is the right version? I have versions that came with their respective distros (8.4.9 in case of Suse) -- Hrvoje From theller at python.net Wed Oct 26 08:38:41 2005 From: theller at python.net (Thomas Heller) Date: Wed, 26 Oct 2005 14:38:41 +0200 Subject: Windows vs Linux References: Message-ID: <64rko3la.fsf@python.net> "Tim Golden" writes: > [bonono at gmail.com] >> But command line in Windows is in no way in the same >> league as *nix shell. Use for command completion and up/down >> arrow or to search for history. > > [darren kirby] >> Try ctrl-r in bash, then type your first few letters... > > Thanks to both of you. But that much I already knew. It's not > that I have *no* knowledge about readline: I did at least > read the manuals when I got stuck! But as far as I can tell > from my experience and from the docs -- and I'm not near a > Linux box at the mo -- having used ctrl-r to recall line x > in the history, you can't just down-arrow to recall x+1, x+2 etc. > Or can you? I don't know. When I discovered this I uninstalled the (windows) readline module from my Python installation. > (Sorry guys; I realise this is more stuff for comp.os.linux or > comp.commandlineshells.bash or whatever it's called. But if > someone *did* know the answer, I'd be really happy!) ;-) Thomas From peter at engcorp.com Wed Oct 12 19:50:27 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 12 Oct 2005 19:50:27 -0400 Subject: Send password over TCP connection In-Reply-To: <1129033311.936104.140960@g14g2000cwa.googlegroups.com> References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> <1128979760.251637.316480@o13g2000cwo.googlegroups.com> <1129033311.936104.140960@g14g2000cwa.googlegroups.com> Message-ID: dcrespo wrote: > then, what you proppose? I'll assume that question was for me, in response to my comment that one should never store passwords in the clear. Do you know how any other system manages to do this? Linux, for example (assuming a properly configured system)? The passwords aren't stored: hashes of the passwords are stored (with additional things thrown in to prevent certain kinds of attacks even if someone nabs the password (/etc/shadow) file). If you store the password or even encrypt it (i.e. something that can be reversed if someone knows the key), it's a risk. If you don't know about this stuff yet, I strongly suggest lots of additional research and reading prior to implementing a serious system. There are _many_ web pages to be found which discuss this sort of thing, probably including lots of tutorials for people starting on the ground floor. I bet Paul R or others more experienced in this area can point us to some excellent ones, but a little googling with "passwords store clear text" or "encrypted passwords" would get you started. I expect that would quickly lead to the term "hashing", since you really don't want to just encrypt the password: that can easily be reversed if anyone has the key, and certainly an administrator could access the key used by some random application that encrypts its passwords. The first few hits for that last search seem to include pages that introduce the concept of "salt", one of the "additional things" I mentioned above. I'm not going to try to give a tutorial: I'm not nearly expert enough to be trusted for that. :-) I just wanted to warn against one of the most basic and easily avoidable problems. -Peter From fredrik at pythonware.com Sat Oct 15 07:16:05 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 15 Oct 2005 13:16:05 +0200 Subject: Problem splitting a string References: <1129373241.881149.245380@o13g2000cwo.googlegroups.com> Message-ID: "SPE - Stani's Python Editor" wrote: > Use re.split, as this is the fastest and cleanest way. > However, iff you have to split a lot of strings, the best is: > > import re > delimiters = re.compile('_| ') > > def split(x): > return delimiters.split(x) or, shorter: import re split = re.compile('_| ').split to quickly build a splitter for an arbitrary set of separator characters, use separators = "_ :+" split = re.compile("[" + re.escape(separators) + "]").split to deal with arbitrary separators, you need to be a little bit more careful when you prepare the pattern: separators = sep1, sep2, sep3, sep4, ... pattern = "|".join(re.escape(p) for p in reversed(sorted(separators))) split = re.compile(pattern).split From robin at reportlab.com Tue Oct 18 05:27:51 2005 From: robin at reportlab.com (Robin Becker) Date: Tue, 18 Oct 2005 10:27:51 +0100 Subject: override a property In-Reply-To: <4354b324$0$21023$636a55ce@news.free.fr> References: <43542065$0$21621$636a15ce@news.free.fr> <4354ABB3.1030203@jessikat.fsnet.co.uk> <4354b324$0$21023$636a55ce@news.free.fr> Message-ID: <4354C017.1010308@chamonix.reportlab.co.uk> bruno modulix wrote: ..... > > Could you elaborate ? Or at least give an exemple ? ..... in answer to Bengt & Bruno here is what I'm sort of playing with. Alex suggests class change as an answer, but that looks really clunky to me. I'm not sure what Alex means by > A better design might be to use, instead of the builtin > type 'property', a different custom descriptor type that is specifically > designed for your purpose -- e.g., one with a method that instances can > call to add or remove themselves from the set of "instances overriding > this ``property''" and a weak-key dictionary (from the weakref module) > mapping such instances to get/set (or get/set/del, if you need to > specialize "attribute deletion" too) tuples of callables. I see it's clear how to modify the behaviour of the descriptor instance, but is he saying I need to mess with the descriptor magic methods so they know what applies to each instance? ## my silly example class ObserverProperty(property): def __init__(self,name,observers=None,validator=None): self._name = name self._observers = observers or [] self._validator = validator or (lambda x: x) self._pName = '_' + name property.__init__(self, fset=lambda inst, value: self.__notify_fset(inst,value), ) def __notify_fset(self,inst,value): value = self._validator(value) for obs in self._observers: obs(inst,self._pName,value) inst.__dict__[self._pName] = value def add(self,obs): self._observers.append(obs) def obs0(inst,pName,value): print 'obs0', inst, pName, value def obs1(inst,pName,value): print 'obs1', inst, pName, value class A(object): x = ObserverProperty('x') a=A() A.x.add(obs0) a.x = 3 b = A() b.x = 4 #I wish I could get b to use obs1 instead of obs0 #without doing the following class B(A): x = ObserverProperty('x',observers=[obs1]) b.__class__ = B b.x = 7 -- Robin Becker From snail at objmedia.demon.co.uk Sun Oct 16 14:31:06 2005 From: snail at objmedia.demon.co.uk (Stephen Kellett) Date: Sun, 16 Oct 2005 19:31:06 +0100 Subject: Need advice on finding memory leak References: <1129485522.439259.211480@o13g2000cwo.googlegroups.com> Message-ID: In message <1129485522.439259.211480 at o13g2000cwo.googlegroups.com>, mark.engelberg at gmail.com writes >I am having trouble identifying the source of a memory leak in a >Windows Python program. The basic gist is as follows: Perhaps Python Memory Validator can help you? http://www.softwareverify.com/beta.php Stephen -- 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 ksnunn at westham98.freeserve.co.uk Fri Oct 21 09:25:39 2005 From: ksnunn at westham98.freeserve.co.uk (kevin) Date: Fri, 21 Oct 2005 14:25:39 +0100 Subject: wanna stop by my homemade glory hole? Message-ID: <000501c5d642$effdcb20$f5714d51@your1p37d9kihs> hi there where are u plz -------------- next part -------------- An HTML attachment was scrubbed... URL: From fredrik at pythonware.com Tue Oct 18 05:53:51 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 18 Oct 2005 11:53:51 +0200 Subject: bug in os.system? References: <1129617198.528491.125830@g44g2000cwa.googlegroups.com> Message-ID: nicksjacobson at yahoo.com wrote: > The following code fails (pythonbugtest.exe takes one parameter, a > string): > > import os > result = os.system('"pythonbugtest.exe" "test"') > assert(result == 0) > > The error message is: > > 'pythonbugtest.exe" "test' is not recognized as an internal or external > command, operable program or batch file. > Traceback (most recent call last): > File "C:\Nick\!My Programs\Python\bugtest\python1.py", line 8, in ? > assert(result == 0) > AssertionError > > If I remove the quote marks around "pythonbugtest.exe" or "test", it > works fine. But sometimes I need those quote marks, if e.g. there are > spaces in filenames. > > I think this is a bug? yup, but unfortunately, it's a bug at the windows level, not in Python. from what I can tell, the problem is that cmd.exe cannot parse the command string it's given by the C-level system() call. possible workarounds: 1. get rid of the quotes around the command name: result = os.system('pythonbugtest.exe "test"') 2. add an extra quote (!) before the quoted command name: result = os.system('""pythonbugtest.exe" "test"') 3. use os.spawn or the subprocess module instead. From howardrh at westerncom.net Mon Oct 10 20:48:39 2005 From: howardrh at westerncom.net (hrh1818) Date: 10 Oct 2005 17:48:39 -0700 Subject: Continuous system simulation in Python References: <20051007011222.1aeab426@linuxcestcomplique.fr> <1128708054.819697.232950@o13g2000cwo.googlegroups.com> <20051007224533.08bde751@linuxcestcomplique.fr> <1128794785.152776.116370@g47g2000cwa.googlegroups.com> <20051008233140.77ad2c2e@linuxcestcomplique.fr> <1128941251.054780.324900@g44g2000cwa.googlegroups.com> <20051010203829.55c3e4b0@linuxcestcomplique.fr> Message-ID: <1128991719.628161.54290@g14g2000cwa.googlegroups.com> In your simulator how much do you want Python to do? I ask this because your subject title implies you want to write your simulation code in Python but a simulator written entirely in Python would be very slow. Python is an interpreted language and pure Python code is not suitable for simulating big continuous systems. Hence to me it appears you have two distinct proplems. One is developing a front end, a user interface, that is easy to use. The other is either finding or writing a good code compiler that wlll produce fast simulation code or writing an interface to existing optimize simulation code. Although most likely not suitable for your applicaion but a good example of this type of program is Mathematica. It is written in two parts a user interface and a kernel that does all of the high power math. Howard Nicolas Pernetty wrote: > > I am aware of some shortcomings and design flaws of Simulink, > > especially in the code generation area. I am interested by > > your paper nonetheless, please send me copy. > > Ok no problem. Let me just a few days to strip any irrelevant data on > it... > > > However, Simulink is used by many people on a day-to-day basis > > in the context of big, industrial projects. The claim that it > > is "next to unusable" is, in my book, an overstatement ... > > Well the exact sentence is "next to unusable for our kind of projects". > You'll see the details on the paper, but I'm not joking. > For instance, under Simulink, our model is so big (well not so, but too > big for Simulink obviously), that you may have a loss of up to 40x in > performance compared to the model in C (how to optimize the Simulink > model is a whole other subject in itself). So to make it usable, we have > to use automatic code generation wich bring a whole new set of > problems... BUT our work is *very* specific, and I'm not talking about > Simulink in general. It may be perfect suited for others, it's just that > for us it's far from perfect... > > > Scicos is not perfect either but you can hardly say that is > > is a simple clone of Simulink. No time and space to go into > > the details ... > > I wasn't in charge of evaluating Scilab/Scicos, so I can only talk about > the conclusion : main motives to switch to Scilab/Scicos would be > because it's free, that's all. Report said that next to almost > everything Scilab/Scicos does, Matlab/Simulink can do, and more often > than not, do it much better. > So if you have a different report, I would be happy to read and transmit > it... > > > Obviously, the python community is very dynamic, but how much > > support will you get in the very specific topic of continuous > > time systems simulation ? > > Well some people already offered me their help. But I believe > that someone _has_ to begin alone some day... > Otherwise people who work on continuous system simulation would never be > interested in Python. > > That's the beauty of open source : do what you can, but do it ! and hope > that someone else will come one day and use your work to build upon it. > Step by step you will have something usable (in theory). > > > IMHO, an hybrid approach, such as the development of bridge > > to include Python components into Simulink/Scicos/Ptolemy/ > > Modelica/pick_your_favorite_simulator may grant you more > > interest from the simulation community. > > I already know some bridges like pymat or mlabwrap and I agree that a > way to include Python to Matlab/Simulink would be a great step. > But : > > 1) I think that it's Mathworks job to do it, and if they don't want to > do it, we'll never have a very good integration. > > 2) For our kind of projects and our kind of developers (mainly > non-IT engineers), I'm very reluctant to introduce too many different > technologies in a project. If we decided to go for Python, fine, let's > do the entire thing in Python/C. If we decided to go for Simulink, fine, > let's do the whole thing in Simulink/Matlab/C. Matlab, for algorithms, > can do almost the same things than Python and sometimes much better, so > if you have already Simulink (and so have the license) why go for Python > and struggle to have a good integration ? > > Regards, > > > > > Cheers, > > > > SB > > > > > > > > Nicolas Pernetty wrote: > > > Simulink is well fitted for small simulators, but when you run into > > > big projects, I find many shortcomings appears which made the whole > > > thing next to unusable for our kind of projects. > > > That's why I'm interested in Python by the way, it is not a simple > > > clone like Scilab/Scicos. It is a real language which bring its own > > > advantages, and its own shortcomings, which I find well suited for > > > our activity. > > > > > > If you want, I can send you a paper I wrote last year, detailing all > > > Simulink shortcomings. I doubt that this mailing list is interested > > > in such things...(and it's in French...). > > > Concerning Scilab/Scicos, I'm not really interested in a technology > > > primarily developed (INRIA and ENSPC) and used by France. Python and > > > all its libraries and communities are so much more dynamic ! > > > And also I've heard that Scilab was developed in Fortran in a way > > > which make it rigid and that the sources are poorly documented, not > > > a good sign for an open source software (and Scilab isn't 'Free' for > > > the FSF). > > > > > > Regards, > > > > > > > > > *********** REPLY SEPARATOR *********** > > > > > > On 8 Oct 2005 11:06:25 -0700, "S?bastien Boisg?rault" > > > wrote : > > > > > > > > > > > Simulink is a framework widely used by the control engineers ... > > > > It is not *perfect* but the ODEs piece is probably the best > > > > part of the simulator. Why were you not convinced ? > > > > > > > > You may also have a look at Scicos and Ptolemy II. These > > > > simulators are open-source ... but not based on Python. > > > > > > > > Cheers, > > > > > > > > SB > > > > > > > > > > > > > > > > > > > > > > > > Nicolas Pernetty a ?crit : > > > > > > > > > Hello Phil, > > > > > > > > > > Yes I have considered Octave. In fact I'm already using Matlab > > > > > and decided to 'reject' it for Python + Numeric/numarray + SciPy > > > > > because I think you could do more in Python and in more simple > > > > > ways. > > > > > > > > > > Problem is that neither Octave, Matlab and Python offer today a > > > > > framework to build continuous system simulator (in fact Matlab > > > > > with Simulink and SimMechanics, do propose, but I was not > > > > > convinced at all). > > > > > > > > > > Regards, > > > > > > > > > > *********** REPLY SEPARATOR *********** > > > > > > > > > > On 7 Oct 2005 11:00:54 -0700, phil_nospam_schmidt at yahoo.com > > > > > wrote : > > > > > > > > > > > Nicholas, > > > > > > > > > > > > Have you looked at Octave? It is not Python, but I believe it > > > > > > can talk to Python. > > > > > > Octave is comparable to Matlab for many things, including > > > > > > having ODE solvers. I have successfully used it to model and > > > > > > simulate simple systems. Complex system would be easy to model > > > > > > as well, provided that you model your dynamic elements with > > > > > > (systems of) differential equations. > > > > > > > > > > > > From vinay_sajip at yahoo.co.uk Wed Oct 5 18:28:25 2005 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: 5 Oct 2005 15:28:25 -0700 Subject: How to prevent logging warning? References: Message-ID: <1128551304.960549.235420@f14g2000cwb.googlegroups.com> Thomas Heller wrote: > I get the behaviour that I want when I add a 'NULL' handler in the > library, but is this really how logging is intended to be used? > The reason for the one-off message is that without it, a misconfiguration or a failure to configure any handlers is notified to a user (who is possibly not used to the logging package). I'm not sure which is more annoying - a one-off message which occurs when no handlers are configured and yet events are logged, or complete silence from logging when something is misconfigured, and not giving any feedback on what's wrong? (It's a rhetorical question - the answer is of course quite subjective). Certainly, I could change things so that e.g. the error is suppressed when logging.raiseExceptions is set to 0 (typically for production use). Regards, Vinay Sajip From nil at dev.nul Sun Oct 16 14:40:14 2005 From: nil at dev.nul (Christian Stapfer) Date: Sun, 16 Oct 2005 20:40:14 +0200 Subject: Comparing lists References: <1128930699.799657.146210@g47g2000cwa.googlegroups.com> <1128952417.0544cc73190bbbd4e683448c137969c8@teranews> <434ba977@nntp0.pdx.net> <1129216693.445956.155490@g47g2000cwa.googlegroups.com> Message-ID: "Steven D'Aprano" wrote in message news:pan.2005.10.16.18.52.56.797555 at REMOVETHIScyber.com.au... > On Sun, 16 Oct 2005 19:42:11 +0200, Christian Stapfer wrote: > >> Pauli's prediction of >> the existence of the neutrino is another. It took >> experimentalists a great deal of time and patience >> (about 20 years, I am told) until they could finally >> muster something amounting to "experimental proof" >> of Pauli's conjecture. > > Pauli's conjecture was the result of experimental evidence that was > completely inexplicable according to the theory of the day: So was it mere experiment or was it the relation between experiment and theory that provided the spur for creative advancement? My position is the latter. Mere experiment does not tell you anything at all. Only experiment on the background of suitable theory does that. > energy and > spin was disappearing from certain nuclear reactions. This was an > experimental result that needed to be explained, and Pauli's solution was > to invent an invisible particle that carried that energy and spin away. Pauli's creativity lay in proposing *this* particular solution to the puzzle. And, surely, if it had not been for Pauli's characterization of that hypothetical particle, experimentalists like Cowan and Reines would not have *anything* to aim for in the first place. But I'm not going to argue Pauli's case any futher in this NG, because this is, in the end, not a physics NG... > (When I put it like that, it sounds stupid, but in fact it was an elegant > and powerful answer to the problem.) > > The neutrino wasn't something that Pauli invented from theoretical first > principles. It came out of hard experimental results. > > Physics of the last half century is littered with the half-forgotten > corpses of theoretical particles that never eventuated: gravitinos, > photinos, tachyons, rishons, flavons, hypercolor pre-quarks, axions, > squarks, shadow matter, white holes, and so on ad nauseum. > > Neutrinos and quarks are exceptional in that experimental predictions of > their existence were correct, and I maintain that is because (unlike all > of the above) they were postulated to explain solid experimental results, > not just to satisfy some theoretical itch. > > So yet again, your triumph of theory is actually a victory for experiment. Well, I might tell now the story of Maxwell, sitting in his garden - and deducing, from his equations (which, admittedly, were inspired by earlier experimental work by Faraday), something really quite shockingly *new*: the existence of electromagnetic waves. Regards, Christian -- ?From a long view of the history of mankind - seen from, say, ten thousand years from now - there can be little doubt that the most significant event of the nineteenth century will be judged as Maxwell's discovery of the laws of electrodynamics. The American Civil War will pale into provincial insignificance in comparison with this important scientific event of the same decade.? - Richard P. Feynman: "The Feynman Lectures" From tim at tt1lock.org Sun Oct 16 10:29:02 2005 From: tim at tt1lock.org (Tim Tyler) Date: Sun, 16 Oct 2005 14:29:02 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: In comp.lang.java.programmer Steven D'Aprano wrote or quoted: > I'm aware of talk that Dell is selling Linux PCs at Walmart for less than > the same hardware plus Windows. Talk is cheap -- I'm not aware of anyone > who has actually seen these Linux PCs. I'd love to know either way. See: ``Dell's Open PC Costs More Than Windows Box'' - http://hardware.slashdot.org/article.pl?sid=05/10/08/034211&tid=190&tid=137 -- __________ |im |yler http://timtyler.org/ tim at tt1lock.org Remove lock to reply. From pmartin at snakecard.com Thu Oct 20 18:41:55 2005 From: pmartin at snakecard.com (Philippe C. Martin) Date: Thu, 20 Oct 2005 22:41:55 GMT Subject: http/urlib pos/get question (newbie) Message-ID: Hi, (I am _very_ new to web programming) I am writing a client module (browser plugin) and server module (Python CGI) that need to exchange information. I want the transaction to be intiated when the client accesses the link. I need data to go back and forth between the client and the server (cgi script) with no impact on what the browser shows. In the end (when I get the above to work), the server will say OK and the actual page will appear or NOK and an ERROR page will appear. I'm pretty clear (I think) as to what to do on the javascript (client) side (XMLHttp) but am not certain if my cgi script must "urlib.open" its own link in order to open the pipe on its side (there'll be some HTML GET/POST tag I assume but where is the pipe/socket ?) Thanks, Philippe From onurb at xiludom.gro Fri Oct 21 08:07:17 2005 From: onurb at xiludom.gro (bruno modulix) Date: Fri, 21 Oct 2005 14:07:17 +0200 Subject: Python vs Ruby In-Reply-To: References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> Message-ID: <4358d9f6$0$19694$626a14ce@news.free.fr> Amol Vaidya wrote: > "Casey Hawthorne" wrote in message > news:02efl19c4n4994vtlt2ubrs7ulg4mcm8ug at 4ax.com... > >>What languages do you know already? >> >>What computer science concepts do you know? >> >>What computer programming concepts do you know? >> >> >>Have you heard of Scheme? >> >> >>Ruby is a bit Perl like -- so if you like Perl, chances are you might >>like Ruby. Ruby is a whole lot Smalltalk-like -- so if you like Smalltalk... !-) >>Python is more like Java. Err... Python is more like what Java would have been if Java was a smart dynamic hi-level object oriented language !-) >>I have heard, but have not been able to verify that if a program is >>about >>10,000 lines in C++ >>it is about >>5,000 lines in Java >>and it is about >>3,000 lines in Python (Ruby to?) For a whole lot of common tasks (like file IO etc), the Java/Python loc ratio is between 5/1 and 10/1. Also, not having the dumbest type system in the world, Python is naturally much more generic than Java, which saves a lot of boilerplate code. I think that the real numbers would be much like 5000 lines in Java -> 1000 lines in Python - and probably 5000 -> 500 in some cases. > > I've done a lot of studying on my own, and taken the classes that my > high-school offers. I feel that I have a fairly good understanding of Java, > and basic OO concepts due to that. Err... I wouldn't start another HolyWar, but Java is not that Object Oriented. 'Class-based' would be more appropriate. Python, while not being class-based (ie: it doesn't impose that all code goes into a 'class' statement), is much more an OO language than Java, since in Python *everything* is an object - even functions, classes and modules. This makes a *big* difference. So yes, you may have learned some basic 00 concepts with Java (classes, instances, inheritence and polymorphism), but with Python and/or Ruby, you will probably realize that there's much more in the OO paradigm than all the Java world can dream of. > > Well, I'm not sure what you mean by programming concepts. I'm familiar with > OO through Java, and procedural programming through C. I'd be more detailed, > but I'm not exactly sure what you are asking. Sorry. patterns, metaclasses, aspects, closures, anonymous functions, higher-order functions, multiple dispatch, properties (computed attributes), generators, list expressions... does that ring a bell ? > I have no idea what Scheme is, but I'll cettainly look it up as soon as I'm > done writing this. Scheme is a Lisp dialect - Lisp being one of the oldest programming languages, and one of the most modern programming languages. Whatever the latest overhyped revolutionary new silver bullet buzzword stuff, you can bet your ass Lisp already had it many years ago. Now Lisp never managed to make it to the mainstream... It's a language (well, a familly of languages should I say) that is worth learning, but probably not until you've become familiar with some Python features and idioms. Another language that failed to make it to the mainstream but is worth giving a try is Smalltalk - the father of OOPLs (Simula being the GrandFather). BTW, most of Ruby's feature have been happily stolen from Smalltalk !-) > I've never given Perl a shot. It was another language I considered learning, > but my father's friend told me to go with Python or Ruby. +1 -- 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 JHoover at fbi.gov Fri Oct 28 22:43:10 2005 From: JHoover at fbi.gov (Gordon Airporte) Date: Fri, 28 Oct 2005 22:43:10 -0400 Subject: Generic utility class for passing data Message-ID: <1u-dnSkSzdnsfP_enZ2dnUVZ_tGdnZ2d@comcast.com> I'm wondering if this is might be bad practice. Sometimes when I need to pass around several pieces of datum I will put them in a tuple, then when I need to use them in a receiving function I get them out with subscripts. The problem is that the subscript number is completely meaningless and I have to remember the order I used. As an alternative I was considering using a dummy class like this: class Dummy: pass Then when I need to pass some related data, Python lets me do this: prefill = Dummy() prefill.foreground = 'blue' #"foreground" is made up on the fly prefill.background = 'red' prefill.pattern = mypattern return prefill Now I can access the data later using meaningful names. Is this going to cause problems somehow? Should I rather go to the trouble of creating more substantial individual classes for every grouping of data I might need to pass (with __init__'s and default values and so on)? Should I just stick with subscripted groupings because of the overhead? From thegreat_lover2003 at yahoo.com Tue Oct 18 02:14:32 2005 From: thegreat_lover2003 at yahoo.com (thegreat_lover2003 at yahoo.com) Date: 17 Oct 2005 23:14:32 -0700 Subject: www.liveboard.8my.com Message-ID: <1129616072.283406.130990@g14g2000cwa.googlegroups.com> Hello Friend You are invited to join www.liveboard.8my.com There you can discuss / post on various topics like Poems, Love, Romance, Flirting, Quotes, Shayris, Movies, Music, Personal Problem Discussions, Computers & Internet (Hacking at security end), Animations, Business, Employment and lots more. Register at www.liveboard.8my.com which is absolutely free. See you there Note: This is not SPAM From mwm at mired.org Wed Oct 12 00:16:45 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 12 Oct 2005 00:16:45 -0400 Subject: piping out binaries properly References: Message-ID: <86u0fnwes2.fsf@bhuda.mired.org> Andy Leszczynski writes: > I have got following program: > > import sys > import binascii > from string import * > sys.stdout.write(binascii.unhexlify("41410A4141")) > > > when I run under Unix I got: > > $ python u.py > u.bin > $ od -t x1 u.bin > 0000000 41 41 0a 41 41 > > and under Windows/Cygwin following: > > $ python u.py > u.bin > $ od -t x1 u.bin > 0000000 41 41 0d 0a 41 41 > 0000006 > > The question is how can I pipe out binary content properly and platform > independently? It's not normal to write binary content to stdout - you normally write it to a file. Open the file with open(name, 'wb') to write binaries. There doesn't appear to be any way to retroactively change the mode on a file. Which is probably a good thing. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From michele.simionato at gmail.com Mon Oct 24 07:50:29 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 24 Oct 2005 04:50:29 -0700 Subject: Python vs Ruby In-Reply-To: <1h4vl5j.1sg46l1irzgfmN%aleaxit@yahoo.com> References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> <1129883505.814349.306860@g44g2000cwa.googlegroups.com> <86fyqt9j9x.fsf@bhuda.mired.org> <1h4ukde.1gc4cgu1a252ggN%aleaxit@yahoo.com> <86y84k95c5.fsf@bhuda.mired.org> <1h4vl5j.1sg46l1irzgfmN%aleaxit@yahoo.com> Message-ID: <1130154629.382286.33090@g43g2000cwa.googlegroups.com> Alex Martelli wrote: > ... remember Pascal's "Lettres Provinciales", > and the famous apology about "I am sorry that this letter is so long, > but I did not have the time to write a shorter one"!-) This observation applies to code too. I usually spend most of my time in making short programs that would have been long. This means: cutting off non-essential features (and you can discover that a feature is non essential only after having implemented it) and/or rethinking the problem to a superior level of abstraction (only possible after you have implented the lower level of abstraction). Michele Simionato From john at castleamber.com Mon Oct 17 17:40:20 2005 From: john at castleamber.com (John Bokma) Date: 17 Oct 2005 21:40:20 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: Roel Schroeven wrote: > John Bokma wrote: >> Roel Schroeven wrote: >>>But that's not the point; the point is that they have the choice. >>>If MS had it its way, they wouldn't have that choice. >> >> >> I doubt that. But even if you're right, do you really think that MS >> is the only evil company on earth working like this? Do you really >> think that companies like Disney, Sony, Intel, AMD, Apple, etc work >> any different? > > No, I do not think that MS is the only company that uses shady > tactics. Also I didn't use the word 'evil', since I think it is too > strong for what even MS does. But the fact is that MS is convicted for > abusing its monopoly position. If just one got convicted it means that some got away with it, and still am. >>>Thousands and thousands of website work perfectly in all of the >>>aforementioned websites right now. >> >> Maybe you define perfectly different then me, but have a look at the >> Acid tests for example. Even between minor versions of for example >> Firefox, or Opera there are differences in rendering. I won't call >> that perfectly, but maybe because I am a programmer. > > Differences in rendering are perfectly acceptable on the World Wide > Web. Not the differences I am talking about. There is ambiguity in for example the CSS working drafts (or recommendations, too lazy to check their current state). Maybe check out what the acid test is (actually there are two IIRC). Also, wonder why if the differences I am talking about are "perfectly acceptable" why some are fixed between different versions (e.g. Opera). >> Others just pick Intel, because it's Intel. The same is happening for >> MS. People just buy MS, they don't care that it's cheaper (or maybe >> "cheaper") to install Linux + OpenOffice (for example). MS, so it's >> good. > > Popularity is not the same as quality. Did I state such a thing? Moreover, quality doesn't (in general) sell in this world. If you think so, wake up. Or do you really consider the Linux desktop (any of them) quality? The fact is that a company has no time to work on quality. If they do, the competition is selling what they hope to release in 2015. > I still fail to see your point. The original issue was the browser > wars. Tim Roberts wondered why Microsoft went through the efforst of > dominating the browser market, even if they don't make any money on > IE. David Schwartz gave the answer: MS did it to prevent the OS from > becoming a commodity, since that would allow users to freely choose > their own OS. *the* answer? LOL. I doubt it, since David's *the answer* isn't happening. As I asked in another reply: can you name several companies MS acquired to justify their fears of a major paradigm shift towards notworking computing? > You seem to be saying that that is not their intention, since users > will always prefer Windows as their OS anyhow. Well I don't think so, > but just maybe you're right. But I'm pretty sure MS didn't want to > take the chance, and did what it did for the reason David gave. Again, I doubt it. MS just wants that every user who doesn't care if there are better products just knows one and one name only: Microsoft. So: Internet = Microsoft, Music = Microsoft, Videos = Microsoft, Blogging = Microsoft. Multimedia = Microsoft. Your keyboard = Microsoft, your mouse = Microsoft. Your computer has a sticker on it: Designed for Microsoft Windows. Microsoft is (creating) a meme. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From OurLab at gmail.com Sun Oct 30 18:12:31 2005 From: OurLab at gmail.com (Alex) Date: 30 Oct 2005 15:12:31 -0800 Subject: Pickling and unpickling inherited attributes Message-ID: <1130713951.953157.270130@g14g2000cwa.googlegroups.com> I have a serious problem and I hope there is some solution. It is easier to illustrate with a simple code: >>> class Parent(object): __slots__=['A', 'B'] def __init__(self, a, b): self.A=a; self.B=b def __getstate__(self): return self.A, self.B def __setstate__(self, tup): self.A, self.B=tup >>> class Child(Parent): __slots__=['C',] def __init__(self, c): self.C=c def __getstate__(self): return self.C, def __setstate__(self, tup): self.C, =tup >>> obj=Child(1) >>> obj.A=2 >>> obj.B=3 >>> obj.A 2 >>> obj.B 3 >>> obj.C 1 >>> objct.Z=4 Traceback (most recent call last): File "", line 1, in -toplevel- objct.Z=4 AttributeError: 'Child' object has no attribute 'Z' So far so good.. Object obj inherited attributes (A and B) from the parent class and refuses to take any new ones. But look what happens when I try to pickle and unpickle it: >>> import cPickle >>> File=open('test', 'w') >>> cPickle.dump(obj, File) >>> File.close() >>> >>> file1=open('test', 'r') >>> objct=cPickle.load(file1) >>> file1.close() >>> objct.A Traceback (most recent call last): File "", line 1, in -toplevel- objct.A AttributeError: A >>> objct.C 1 Its own attribute (C) value is restored but the value of an inherited attribute (A) is not. I tried pickling protocol 2, and module pickle instead of cPickle, all with the same result. What can be done?! Or maybe nothing can be done? I would greatly appreciate an advice. A lot of code is written, but now we have a need for pickling and unpickling objects and discovered this problem. From nephish at xit.net Fri Oct 21 13:44:45 2005 From: nephish at xit.net (nephish at xit.net) Date: 21 Oct 2005 10:44:45 -0700 Subject: need some advice on x y plot In-Reply-To: <4359244e$1_2@newspeer2.tds.net> References: <1129823043.104864.73750@f14g2000cwb.googlegroups.com> <11lfgebn85liq1b@corp.supernews.com> <1129825379.218308.242010@g47g2000cwa.googlegroups.com> <4357d998$1_2@newspeer2.tds.net> <1129831950.926154.196420@g47g2000cwa.googlegroups.com> <1129912485.866312.298390@g47g2000cwa.googlegroups.com> <4359244e$1_2@newspeer2.tds.net> Message-ID: <1129916685.172187.224140@o13g2000cwo.googlegroups.com> the time is DateTime.DateTime object from a mySQLdb query. the value is a number anywhere between 0 and 15. the datetime is formatted like 2005-10-20 08:40:34 i could strip it and make a timestamp out of it. but reading the number of seconds since january of 1970 doesn't make a neat chart. any suggestions? oh, and can you output from Gnuplot to a png or jpeg or something like that. the Gnuplot documentation says that it can make a bitmap png but i dont know how to do that with the python wrapper. the docs for this are a little cryptic. still a newbie here. if you know a good tutorial on this, i would really appreciate the link. thanks for your time, and brain From mystilleef at gmail.com Tue Oct 11 01:58:08 2005 From: mystilleef at gmail.com (mystilleef at gmail.com) Date: 10 Oct 2005 22:58:08 -0700 Subject: Let My Terminal Go Message-ID: <1129010288.251817.147690@z14g2000cwz.googlegroups.com> Hello, A user of my application points me to a behavior in gVim, the text editor, that I would like to implement in my application. When gVim is launched from a shell terminal, it completely frees the terminal. You can continue to use the terminal for whatever purpose you wish, including closing and exiting it, without any effect on the running gVim instance. How do I implement this in my application written in python? I would like to believe it does not involve me forking my application in a new process. Maybe there is signal I can send to the operating system to achieve this, right? Your help is appreciated. Thanks From chris.cavalaria at free.fr Tue Oct 18 12:45:24 2005 From: chris.cavalaria at free.fr (Christophe) Date: Tue, 18 Oct 2005 18:45:24 +0200 Subject: UI toolkits for Python In-Reply-To: <86r7aiyg4g.fsf@bhuda.mired.org> References: <7xslv56ud1.fsf@ruckus.brouhaha.com> <3ras6oFit2djU1@individual.net> <4350dd34$0$6774$9b4e6d93@newsread4.arcor-online.net> <863bn12k6i.fsf@bhuda.mired.org> <7xslv02aoj.fsf@ruckus.brouhaha.com> <87psq39aur.fsf@wilson.rwth-aachen.de> <7xwtkbud5q.fsf@ruckus.brouhaha.com> <1h4mhm2.1rmv4fh1czi843N%aleaxit@yahoo.com> <86r7aiyg4g.fsf@bhuda.mired.org> Message-ID: <435526A4.6080607@free.fr> Mike Meyer a ?crit : > aleaxit at yahoo.com (Alex Martelli) writes: > >>Maybe that's the key difference between the mindset of a >>mathematician and that of an engineer -- I consider reaching over >>95% of visitors to be _quite good indeed_, > > > Oh? So you'd consider an SMTP/IMAP/POP/DNS/NFS/etc server that > rejected 5% of the systems connecting to be _quite good indeed_? I > think I'm glad that the internet wasn't built by people who agreed > with that. > > If you know what you're doing, you can have the best of both worlds > for a lot of web applications. Yes, it won't be as rich or functional > for the five percent who worry about security (or whatever), but it'll > still work. And yes, you can't do it for every application. For those, > anyone vaguely competent will add a warning. > > What surprises me is that marketing types will accept turning away - > what's the current internet user base? 200 million? - 10 million > potential customers without a complaint. Or maybe they just don't get > told that that's what's going on. > > References: Message-ID: <1129822629.250883.78570@g49g2000cwa.googlegroups.com> for new style classes __getattribute__ is defined, see eg. http://www.python.org/2.2.3/descrintro.html From mwm at mired.org Wed Oct 12 19:49:40 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 12 Oct 2005 19:49:40 -0400 Subject: Jargons of Info Tech industry References: <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> <86zmpjkml4.fsf@bhuda.mired.org> Message-ID: <864q7mwb1n.fsf@bhuda.mired.org> Roedy Green writes: > On Sun, 09 Oct 2005 06:32:07 -0400, Mike Meyer wrote > or quoted : >>Formatted spam can include pictures of words. That's a common spam >>tactic - send a multipart/alternative with a text part that look like >>a letter from aunt jane - and mention that you're sending a >>picture. The picture part is basically a jpeg of a flyer for the spam >>companies product. > Such a jpg would have a lot more sharp edges than a usual photo. Also > you tend to have areas of just two colours. Some edge detecting > software might have a go at it. It's probably possible. No one has done it yet. > However, my rule of thumb is I would not accept photos from the > general public, only from a subset of my correspondendents. That > makes a photo a strong spam indicator. But you also said (in <3g3rk1lv2dhcerqcn3hambu6p4l6mn70gq at 4ax.com>): > Censoring content and style is none of our business. Spam is all about censoring content. But you're proposing censoring style to deal with pictures of words. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From michaels at rd.bbc.co.uk Tue Oct 11 08:57:42 2005 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Tue, 11 Oct 2005 13:57:42 +0100 Subject: ANN: Kamaelia 0.3.0 released! Message-ID: Kamaelia 0.3.0 has been released! Introduction ============ 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. A subset of the system has been tested on series 60 phones. General feedback is welcome either directly, mailing lists or via IRC (#kamaelia, freenode). People are also more than welcome to use the system and suggest improvements not directly related to our specific goals, because we recognise the system can be used in more areas, not just networked multimedia. A diversity of systems built improves the system (for all users of course!) as a whole. What's New & Changed? ===================== *NOTE* Kamaelia 0.3.0 requires Axon-1.1.2 to run for some newer components (which has also just been released). Full release notes and change log: * http://kamaelia.sourceforge.net/Kamaelia-0.3.0-ReleaseNotes.html New Examples - 7 new examples including: * Simple reliable multicast based streamer using Ogg Vorbis. * Dirac Player * Dirac encode & playback. * Simple bouncing images game. Designed for very small children who are amused by things take beep and react when you press left/right mouse buttons. * Simple example showing how to use the ticker (First developed for showing subtitles). * Demonstration system showing how to use the new software chassis facility in the context of multiple chassis. New Tools, Notable Additions * Visual tool for building Kamaelia pipelines * Tk Support * Video encode, decode and playback. (dirac) New Packages & Subsystems These names should provide you with a flavour of the new subsystems that have been added: * Kamaelia.Codec * Kamaelia.Chassis * Kamaelia.File * Kamaelia.UI.Tk * Kamaelia.Internet.Simulate Other Highlights * Software chassis (software backplane will be coming in Kamaelia-NEXT) * Tk integration. (The pipeline builder is a nice example of a tool this enables) * Dirac encoded video decoders and encoders * Support for video playback. (dirac & YUV) * Variety of pygame based components, including * Tools for greater control over the pygame surface managed environment * Tools for building simple games. (controlling sprite behaviour for example) * Much richer tools for file reading and writing * Includes re-usable file readers. * More utilities for message filters and splitting of messages * Basic tools for simuluating error conditions and failure rates for delivery of messages (Sufficient for simulating an unstable underlying internet infrastructure). What is Kamaelia? ================= The project aims to make it easy to build networked multimedia systems (eg audio, video, interactive systems). The result is systems which are naturally componentised. Also, the resulting systems are /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) * Create Video players & streaming systems (for dirac). * With subtitles. ???*?Simple?network?aware?games?(via?pygame) ???*?Quickly?build?TCP?& Multicast based?network?servers?and?clients * Presentation tools * A networked audio mixer matrix (think multiple audio sources over network connections mixed and sent on to multiple locations with different mixes) * Look at graph topologies & customise the rules of display & particle types. .... Mix and match all of the above. You can also do a lot of this *visually* using the new PipeBuilder application in Tools. Essentially if the system you want to build involves audio or moving pictures, and you want to be able to make the system network aware, then this should be quick and easy to do using Kamaelia. (If it isn't, then a) it's a bug b) needs improving :-) 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. Oh, and due to things like the visual editor, the use of pygame in a lot of examples, the use of dirac & vorbis, it's quite a lot of fun too :-) Requirements ============ * Python 2.3 or higher recommended, though please do report any bugs with 2.2. * Axon (1.1.2 required) * vorbissimple (if you want to use the vorbis decode component/examples) * dirac bindings (again from kamaelia site) if you want to use the dirac encode/decode components & examples). (And dirac of course :-) Axon, vorbissimple and python-dirac 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/ Tutorial for the core component/concurrency system: * http://kamaelia.sourceforge.net/MiniAxon/ Project Motivations: * http://kamaelia.sourceforge.net/Challenges/ 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 cowie.rob at gmail.com Sat Oct 8 15:42:35 2005 From: cowie.rob at gmail.com (Rob Cowie) Date: 8 Oct 2005 12:42:35 -0700 Subject: noob question Letters in words? In-Reply-To: References: <1128735204.407666.193440@g14g2000cwa.googlegroups.com> Message-ID: <1128800555.639954.9780@g44g2000cwa.googlegroups.com> Well.. that put me in my place! Fredrik Lundh - I hadn't realised that 'is' does not test for equivalence. Thanks for the advice. From gg at fauskes.net Wed Oct 26 09:07:05 2005 From: gg at fauskes.net (propell) Date: 26 Oct 2005 06:07:05 -0700 Subject: tool for syntax coloring in html In-Reply-To: <1130330426.059794.282450@g49g2000cwa.googlegroups.com> References: <1130330426.059794.282450@g49g2000cwa.googlegroups.com> Message-ID: <1130332025.206073.33560@o13g2000cwo.googlegroups.com> I use Silvercity for my web site. SilverCity is a Python interface to the Scintilla lexers. It's available at http://silvercity.sourceforge.net/ I find the output from silvercity a bit verbose, so I have written a few Python classes for cleaning up the output. The code is available at http://fauskes.net/nb/syntaxhighlighting/ - Kjell Magne Fauske From bdesth.quelquechose at free.quelquepart.fr Tue Oct 25 16:59:34 2005 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Tue, 25 Oct 2005 22:59:34 +0200 Subject: security In-Reply-To: <1130247483.668999.322640@g43g2000cwa.googlegroups.com> References: <1130247483.668999.322640@g43g2000cwa.googlegroups.com> Message-ID: <435e92fc$0$21322$626a54ce@news.free.fr> Mattia Adami a ?crit : > Hi to all. > I'm intristing in write a plugin for browsers that can execute python > code. > I know the main problem is security. Many thread were opened about this > in the ng. > I would know if fork python rewriting some library could avoid > problems. I.e. one problem is the possibility to access files. If I > rewrite the open() function so that raises exception if the program try > to access a file out of a defined directory. > I'm sure not a security expert, so please be patient if my question is > stupid. > Thanks to all. I'm not a security expert either, but you may want to have a look at the way Zope 2.x handles this kind of restrictions for TTW scripts. From hyakugei at gmail.com Mon Oct 3 22:14:40 2005 From: hyakugei at gmail.com (Jos) Date: 3 Oct 2005 19:14:40 -0700 Subject: Thread's, async_chat and asyncore Message-ID: <1128392080.485892.287770@g43g2000cwa.googlegroups.com> Hello. I'm using the asyncore and _chat modules to create a network server. I also have, running in a separate thread(s), a "producer" which needs to "push" data onto the network connection(s). (This is all for a multi-player game server, so the threads would be individual games, that need to update the players when new events happen in the game) I currently have a module level list of async_chat instances, which the thread then reads and uses the 'push' method of async_chat. I've done some very quick tests, but wanted to know more formally if the async_chat.push() method is thread safe? ie. can i be sure that the data that the thread pushes onto the connection will always be complete, and never "over-written" by another thread? Here is an example, which creates a whack of threads, which push their message down the first connection made to the server. I just use a telnet client to test it. I haven't seen any over-writing of values, but this is a very basic test/example of what i'm doing. I just want to make sure that this _is_ ok, or if i should be using a Queue... import asynchat import asyncore import socket from threading import Thread import time import random clients = [] class pulse_thread(Thread): def __init__(self, string): Thread.__init__(self) self.msg = string def run(self): while True: time.sleep(random.random()) if(len(clients)): clients[0].push(self.msg) class Chat(asynchat.async_chat): def __init__(self, sock, addr, terminator="\r\n", name="me"): asynchat.async_chat.__init__(self, conn=sock) self.rmq = [] self.terminator = terminator self.set_terminator(self.terminator) # push self onto module client list, so threads can access me clients.append(self) def collect_incoming_data(self, data): """Buffer the data""" self.rmq.append(data) def found_terminator(self): print "".join(self.rmq) self.rmq = [] class cServer(asyncore.dispatcher): # constructor method def __init__(self, addr, terminator="\r\n"): # initalize asyncore asyncore.dispatcher.__init__(self) self.terminator = terminator # create a socket to listen on self.create_socket(socket.AF_INET, socket.SOCK_STREAM) # bind the socket to the ip/port self.bind(addr) # listen ??? don't know about the 5 ???? self.listen(50) # EVENT handle_accept - fired when server accepts an new connection def handle_accept (self): # fire the accept method > returns a connection object conn, addr = self.accept() # extend the connection with cSock Class (another asyncore) #cSock(conn, addr) Chat(conn,addr,self.terminator) if __name__ == '__main__': for i in range(1,99): x = pulse_thread(":%02d:\n\r" % (i,)) x.start() myserver = cServer(('127.0.0.1',7000)) asyncore.loop() Please let me know if this is totally the _wrong_ way to do it! Thanks, Jos From nyamatongwe+thunder at gmail.com Fri Oct 14 22:42:19 2005 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Sat, 15 Oct 2005 02:42:19 GMT Subject: wierd threading behavior In-Reply-To: <1129330815.876193.147800@g49g2000cwa.googlegroups.com> References: <1129330815.876193.147800@g49g2000cwa.googlegroups.com> Message-ID: Qun Cao: > import thread > def main(): > thread.start_new(test.()) > > def test(): > print 'hello' > > main() > " > this program doesn't print out 'hello' as it is supposed to do. > while if I change main() The program has exited before the thread has managed to run. It is undefined behaviour whether secondary threads survive main thread termination but it looks like they don't on your system. Use the threading module and call join to wait for all threads to complete before exiting the program. Neil From bh at intevation.de Wed Oct 12 12:05:22 2005 From: bh at intevation.de (Bernhard Herzog) Date: Wed, 12 Oct 2005 18:05:22 +0200 Subject: C Wrapper Function, crashing Python? References: <1129122046.417746.100120@g47g2000cwa.googlegroups.com> <1129123866.536068.69520@g43g2000cwa.googlegroups.com> Message-ID: "Java and Swing" writes: > static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { [...] > char *aString = 0; > char *bString = 0; [...] > int ok = PyArg_ParseTuple(args, "sss", &in, &aString, &bString); [...] > free(aString); > free(bString); aString and bString are pointers to memory managed by the strings in your args tuple. You must not free them! The memory is automatically managed by Python. Bernhard -- Intevation GmbH http://intevation.de/ Skencil http://skencil.org/ Thuban http://thuban.intevation.org/ From zanesdad at bellsouth.net Thu Oct 27 11:57:36 2005 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Thu, 27 Oct 2005 11:57:36 -0400 Subject: socket.error: (32, 'Broken pipe'): need help In-Reply-To: References: Message-ID: <4360F8F0.1040806@bellsouth.net> Junhua Deng (AL/EAB) wrote: >Hi, >I have a simple server-client application with threading. It works fine when both server and client on the same machine, but I get the following error message if the server is on another machine: > >... ... > self.socket.send(outgoingMsg) >socket.error: (32, 'Broken pipe') > >I do not know where to start with? > >Thanks >Junhua > > Can you tell if the recipient actually got any of the data? At what point do you get this error? Is the client able to connect to the server? Could you extract some more code (connection made, the sender's sending code, receiver's receiving code, etc.) so we can see what you're doing? Did you happen to tell the server to bind "localhost" or 127.0.0.1? - jmj From steve at holdenweb.com Tue Oct 11 06:37:54 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 11 Oct 2005 11:37:54 +0100 Subject: strange import error with Python-2.4.1 In-Reply-To: <434B8EDF.3060905@chamonix.reportlab.co.uk> References: <434B8EDF.3060905@chamonix.reportlab.co.uk> Message-ID: <434B9602.9070001@holdenweb.com> Robin Becker wrote: > Whilst testing the excellent xlrd http://www.python.org/pypi/xlrd/0.3a1 > I came across the following strangeness when trying to add an import of os to > assist with debugging/tracing. > > > At line 66 I replaced > > import sys > > with import sys, os > > and then ran python runxlrd.py --help and got this error which is not a real > syntax problem > > Traceback (most recent call last): > File "runxlrd.py", line 5, in ? > import xlrd > File "C:\python24\lib\site-packages\xlrd\__init__.py", line 552 > if DEBUG: print >> self.logfile, "SST Processing" > > if I remove the , os then the run produces the expected > > usage: runxlrd.py [options] command input-file-patterns > > options: > -h, --help show this help message and exit > -l LOGFILENAME, --logfilename=LOGFILENAME > contains error messages > -v VERBOSITY, --verbosity=VERBOSITY > level of information and diagnostics provided > > I also am able to change the line to > > import sys > import os > > without error. > > This behaviour doesn't occur with 2.4.2 or 2.4 only with 2.4.1. I looked for > some bug fix in the recently released 2.4.2 that related, but couldn't find > anything obvious. My system doesn't have psyco so xlrd's attempted psyco use > shouldn't be an issue. Thanks for 2.4.2, but is this one of the fixed bugs or > has it just got harder to induce? Robin: Can I ask if you are specifying a source encoding in your file with a pragma (?) like # -*- coding: iso-8859-15 -*- I've noticed what appear to be spurious syntax errors from time to time on such files, and have been attempting to debug the problem for some time without any apparent success. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From bokr at oz.net Tue Oct 25 11:12:34 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 25 Oct 2005 15:12:34 GMT Subject: Syntax across languages References: <1130052687.396109.145420@o13g2000cwo.googlegroups.com> <0fkrl15cteikfb09ah670kv9bupr902soi@4ax.com> Message-ID: <435e45fe.929142326@news.oz.net> On 25 Oct 2005 07:46:07 GMT, Duncan Booth wrote: >Tim Roberts wrote: > >>> >>>- Nestable Pascal-like comments (useful): (* ... *) >> >> That's only meaningful in languages with begin-comment AND end-comment >> delimiters. Python has only begin-comment. Effectively, you CAN nest >> comments in Python: > >I believe that the OP is mistaken. In standard Pascal comments do not nest, >and you can mix delimiters so, for example: > > (* this is a comment } > >Most Pascal implementations require the delimeters to match and allow you >to nest comments which use different delimiters, but I'm not aware of any >Pascal implementations which would allow you to nest comments with the same >delimiter: > > (* This is not a valid (* comment within a comment. *) *) > >To this extent Python (if you consider docstrings as a type of comment) >does exactly the same thing: > >""" this is # a docstring! """ > ># and this is """ a comment """ > Dusting off old ((c) '74, corrected '78 printing, bought in '79) Jensen/Wirth Pascal User manual & Report, 2nd edition: (had to search, since 'comment' was not in the index!) """ The construct { } maybe inserted between any two identifiers, numbers (cf. 4), or special symbols. It is called a _comment_ and may be removed from the program text without altering its meaning. The symbols { and } do not occur otherwise in the language, and when appearing in syntactic description they are meta-symbols like | and ::= . The symbols pairs (* and *) are used as synonyms for { and }. """ I suspect whether you can match a (* with a } depends on a particular implementation. I think I have run across at least one where they were independent, so you could use one to comment out blocks of mixed program and comment source commented with the other. ... aha, it must have been Borland Delphi Object Pascal: """ The following constructs are comments and are ignored by the compiler: { Any text not containing right brace } (* Any text not containing star/right parenthesis *) A comment that contains a dollar sign ($) immediately after the opening { or (* is a /compiler directive/. A mnemonic of the compiler command follows the $ character. """ Regards, Bengt Richter From nephish at xit.net Tue Oct 25 15:06:43 2005 From: nephish at xit.net (nephish at xit.net) Date: 25 Oct 2005 12:06:43 -0700 Subject: need some advice on x y plot In-Reply-To: References: <1129823043.104864.73750@f14g2000cwb.googlegroups.com> <1130253519.330211.92880@o13g2000cwo.googlegroups.com> Message-ID: <1130267203.357225.180410@g14g2000cwa.googlegroups.com> tics.append('"%s" %s' % (time.strftime(...), x)) # might need time.localtime(x) for that last term. ok, tried this and it worked. but the first plot is at the last plot of data back to that math mistake i mentioned earlier. so, thanks much, i will be back when i mess around with it some more and see if i can get it right. thanks very very much guys, i know i sound frustrated and ignorant, but i am having a lot of fun with this From nospam at here.com Tue Oct 4 06:58:21 2005 From: nospam at here.com (Matt Feinstein) Date: Tue, 04 Oct 2005 06:58:21 -0400 Subject: Processing an image with numarray.nd image References: <434251e3$0$11154$636a15ce@news.free.fr> Message-ID: On Tue, 04 Oct 2005 11:56:51 +0200, Rapha?l MARC wrote: >Hello, > >Can anyone tell me how to open an image >and transform it into a list so that >the functions of the multi dimensionnal module of >numarray (numarray.nd image) can process it ? > >Do I have to use PIL ? > >So I would code something like : >import Image >im = Image.open("Python.jpg") >data = list(im.getdata()) >import numarray.nd image as ti >ti.median filter(data,...) I've been doing something like that... from numarray import * import numarray.nd_image as Filter import PIL.Image as Image im = Image.open(file_name) array_dat = reshape(array(list(im.getdata())), im.size) filt_array_dat = Filter.correlate(array_dat, my_filter) et cetera... Matt Feinstein -- There is no virtue in believing something that can be proved to be true. From lsumnler at gmail.com Thu Oct 6 11:58:33 2005 From: lsumnler at gmail.com (len) Date: 6 Oct 2005 08:58:33 -0700 Subject: Newbie ? MS Sql update of record Message-ID: <1128614313.274710.172080@g49g2000cwa.googlegroups.com> I have created a python program that takes a flat file and changes some of the data and create a new flat file with the changes. Part of this process requires that I try to find a particular model car in an MS Sql table. This part of the program is now working great. It has come to my attention that some of the information in the flat file could be used to update our information in the MS Sql table that I currently run the query on. Basicly I create a recordset of vehicles from the MS Sql table based on vehicle year and make and once I have this recordset I run it through logic which does a reqular expression compare on the vehicle VIN no to the VIN number in the table to get a match. I would like to update this record in the table with info. in the flat file. I believe there should be some way to update the fields in this record of the recordset and then update the table. I am not an sql expert and would appreciate someone pointing me in the right direction. Contained below is a listing of my code; # The following code creates a connection object, # assigns the connection string, opens the # connection object, and then verifies a good # connection. oConn = Dispatch('ADODB.Connection') oConn.ConnectionString = "Provider=SQLOLEDB.1;" +\ "Data Source=uicesv05;" +\ "uid=aiis;" +\ "pwd=aiis;" +\ "database=auto_mo_001" oConn.Open() if oConn.State == adStateOpen: print "Database connection SUCCEEDED" else: print "Database connection FAILED" # The following code creates a command object, # assigns the command to the connection object, # sets the query, creates the parameters objects to # be passed to the command object and requests the # query to be prepared (compiled by the SQL system). oCmd = Dispatch('ADODB.Command') oCmd.ActiveConnection = oConn oCmd.CommandType = adCmdText oCmd.CommandText = """\ SELECT VA_MK_YEAR,VA_MK_DESCRIP,VO_VIN_NO,VO_MODEL,VO_BODY, VO_DESCRIPTION,VO_MODEL_ID FROM D014800 INNER JOIN D014900 ON VA_MK_NUMBER_VER = VO_MAKE_NO AND VA_MK_YEAR = VO_YEAR WHERE VA_MK_YEAR = ? AND VA_MK_DESCRIP = ? """ vyear = '' vmake = '' oParmYear = oCmd.CreateParameter(vyear,adChar,adParamInput) oParmYear.Size = 4 oParmMake = oCmd.CreateParameter(vmake,adChar,adParamInput) oParmMake.Size = 10 oCmd.Parameters.Append(oParmYear) oCmd.Parameters.Append(oParmMake) oCmd.Prepared = True ... def wrkveh(ifile,strstart,maxcnt): """ wrkveh function does an SQL record lookup to try an select the correct vehicle in the V1sta make and model files. If the correct model is found I move V1sta's make model and body descriptions to the flat file. Currently, I hard code a 1 for vehicle use. The drive segment is an occurs 6""" cnt = 0 vehwrk = '' while cnt < maxcnt: if ifile[strstart:strstart + 10] == ' ': vehwrk = vehwrk + ifile[strstart:strstart + 133] else: vmake = ifile[strstart:strstart + 10] vyear = ifile[strstart + 98:strstart + 102] vvin4_8 = ifile[strstart +53:strstart + 58] vmodel = '' vbody = '' oParmYear.Value = vyear oParmMake.Value = vmake (oRS, result) = oCmd.Execute() while not oRS.EOF: wvin = oRS.Fields.Item("VO_VIN_NO").Value.replace('*','.') wvin.replace('*','.') wvin = wvin[0:5] r1 = re.compile(wvin) if r1.match(vvin4_8): vmake = oRS.Fields.Item("VA_MK_DESCRIP").Value vmodel = oRS.Fields.Item("VO_MODEL").Value vbody = oRS.Fields.Item("VO_DESCRIPTION").Value vmodelid = oRS.Fields.Item("VO_MODEL_ID").Value print 'DRC model ' + vmake + ' ' + vyear + ' ' + vmodel + \ ' ' + vmodelid break else: oRS.MoveNext() else: print 'DRC model NOT FOUND' vehwrk = vehwrk + vmake + vmodel + vbody vehwrk = vehwrk + ifile[strstart + 50:strstart + 107] vehwrk = vehwrk + '1' vehwrk = vehwrk + ifile[strstart + 108:strstart + 133] strstart += 133 cnt += 1 return vehwrk From jari.aalto at cante.net Sat Oct 15 14:40:00 2005 From: jari.aalto at cante.net (Jari Aalto) Date: Sat, 15 Oct 2005 21:40:00 +0300 Subject: how to improve simple python shell script (to compile list of files) References: Message-ID: <4q7ityin.fsf@blue.sea.net> "Chris F.A. Johnson" writes: > On 2005-10-15, Jari Aalto wrote: > Don't indent: > > function compile () > { > python -c ' > import os, sys, py_compile; > i = 0; > for arg in sys.argv: > file = os.path.basename(arg); > dir = os.path.dirname(arg); > i += 1; > if i > 1 and os.path.exists(dir): > os.chdir(dir); > print "compiling %s\n" % (file); > py_compile.compile(file); > ' $* > } Thanks, is there equivalent to this Perl statement in Python? @list = @ARGV[1 .. @ARGV]; or something similar so that I could avoid the 1 > 1 (sys.argv) check altogether? Jari From spammers-go-here at spam.invalid Mon Oct 17 16:43:19 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Mon, 17 Oct 2005 16:43:19 -0400 Subject: List of strings to list of floats ? References: <4351d29e$0$41148$14726298@news.sunsite.dk> <4353d2a2$0$41138$14726298@news.sunsite.dk> Message-ID: <43540cc0$0$41147$14726298@news.sunsite.dk> Erik Max Francis wrote: > Madhusudan Singh wrote: > >> Thanks. Now, a slightly more complicated question. >> >> Say I have two lists of floats. And I wish to generate a list of floats >> that is a user defined function of the two lists. > > result = [sqrt(x**2 + y**2) for x, y in zip(xs, ys)] > Works perfectly. Thanks ! From max at alcyone.com Sat Oct 15 00:59:51 2005 From: max at alcyone.com (Erik Max Francis) Date: Fri, 14 Oct 2005 21:59:51 -0700 Subject: Problem splitting a string In-Reply-To: References: Message-ID: Anthony Liu wrote: > I have this simple string: > > mystr = 'this_NP is_VL funny_JJ' > > I want to split it and give me a list as > > ['this', 'NP', 'is', 'VL', 'funny', 'JJ'] > > 1. I tried mystr.split('_| '), but this gave me: > > ['this_NP is_VL funny_JJ'] > > It is not splitted at all. Use re.split: >>> re.split('_| ', s) ['this', 'NP', 'is', 'VL', 'funny', 'JJ'] -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis To love without criticism is to be betrayed. -- Djuna Barnes From davids at webmaster.com Thu Oct 27 18:17:29 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 15:17:29 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <66u633-etj.ln1@news.it.uc3m.es> <7xbr1aewtq.fsf@ruckus.brouhaha.com> <86acgulv5z.fsf@localhost.localdomain> <7xvezi8ypy.fsf@ruckus.brouhaha.com> Message-ID: "Paul Rubin" wrote in message news:7xvezi8ypy.fsf at ruckus.brouhaha.com... > "David Schwartz" writes: >> Sorry to be pedantic, but I think it's an important point that no >> court >> ever found that Microsoft illegally acquired a monopoly. So to >> characterize >> the monopoly itself as "illegal" is simply erroneous. > Who is paying you to tell these ridiculous crap? The monopoly is illegal > if maintained by anticompetitive means regardless of how it was acquired. > From http://cyber.law.harvard.edu/msdoj/conclusions-l.html: Is it your position that Micorosoft's monopoly was illegal when they first acquired it? > The threshold element of a sec 2 monopolization offense being "the > possession of monopoly power in the relevant market... If that were true, how could a person ever legally acquire a monopoly, which is exactly what the courts held with respect to Microsoft? > David Schwartz, I have a direct question for you: are you on > Microsoft's payroll? No. I have never received a dime from Microsoft, either directly or indirectly. I am one of those people who believes that conduct that's perfectly legal, moral and ethical before you can be said to have a monopoly does not suddenly become immoral or unethical the day you acquire 51% of what someone calls a market. I am not the only person with this view. http://www.capitalism.org/faq/antitrust.htm http://www.amazon.com/exec/obidos/tg/detail/-/0945999623?v=glance http://www.cato.org/pubs/pas/pa-169.html http://www.independent.org/publications/books/book_summary.asp?bookID=31 http://www.ntu.org/main/press.php?PressID=344&org_name=NTUF DS From dima_turbiner at yahoo.com Wed Oct 26 19:11:45 2005 From: dima_turbiner at yahoo.com (dima_turbiner at yahoo.com) Date: 26 Oct 2005 16:11:45 -0700 Subject: tool for syntax coloring in html In-Reply-To: <1130351182.476810.210140@g14g2000cwa.googlegroups.com> References: <1130330426.059794.282450@g49g2000cwa.googlegroups.com> <1130351182.476810.210140@g14g2000cwa.googlegroups.com> Message-ID: <1130368304.976043.170290@o13g2000cwo.googlegroups.com> A really easy one to use is Doxygen Good luck, Dimitri Googmeister wrote: > Xah Lee wrote: > > in some online documentations, for examples: > > > > http://perldoc.perl.org/perlref.html > > http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z-H-17.html > > http://www.haskell.org/hawiki/HaskellDemo > > > > the codes are syntax colored. > > > > Is there a tool that produce codes in html with syntax coloring? > > I've used GNU Source-highlight with success. > > http://www.gnu.org/software/src-highlite/source-highlight.html From akameswaran at gmail.com Thu Oct 20 17:13:16 2005 From: akameswaran at gmail.com (akameswaran at gmail.com) Date: 20 Oct 2005 14:13:16 -0700 Subject: newbie question about SocketServer Message-ID: <1129842796.819897.309040@g49g2000cwa.googlegroups.com> Is it just me or do the server_close() methods do squat? I'm primarily working with a ThreadingTCPServer object and trying to create a simple server that can shut itself down. But even simplest cases don't seem to work. Admittedly I am trying it from within my handler class, but for some odd reason, the server is allways willing to handle one more request before dying. Then it dies. From perl at my-header.org Sun Oct 2 15:02:25 2005 From: perl at my-header.org (Matija Papec) Date: Sun, 02 Oct 2005 21:02:25 +0200 Subject: OT: Phases of the moon [was Re: A Moronicity of Guido van Rossum] References: <1128003857.930444.47650@g14g2000cwa.googlegroups.com> <1128013745.763757.144280@g44g2000cwa.googlegroups.com> <1128015868.201617.153240@g14g2000cwa.googlegroups.com> <0001HW.BF63479501083049F0407550@news.individual.de> Message-ID: X-Ftn-To: Paul F. Dietz "Paul F. Dietz" wrote: >> As a similar example: I've been told by various women independently, >> that "there are more babies born near a full moon." > >That's also a myth. Perhaps not, consider deamon or vampire babies. :) -- Matija From sybrenUSE at YOURthirdtower.com.imagination Tue Oct 11 02:44:11 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Tue, 11 Oct 2005 08:44:11 +0200 Subject: Batteries Included? References: <1129010199.291968.142720@g47g2000cwa.googlegroups.com> Message-ID: Alex enlightened us with: > Python's moto is "Batteries Included", but where are the batteries > for making exe files and making an installer file? Those aren't "batteries". Those are things you can do with the program, but are outside the programming language. Writing and distributing software is one thing. Converting them to a platform-specific executable is another. > I had to download, install and use py2exe and Inno Setup in order to > accomplish this. Well done. > I might be wrong expecting that a language whose moto is "Batteries > Included" would be able to produce exe files. Indeed, you're wrong. Why would such an ability be included in Python? It's a cross platform language. What need would Mac, Linux, BSD, Solaris etc. users have for such a feature? And why would it have to be included, when there is an easy solution just around the corner? You prooved that it was easy enough to install and use by someone who just learned Python. I really don't see the problem here. > Are there plans to do this in the future version of Python? I doubt it. 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 my_email_is_posted_on_my_website at munged.invalid Wed Oct 12 17:37:43 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 12 Oct 2005 21:37:43 GMT Subject: Jargons of Info Tech industry References: <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <86y853mzmr.fsf@bhuda.mired.org> <86mzlil269.fsf@bhuda.mired.org> <86slv8xdkw.fsf@bhuda.mired.org> Message-ID: On Tue, 11 Oct 2005 11:45:03 -0400, Mike Meyer wrote or quoted : >Jeff Poskanzer, now *he* has a spam problem. He gets a few million >spams a day: . It is a bit like termites. If we don't do something drastic to deal with spam, the ruddy things will eventually make the entire Internet unusable. the three keys to me are: 1. flipping to a digital id based email system so that the sender of any piece of mail can be legally identified and prosecuted. If every piece of anonymous email disappeared that would go a long way to clearing up spam. Let those sending ransom notes, death threats and hate mail use snail mail. As a second best, correspondents are identified by permission/identity/encryption keys given to them by their recipients. 2. flipping to a sender pays system so that the Internet does not subsidise spam. 3. Mail is not transported without prior permission. The receiver can turn that permission on and off any time he chooses. This is basically an automated version of what Zaep does where the sender is not consciously aware of the permission-getting step. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From sybrenUSE at YOURthirdtower.com.imagination Wed Oct 26 09:27:19 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Wed, 26 Oct 2005 15:27:19 +0200 Subject: How do I access the property info in this example ? References: <1130332635.319629.91900@o13g2000cwo.googlegroups.com> Message-ID: David Poundall enlightened us with: > class C(object): > def getx(self): return self.__x > def setx(self, value): self.__x = value > def delx(self): del self.__x > x = property(getx, setx, delx, "I'm the 'x' property.") > > I would like to get at ... > > "I'm the 'x' property." As usual: C.x.__doc__ 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 codecraig at gmail.com Tue Oct 25 07:30:04 2005 From: codecraig at gmail.com (jas) Date: 25 Oct 2005 04:30:04 -0700 Subject: Redirect os.system output In-Reply-To: References: <1129927486.854143.169670@g49g2000cwa.googlegroups.com> <43596c70$1_3@newspeer2.tds.net> <1130154552.795209.25830@g43g2000cwa.googlegroups.com> <435cd10c$1_2@newspeer2.tds.net> <1130157195.954433.131650@g49g2000cwa.googlegroups.com> <1130159194.833666.250820@g47g2000cwa.googlegroups.com> <435d04b8$1_2@newspeer2.tds.net> <1130170339.476122.61080@o13g2000cwo.googlegroups.com> Message-ID: <1130239804.889031.139640@g44g2000cwa.googlegroups.com> Paul, I did ceck out the PExpect, however, I thought it was not ported for Windows. Did you find a ported version? If not, what did you have to do to be able to use it? Thanks Paul Dale wrote: > You might want to try python expect which gives you a very simple and > scriptable interface to a process. > > http://pexpect.sourceforge.net/ > > I've been using it on windows to automate a few things. > > Cheers, > > Paul > > jas wrote: > > >Kent, > > Yes, your example does work. So did os.popen...however, the problem > >is specific to "cmd.exe". > > Have you tried that yet? > > > >Thanks! > > > >Kent Johnson wrote: > > > > > >>jas wrote: > >> > >> > >>>Ok, I tried this... > >>> > >>>C:\>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 subprocess as sp > >>>>>>p = sp.Popen("cmd", stdout=sp.PIPE) > >>>>>> > >>>>>>result = p.communicate("ipconfig") > >>>>>> > >>>>>> > >>>'result' is not recognized as an internal or external command, > >>>operable program or batch file. > >>> > >>> > >>> > >>>basically I was opening to send the "ipconfig" command to cmd.exe and > >>>store the result in the "result" variable. But you can see there was > >>>an error with result. > >>> > >>> > >>This works for me: > >>import subprocess as sp > >>p = sp.Popen("ipconfig", stdout=sp.PIPE) > >>result = p.communicate()[0] > >>print result > >> > >>Kent > >> > >> > > > > > > From fredrik at pythonware.com Thu Oct 13 03:43:41 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 13 Oct 2005 09:43:41 +0200 Subject: Multiple assignments simplification References: <1129162253.273873.277050@g14g2000cwa.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > I don't know if C++ compilers can do such optimizations. working on a Python to C/C++ translator without knowing what kind of optimizations a C/C++ compiler can do for you sounds like a great way to waste your time... (I would be rather bit surprised if any contemporary C or C++ compiler didn't generate optimal machine code for source code that contains swaps like the one you posted. it won't look at just the swap statement, however; the interesting thing is where the values came from, and what you're doing with the values later on. minimizing the number of assignment statements in the swap translation won't change a thing...) From mrstephengross at hotmail.com Tue Oct 4 09:43:14 2005 From: mrstephengross at hotmail.com (mrstephengross) Date: 4 Oct 2005 06:43:14 -0700 Subject: Which SQL module to use? Message-ID: <1128433394.470896.89770@g44g2000cwa.googlegroups.com> I'd like to do some basic SQL stuff in Python. It seems like there are a heck of a lot of SQL modules for Python. What's the simplest and easiest one to use? Thanks, --Steve (mrstephengross at hotmail.com) From superprad at gmail.com Fri Oct 14 15:11:58 2005 From: superprad at gmail.com (PyPK) Date: 14 Oct 2005 12:11:58 -0700 Subject: Function to execute only once Message-ID: <1129317118.937439.159550@g43g2000cwa.googlegroups.com> Hi if I have a function called tmp=0 def execute(): tmp = tmp+1 return tmp also I have def func1(): execute() .... and def func2(): execute() .... now I want execute() function to get executed only once. That is the first time it is accessed. so taht when funcc2 access the execute fn it should have same values as when it is called from func1. From robin at reportlab.com Fri Oct 7 05:39:46 2005 From: robin at reportlab.com (Robin Becker) Date: Fri, 07 Oct 2005 10:39:46 +0100 Subject: [Info] PEP 308 accepted - new conditional expressions In-Reply-To: References: <3q4ro9Fd770nU3@individual.net> <0qh%e.20023$Ix4.15230@okepread03> Message-ID: <43464262.3040406@chamonix.reportlab.co.uk> As mentioned earlier only a dictator can make such decisions and of course as with many dictatorships the wrong decision is often made. There's no such thing as a benevolent dictatorship. -- Robin Becker From bretthoerner at gmail.com Tue Oct 18 13:39:39 2005 From: bretthoerner at gmail.com (Brett Hoerner) Date: 18 Oct 2005 10:39:39 -0700 Subject: Web based applications are possible with wxPython? In-Reply-To: References: Message-ID: <1129657179.693127.277100@g49g2000cwa.googlegroups.com> I don't think this is possible, unless I am grossly misunderstanding. For the web, pretty much every "UI" is build with some variation of HTML (XHTML is the new standard) with JavaScript thrown in for fancy GUI-like interfaces. You can't use OS-native widgets in the web browser, no. From fredrik at pythonware.com Tue Oct 25 04:31:38 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 25 Oct 2005 10:31:38 +0200 Subject: more than 100 capturing groups in a regex References: <1130160675.270886.208420@z14g2000cwz.googlegroups.com> <1130225565.592108.197670@z14g2000cwz.googlegroups.com> Message-ID: Joerg Schuster wrote: > I just want to use more than 100 capturing groups. define "more" (101, 200, 1000, 100000, ... ?) From paul at boddie.org.uk Tue Oct 4 09:34:28 2005 From: paul at boddie.org.uk (Paul Boddie) Date: 4 Oct 2005 06:34:28 -0700 Subject: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please! References: <43424bee$0$38666$edfadb0f@dread12.news.tele.dk> <1128419720.504389.323330@g14g2000cwa.googlegroups.com> Message-ID: <1128432868.933546.45780@f14g2000cwb.googlegroups.com> Lasse V?gs?ther Karlsen wrote: > While Microsoft and other big software vendors might have a roadmap > that ties you very tightly in with their budget, and also changes that > roadmap from time to time which breaks your current software, a lot of > open source projects have no roadmap at all. > > This means that a .x.y.2 upgrade might very well kill your software in > the same way a 6-7 upgrade with VB might. I think this explanation confuses the term roadmap with general release discipline. A lot of open source projects are, well, open about things like API stability and will label their stuff as "alpha" if things are going to change frequently - one complaint heard relatively often is that many open source projects are reluctant to put out a 1.0 release because they don't consider their work to be finished. Meanwhile, many open source projects do try and preserve consistency between micro-releases, with any inconsistency being a fault that should be raised with the maintainers - such faults being a phenomenon not limited to open source software, either. > The biggest reason for this, as far as I can tell, is that open source projects are very > much built to integrate with other projects, simply because the source is > available and it's thus far easier to integrate them, but that also > means that unless you upgrade two integrated projects at the same time, > you risk an upgrade in one breaking the other. I'm not sure whether source availability is really the problem here. I've experienced micro-release breakage and it was due to the integration of lots of different libraries, many of which were upgraded in the process of making the new micro-release of the software in question, but with some of the more egregious breakage coming about because in some micro-update of one of the libraries, the author decided to radically change the available features of that library. Since this was all Java-based, source availability really wasn't a factor (these were all .jar files, after all); the problem could be boiled down to good old release discipline: if one of your dependencies plays fast and loose with API stability, expect some users to get caught out. If package maintainers make transitions of their software from release 2.4.2 to release 2.4.3 involve significant rewrites of your own application, my advice involves either avoiding such packages from the beginning or, if it's too late, considering what would be necessary to maintain/subvert acceptably stable versions of them. > I think a main point in a lot of projects is that unless you have to > upgrade, don't. That way you can avoid a lot of problems by default. This is good advice! The big difference between open source and Microsoft, however, is that you can feasibly choose not to upgrade to the next bloated/misguided release of some software and yet attempt to roll in all the security updates and useful enhancements whose absence would otherwise expose your applications to misuse or obsolescence. Either path can involve a lot of hard work, but at least you get the choice with open source software. Paul From mlist at fastwebnet.it Mon Oct 10 16:33:29 2005 From: mlist at fastwebnet.it (billie) Date: Mon, 10 Oct 2005 22:33:29 +0200 Subject: how to capture key pressing References: Message-ID: > Look at curses. I was searching for something portable on multiple platforms. Curses doesn't work on Windows. From Vulvazb at hotmail.com Tue Oct 11 03:22:01 2005 From: Vulvazb at hotmail.com (Vulvazb at hotmail.com) Date: 11 Oct 2005 00:22:01 -0700 Subject: LINDA WEST (925) 876-7441 of CHIPMAN UNITED VAN LINES likes to commit Fraud & Forgery and she likes to put peoples names on moving contracts with out there Knowledge.Caton Mayflower Moving & Storage Dublin, ca & concord, ca (925) 876-7441, 925-887-5515, Message-ID: <1129015321.911485.72220@g43g2000cwa.googlegroups.com> LINDA WEST (925) 876-7441 of CHIPMAN UNITED VAN LINES likes to commit Fraud & Forgery and she likes to put peoples names on moving contracts with out there Knowledge.Caton Mayflower Moving & Storage Dublin,ca & concord,ca (925) 876-7441, 925-887-5515, 925-825-5000, 800-825-3866,800-447-9771, 925-609-1800, 800-447-1771, 925-935-4073, 925-828-3985 From fredrik at pythonware.com Tue Oct 18 06:42:44 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 18 Oct 2005 12:42:44 +0200 Subject: Bloodhound.Exploit.49 trojan found in MIMEBase.pyc References: Message-ID: Alex Hunsley wrote: > Symantec antivirus has apparently picked up a virus in my Python 2.4 > (under cygwin): > > Scan type: Scheduled Scan > Event: Threat Found! > Threat: Bloodhound.Exploit.49 > File: C:\cygwin\lib\python2.4\email\MIMEBase.pyc > Location: Quarantine > Action taken: Quarantine succeeded > > There's info to be found on various pages, but it's a pretty terse > explanation: > http://secunia.com/virus_information/22534/bloodhound.exploit.49/ > > Has anyone had this also? Is it perhaps a false positive? if Python had anything to do with this, they would probably have mentioned it in the related documents: http://www.sarc.com/avcenter/venc/data/bloodhound.exploit.49.html http://www.microsoft.com/technet/security/bulletin/MS05-048.mspx From zhu_dave at yahoo.com Tue Oct 11 18:11:34 2005 From: zhu_dave at yahoo.com (Dave) Date: Tue, 11 Oct 2005 15:11:34 -0700 (PDT) Subject: Profiling Python using gprof Message-ID: <20051011221135.3188.qmail@web30608.mail.mud.yahoo.com> Hello, I would like to profile a Python program using gprof. I already rebuilt Python with CC="gcc -pg" ./configure. So, I should be able to use gprof. How do I do that? Should I first run Python and then gprof? What are the steps? Thanks a lot! __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com From smadim2 at grads.ece.mcmaster.ca Tue Oct 4 14:13:25 2005 From: smadim2 at grads.ece.mcmaster.ca (Mohammed Smadi) Date: Tue, 4 Oct 2005 14:13:25 -0400 (EDT) Subject: tcp socket programming In-Reply-To: <4342bc6d$0$11074$e4fe514c@news.xs4all.nl> Message-ID: On Tue, 4 Oct 2005, Irmen de Jong wrote: > Mohammed Smadi wrote: > > hi; > > If i have a tcp connection with a remote server, what is a good way to > > read all the data into a buffer before starting to process the data? > > I know that the data recieved will be 3 lines with CRLF between them. > > However if I can sock.recv(1024) the output is not consistent all the > > time, sometime i get one line and sometimes i get two. So I figures I > > should read all the data first then work on it and I used the following > > code: > > result = [] > > while True: > > got=s.recv(1024) > > print got > > if not got: break > > result.append(got) > > got = [] # i tried also taking this out > > s.close() > > > > but this code just hangs in the loop and never quits > > ... because it doesn't 'know' when to stop reading. > The socket recv() returns anything from 0 to 1024 bytes > depending on the amount of data that is available at that time. > > You have to design your wire protocol a bit differently if you want > to do this in a consistent, reliable way. > For instance, you can decide on sending *one* byte first that > signifies the amount of bytes to read after that. (limiting the > size to 255 ofcourse). > > Or you will have to change your read-loop to read until it > encountered the third CRLF occurrence (and no more!) > > The latter is actually quite easily done by not reading directly > from the socket object, but first converting it to a file-like > object: > > s=socket.socket(....) > s.connect(...) > > fs=s.makefile() > fs.readline() > fs.readline() > fs.readline() > > > --Irmen. > that seems to have worked. I need to do more testing. Thanks From bretthoerner at gmail.com Sat Oct 1 21:53:41 2005 From: bretthoerner at gmail.com (Brett Hoerner) Date: 1 Oct 2005 18:53:41 -0700 Subject: How is wxWindows related to Python? In-Reply-To: <1128216966.664758.179160@f14g2000cwb.googlegroups.com> References: <1128216966.664758.179160@f14g2000cwb.googlegroups.com> Message-ID: <1128218021.449328.269790@f14g2000cwb.googlegroups.com> I guess it is referring to the closely related (maybe even same dev group? I don't know why the wxWindows docs would mention Python unless they specifically support the wxPython project, too.) "wxWindows + Python = wxPython wxPython is a Python extension module that provides a set of bindings from the wxWindows library to the Python language. In other words, the extension module allows Python programers to create instances of wxWindows classes and to invoke methods of those classes. More from this Chapter: ? Using Tkinter ? Using PythonWin The wxPython extension module attempts to mirror the class hierarchy of wxWindows as closely as possible. This means that there is a wxFrame class in wxPython that looks, smells, tastes, and acts almost the same as the wxFrame class in the C++ version. wxPython is close enough to the C++ version that the majority of the wxPython documentation is actually annotations to the C++ documentation that describe the places where wxPython is different. There is also a series of sample programs included, and a series of documentation pages that assist the programmer in getting started with wxPython. " http://www.onlamp.com/pub/a/python/excerpts/chpt20/wxpython.html http://www.wxpython.org/ From mtebeka at qualcomm.com Mon Oct 24 05:33:09 2005 From: mtebeka at qualcomm.com (Miki Tebeka) Date: Mon, 24 Oct 2005 11:33:09 +0200 Subject: wxPython advice In-Reply-To: <1129538114.173460.176180@g47g2000cwa.googlegroups.com> References: <1129538114.173460.176180@g47g2000cwa.googlegroups.com> Message-ID: <20051024093309.GA2208@qualcomm.com> Hello vpr, > I've written a p2p program using socketserver that's nice and quick. > I'd like to give the user a tray applet (part of the p2p service) that > will allow the user to activate / deactivate / config and exit the > service. > However I'm starting to bang my head on the mainloop funtions that > manage > wx and socket events. > > Anyone been down this road that can give me some advice One common solution is to do all the work in a "worker thread" and keep the GUI responsive to command. Note that Python don't have native support to pause/resume threads. You'll need to get your thread to check for new state every now and then. (Usually this means keep transactions small) or use processes instead of threads (see http://home.pacbell.net/ouster/threads.pdf). You might want to use async socket reading as well. HTH. -- ------------------------------------------------------------------------ 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: 215 bytes Desc: not available URL: From quncao at gmail.com Fri Oct 14 17:09:44 2005 From: quncao at gmail.com (Sophia Cao) Date: 14 Oct 2005 14:09:44 -0700 Subject: threading/forking and IPC Message-ID: <1129324184.818503.7760@g47g2000cwa.googlegroups.com> Hello, I am seeking a python solution for my project. I am trying to implement an architecture where there is a server who receives incoming messages from several clients, then those messages need to be written to a MySQL database. To avoid too many connections to the database, I plan to save the incoming messages into a queue, while use a seperate process/thread to constantly monitoring the queue and storing the messages to the database. I am not sure wheather I should use threading or forking and how to implement the sharing of this message queue. Thanks a lot for any advice. From thomasbartkus at comcast.net Tue Oct 18 18:03:05 2005 From: thomasbartkus at comcast.net (Thomas Bartkus) Date: Tue, 18 Oct 2005 17:03:05 -0500 Subject: Dealing with Excel References: <1129670191.061006.146320@g47g2000cwa.googlegroups.com> Message-ID: "Robert Hicks" wrote in message news:1129670191.061006.146320 at g47g2000cwa.googlegroups.com... > I need to pull data out of Oracle and stuff it into an Excel > spreadsheet. What modules have you used to interface with Excel and > would you recommend it? What does one use to bind Microsoft libraries to Python? I think it would be "win32com" and I confess to not having used it. Best bet would be to use Microsofts ADODB library together with Excels own CopyFromRecordset function. Using ADODB, you can easily create a connection to an Oracle server. You would use this to stuff an ADODB.Recordset object with query results. Once you have your recordset stuffed with query results you can pass it to the Excel "CopyFromRecordset" function: Worksheets("Whatever").Cells(1,1).CopyFromRecordset {recordset object} and wham! - You have it in a table on a worksheet. Thomas Bartkus From donn at u.washington.edu Tue Oct 4 14:05:41 2005 From: donn at u.washington.edu (Donn Cave) Date: Tue, 04 Oct 2005 11:05:41 -0700 Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> <434245F5.6060500@REMOVEMEcyber.com.au> <7xr7b14lk0.fsf@ruckus.brouhaha.com> <4342bd9a.3192006743@news.oz.net> Message-ID: In article <4342bd9a.3192006743 at news.oz.net>, bokr at oz.net (Bengt Richter) wrote: > On Tue, 04 Oct 2005 10:18:24 -0700, Donn Cave wrote: > [...] > >In the functional language approach I'm familiar with, you > >introduce a variable into a scope with a bind - > > > > let a = expr in > > ... do something with a > > > >and initialization is part of the package. Type is usually > >inferred. The kicker though is that the variable is never > >reassigned. In the ideal case it's essentially an alias for > >the initializing expression. That's one possibility we can > >probably not find in Python's universe. > > > how would you compare that with > lambda a=expr: ... do something (limited to expression) with a > ? OK, the limitations of a Python lambda body do have this effect. But compare programming in a language like that, to programming with Python lambdas? Maybe it would be like living in a Zen Monastery, vs. living in your car. Donn Cave, donn at u.washington.edu From david at jotax.com Wed Oct 19 04:46:10 2005 From: david at jotax.com (spinner) Date: 19 Oct 2005 01:46:10 -0700 Subject: How to organize Python files in a (relatively) big project References: Message-ID: <1129711570.361702.21300@g49g2000cwa.googlegroups.com> I have this problem myself, and as I am a recent Python convert my aproach may not be conventional - but as it is working for me I thought I would share. First off you need to split your code into logical objects. In my case I have an obvious client and server object, But within each I have individual stand alone major objects and so my directory structure reflects this... Prog Dir -- MainApp.py Bin __init__.py --- main.py --- lib.py Client __init__.py --- main.py Browser 1 __init__.py --- main.py --- B1_file1.py --- B1_file2.py Browser 2 __init__.py --- main.py --- B2_file1.py --- B2_file2.py Server __init__.py --- main.py Server Object 1 __init__.py --- main.py --- SO1_file1.py --- SO1_file2.py Server Object 2 __init__.py --- main.py --- SO2_file1.py --- SO2_file2.py Each main.py file is used to call each downstream main.py file be it as a thread or once only run. The beauty of this idea is that if I want to completely change say Server Object 2, I can do whatever I like within the downstream directory as the only outside call is via an external reference to the main.py file. If you have a mind, you could have a library file of common apps held within the bin directory that you can make available to all downstream modules. As I say - it only works if you can logically split your program into independent blocks. If there is a more Pythonesque way of doing this I be grateful if someone could share. HTH From steve at REMOVETHIScyber.com.au Tue Oct 18 19:24:02 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Wed, 19 Oct 2005 09:24:02 +1000 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <867jcbzdw9.fsf@bhuda.mired.org> Message-ID: On Tue, 18 Oct 2005 11:53:29 -0700, David Schwartz wrote: >>> Wrong. The only obligation Microsoft has is to their shareholders. >> >> If you genuinely believe that, you are a psychopath. > > That's almost as convincing as "that's what you think". > > DS When you are repeating a fact with as much psychological research supporting it as that one, it isn't necessary to justify it, any more than it would be necessary to justify a statement like "parents love their children". It isn't John Kennedy's fault that you aren't up to date. Both statements are generalisations, it is true, and both are probably true about the same percentage of time. Oh, and if you think I'm saying something shocking by suggesting that somebody is a psychopath, I'm not. Something like one in five of the general population are psychopaths, a much higher percentage of "go-getters" like company CEOs, generals, politicians, executives, etc. Very few of them chop people up into small pieces and bury them in the wall cavities of their house. With training and/or a good dose of enlightened self-interest, most psychopaths are perfectly capable of learning to not be selfish vicious brutes who care only for themselves and perhaps a few others. Or rather, to stop *acting* as selfish vicious brutes. Not caring about the harm done by your corporate machinery is not a crime. Actually doing that harm is, or at least should be, although sadly when we allow the psychopaths to make the rules, they tend to make rules that allow themselves to prosper at our expense. -- Steven. From dcrespo at gmail.com Thu Oct 13 16:25:40 2005 From: dcrespo at gmail.com (dcrespo) Date: 13 Oct 2005 13:25:40 -0700 Subject: Send password over TCP connection In-Reply-To: References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> <1128979760.251637.316480@o13g2000cwo.googlegroups.com> <1129033311.936104.140960@g14g2000cwa.googlegroups.com> Message-ID: <1129235140.938321.134990@g49g2000cwa.googlegroups.com> Ok, I understand... What about the MD5? Is it good enough to use when saving a hashed password on the database? For example: user_input = raw_input("Type your password: ") password = md5.md5(user_input).hexdigest() SavePasswordInDatabase(user,password) From xah at xahlee.org Thu Oct 13 02:51:05 2005 From: xah at xahlee.org (Xah Lee) Date: 12 Oct 2005 23:51:05 -0700 Subject: Perl-Python-a-Day: Sorting In-Reply-To: References: <1128937897.500935.254770@o13g2000cwo.googlegroups.com> <1129170241.274868.45680@g43g2000cwa.googlegroups.com> Message-ID: <1129186265.871236.166670@g43g2000cwa.googlegroups.com> Lasse V?gs?ther Karlsen wrote: > Like the sorted function in Python ? > > li2 = sorted(li) > > you can also specify a key and a cmp function if you need to. Thanks. I didn't know there's also a sort function in Python (2.4), besides the method. (i've mentioned your name as acknowledgement at my website essay) The Python doc really should mention it at the place where the sort method is documented. Xah xah at xahlee.org ? http://xahlee.org/ From dave.benjamin at gmail.com Mon Oct 17 14:43:12 2005 From: dave.benjamin at gmail.com (dave.benjamin at gmail.com) Date: 17 Oct 2005 11:43:12 -0700 Subject: Yes, this is a python question, and a serious one at that (moving to Win XP) In-Reply-To: References: <434f8a54$0$16641$626a14ce@news.free.fr> Message-ID: <1129574592.754495.72530@g43g2000cwa.googlegroups.com> Jorgen Grahn wrote: > On Fri, 14 Oct 2005 12:37:25 +0200, Christophe wrote: > > Kenneth McDonald a ?crit : > >> For unfortunate reasons, I'm considering switching back to Win XP (from > >> OS X) as my "main" system. Windows has so many annoyances that I can > ... > >> Yes, I know that Cygwin is out there, but last I looked, they still > >> went through the Win command-line window, which imposes a lot of > >> restrictions. > ... > > Last time I checked, you could install a native win32gui version of rxvt > > with cygwin. This would give you a better terminal window than that > > crappy thing you get in XP. > > Last time /I/ checked (two years ago or so) that rxvt looked nice enough, > but was impossible to use in practice. I cannot remember /what/ the problem > was -- possibly it was that it could only run CygWin-compiled commands, or > something vital only worked with CygWin-compiled commands. Google probably > knows more. Cygwin comes with a fully-functioning X server, from which you can run just about any terminal program you like. For awhile, I was using Konsole, but KDE on Cygwin is a bit slow and buggy. Recently I switched to "mrxvt", which is like "rxvt" but with tab support and keyboard shortcuts almost identical to Konsole. It's easy to compile for Cygwin, and so far I'm really enjoying the improved speed. Here's my .mrxvtrc: mrxvt*bottomTabbar: true mrxvt*scrollBar: false mrxvt*font: neep-alt-bold-14 mrxvt*boldFont: neep-alt-bold-14 mrxvt*foreground: snow mrxvt*background: black mrxvt*geometry: 80x40 mrxvt*saveLines: 65535 mrxvt*hotkey*Dummy: Ctrl+Shift+underscore I like my tabs at the bottom, Konsole-style, and don't really like scrollbars on terminals. I use the Neep Alt font, which is nice for coding because it makes 'l', '|', '1', etc. all look different, and I like thick console fonts. I was a Fixedsys diehard for a long time. The "saveLines" variable lets you increase the scrollback buffer (shift-PgUp/Down) pretty high - I have it maxxed out. And that last line tells mrxvt to ignore C-_, which is undo in emacs. There are still a few other keyboard bindings that I'd like to turn off at some point. One drawback of mrxvt is that it doesn't support UTF-8. I don't do much multi-language stuff, but on most Linux distributions the manpages are in UTF-8, so you get garbage characters unless you fiddle with your LANG/LOCALE settings. Oh yeah, and to keep this on topic, Cygwin's Python works just fine in mrxvt, though the native Windows version doesn't work so well. It doesn't print any output, which I think is due to buffering... however, I tend to use PythonWin for interactive development, and emacs with M-x shell to actually test and run (native) Python scripts. I'm pretty happy with it, overall. Dave From dotpyFE at gmail.com Sun Oct 2 11:04:37 2005 From: dotpyFE at gmail.com (Lucas Raab) Date: Sun, 02 Oct 2005 15:04:37 GMT Subject: A Moronicity of Guido van Rossum In-Reply-To: <1128176637.146092.314200@o13g2000cwo.googlegroups.com> References: <1128003857.930444.47650@g14g2000cwa.googlegroups.com> <1128013745.763757.144280@g44g2000cwa.googlegroups.com> <1128176637.146092.314200@o13g2000cwo.googlegroups.com> Message-ID: <9GS%e.7067$vw6.1891@newsread1.news.atl.earthlink.net> Xah Lee wrote: [snip] >(they tried, with their limited implementation of lambda and > shun it like a plaque) Can't say I've heard that expression before... -- -------------------------- Lucas Raab lvraab"@"earthlink.net dotpyFE"@"gmail.com AIM: Phoenix11890 MSN: dotpyfe "@" gmail.com IRC: lvraab ICQ: 324767918 Yahoo: Phoenix11890 From rrr at ronadam.com Wed Oct 26 08:56:34 2005 From: rrr at ronadam.com (Ron Adam) Date: Wed, 26 Oct 2005 12:56:34 GMT Subject: Top-quoting defined [was: namespace dictionaries ok?] In-Reply-To: References: Message-ID: <62L7f.213783$p_1.129087@tornado.tampabay.rr.com> Duncan Booth wrote: > No, I didn't think it was malice which is why I just added what I > considered to be a polite request at the end of my message. I assumed that > most people either knew the phrase or could find out in a few seconds using > Google so there wasn't much point in rehashing the arguments. Probably I > should have equally lambasted Ron for the heinous crime of bottom-quoting. I usually try to keep things in reasonable context and or order. I tend to bottom quote only when either the message is short enough to fit on a single page, or when I'm adding new content that isn't a direct response to an individual item but builds on the above ideas. Sometimes deciding what to trim out of various really good replies is difficult. ;-) In any case, I don't take offense to any suggested improvements. I wouldn't be surprised if many of my posts were considered hard to follow at times. A chronic sleeping disorder combined with dyslexia can sometimes make expressing my thoughts in words rather challenging on some (most) days. >>quote from James (4) > > comment from Ron (5) > >>>>quote from James (2) >>> >>>comment from Ron (3) >>> >>>>quote from James (2) >>>> >>>>>quote from Ron (1) > > I spent a while trying to trim that down to relevant context, and in > particular trying to work out in what order the original statements had > been made. In the end I gave up and replied to an earlier message which was > more easily trimmable. I was undecided weather to trim the later (earlier) responses or not, but decided to leave them in. >>Also, here is a well written synopsis of the arguments in >>favor of top-posting and they may even be strong enough to legitimize the >>practice: > > The arguments are mostly sound, but I would draw slightly different > conclusions: > > Follow the conventions of the particular newsgroup or mailing list, but > with that in mind, for all replies, Middle Post. Respond to each point in > turn with lots of snipping. In general I find a well written top post in a friarly prompt *email* to be fine. What I refer to as well written in this case, is where the author restates the question, points, or issues in their own word first, and then follow that up with their response and or conclusions. Especially if it's any sort of official or at least non casual interchange. In that case the quotes appended to the end serves as history that can be referenced if needed. But in news groups, it's best to try and keep things conversational with as you call middle posts. It allows people to add to the conversation as if they were all present at the same time, even though they may actually be replying at varying different times. I tend to try not to break up paragraphs if possible though, and attempt to break my posts up into short paragraphs to leave spaces for others to insert their replies. But I wouldn't claim I'm completely consistent on these issues myself. > He's right though, its not a religious issue. Yep, I agree with this also. ;-) Cheers, Ron From hancock at anansispaceworks.com Sat Oct 22 13:54:01 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Sat, 22 Oct 2005 12:54:01 -0500 Subject: UI Design, XUL, Blender Message-ID: <200510221254.02078.hancock@anansispaceworks.com> Newcomers to Blender (3D modelling/animation program) often find its fairly unique UI a bit off-putting, but on closer inspection, I find it's a very compelling design for "power users" (i.e. professionals who need to use a given program on a daily basis, and who are therefore willing to make the effort to learn the specific interface). It is much better than either a command line interface or a more conventional GUI, for that purpose, IMHO. Unfortunately, Blender doesn't really follow a Model-View- Controller design, so I'm not sure how separable the interface is from the rest of the program (I'm asking that question elsewhere). My question here, is just how unique, really, is that interface? Could it be implemented with "standard" GUI toolkits (using complex widgets and customizing button appearance, for example)? The main things I notice as a user are that: * The buttons are smaller and use iconic graphics, so you can access more controls at once. * Extensive use of "tabs" allowing control pallettes to be brought up or expanded, facillitating highly hierarchical pallettes. * Widgets are color-coded as to functionality and fall into several important categories: o ON/OFF (Bistate) o ON/OFF/FLOATING (Tristate) o Numerical data entry, which act simultaneously as sliders and data-entry widgets * The main thing is that these "buttons" actually have fairly complicated behavior, acting as sliders, text-entry, and selectboxes simultaneously. (I may be missing things that would be more apparent to GUI designers, though, so I'd be even more interested in a reply from someone who's actually seen the Blender UI themselves.) I'm wondering if this could be achieved in a Python program by using wxPython or PyGTK or another popular, cross-platform GUI toolkit? Also, is a GUI specification language like XUL capable of expressing this kind of interface so that it could be made functional on multiple GUI implementations? I'm trying to compare two alternatives: 1) Figure out how to mimic the Blender GUI in a more conventional, separable GUI toolkit, so that an MVC design can be more easily used. (This leaves a fairly complication "View" component, but there are other fairly advanced 3D visualization components). 2) Use Blender itself, using the Python scripting facility to wedge an MVC design into it (probably by hacking Blender to create a bridge between Blender's internal (C struct based) model, and an external model (probably represented in an object database component, such as ZODB). in order to figure out which would be easier. Any more informed comments from people who know the various GUI packages would be a lot of help. I assume it goes without saying that I'm looking at Python as an integration language. In my ideal design, the M,V, and C components are separate Python modules, so that the communications are all at the Python level. Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From joerg.schuster at gmail.com Wed Oct 19 06:25:39 2005 From: joerg.schuster at gmail.com (Joerg Schuster) Date: 19 Oct 2005 03:25:39 -0700 Subject: "dynamical" importing In-Reply-To: <1129711017.413612.60350@f14g2000cwb.googlegroups.com> References: <1129711017.413612.60350@f14g2000cwb.googlegroups.com> Message-ID: <1129717539.628747.314510@z14g2000cwz.googlegroups.com> Thanks a lot to all. From jabel at plus.net Wed Oct 19 04:52:49 2005 From: jabel at plus.net (John Abel) Date: Wed, 19 Oct 2005 09:52:49 +0100 Subject: "dynamical" importing In-Reply-To: <1129711017.413612.60350@f14g2000cwb.googlegroups.com> References: <1129711017.413612.60350@f14g2000cwb.googlegroups.com> Message-ID: <43560961.9070504@plus.net> Try: userModule = _importModule( pathToModule ) def _importModule( moduleName ): modName = __import__ ( moduleName ) modComponents = moduleName.split( '.' ) for indivComp in modComponents[ 1: ]: modName = getattr( modName, indivComp ) return modName HTH, J Joerg Schuster wrote: >Hello, > >I need to import modules from user defined paths. I.e. I want to do >something >like: > >module_dir = sys.argv[1] > >my_path = os.path.join(module_dir, 'bin', 'my_module') > >from my_path import my_object > >Obviously, it doesn't work this way. How would it work? > >J?rg Schuster > > > From bdesth.quelquechose at free.quelquepart.fr Wed Oct 26 17:26:17 2005 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 26 Oct 2005 23:26:17 +0200 Subject: assignment to reference In-Reply-To: References: Message-ID: <435feab7$0$31384$626a14ce@news.free.fr> Loris Caren a ?crit : > If > > a = 'apple' > b = 'banana' > c = 'cabbage' > > How can I get something like:- > > for i in 'abc': > r = eval(i) > if r == 'cabbage': r = 'coconut' > > actually change the object referenced by r rather > than creating a new object temporarily referenced by it? > > I've tried playing with eval and exec without the desired > effect. for obj in (a, b, c): if obj == 'cabbage': obj = 'coconut' From panewman at uiuc.edu Tue Oct 25 23:28:13 2005 From: panewman at uiuc.edu (Peter Newman) Date: Wed, 26 Oct 2005 03:28:13 +0000 (UTC) Subject: Embedded Python interpreter, runtime libs, and crashing Message-ID: I'm embedding a Python interpreter into a project, and compiling with MSVC. It all runs great in the "Debug" configuration, but everything gets scary when I switch to "Release". I've read about things that can go wrong when you use the wrong runtime library when compiling a program that uses Python. I've done my best to follow the suggestions I've read, but I still seem to be having trouble. Here's a summary of how I've configured my project: Release: ======== - C/C++->Code Generation->Runtime Library: Multithreaded DLL - Linker->Input->Additional Dependencies: ... python24.lib - Output EXE runs beside Python24.dll Debug: ====== - C/C++->Code Generation->Runtime Library: Multithreaded Debug DLL - Linker->Input->Additional Dependencies: ... python24_d.lib - Output EXE runs beside Python24_d.dll The debug configuration works flawlessly. Release is another story altogther. It usually crashes with a segmentation fault or access violation (reading memory address 0). At one point it ran, but the code seemed to be executing in the wrong order (stuff getting called before initialization functions were finished, etc.) -- Peter Newman (panewman at uiuc.edu) From grante at visi.com Thu Oct 20 12:11:55 2005 From: grante at visi.com (Grant Edwards) Date: Thu, 20 Oct 2005 16:11:55 -0000 Subject: need some advice on x y plot References: <1129823043.104864.73750@f14g2000cwb.googlegroups.com> Message-ID: <11lfgebn85liq1b@corp.supernews.com> On 2005-10-20, nephish at xit.net wrote: > [...] I need to make an x y chart for some data that comes in > from sensors at different times durring the day. i need it to > show the value in the y and the time in the x . no problem so > far. But what i cannot get to happen is to scale x (time of > the plot) with respect to time. Gnuplot does that just fine. Just give it two columns of data, the first being the x value (time) and the second being the y value. All of the other plotting packages handle this as well. -- Grant Edwards grante Yow! I hope I at bought the right visi.com relish... zzzzzzzzz... From steve at holdenweb.com Sun Oct 9 06:34:33 2005 From: steve at holdenweb.com (Steve Holden) Date: Sun, 09 Oct 2005 11:34:33 +0100 Subject: Question about StringIO In-Reply-To: <1128849763.117104.34370@f14g2000cwb.googlegroups.com> References: <1128849763.117104.34370@f14g2000cwb.googlegroups.com> Message-ID: Frank Millman wrote: > Hi all > > I understand that StringIO creates a file-like object in memory. > > Is it possible to invoke another program, using os.system() or > os.popen(), and use the < redirect operator, so that the other program > reads my StringIO object as its input? > > I will provide more details if required, but hopefully this is enough > for a simple yes or no answer, and if so, how. > > BTW, I have tried using popen2() and passing my data via stdin, but the > other program (psql) does not react well to this - again, I will give > more info if necessary. > Unfortunately the StringIO module only creates instances inside the process they are called: these objects have no existence to the operating system or to other processes, and so can't be used for inter-process communication. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From exarkun at divmod.com Mon Oct 3 15:56:56 2005 From: exarkun at divmod.com (Jp Calderone) Date: Mon, 3 Oct 2005 15:56:56 -0400 Subject: Dynamical loading of modules In-Reply-To: <43418BF5.90504@gmail.com> Message-ID: <20051003195656.3914.1640379349.divmod.quotient.23611@ohm> On Mon, 03 Oct 2005 21:52:21 +0200, Jacob Kroon wrote: >Hi, I'm having some problems with implementing dynamical module loading. >First let me >describe the scenario with an example: > >modules/ > fruit/ > __init__.py > apple.py > banana.py > >apple.py defines a class 'Apple', banana defines a class 'Banana'. The >problem lies in the >fact that I want to be able to just drop a new .py-file, for instance >peach.py, and not change >__init__.py, and it should automatically pickup the new file in >__init__.py. I've come halfway >by using some imp module magic in __init__.py, but the problem I have is >that the instantiated >objects class-names becomes fruit.apple.Apple/fruit.banana.Banana, whild >I want it to be >fruit.Apple/fruit.Banana. > >Is there a smarter way of accomplishing what I am trying to do ? >If someone could give me a small example of how to achieve this I would >be very grateful. The __module__ attribute of class objects is mutable. I don't understand *why* this makes a difference, though. The class's name is a pointer to where it is defined: this is useful because it saves a lot of grepping, and unambiguously tells the reader where the class came from. If you start making it mean something else, you'll end up confusing people. If you just want a pretty name, use something /other/ than the class's fully qualified Python name. Jp From Florian.Lindner at xgm.de Tue Oct 4 04:59:09 2005 From: Florian.Lindner at xgm.de (Florian Lindner) Date: Tue, 04 Oct 2005 10:59:09 +0200 Subject: Graphical debugger/code explorer References: <1128357577.579290.122340@z14g2000cwz.googlegroups.com> Message-ID: benz wrote: >>>>PYTHON_IDE={ > 'spe' : 'http://spe.pycs.net/', > 'eric3' : 'http://www.die-offenbachs.de/detlev/eric3.html', > 'drpython' : 'http://drpython.sourceforge.net/'} I've tried out eric3 and it looks promising. However, I have one problem. I open a file which is part of Zope and set a breakpoint. Now I open the runzope start script and execute it from within eric. This runzope script calles (after running through a larger call-tree) the function where I set the breakpoint. But execution is not stopped there.... Why? Thanks, Florian From csubich.spam.block at spam.subich.block.com Tue Oct 25 13:06:39 2005 From: csubich.spam.block at spam.subich.block.com (Christopher Subich) Date: Tue, 25 Oct 2005 13:06:39 -0400 Subject: Would there be support for a more general cmp/__cmp__ In-Reply-To: References: Message-ID: Antoon Pardon wrote: > Op 2005-10-25, Christopher Subich schreef : > >>Which is exactly why a < b on sets returns True xor False, but cmp(a,b) >>throws an exception. > > > I don't see the conection. > > The documentation states that cmp(a,b) will return a negative value if > a < b. So why should it throw an exception? Because it's useful that cmp(a1, a2) should either (return a value) or (throw an exception) for any element a1, a2 within type(a1) cross type(a2). If cmp sometimes is okay and sometimes throws an exception, then it leads to weird borkage in things like trees. With that in mind, not all sets are comparable. {a} and {b} have no comparison relationship, as you've pointed out, aside from not-equal. I'll get to why "not-equal" is a bad idea below. >>cmp(a,b) asks for their relative rankings in some total ordering. > > > The documentation doesn't state that. I also didn't find anything in > the documentation on how the programmer should code in order to > enforce this. Most programmers are simply programmers; they haven't had the benefit of a couple years' pure-math education, so the distinction between "partial order" and "total order" is esoteric at best. With that in mind, compare should conform, as best as possible, to "intuitive" behavior of comparison. Since comparisons are mostly done on numbers, an extension of comparisons should behave "as much like numbers" as possible. > > So someone who just use the rich comparisons to implement his > partial order will screw up this total order that cmp is somehow > providing. > > And cmp doesn't provide a total ordering anyway. Sets are clearly > uncomparable using cmp, so cmp doesn't provide a total order. Cmp isn't supposed to "provide" a total order, it's supposed to reflect relative standing in one if one already exists for P1 x P2. If one doesn't exist, I'd argue that it's the best course of action to throw an exception. After all, rich comparisons were put in precisely to allow support of limited comparisons when a total order (or indeed full comparison) isn't appropriate. > > Maybe the original idea was that cmp provided some total ordering, > maybe the general idea is that cmp should provide a total ordering, > but that is not documented, nor is there any documentation in > helping the programmer in this. I doubt that anyone was thinking about it in such depth. My bet is that the thought process goes this way: Og compare numbers. Numbers good, compare good. Grunt grunt. Language designers: Wouldn't it be nice if we could allow user-defined objects, such as numbers with units, to compare properly with each other? This would let us say (1 m) < (.5 mile) pretty easily, eh? Guido: Let's let classes override a __cmp__ function for comparisons. In programming language theory, comparisons were firstly about numbers, and their leading-order behaviour has always stayed about numbers. Comparing entities which are best represented in an... interesting formal mathematical way (i.e. partial orders, objects for which some comparisons are Just Plain Weird) works only as a side-effect of number-like behavior. The lesson to take home from this: the less a custom class behaves like a number, the less intutitively meaningful (or even valid) comparisons will be on it. > > And even if we leave sets aside it still isn't true. > > >>>>from decimal import Decimal >>>>Zero = Decimal(0) >>>>cmp( ( ) , Zero) > > -1 > >>>>cmp(Zero, 1) > > -1 > >>>>cmp(1, ( ) ) > > -1 I'd argue that the wart here is that cmp doesn't throw an exception, not that it returns inconsistent results. This is a classic case of incomparable objects, and saying that 1 < an empty tuple is bordering on meaningless. > >>For a >>space that does not have a total ordering, cmp(a,b) is meaningless at >>best and dangerous at worst. > > > The current specs and implemantation are. > > I see nothing wrong with a function that would provide four kinds of > results when given two elements. The same results as cmp gives now > when it applies and None or other appropiate value or a raised > exception when not. > > Given how little this functionality differs from the current cmp, > I don't see why it couldn't replace the current cmp. My biggest complaint here is about returning None or IncomparableValue; if that happens, then all code that relies on cmp returning a numeric result will have to be rewritten. Comparing incomparables is an exceptional case, and hence it should raise an exception. As for saying that cmp should return some times and raise an exception other times, I just find it squicky. Admittedly, this is entirely up to the class designer, and your proposed guideline wouldn't change cmp's behavior for clases that /are/ totally ordered. Then again, sets excepted, your guideline doesn't seem very applicable in standard library code. >>It /should/ throw an exception when the >>results of cmp aren't well-defined, consistent, antisymmetric, and >>transitive. > > > That an order is not total in no way implies any of the above. > The order on sets is well-defined, consistent, antisymmetric > and transitive. A partial order is by definition consistent, antisymmetric, and transitive. A total order is furthermore universal, such that if a != b, aRb xor bRa. This matches the normal use of cmp, and comparing two incomparable objects is an exceptional case -- hence the exception. Although again, you're free to provide a cmp for your classes that operates only on a subset of type x type. From steve at REMOVETHIScyber.com.au Tue Oct 25 13:25:35 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Wed, 26 Oct 2005 03:25:35 +1000 Subject: Documentation for iteration in mappings References: <435e49b8$1@news.uni-ulm.de> <7i1233-qcv.ln1@nb2.stroeder.com> Message-ID: On Tue, 25 Oct 2005 18:02:47 +0200, Michael Str?der wrote: > Dennis Benzinger wrote: >> >> I must be blind because I didn't find anything in the documentation >> which says iterating over an dictionary iterates over its keys. [snip] >> Where is this information hidden? :) > > You should examine your program. Simply pasting the code above to the > Python shell fails as expected: Yes, this is true, but also irrelevant. The question isn't about the code, but about the documentation. The answer does appear to be hidden quite deeply. I had to dig out an old "What's New" for version 2.2 to find it, hidden away in a section on iterators: http://aspn.activestate.com/ASPN/docs/ActivePython/2.2/whatsnew/2.2/index.html#SECTION000400000000000000000 -- Steven. From nospam at here.com Mon Oct 3 10:46:19 2005 From: nospam at here.com (Matt Feinstein) Date: Mon, 03 Oct 2005 10:46:19 -0400 Subject: morphological image processing in Python References: Message-ID: On Mon, 3 Oct 2005 14:23:11 +0000 (UTC), Alexandre Fayolle wrote: >Hello, > >I'm about to start a project which will involve some greyscale image >processing using morphological operators (erosion, dilation, distance >transforms...), and I was wondering if these operators were available in >Python through some open source libraries. > >A quick google search returned pymorphpro[1], which is unfortunately not >free software, and there also seem to be something available in ITK [2]. >Unless I'm mistaken, the PIL does not provide these operations, nore do >Numeric/numarray/scipy. > >Have I missed the one true Python mathematical morphology toolbox? > >Thanks in advance for any advice. Actually, numarray does support morphological array operations. See the chapter on 'Multi-dimensional image processing' in the numarray docs. Matt Feinstein -- There is no virtue in believing something that can be proved to be true. From mwm at mired.org Sun Oct 2 16:25:06 2005 From: mwm at mired.org (Mike Meyer) Date: Sun, 02 Oct 2005 16:25:06 -0400 Subject: Will python never intend to support private, protected and public? References: <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xll1gvk7w.fsf@ruckus.brouhaha.com> <1128001308.905398.321670@g44g2000cwa.googlegroups.com> <311b5ce105092908332c12164c@mail.gmail.com> <7xbr2btv84.fsf@ruckus.brouhaha.com> <7xy85fvxny.fsf@ruckus.brouhaha.com> <86vf0inlt3.fsf@bhuda.mired.org> <7xd5mq9ir9.fsf@ruckus.brouhaha.com> <86wtkym33t.fsf@bhuda.mired.org> <7xll1d7l2c.fsf@ruckus.brouhaha.com> <86slvlmdnv.fsf@bhuda.mired.org> <7xr7b3spri.fsf@ruckus.brouhaha.com> Message-ID: <86br27mztp.fsf@bhuda.mired.org> Paul Rubin writes: > Mike Meyer writes: >> > Yes, the point is that it's something that you can check for by >> > examining the class in question without having to examine any other >> > classes. >> >> That's a pretty restrictive convention to follow. > > What convention? It just makes it possible to write code with some > specific invariants if there's a need to do so. That you don't pass private variables to a function unless it's a buitin. Python is *not* a strict OO language, and uses utility functions for lots of things. To make private work the way you have to change the library to use a strict OO approach, probably including providing a real hierarchy instead of just duck typing. >> So it turns out that getting the behavior you desire involves >> following a lot of conventions. > > That improves on the current situation. Right now the behavior is > impossible to obtain in Python no matter how many conventions you > follow, unless you follow them through a whole program of arbitrary > size instead of just in the class that you're trying to protect a > variable in. Just adding private doesn't change this significantly - it just makes the compiler enforce one of the large number of conventions you have to follow. >> In other words, by adding private to python, you're making it so that >> bugs involving overwriting a private attribute will involve only the >> owning classes code so long as everyone follows the conventions that >> exist about the use of such variables. > Not everyone, just the author of the class that uses the private > variable. That's the point. Except that, with Python as it exists today with a private keyword added, it's *still* everyone. The only convention breaking the private keyword would allow the compiler to catch is a reference to foo.private. It wouldn't catch overriding things in __builtins__ or overriding builtins in a module, or things poking at the variable through __dict__, or - well, there are probably lots of things that need to be dealt with. >> > I don't see how pylint could know which instances to flag, >> I was thinking it would flag any use of such a variable where the >> target variable wasn't "self". That may be a stronger constraint than >> you wanted - but that's good, right? > Shrug. That might be of some limited usefulness, but all it tries to > do is prevent accidents. And it does nothing about setattr/getattr. Preventing accidents is all "private" does - without fundamental changes to the implementation of the language. You have to catch every mechanism that can be used to find a reference to an attribute, like references to __dict__ and to the class variable. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From max at alcyone.com Mon Oct 24 00:44:48 2005 From: max at alcyone.com (Erik Max Francis) Date: Sun, 23 Oct 2005 21:44:48 -0700 Subject: An interesting question about "print '\a'" In-Reply-To: References: Message-ID: Anthony Liu wrote: > We know that if we do > > print '\a' > > the bell will sound. > > Now, why do I hear the sound on my local machine when > I run a python script on a remote host? Because print '\a' just prints the BEL ASCII character, which most terminals respond by beeping. Since, when you're logged into a remote machine, it's your terminal that's displaying the output of your remote session, that's why you hear the beep on your local machine. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis Maybe soul mates exist / After all -- Des'ree From stijndesaeger at gmail.com Fri Oct 21 10:07:47 2005 From: stijndesaeger at gmail.com (vdrab) Date: 21 Oct 2005 07:07:47 -0700 Subject: Python vs Ruby In-Reply-To: References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> <1129853715.441205.322480@g49g2000cwa.googlegroups.com> <86wtk7ty71.fsf@bhuda.mired.org> Message-ID: <1129903667.255441.133490@g47g2000cwa.googlegroups.com> You can tell everything is well in the world of dynamic languages when someone posts a question with nuclear flame war potential like "python vs. ruby" and after a while people go off singing hymns about the beauty of Scheme... I love this place. v. From mwm at mired.org Sun Oct 23 20:55:21 2005 From: mwm at mired.org (Mike Meyer) Date: Sun, 23 Oct 2005 20:55:21 -0400 Subject: how to count and extract images References: Message-ID: <86pspv7myu.fsf@bhuda.mired.org> Joe writes: > start = s.find(' stop = s.find('">Save File
', > start) fileName = s[start:stop] > and then construct the url with the filename to download the image > which works fine as cause every image has the Save File link and I can > count number of images easy the problem is when there is more than image I > try using while loop downlaod files, wirks fine for the first one but > always matches the same, how can count and thell the look to skip the fist > one if it has been downloaded and go to next one, and if next one is > downloaded go to next one, and so on. To answer your question, use the first optional argument to find in both invocations of find: stop = 0 while end >= 0: start = s.find('Save File
', start) fileName = s[start:stop] Now, to give you some advice: don't do this by hand, use an HTML parsing library. The code above is incredibly fragile, and will break on any number of minor variations in the input text. Using a real parser not only avoids all those problems, it makes your code shorter. I like BeautifulSoup: soup = BeautifulSoup(s) for anchor in soup.fetch('a'): fileName = anchor['href'] to get all the hrefs. If you only want the ones that have "Save File" in the link text, you'd do: soup = BeautifulSoup(s) for link in soup.fetchText('Save File'): fileName = link.findParent('a')['href'] http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From bokr at oz.net Tue Oct 25 11:46:35 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 25 Oct 2005 15:46:35 GMT Subject: Tricky Areas in Python References: <1130097286.772836.94930@g44g2000cwa.googlegroups.com><1h4wbvb.1dblc4317zeuw2N%aleaxit@yahoo.com><435CA1DE.2060101@REMOVEMEcyber.com.au> <1h4xfdx.azxzrkhr5xukN%aleaxit@yahoo.com> Message-ID: <435e4cb3.930859184@news.oz.net> On Tue, 25 Oct 2005 10:44:07 +0200, "Fredrik Lundh" wrote: >Alex Martelli wrote: > >>> my hard-won ignorance, and admit that I don't see the >>> problem with the property examples: >>> >>> > class Sic: >>> > def getFoo(self): ... >>> > def setFoo(self): ... >>> > foo = property(getFoo, setFoo) >> >> Sorry for skipping the 2nd argument to setFoo, that was accidental in my >> post. The problem here is: class Sic is "classic" ("legacy", >> "old-style") so property won't really work for it (the setter will NOT >> trigger when you assign to s.foo and s is an instance of Sic). > >what's slightly confusing is that the getter works, at least until you attempt >to use the setter: > >>>> class Sic: >... def getFoo(self): >... print "GET" >... return "FOO" >... def setFoo(self, value): >... print "SET", value >... foo = property(getFoo, setFoo) >... >>>> sic = Sic() >>>> print sic.foo >GET >FOO >>>> sic.foo = 10 >>>> print sic.foo >10 > >(a "setter isn't part of an new-style object hierarchy" exception would have >been nice, I think...) > Hm, wouldn't that mean type(sic).__getattribute__ would have to look for type(sic).foo.__get__ and raise an exception (except for on foo functions that are supposed to be methods ;-) instead of returning type(sic).foo.__get__(sic, type(sic)) without special casing to reject non-function foos having __get__? I guess it could. Maybe it should. BTW, I know you know, but others may not realize you can unshadow foo back to the previous state: >>> sic.foo = 10 >>> print sic.foo 10 >>> del sic.foo >>> print sic.foo GET FOO and that applies even if __delete__ is defined in the property: >>> class Sic: ... def getFoo(self): ... print "GET" ... return "FOO" ... def setFoo(self, value): ... print "SET", value ... def delFoo(self): ... print "DEL" ... foo = property(getFoo, setFoo, delFoo) ... >>> sic = Sic() >>> print sic.foo GET FOO >>> sic.foo = 10 >>> print sic.foo 10 >>> del sic.foo >>> print sic.foo GET FOO but it won't go beyond the instance for del foo >>> del sic.foo Traceback (most recent call last): File "", line 1, in ? AttributeError: Sic instance has no attribute 'foo' Regards, Bengt Richter From ddelay at club-internet.fr Sun Oct 9 12:15:14 2005 From: ddelay at club-internet.fr (Daniel Delay) Date: Sun, 09 Oct 2005 18:15:14 +0200 Subject: What about letting x.( ... ? ... ) be equivalent to ( ... x ... ) In-Reply-To: <3qsi6lFgk1ndU1@uni-berlin.de> References: <43490d16$0$6485$626a14ce@news.free.fr> <3qsi6lFgk1ndU1@uni-berlin.de> Message-ID: <434941f6$0$458$7a628cd7@news.club-internet.fr> Diez B. Roggisch a ?crit : > Apart from that, I don't think your proposal does any good - it is ugly > (or at least not less ugly than the things you want to fix) and confuses > the reader because of the colliding use of . for attribute access. There is no ambiguity ( in one case "." is followed by a name, in another case it is followed by a parenthesis) but there is a similarity that I wanted and that I try here to illustrate : #********************** # Classical way : you need to evaluate # something for few instances of a class # so you write a mumber function #********************** class Rectangle : def area(self): return self.height * self.width ... (... an expression....).area() #********************** # Alternative way : you need only once to evaluate something, # and you work on a big expression #********************** (... an expression....).( this.height * this.width ) But one of the advantages of this syntax is the ability to compose very easily those expressions : (... an expression....).(..expr 1..).(..expr 2..).(..expr 3..) etc... > > E.g. your own example > > f(g(h(j(x))) > > becomes > > x.(j(?)).(h(?)).(g(?)).(h(?)) > > Not x.(j).(h).(g).(h), as you told us. And certainly way uglier than the > above way of doing. Besides, you reasoning by comparing with the > mathematical o-operator is misleading: the operator creates a new > function, that will apply it's parametesr (e.g. f and g) after each > other to the argument. I agree the comparison to the mathematical o-operator is misleading, it was just to say sometimes, it can be usefull introduce new syntax to avoid too many nested parenthesis Paul Rubin asked for ways to do that, and has > been shown some ways to do so - actually not overly nice looking, but > they'd allow for > > (f * g * h)(x) > > which beats your solution on readability, too :) This is usefull when you need to compose few already defined functions, but I more often have to compose few expressions, which is the goal of my proposition. > Overall, it tries to obfuscate code - by creating perl-like "magic" > variables. And that is not what Python is known for. The wildcard "?" does does not sound very pythonic, but a few too magic. Perhaps a keyword like "this" is better, that's what I used in the above example. In fact it has nothing to do with magical expression : "this" will represent the value of the current expression you work on, in the same way "self" represent the value of the object you work on. > > I too have some convoluted constructs as your html-joining example. But > if the get too complicated, replacing them by some explicit lines is > better than trying to cough up a scheme that makes them work. > > Regards, > > Diez From future_retro at yahoo.co.uk Wed Oct 5 05:50:53 2005 From: future_retro at yahoo.co.uk (future_retro at yahoo.co.uk) Date: 5 Oct 2005 02:50:53 -0700 Subject: Python script to install network printers In-Reply-To: <1128468336_42527@spool6-east.superfeed.net> References: <1128468336_42527@spool6-east.superfeed.net> Message-ID: <1128505853.852505.30720@g47g2000cwa.googlegroups.com> These functions should get you started and probably finished... def createprinterport(IPAddress,ServerName): WBEM = win32com.client.GetObject(r"winmgmts:{impersonationLevel=impersonate}!\\" + ServerName + r"\root\cimv2") WBEM.Security_.Privileges.AddAsString("SeLoadDriverPrivilege") printerport = WBEM.Get("Win32_TCPIPPrinterPort").SpawnInstance_() printerport.Properties_('Name').Value = 'IP_'+IPAddress printerport.Properties_('Protocol').Value = 1 printerport.Properties_('HostAddress').Value = IPAddress printerport.Properties_('PortNumber').Value = '9100' printerport.Properties_('SNMPEnabled').Value = 'False' printerport.Put_() def createprinter(PrinterName,DriverName,Location,ShareName,IPAddress,ServerName): WBEM = win32com.client.GetObject(r"winmgmts:{impersonationLevel=impersonate}!\\" + ServerName + r"\root\cimv2") WBEM.Security_.ImpersonationLevel = 3 WBEM.Security_.Privileges.AddAsString("SeLoadDriverPrivilege") printer = WBEM.Get("Win32_Printer").SpawnInstance_() printer.Properties_('DeviceID').Value = PrinterName printer.Properties_('DriverName').Value = DriverName printer.Properties_('Location').Value = Location printer.Properties_('Network').Value = 'True' printer.Properties_('Shared').Value = 'True' printer.Properties_('ShareName').Value = ShareName printer.Properties_('PortName').Value = 'IP_'+IPAddress printer.Put_() I also created one for migrating print drivers but had loads of problems with it. If the driver doesn't pass Microsoft logo testing the scripts fail even if it is signed by Microsoft. I never worked out why there were 2 levels of protection. From bonono at gmail.com Wed Oct 19 06:09:13 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 19 Oct 2005 03:09:13 -0700 Subject: write a loopin one line; process file paths In-Reply-To: <1129715281.505043.60640@o13g2000cwo.googlegroups.com> References: <1129672592.328278.41490@g14g2000cwa.googlegroups.com> <1129696357.539158.233870@g47g2000cwa.googlegroups.com> <1129699998.324180.56530@f14g2000cwb.googlegroups.com> <1129701270.792327.168620@z14g2000cwz.googlegroups.com> <1129708210.963305.43270@g49g2000cwa.googlegroups.com> <1129710240.173768.151950@g14g2000cwa.googlegroups.com> <1129715281.505043.60640@o13g2000cwo.googlegroups.com> Message-ID: <1129716553.375057.62940@g14g2000cwa.googlegroups.com> Xah Lee wrote: > This i'm not sure. Of the past couple of years i increasingly developed > a theory (probably well-known among proper experts), that the > difficulty of human feats of various forms, are primarily a perception > and familiarity thing. This may be getting off topic, but i wrote an > essay expresising much of the idea using Juggling as a example: > Difficulty Perceptions in Human Feats > http://xahlee.org/Periodic_dosage_dir/t2/juggling.html > > likewise, i think this applies to mental feats as well. In particular, > i think that whether imperative code or functional code is easier for > the mind is almost ENTIRELY dependent on which one the person is more > familiar with, coulped with a innate attitude one may have picked up. But most of us start learning programming with imperative language, I started with COBOL and Pascal(are they still taught). Then we would hit the problem of looping one way or another pretty soon. Without a doubt, some experienced programmer would tell you to use for loop or search for one. This is even true in two heavily used declarative tools, SQL and Excel. If there is foldl/scanl/map in SQL, I think it would be much easier to code. Likewise for Excel, it is very functional(like its ancestors 1-2-3) then VBA was thrown in. In fact, I think haskell should be taught in any CS course as it opens up a completely different way of approaching problem and it is easier to read than LISP. > oh Haskell, my love! I am really going to learn it now. (maybe i'll > start A-Java-Haskell-A-Day) This month i just learned and read about > how Perl 6 is implemented in Haskell! (because one Taiwaness hacker > single-handedly by happenstance tried to do it, as a by-product of > learning Haskell) This Pugs (Perl6 in Haskell) really brought two > rather incompatible communities together somewhat for mutual exchange. > (the learning, on the surface, is politely said to be mutual, but i'm > pretty sure it's mostly Perlers learning from the Haskell folks) After seeing Haskell, I don't think I would go back to Perl(which I like better than python but python has the momentum as a general purpose language). That is why I am doing the think in haskell, code in python, whenever possible. > > ... there is a sentiment among the elite tech-geeking morons, early on > imbued by the concept of troll, so that they in general don't > communicate and learn from any other language except their own. > Anything cross-posted is considered as troll, and the inter-language > communication has been essentially completely cut off. Basically, the > only ones generating all the garbage posts are these troll-criers > themselves. (will have to flesh out on this particular point of > net-sociology in a essay some other day.) > May be you can tone down a bit if you want a constructive discussion. I am too old to have feelings about opinionated posts(and insensitive to) so I can go through the technical stuff. Confucius said "I can always learn something whenever there is 3 people getting together", lousy translation :-) From lsumnler at uniqueinsuranceco.com Fri Oct 28 16:14:40 2005 From: lsumnler at uniqueinsuranceco.com (LenS) Date: 28 Oct 2005 13:14:40 -0700 Subject: ? Pythoncard Message-ID: <1130530479.983395.118810@f14g2000cwb.googlegroups.com> I have created a small gui stub as follows using Pythoncard: c:\myhome lmsgui.py lmsgui.rsrc.py When I try to run I get the following error: (Errno2) no such file or directory lmsqui.rsrc.py I understand why I am getting the error the question is how do I fix this so it looks in the proper directories. Len Sumnler From steve at holdenweb.com Fri Oct 14 00:57:15 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 14 Oct 2005 05:57:15 +0100 Subject: wxPython & Cygwin In-Reply-To: <3r8bo1Fi9etjU1@uni-berlin.de> References: <434e8dbf$0$452$7a628cd7@news.club-internet.fr> <3r8bo1Fi9etjU1@uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > Gilles DRIDI wrote: > >>Does someone has installed wxPython on the Cygwin platform, environment ? > > > Why? Use windows python, wxPython for it - and put it in your path to > use it inside cygwin. > Don't think that'll work for an extension module. > But maybe you _can_ compile it yourself - I didn't try, though. > > Diez Probably a daunting task. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From lycka at carmen.se Thu Oct 20 07:14:13 2005 From: lycka at carmen.se (Magnus Lycka) Date: Thu, 20 Oct 2005 13:14:13 +0200 Subject: Writing an immutable object in python In-Reply-To: <1129649265.168515.306010@o13g2000cwo.googlegroups.com> References: <1129562898.812915.238430@g14g2000cwa.googlegroups.com> <1129649265.168515.306010@o13g2000cwo.googlegroups.com> Message-ID: Mapisto wrote: > Ok, I've understood my mistake. > > Now, my list contains a shared entry of an empty object. When an entry > is needed to be changed, I check if the entry is the shared empty > object; in that case I create a new unique instance. If the entry is > already a unique instance, I use it, so the empty object isn't touched. If you know that you'll use all list entries, you might as well do it right from the start. Instead of: l = [C()] * n you can do: l = [C() for i in range(n)] From aleaxit at yahoo.com Mon Oct 24 00:06:22 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 23 Oct 2005 21:06:22 -0700 Subject: High Order Messages in Python References: <1130015536.273136.295800@g43g2000cwa.googlegroups.com> <435bb315$0$15040$ed2619ec@ptn-nntp-reader02.plus.net> <1130118446.643842.178950@g47g2000cwa.googlegroups.com> <1130122476.079450.216280@g47g2000cwa.googlegroups.com> Message-ID: <1h4wiqv.m4hrpogqt6tvN%aleaxit@yahoo.com> bonono at gmail.com wrote: > could someone enlighten me what is the advantage of block over named > function ? > > One thing that I can see a difference may be lexical scope ? "Yes, but" -- according to the latest Ruby book, the "mixed lexical scope" of blocks is a highly controversial notion in the Ruby community; so I wouldn't necessarily count it as an _advantage_ of Ruby blocks... Alex From no at spam Mon Oct 3 12:01:57 2005 From: no at spam (D H) Date: Mon, 03 Oct 2005 11:01:57 -0500 Subject: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please! In-Reply-To: References: Message-ID: spiffo wrote: > Ok, I LOVE python, so that is not the issue, but, I am getting very worried > about it's growth. I recently re-visted the web looking at alot of projects > I assumed would be up and running by now from over a year ago, such as Boa > Constructor, Iron Python etc... it seems all these projects get started, but > never finished. > > Also, more and more I need *complete* control of ms sql from my apps, which > is simply not available from the adodbapi module I got off the internet... > also, ms sql 2005 is getting ready to come out... what if the guy that wrote > adodbapi.py does not feel like upgrading it so it even works with MS SQL > SERVER 2005? Yeesh... you get the picture... If everything revolves tightly around a microsoft product (ms sql 2005, which isn't even released yet), you probably are boxed in more towards other microsoft products. That's vendor lock-in for you. You might try VS.NET 2005 and see if C# or VB.NET and the ADO.NET api work well for you: http://lab.msdn.microsoft.com/vs2005/ Of course that plus ms sql 2005 will end up costing a great deal of money. Plus none of it is cross-platform, but you already said you do not need that. There are free .NET alternatives like Mono, Sharpdevelop, boo ( http://boo.codehaus.org/ ) and nemerle, but they are not caught up with .NET 2 stuff yet. Again, it hasn't even been released yet, and there are still bugs in their beta versions. So it wouldn't surprise me if the python libraries can't handle ms sql 2005-specific stuff yet either. So, if you need a short answer now, I'd say go with vs.net 2005, but if you can afford to wait a while, free python and .net alternatives will catch up. From exarkun at divmod.com Thu Oct 6 16:27:00 2005 From: exarkun at divmod.com (Jp Calderone) Date: Thu, 6 Oct 2005 16:27:00 -0400 Subject: Lambda evaluation In-Reply-To: <1128629895.5816.5.camel@localhost.localdomain> Message-ID: <20051006202700.3914.338280121.divmod.quotient.24966@ohm> On Thu, 06 Oct 2005 16:18:15 -0400, Joshua Ginsberg wrote: >So this part makes total sense to me: > >>>> d = {} >>>> for x in [1,2,3]: >... d[x] = lambda y: y*x >... >>>> d[1](3) >9 > >Because x in the lambda definition isn't evaluated until the lambda is >executed, at which point x is 3. > >Is there a way to specifically hard code into that lambda definition the >contemporary value of an external variable? In other words, is there a >way to rewrite the line "d[x] = lambda y: y*x" so that it is always the >case that d[1](3) = 3? There are several ways, but this one involves the least additional typing: >>> d = {} >>> for x in 1, 2, 3: ... d[x] = lambda y, x=x: y * x ... >>> d[1](3) 3 Who needs closures, anyway? :) Jp From my_email_is_posted_on_my_website at munged.invalid Mon Oct 24 21:14:59 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Tue, 25 Oct 2005 01:14:59 GMT Subject: Microsoft Hatred FAQ References: <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> Message-ID: <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> On Mon, 24 Oct 2005 12:59:33 -0700, "David Schwartz" wrote, quoted or indirectly quoted someone who said : > I think you need to look up "extortion" in a dictionary. In the days prior to Win95, Microsoft said "Co-operate with us is this immoral scheme to screw OS/2 or go out of business. Your choice." I call that extortion, even if their lawyers were careful enough to skirt the letter of the law. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From aleaxit at yahoo.com Wed Oct 26 10:42:19 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Wed, 26 Oct 2005 07:42:19 -0700 Subject: namespace dictionaries ok? References: Message-ID: <1h4zlsn.15t73ko1d685iuN%aleaxit@yahoo.com> Ron Adam wrote: ... > class namespace(dict): > def __getattr__(self, name): > return self.__getitem__(name) ... > Any thoughts? Any better way to do this? If any of the keys (which become attributes through this trick) is named 'update', 'keys', 'get' (and so on), you're toast; it really looks like a nasty, hard-to-find bug just waiting to happen. If you're really adamant on going this perilous way, you might try overriding __getattribute__ rather than __getattr__ (the latter is called only when an attribute is not found "in the normal way"). If you think about it, you're asking for incompatible things: by saying that a namespace X IS-A dict, you imply that X.update (&c) is a bound method of X; at the same time, you also want X.update to mean just the same thing as X['update']. Something's gotta give...!-) Alex From dcrespo at gmail.com Mon Oct 10 16:31:51 2005 From: dcrespo at gmail.com (dcrespo) Date: 10 Oct 2005 13:31:51 -0700 Subject: Send password over TCP connection In-Reply-To: <7xd5md76kd.fsf@ruckus.brouhaha.com> References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> <7xd5md76kd.fsf@ruckus.brouhaha.com> Message-ID: <1128976311.779178.304900@g14g2000cwa.googlegroups.com> Hi. I found TSL, a Python Library that supports SRP. Do you know where can I find a sample client and server code? Thanks for your help. From rubencharles at gmail.com Tue Oct 18 12:23:30 2005 From: rubencharles at gmail.com (Ruben Charles) Date: Tue, 18 Oct 2005 12:23:30 -0400 Subject: [wxPython-users] Web based applications are possible with wxPython? Message-ID: Hi, I am reading some essays --http://www.paulgraham.com/avg.html "Beating the averages"-- and i am very interested in the web-based applications. I want to take the advantages having the application on a server. Is easy to update, maintain, etc... My questions is Can i have a wxPython GUI app available on a web browser? I founded some doc on the www but the most refers to GUI wrote in java script and tool kits relates with java. Some java script samples are interesting but is not what i am looking for. There is a way for having wxpython frames, dialogs etc on a web browser? If not, can you suggest me any kind oh method for have something similar? Thanks. From kent37 at tds.net Sat Oct 22 09:23:21 2005 From: kent37 at tds.net (Kent Johnson) Date: Sat, 22 Oct 2005 09:23:21 -0400 Subject: Module Importing Question In-Reply-To: References: Message-ID: <435a3b3d$1_3@newspeer2.tds.net> James Stroud wrote: > Hello All, > > I have two modules that I use interchangably depending on the circumstances. > These modules are imported by yet another module. I want the "importation" of > these two alternatives to be mutually exclusive and dependent on the state of > the "outermost module" > > A diagram: > > mainApp ==imports==> aModule ==imports==> [oneMod | orTheOtherMod] > > I want the importing of oneMod or orTheOtherMod to depend on the state of the > mainApp. aModule is frozen, as are oneMod and orTheOtherMod. How might I > accomplish this? I don't know what you mean by frozen, so maybe this is no good, but I would avoid having aModule look back at the state of mainApp. Instead use another module to communicate state. This could be a simple as # in mainApp import helper if something: import oneMod as theMod else: import orTheOtherMod as theMod helper.theMod = theMod import aModule # in aModule import helper.theMod as theMod theMod.someFunction() Kent From mal at egenix.com Mon Oct 17 17:58:17 2005 From: mal at egenix.com (M.-A. Lemburg) Date: Mon, 17 Oct 2005 23:58:17 +0200 Subject: ANN: eGenix mxODBC Zope Database Adapter 1.0.9 Message-ID: <43541E79.5090906@egenix.com> ________________________________________________________________________ ANNOUNCEMENT EGENIX.COM mxODBC Zope Database Adapter Version 1.0.9 Usable with Zope and the Plone CMS. Available for Zope 2.3 through 2.8 on Windows, Linux, Mac OS X, Solaris and FreeBSD ________________________________________________________________________ INTRODUCTION The eGenix mxODBC Zope Database Adapter allows you to easily connect your Zope or Plone installation to just about any database backend on the market today, giving you the reliability of the commercially supported eGenix product mxODBC and the flexibility of the ODBC standard as middle-tier architecture. The mxODBC Zope Database Adapter is highly portable, just like Zope itself and provides a high performance interface to all your ODBC data sources, using a single well-supported interface on Windows, Linux, Mac OS X, Solaris and FreeBSD. This makes it ideal for deployment in ZEO Clusters and Zope hosting environments where stability and high performance are a top priority, establishing an excellent basis and scalable solution for your Plone CMS. ________________________________________________________________________ NEWS The new version includes a number of enhancements which make the mxODBC Zope Database Adapter even more robust and reliable. The adapter includes a new, more careful connection pool management and options to adjust the result set size in a more flexible way. We are very pleased to also include a build for Mac OS X with this release. This will make connecting your Zope or Plone installation on Mac OS X to local or remote databases a breeze. Starting with this release, we will now ship binaries for both Unicode build variants of Zope: UCS2 and UCS4. Most recent Linux distributions come pre-built with the UCS4 variant, e.g. SuSE 9 and 10, RedHat 9. ________________________________________________________________________ UPGRADING If you have already bought mxODBC Zope DA 1.0.x licenses, you can use these license for the 1.0.9 version as well. There is no need to buy new licenses. The same is true for evaluation license users. ________________________________________________________________________ MORE INFORMATION For more information on the mxODBC Zope Database Adapter, licensing and download instructions, please visit our web-site: http://zope.egenix.com/ You can buy mxODBC Zope DA licenses online from the eGenix.com shop at: http://shop.egenix.com/ ________________________________________________________________________ Thank you, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Oct 17 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 fredrik at pythonware.com Thu Oct 13 13:12:35 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 13 Oct 2005 19:12:35 +0200 Subject: Let My Terminal Go References: <1129010288.251817.147690@z14g2000cwz.googlegroups.com><1129012665.29863.2.camel@blackwidow><1129026623.319531.97420@g43g2000cwa.googlegroups.com> Message-ID: Jorgen Grahn wrote: > > Done once, it's usually not unacceptable. > > In fact, I can't think of a scenario where it /would/ be unacceptable ;-) if you're stuck on a system that doesn't use copy-on-write ? From jussij at zeusedit.com Tue Oct 4 20:29:34 2005 From: jussij at zeusedit.com (jussij at zeusedit.com) Date: 4 Oct 2005 17:29:34 -0700 Subject: ssh or other python editor In-Reply-To: <1128430526.531749.68600@g47g2000cwa.googlegroups.com> References: <1128430526.531749.68600@g47g2000cwa.googlegroups.com> Message-ID: <1128472174.246395.27200@g43g2000cwa.googlegroups.com> > I'm working/making my python scripts in a windows OS > with putty now. If you need an FTP editor take a look at Zeus: http://www.zeusedit.com/features.html Zeus will do SSH, SSL/TLS and plain old FTP editing, with support for Unix, Windows, VM and MVS FTP servers. Just remember to setup your host configuration, otherwise it will default to the FTP protocol. > But I really want the python text colors and tab > spacing like the python windows IDE but the problem > is that I can't find a good program. Zeus does Python syntax highlighting, code folding, class browsing, smart indenting, project/workspace management etc etc. You can even write Zeus macros in Pyhton :) Note: Zeus is shareware (45 day trial). Jussi Jumppanen Author: Zeus for Windows From grig.gheorghiu at gmail.com Mon Oct 10 10:27:56 2005 From: grig.gheorghiu at gmail.com (Grig Gheorghiu) Date: 10 Oct 2005 07:27:56 -0700 Subject: TurboGears slashdotted Message-ID: <1128954476.383270.111250@g43g2000cwa.googlegroups.com> "TurboGears: Python on Rails?" post: http://developers.slashdot.org/developers/05/10/10/0650207.shtml?tid=156 From tsaparas4life at hotmail.com Mon Oct 17 11:12:35 2005 From: tsaparas4life at hotmail.com (Nikola) Date: 17 Oct 2005 08:12:35 -0700 Subject: Installing Python at Work Message-ID: <1129561955.452114.53290@g44g2000cwa.googlegroups.com> I'm currently learning Python for my own use. I'm considering installing it on a work laptop, knowing that it is non-licensed, distributable software. However, does it access communication ports? I know the company checks their ports regularly for activity. I won't be doing anything very serious; I'm just trying out Python, learning the basics from 'Learning Python' by O'Reilly. From uche.ogbuji at gmail.com Sun Oct 30 14:50:11 2005 From: uche.ogbuji at gmail.com (uche.ogbuji at gmail.com) Date: 30 Oct 2005 11:50:11 -0800 Subject: XML Tree Discovery (script, tool, __?) In-Reply-To: <1130597464.844648.231940@g44g2000cwa.googlegroups.com> References: <1130183060.195730.178330@g47g2000cwa.googlegroups.com> <1130491182.405885.49010@g14g2000cwa.googlegroups.com> <1130531839.145106.287950@g44g2000cwa.googlegroups.com> <1130597464.844648.231940@g44g2000cwa.googlegroups.com> Message-ID: <1130701811.740803.233560@g43g2000cwa.googlegroups.com> "Neat, though non-trivial XSLT makes my head spin." Well, you don't have to know XSLT at all to use the Examplotron transform, although I can understand wanting to understand and hack what you're using. "Just for kicks, I rewrote in python Michael Kay's DTDGenerator (http://saxon.sourceforge.net/dtdgen.html), though as the original it has several limitations on the accuracy of the inferred DTD. " Ah. Cool. Got a link? -- Uche Ogbuji Fourthought, Inc. http://uche.ogbuji.net http://fourthought.com http://copia.ogbuji.net http://4Suite.org Articles: http://uche.ogbuji.net/tech/publications/ From chris.lasher at gmail.com Tue Oct 18 15:28:17 2005 From: chris.lasher at gmail.com (Chris Lasher) Date: 18 Oct 2005 12:28:17 -0700 Subject: Vim capable IDE? In-Reply-To: References: <1129603486.291175.167860@f14g2000cwb.googlegroups.com> <4354b229$0$21286$626a54ce@news.free.fr> <1129644971.811765.105900@g49g2000cwa.googlegroups.com> <22a5f.20376$ae.2646@tornado.tampabay.rr.com> Message-ID: <1129663697.620665.99040@g44g2000cwa.googlegroups.com> Thanks again for your responses, guys. To answer the question,the features I'd love to see in a Python IDE are: * First and foremost, Vim editing behavior. Let me keep my fingers on the homerow. I'm lazy. Point and click and CTRL + SHIFT has its moments, but text editing is not one of them. * Graphical symbolic debugger: the course I'm auditing, Software Carpentry, by Greg Wilson of University of Toronto, devoted a whole lecture to debuggers. See http://www.third-bit.com/swc/www/debugging.html . So now I want to try this crazy thing. I love the idea of being able to watch the values of variables change in "realtime" as the program runs, from the convenience of a little side window. I also love the concept of not having to insert debugging code into the production code--just a click in the left column and you set the debugging command. Keep the production code clean by putting the debugging commands outside the program. * Source browser: the ability to jump back and forth between specific blocks of code very quickly, and to see the overall layout of the file in terms of classes, methods, functions, etc. I want the big picture in a side window to keep me on task and remind me of how far I've come when I start feeling bogged down in details. * Autocompletion: PythonWin by ActiveState has nice autocompletion. When I import a module, it can dive down into those namespaces and allow autocompletion on them. That's a nice, productive feature. * Usage tips/tooltips: Also something I found in PythonWin. During the writing of the method, a little tip box pops up advising me what the inputs are for a method or an instance construction for a class. Very nice, very productive. * Linux compatibility: Nothing against Microsoft, or Apple, I just like to use a Linux box more. It seems like the IDEs I've looked at have most of the features, but none do Vim. Crazy. I agree that you can do all your coding using just Vim. That's how I've been doing it. But following along with Greg Wilson's Software Carpentry has made me realize that I could be more productive using the additional, apparently now-standard tools of a good IDE. I just don't want to sacrifice productivity in in keystrokes. It just seems like a compromise programmers shouldn't have to make. the other Chris Chris Lambacher wrote: > I would second that. I use Vim for editing. I find I don't need an IDE (not > even for C/C++). Vim does everything I need. If I want a debugger I will use > the shell debugger. Most other things can be added to Vim, though I tend to > run with very few plugins. > > -Chris > > > On Tue, Oct 18, 2005 at 05:12:30PM +0000, Ron Adam wrote: > > What features are you looking for. I think most Vim users just add what > > they want to Vim. > > From jjl at pobox.com Fri Oct 28 14:42:54 2005 From: jjl at pobox.com (John J. Lee) Date: 28 Oct 2005 19:42:54 +0100 Subject: urllib2 problem References: <32919.5531704046$1130385306@news.gmane.org> Message-ID: "Jeremy Martin" writes: [...] > website. I originally just used urllib.urlopen and everything worked > fine on my Windows PC at work. I tried the same script at home on my > Fedora COre 3 box using python 2.4, and whenever I try to connect to > the site I get the (110, Connection Timed Out) Error. > > At first I thought my firewall was causing problems with the script but > I noticed an odd patten. If the web site asked to accept cookies (like > the site I need) the script times out), if I point it to a site that > doesnt it works fine. Ive tried several attempts at using urllib2 and > the HTTPCookieProccessor and I still have no luck. If this is just a single server you're talking to, this doesn't necessarily implicate HTTPCookieProccessor -- it may be that that server does different stuff depending on whether you return cookies or not (not much point in having the cookies if not ;-), so the timeout might be caused by all kinds of unrelated problems. > Can anyone give me > any advice or pointers on what may be the problem here? I apologize if > this is kind of a rookie question but Ive been searching for about a > week with no luck. I'm the author of cookielib and HTTPCookieProccessor. It's very hard to guess what's wrong without being able to reproduce the problem. If you can send me your script (jjl at pobox.com), I may be able to help. One point, though. This doesn't seem to be the problem you are having, but it's a good thing for this info to be more easily Google-able for others: Are you using threads? cookielib is thread-broken, I suspect (poorly-tested thread support code was left in when I contributed the module, which was a mistake: I'm almost certain it's incorrect, and intend to request the thread synchronisation code be removed in 2.5). I suspect that could cause deadlock if you are using threads. It's probably possible to work around this, but I reccommend just not using threads (and not only because of my buggy synchronisation code!). But as I say, I don't think this is your problem. John From mwm at mired.org Mon Oct 3 23:36:40 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 03 Oct 2005 23:36:40 -0400 Subject: Controlling who can run an executable References: <1128395422.904212.318930@g44g2000cwa.googlegroups.com> Message-ID: <86y85ahs1j.fsf@bhuda.mired.org> "Cigar" writes: > Now that I'm three months into the development of this program, my > client tells me she would like to protect her investment by preventing > her employees from doing the same to her. (Going to the competition > and using her program.) First thing to know; you can't stop someone who's sufficiently determined to run the program. The best you can do is raise the cost of breaking your security to be more than any value that could be gained from doing so. > What my client cannot prevent: > - access to the .exe > > What my client is looking to prevent: > - running of the exe by un-authorized individuals. Not quite. > Ideas I've had to prevent someone from running the app: > - ask for a password every time the program is run. (I wonder how > quickly they will complain about this, not very secure once everyone > eventually finds out what the password is) If only authorized people have the password, then this works. The problem is that her employees are probably authorized, but she doesn't trust them to not take the program to her competition. Which brings up an alternative goal: Prevent running of the exe on unauthorized hardware. > - make a little hardware dongle and check to see if it's on the > parallel port. (old idea) > - check for an encrypted flash drive and try to read an encrypted file > from it. (new idea) > - buy the client a Microsoft Fingerprint Keyboard and figure out if it > will make the clients life easier (two minutes of research showed this > idea has multiple problems) Note that these three all use the idea of unauthorized hardware, not people. You don't need to install special hardware to get that. There are a number of pieces of hardware that you can find in a modern computer that may have a unique serial number you can use as a dongle. Possibilities include a CPU serial number, an HD serial number, and the MAC address of any network cards: ethernet, wireless, and apparently FireWire drivers have them. People have used all of them in the past. > What I want: > - the simplest thing that could possibly work! Telling her "Don't let your employees near the computer with media, or when it's connect to a network." That could possibly work, for some definition of work. You need to define how difficult you want breaking your security to be. Then we know what "work" means, and can figure out what "the simplest thing" is. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From pdr14 at comcast.net Wed Oct 26 20:33:33 2005 From: pdr14 at comcast.net (David) Date: Wed, 26 Oct 2005 20:33:33 -0400 Subject: help with sending data out the parallel port Message-ID: I'm wondering if python is capable of fairly precise timing and also sending data out the parallel port. For example ; making a 7.5 KHz square wave come out of one of the data pins on the printer port. I've tried to help myself with this one but searching in the "Python Library Reference" that installed with my version, [ Python 2.4.1. ] yielded nothing on the subject of either timing or parallel port. Id be thankful for any help. David KG2LI From g.franzkowiak at onlinehome.de Tue Oct 11 11:34:54 2005 From: g.franzkowiak at onlinehome.de (g.franzkowiak) Date: Tue, 11 Oct 2005 17:34:54 +0200 Subject: python interpreter Message-ID: Hi everybody, my interest is for the internals of the Python interpreter. I've used up to now FORTH for something and this indirect interpreter is very smart. --- ASM --------------------------------------------------------------- NEXT: LODSW ; WA <- [IP] ; IP <- IP+2 MOV T,WA ; T <- WA1 (CFA) JMP [T] ; JMP [CFA] --- C ----------------------------------------------------------------- for (;;) { w = *ip++; (**w) (); } ------------------------------------------------------------------------- Where can I find informations like this for Python ? gerd From larry.bates at websafe.com Thu Oct 6 15:53:05 2005 From: larry.bates at websafe.com (Larry Bates) Date: Thu, 06 Oct 2005 14:53:05 -0500 Subject: date reformatting In-Reply-To: References: Message-ID: <434580A1.8070103@websafe.com> There's more than one way, but this one will work for dates prior to 2000. import time datestring='8-15-05' d=time.strptime(datestring,'%m-%d-%y') number=10000*d[0]+100*d[1]+d[2] print number -Larry Bates Bell, Kevin wrote: > Anyone aware of existing code to turn a date string "8-15-05" into the > number 20050815? > > The dateutil module has a parse method that looks perfect, I downloaded > and unzipped it, but could figure out how to install it. I using > windows XP and py2.4. > > Any ideas? > > > Kev > From dong.ge.wh at gmail.com Wed Oct 26 11:11:41 2005 From: dong.ge.wh at gmail.com (Gonnasi) Date: 26 Oct 2005 08:11:41 -0700 Subject: How to processing multi redirect? Message-ID: <1130339501.262577.230280@g43g2000cwa.googlegroups.com> I want fetching some articles from nytimes.com for my Palm, and I want a clear, simple article too, my Palm has only 8M RAM. With the WGET, I can fetching the page like: "http://www.nytimes.com/2005/10/26/business/26fed.html?pagewanted=print", and when WGET works, I can see the URL have been redirect many times. When I run the below code with Python: >>> thing = urllib2.HTTPRedirectHandler() >>> opener = urllib2.build_opener(thing) >>> url = http://www.nytimes.com/2005/10/26/business/26fed.html?pagewanted=print' >>> page = opener.open(url) I just get a error message: "HTTP Error 302: The HTTP server returned a redirect error that would lead to an infinite loop. The last 30x error message was: Moved Temporarily" Why I can't fetching the page with python, but WGET can do it? Thanks for your help in advance! -- Gonnasi From fredrik at pythonware.com Mon Oct 10 04:26:54 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 10 Oct 2005 10:26:54 +0200 Subject: 2D graphics References: <006a01c5cd73$a91c1450$0a01a8c0@NEWLAT> Message-ID: "Peres" wrote: > As a Python beginner, I feel a bit lost among all possible libraries... > so I wondered whether soemone could help me find my way... I > just need to generate animated sequences of 2D primitives (dots > and lines), as fast as possible, checking the computer clock for > the time elapsed for each image, and checking the mouse click. "animated" as in "animated on screen" ? all Python GUI toolkits can do that. which one(s) do you have installed on your machine? From scott.daniels at acm.org Thu Oct 6 20:01:44 2005 From: scott.daniels at acm.org (Scott David Daniels) Date: Thu, 06 Oct 2005 17:01:44 -0700 Subject: Force flushing buffers In-Reply-To: <4345b6e8$0$49009$14726298@news.sunsite.dk> References: <4345b6e8$0$49009$14726298@news.sunsite.dk> Message-ID: <4345baa9$1@nntp0.pdx.net> Madhusudan Singh wrote: > I have a python application that writes a lot of data to a bunch of files > from inside a loop. Sometimes, the application has to be interrupted and I > find that a lot of data has not yet been writen (and hence is lost). How do > I flush the buffer and force python to write the buffers to the files ? I > intend to put this inside the loop. > > Thanks. ... files_to_close = [] try: somefile = open(somename, 'w') files_to_close.append(somefile) ... calculations, probably in a loop ... finally: for afile in files_to_close: afile.close() ... --Scott David Daniels scott.daniels at acm.org From rrr at ronadam.com Fri Oct 21 14:02:35 2005 From: rrr at ronadam.com (Ron Adam) Date: Fri, 21 Oct 2005 18:02:35 GMT Subject: classmethods, class variables and subclassing In-Reply-To: <4357EE59.1000005@bakerjaffe.plus.com> References: <4357EE59.1000005@bakerjaffe.plus.com> Message-ID: <%2a6f.162828$xl6.82276@tornado.tampabay.rr.com> Andrew Jaffe wrote: > Hi, > > I have a class with various class-level variables which are used to > store global state information for all instances of a class. These are > set by a classmethod as in the following (in reality the setcvar method > is more complicated than this!): > > class sup(object): > cvar1 = None > cvar2 = None > > @classmethod > def setcvar1(cls, val): > cls.cvar1 = val > > @classmethod > def setcvar2(cls, val): > cls.cvar2 = val > > @classmethod > def printcvars(cls): > print cls.cvar1, cls.cvar2 How about just using a mutable list? class sup(object): states = [None,None] # [s1, s2, ...] def set_s1(self, val): self.states[0] = val def get_s1(self): return self.states[0] def set_s2(self, val): self.states[1] = val def get_s2(self): return self.states[1] It keeps the states because the list isn't ever reassigned after it's created, so the values in it can change and all instances and subclasses can see the changed values. Cheers, Ron From fredrik at pythonware.com Thu Oct 6 11:55:12 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 6 Oct 2005 17:55:12 +0200 Subject: shelve object back to dictionary References: Message-ID: Ryan Krauss wrote: > Is there an easy way to convert a shelved object back to a dictionary? > When I save a dictionary using shelve and then load it in a later > session, I have an object whose property names are the keys of the > dictionary used as an input to shelve. For example, instead of > user['name'] I have user.name. I would prefer to have the scripts I > write to analyze the saved data have a similar syntax to the ones I > used to create it, so I would rather deal with a dictionary after I > load the shelved data. session 1: >>> import shelve >>> db = shelve.open("foo") >>> d = {"a": 1, "b": 2} >>> db["key"] = d >>> print d {'a': 1, 'b': 2} >>> print db["key"] {'a': 1, 'b': 2} >>> db.close() session 2: >>> import shelve >>> db = shelve.open("foo") >>> db["key"] {'a': 1, 'b': 2} >>> type(db["key"]) >>> db["key"].key Traceback (most recent call last): File "", line 1, in ? AttributeError: 'dict' object has no attribute 'key' >>> are you sure you're saving dictionaries? what does "print type(obj)" print for objects from your shelve? what does the following print for your data- base ? >>> import anydbm >>> db = anydbm.open("") >>> db[db.keys()[0]] From mwm at mired.org Wed Oct 12 01:41:51 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 12 Oct 2005 01:41:51 -0400 Subject: piping out binaries properly References: <86u0fnwes2.fsf@bhuda.mired.org> Message-ID: <86psqbwau8.fsf@bhuda.mired.org> Andy Leszczynski writes: > Mike Meyer wrote: >> It's not normal to write binary content to stdout - you normally write > > Well, I grew up in the Unix world and it is normal over there. I watched the Unix world grow up, and it ain't normal to me. I don't think I've ever written a program that wrote binary data to standard out, not in nearly 30 years of unix programming. I've written lots of things whose standard out was designed specifically to be read by another program, but never as binary data. > I am still curious which layer adds that 0xd. Is it python, cygwin, > windows ... It's Python. You tell Python whether or not it needs to do platform-dependent newline mangling when you open the file. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From mail at tuxipuxi.org Sat Oct 8 16:25:58 2005 From: mail at tuxipuxi.org (Michael Goettsche) Date: Sat, 8 Oct 2005 22:25:58 +0200 Subject: Daisy Daisy, give me your answer do In-Reply-To: <1128802217.156887.234490@g43g2000cwa.googlegroups.com> References: <1128802217.156887.234490@g43g2000cwa.googlegroups.com> Message-ID: <200510082225.58223.mail@tuxipuxi.org> On Saturday 08 October 2005 22:10, Xah Lee wrote: > there is a MacPerl program posted in 1998 that uses Mac's speech synth > to sing Daisy Bell. > See: > > http://bumppo.net/lists/macperl/1998/11/msg00412.html > > can anyone modify it so it runs out of the box on today's OS X? > > PS i'm posting this also in python and lisp group, i hope it'd be some > general interest. For some background of this song, see > http://xahlee.org/Periodic_dosage_dir/sanga_pemci/daisy_bell.html > > i'm interested in getting versions that can sing the song in Windows, > Mac, Linux using whatever speech synth each OS may provide. Thanks. > > Xah > xah at xahlee.org > ? http://xahlee.org/ You're asking "tech geekers" and "morons" to do this job? Isn't that a task for somebody more professional like you? From steve at REMOVETHIScyber.com.au Fri Oct 7 23:26:14 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sat, 08 Oct 2005 13:26:14 +1000 Subject: noob question Letters in words? References: Message-ID: On Fri, 07 Oct 2005 22:21:38 -0400, Ivan Shevanski wrote: > Yes, I realize that. . .Heres another question then. I was trying somehting > before so that if the user just pressed enter by accident, it would not > accept the input and ask them to put in another. But the thing is I couldnt > get it to work. I tryed if choice1 == None it would loop and ask for a new > input but that didnt seem to work. . .Any ideas for that? Test for choice1 == "" (the empty string) instead of None. -- Steven. From beliavsky at aol.com Sat Oct 8 08:36:01 2005 From: beliavsky at aol.com (beliavsky at aol.com) Date: 8 Oct 2005 05:36:01 -0700 Subject: Python 2nd favorite language in Linux Journal poll References: <1128692292.832209.66860@g47g2000cwa.googlegroups.com> <1128701207.508209.231450@g47g2000cwa.googlegroups.com> Message-ID: <1128774961.174013.9620@g44g2000cwa.googlegroups.com> beza1e1 wrote: > Hm, you didn't include a link and my google did not find the final > results. I could not find a link, but the results appear on page 88 of the November 2005 issue of Linux Journal. From skromta at gmail.com Wed Oct 5 16:26:50 2005 From: skromta at gmail.com (Kalle Anke) Date: Wed, 5 Oct 2005 22:26:50 +0200 Subject: What documentation "standard" to use Message-ID: <0001HW.BF6A03AA00B1AD5CF0284550@news.individual.de> I'm confused of how I should document my code, I've always liked being able to document my code directly in my source file and then to use some tool to extract the documentation to some other format. My problem with Python is that there are so many tools and formats ... I don't know which one I should use. I've tried to figure out if there is one that is the "de-facto standard" but ... Could someone advice me on what format/tool I should use? From larry.bates at websafe.com Fri Oct 21 16:30:37 2005 From: larry.bates at websafe.com (Larry Bates) Date: Fri, 21 Oct 2005 15:30:37 -0500 Subject: Help with language, dev tool selection In-Reply-To: <1129915422.693950.97000@g43g2000cwa.googlegroups.com> References: <1129915422.693950.97000@g43g2000cwa.googlegroups.com> Message-ID: 1) Python can do this easily 2) No tools required 3) Don't do it the way you describe. Here's what I would do: Load the information that you have in the text file into a MySQL database (MySQL import has tab delimited as its default so it is easy) and write a few lines of PHP to serve up the HTML pages dynamically. I say PHP and MySQL because almost every Internet Service Provider installs those tools for free when you host a website. If you are self hosting, use Python to create the pages dynamically as they are required. Besides, it will take you almost as long to upload the 30000 html pages to your webserver as to write this entire application. -Larry Bates vasilijepetkovic at yahoo.com wrote: > I have a problem that I have to solve programmatically and since HTML > is pretty much the only code I have been exposed to I need an advice on > how to develop the programmatic solution to the problem I have. > > In the nutshell, it'd be great if you can give me guidance in terms > of: > > 1) What programming language to use > 2) What development tools to use > 3) Tips on how to code the solution > > So, here is my challenge: > > I have a flat text file, 30000 records, each record has two columns, > the columns are tab separated. > > The file looks like this (approximately) > > Sarajevo 431104-133111 > Mostar 441242-133421 > Zagreb 432322-134423 > > > The first value is a name of a town, and the second value represent > longitude-latitude in degrees, minutes and seconds. > > For each record I have to create an html file that will be named as the > name of the town (i.e. Sarajevo.html). The content of the file will be > rather simple; in the first row it will contain the header (i.e. > "This page displays longitude-latitude information") - The second > row will have the following word: "Grad" - and the third row will > contain the name of the city and the fourth row will have the > longitude-latitude info. > > The program also needs to prompt me (before it starts spitting the html > pages) and ask what test should be entered in line one (I would than > manually enter "This page displays longitude-latitude information") > and it also need to prompt me about the text that should be entered in > line two (I'd go and manually enter "grad"). > > I'd greatly appreciate any coment and/or guidance. > > > Best, > > Vasilije Petkovic Vasa > From my_email_is_posted_on_my_website at munged.invalid Wed Oct 12 18:27:26 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 12 Oct 2005 22:27:26 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <11kj8ghonmialfc@corp.supernews.com> Message-ID: On Sun, 09 Oct 2005 23:04:49 -0000, gordonb.pru8x at burditt.org (Gordon Burditt) wrote or quoted : >I think one necessary function of email and USENET is that it should >allow you to SAFELY communicate with strangers or, worse, people >you know but do not trust at all, Yes, but with spam ANY communication with an unwanted stranger is a nuisance. There are two kinds of stranger: 1. ones you want to talk to 2. ones you don't. How can you sort people? 1. ones that appear to be trying to sell something 2. ones that others have said were pests. 3. ones you have given temporary/special permission to contact you --- a code word in a personal ad or newsgroup post. 4. Ones who can convince you of their case in a single sentence. 5. Ones who have a reputation as non-spammers (by some sort of consumer reports bureau that issues digital ids.) 6. Ones you have rejected in past (aided by digital ids expensive enough people won't change them like underwear). -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From joe at invalid.address Sat Oct 15 20:37:31 2005 From: joe at invalid.address (joe at invalid.address) Date: 15 Oct 2005 19:37:31 -0500 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: John Bokma writes: > joe at invalid.address wrote: > > > John Bokma writes: > > > >> "David Schwartz" wrote: > >> > > >> > "Tim Roberts" wrote in message > >> > news:a103l1tkejrc99s0385qjqqhm96d46dpc4 at 4ax.com... > >> > > >> >> Part of their behavior really escape me. The whole thing > >> >> about browser wars confuses me. Web browsers represent a zero > >> >> billion dollar a year market. Why would you risk anything to > >> >> own it? > >> > > >> > It really isn't that hard to understand that web-based > >> > applications that work in any browser on any OS threaten to > >> > make it irrelevent what OS you're running. > >> > >> And it's even easier to understand that your statement is > >> nonsense. > >> > >> It doesn't matter which Linux distribution you pick, all use the > >> Linux kernel. On all I can run OpenOffice, and get the same > >> results. Yet people seem to prefer one distribution over one > >> other. > > > > He was talking about the browser war, and gave a pretty good > > reason why it was important. So you respond by pointing out that > > people choose a linux distribution for personal (non-technical, > > non-marketing) reasons. I think I missed the connection. > > web based applications that work with any browser make OS irrelevant > -> not true, since for OpenOffice it doesn't matter which Linux > distribution one runs (or even if it's Linux), yet people seem to > make a point of which distribution they use. A linux distribution isn't an OS, it's a distribution, so I'm not sure what your point here is. In fact, there are lots of Microsoft-centric web pages that don't work well when accessed from a linux system. ActiveX, MS Java, etc. > >> > MS has a strong interest in making sure it's important > >> > to be running on one of their OSes. > >> > >> Maybe *they* do have a point :-). > > > > Which is? > > That it *does* matter. It doesn't matter which brand makes your > graphics card, since most stick close to the reference design of the > GPU chip supplier, yet people take the brand in consideration when > they buy. I don't think that's true, at least not yet. I recently bought a Compaq Presario, which came with XP installed. I wiped the disk and installed Linux, only to find that the hardware would only work under XP. So I then had to install network, video, sound etc cards to get it working. joe -- Gort, klatu barada nikto From deets at nospam.web.de Mon Oct 17 11:55:14 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 17 Oct 2005 17:55:14 +0200 Subject: Writing an immutable object in python In-Reply-To: <1129562898.812915.238430@g14g2000cwa.googlegroups.com> References: <1129562898.812915.238430@g14g2000cwa.googlegroups.com> Message-ID: <3rhvr3Fja33iU1@uni-berlin.de> > The change in the poision occurs becouse int() is an immutable object. > > if I will do the same with a user-defined object, This reference > manipulating will not happen. So, every entry in the array will refer > to the same instance. > > Is there a way to bypass it (or perhaps to write a self-defined > immutable object)? This has nothing to do with int being mutable or not. It only has to do with _list_ being mutable, and of course teh semantics of the _ * _ : list x int -> list operator, which simply shallow copies the list. So assigning to some l[i] will replace that entry - regardless of what is stored there. And that is all you do. The mutablity of an object only comes into place if you try and do l[i].some_mutating_op() That catches many people by surprise - but you don't do such a thing :) And besides: making an object immutable would mean that the only way to create an instance would be the constructor - rendering the purpose of the whole exercise somewhat moot - as then you'd have to call the constructor individually for each index you want to alter anyway. Which you have to do in the case of mutable objects, too. So - no gain there. Regards, Diez From david at jotax.com Thu Oct 27 19:38:36 2005 From: david at jotax.com (David Poundall) Date: 27 Oct 2005 16:38:36 -0700 Subject: Counting Threads In-Reply-To: References: <1130435220.846203.86320@g44g2000cwa.googlegroups.com> <1130435796.917475.295830@g14g2000cwa.googlegroups.com> Message-ID: <1130456316.569328.323480@f14g2000cwb.googlegroups.com> First time I have used thread locking. This seems to work but is it correct? from threading import Thread, Event, Lock . . . def launch(self, ThreadTitle, SubToLaunch, SubsArgs=(), SubsKwargs={}, AsDaemon=True): my_lock = Lock() my_lock.acquire() try: # --------------------- t = Thread(target=SubToLaunch, args = SubsArgs, kwargs = SubsKwargs) t.setDaemon(AsDaemon) t.start() self.Threads[len(self.Threads)] = t # Stash the thread in an instance local # --------------------- ServerThreads.threadcount += 1 finally: my_lock.release() . . . From gagenellina at softlab.com.ar Wed Oct 26 08:36:56 2005 From: gagenellina at softlab.com.ar (Gabriel Genellina) Date: 26 Oct 2005 05:36:56 -0700 Subject: Pickle to source code In-Reply-To: References: <1130315056.793178.232760@g14g2000cwa.googlegroups.com> Message-ID: <1130330216.445815.263380@g49g2000cwa.googlegroups.com> Benjamin Niemann ha escrito: > Gabriel Genellina wrote: > > > I want to convert from pickle format to python source code. That is, > > given an existing pickle, I want to produce a textual representation > > which, when evaluated, yields the original object (as if I had > > If all objects correctly implement the __repr__ method (true for built-in > stuff like list, dict, set...): > Just unpickle it and call repr() on the resulting object. Unfortunately I need a more general approach... Gabriel Genellina Softlab SRL From gordonb.e2yfo at burditt.org Wed Oct 12 19:07:15 2005 From: gordonb.e2yfo at burditt.org (Gordon Burditt) Date: Wed, 12 Oct 2005 23:07:15 -0000 Subject: Jargons of Info Tech industry References: <1124804082_1011@spool6-east.superfeed.net> <5hrik11q3p5ugcjm4hmmgqgq20o8fdrhr9@4ax.com> <7x4q7q2yer.fsf@ruckus.brouhaha.com> <8q0rk1tiktr86ksdu55mgsqffpkf2uus1c@4ax.com> Message-ID: <11kr5p3hstor935@corp.supernews.com> >However, formatted text is not code. HTML is much more than formatted text. >Pictures are not code. It is >unfair to tar them with the brush of JavaScript or the goofy things >Outlook does with enclosures. If you take all the dangerous stuff out of HTML, like: Links Javascript Forms References to other files you'd have very little left. I suggest that for formatted text, TROFF would be a better start. Gordon L. Burditt From mschreiner at tvpaint.fr Mon Oct 24 05:10:36 2005 From: mschreiner at tvpaint.fr (Mike) Date: Mon, 24 Oct 2005 11:10:36 +0200 Subject: several interpreters and suspend script Message-ID: <435ca50d$0$5371$8fcfb975@news.wanadoo.fr> Hello All, I'm working ( and a beginner ) with mixing Python scripting and C++. And I need some little help. :) I've searched on the net, but found no answer. So I ask you directly. Globally, I'd like to do 2 things. The first, when I'm in the program, I call a script, which call a function to open a window. And when the window is opened the script should stop / wait, until the window closes, and then continue. Does any function exists to do this ? #--------------------------------------------------------------------------------------------------------------------- import MyModule def ok_cb(): global w MyModule.Warning_All( "closing window" ) w.Close() #after here, the script should continue #create the window w = MyModule.cPythonWindow( "win", U"win", 0 ) #add some buttons, and when we push one, the function ok_cb is called w.AddActionButton( "ok", "OK", ok_cb ) w.AddIntegerButton( "int", "Nb", 2541, ok_cb ) #open the window w.Open() #we should stay here until the callback ends (when we push a button) and the window close #it should show this message when the window closes and not directly after the window is created MyModule.Warning_All( "exiting script" ) #--------------------------------------------------------------------------------------------------------------------- The second problem ( which is in relation with the first ) is when we have 2 non-modal windows, at the same time. If the 2 scripts stops/are suspended, all the variables in the scripts must be totally independent. So, I'd like that the 2 "spaces" of these scripts are independent. I wanted to use the Py_NewInterpreter() but it failed in PyThreadState_Swap() with this error : "PyFatalError("Invalid thread state for this thread");". So I use 2 dictionaries for each script, but is it sufficient? What about the call stack ? Where/how is it saved ? //--------------------------------------------------------------------------------------------------------------------- class cPython { public: virtual ~cPython(); cPython(); public: int Run( const char* iArgs ); void Module( const char* iModuleName, PyMethodDef* iModuleMethod ); void Dictionary( const char* iModuleName ); private: PyObject* mMainModule; PyObject* mGlobalDictionary; PyObject* mLocalDictionary; }; void cPython::Module( const char* iModuleName, PyMethodDef* iModuleMethod ) { mMainModule = Py_InitModule( iModuleName, iModuleMethod ); PyDict_Merge( PyModule_GetDict( mMainModule ), PyModule_GetDict( PyImport_AddModule( "__main__" ) ), true ); } void cPython::Dictionary( const char* iModuleName ) { mGlobalDictionary = PyDict_Copy( PyModule_GetDict( mMainModule ) ); PyDict_SetItemString( mGlobalDictionary, iModuleName, mMainModule ); mLocalDictionary = PyDict_Copy( PyModule_GetDict( mMainModule ) ); } int cPython::Run( const char* iArgs ) { PyObject* run_string = PyRun_String( iArgs, Py_file_input, mGlobalDictionary, mLocalDictionary ); Py_XDECREF( run_string ); return 0; } cPython pyt; pyt.Module( L"MyModule", sgMethods ); //create the module "MyModule" InitPythonProject( pyt.Module() ); //add the "class" project in the module "MyModule" InitPythonLayer( pyt.Module() ); //add the "class" layer in the module "MyModule" InitPythonWindow( pyt.Module() ); //add the "class" window in the module "MyModule" pyt.Dictionary( L"MyModule ); //create the 2 dictionary pyt.Run( L"MyPath/MyFile.py" ); //--------------------------------------------------------------------------------------------------------------------- If I create more python objects, the dictionaries are different but not the module( there is no copy of the module for the next python object ), right? And can this make problems for globals variables or callstack for each suspended script ? Here, that's all :) So, if you have any suggestions ( or even solutions ). Thanks for reading Regards From mscottschilling at hotmail.com Mon Oct 17 18:16:47 2005 From: mscottschilling at hotmail.com (Mike Schilling) Date: Mon, 17 Oct 2005 22:16:47 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: "John Bokma" wrote in message news:Xns96F1E574E6873castleamber at 130.133.1.4... > Roedy Green wrote: > >> On 16 Oct 2005 05:22:47 GMT, John Bokma wrote >> or quoted : >> >>>No, it's a recommendation, an advise, nothing else. Otherwise they >>>would call it a standard. Why do you think W3C calls it >>>recommendations? Because it are no standards. There is an ISO HTML >>>standard though, but when people babble about HTML standards they talk >>>about W3C *recommendations*. >> >> What do you think the Internet is based on? RFCs. > > Yup, I know. Hence no standards. > > Like I said: there is ISO HTML, and there is a w3c HTML 4.01 > recommendation. The former is a standard, the latter is a defacto > standard. > For some the difference does matter. What matters in generating HTML is which browsers you want to support and what they understand. Standards and recommendations are both irrelevant. From david at jotax.com Thu Oct 27 13:47:00 2005 From: david at jotax.com (David Poundall) Date: 27 Oct 2005 10:47:00 -0700 Subject: Counting Threads Message-ID: <1130435220.846203.86320@g44g2000cwa.googlegroups.com> I have a thread class and I want to be able to track its usage within an application. FYI the class launches aplications in their own thread when the 'launch' method is called. That works OK However I want to take things a bit further and my thinking was that I could use a class parameter to do a count but I am having no luck I am afraid. Its 'GlobalThreadCount' I am trying to get to work. I may need to use the globals built in - or do I. Thanks in advance David #-------------------------------------------------------- from threading import Thread, Event class ServerThreads: """ Wrapper for thread handling. Thread ID 0 = Controller Thread ID 1 = Plant Object 1 Thread ID 2 = Plant Object 2 """ GlobalThreadCount = 0 def __init__(self): self.Threads = {} def launch(self, SubToLaunch, SubsArgs=(), SubsKwargs={}, AsDeamon=True): t = Thread(target=SubToLaunch, args = SubsArgs, kwargs = SubsKwargs) t.setDaemon(AsDeamon) t.start() self.Threads[len(self.Threads)] = t # Stash the thread in an instance local GlobalThreadCount += 1 def globalusagecount(self): """ Returns a count figure for how many threads are running in total using this class. """ return GlobalThreadCount def stop(self,ThreadID): t = self.Threads[ThreadID] t.stop() self.Threads.clear[ThreadID] def count(self): """ Returns alist of how many threads are running in the instance """ return len(self.Threads) def runningkeys(self): """ Returns a llist of all running Keys """ return self.Threads.keys def allOK(self): """ Returns a list of all threads that are down if any) """ ThreadsDown = [] for t in self.Threads: if not self.Threads[t].isAlive: ThreadsDown.append(t) return ThreadsDown From fredrik at pythonware.com Sun Oct 16 09:52:54 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 16 Oct 2005 15:52:54 +0200 Subject: subtle side effect of generator/generator expression References: <1129470158.623786.135010@g14g2000cwa.googlegroups.com> Message-ID: bonono at gmail.com wrote: > I initially thought that generator/generator expression is cool (sort of > like the lazy evaluation in Haskell) until I notice this side effect. > > >>>a=(x for x in range(2)) > >>>list(a) > [1,2] > >>>list(a) > [] > > Would this make generator/generator expression's usage pretty limited ? nope. > As when the program/system goes beyond a single module, this behaviour > can cause subtle bugs ? sure, in the same way as >>> f = open(filename) >>> f.read() 'hello world\n' >>> f.read() # oops! '' causes subtle bugs (that is, almost never) From steve at holdenweb.com Thu Oct 20 12:10:57 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 20 Oct 2005 17:10:57 +0100 Subject: Modules and Namespaces In-Reply-To: <02d301c5d58b$b4a50050$0b01a8c0@JELLE> References: <02d301c5d58b$b4a50050$0b01a8c0@JELLE> Message-ID: Jelle Feringa / EZCT Architecture & Design Research wrote: > ##I'm sorry to stir up such a well discussed topic yet again, but namespaces > are a point of confusion to me... > > I took the effort of organizing my Python code (scripting a cad program > calles Rhino) in well defined classes, which would be a terrific thing if I > didn't got stuck in namespace issues. > > I have a module that launches the application I'm scripting via win32com; > rhino.load > > from rhino import load > RS = load.RS > > So the application, with all its methods are now available through the RS > (RhinoScript) object > > from rhino import SRF # is where things get stuck > > The RS object is the application scripted via COM, where all its method > reside. > In my module, SRF, I'm not importing anything, though it refers to the RS > object all the time. > Such as: > > class srfBase: > '''Base class inherited by the srf* classes, binding general Rhino > surface functionality to a particular > surface generation method''' > def __init__(self): > self.id = 'self.id srfBase' > pass > def isBrep(self): > return RS.IsBrep(self.id) > def isPointInSurface(self, coord): > return RS.IsPointInSurface(self.id, coord) > > > How do I make the RS object available to the imported SRF module, such that > my module code and program code both refer to RS as the application object > being scripted? > One relatively simple way (though not a perfect solution) is to provide a function in the SRF module that allows the caller to provide a reference to the RS object, which is then stored as a module global. Similar to this: # Somewhere in SRF's code RS = None # This RS is global to the SRF module def RSreg(rs): global RS # Ensures it isn't treated as function-local RS = rs Then all you have to do is from rhino import load RS = load.RS from rhino import SRF SRF.RSreg(RS) and everything inside SRF can refer to RS as a module global quite happily. Note that this falls over horribly if you ever want to handle several RS objects at the same time. In that case you might be better explicitly passing RS references into each function that uses them. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From nyamatongwe+thunder at gmail.com Fri Oct 14 22:25:53 2005 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Sat, 15 Oct 2005 02:25:53 GMT Subject: win32api.FindFiles Win2003, problem with Short Name In-Reply-To: <1129315861.886705.116980@g44g2000cwa.googlegroups.com> References: <1129245942.185252.171220@o13g2000cwo.googlegroups.com> <1129315861.886705.116980@g44g2000cwa.googlegroups.com> Message-ID: Frank Borell: > On all three types of PC/Servers they are set to 0. > > For now I'll have to process this script on non 2003 servers?!? What do you get if you call win32api.GetShortPathName on the long name? Neil From steve at holdenweb.com Mon Oct 10 11:52:23 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 10 Oct 2005 16:52:23 +0100 Subject: Comparing lists In-Reply-To: References: <1128930699.799657.146210@g47g2000cwa.googlegroups.com> <1128952417.0544cc73190bbbd4e683448c137969c8@teranews> Message-ID: Christian Stapfer wrote: > "George Sakkis" wrote in message > news:1128952417.0544cc73190bbbd4e683448c137969c8 at teranews... > >>"Christian Stapfer" wrote: >> >> >>> wrote: >>> >>>>try to use set. >>> >>> Sorting the two lists and then extracting >>>A-B, B-A, A|B, A & B and A ^ B in one single >>>pass seems to me very likely to be much faster >>>for large lists. >> >>Why don't you implement it, test it and time it >>to be more convincing about your intuition ? > > > The problem is in the generation of the test data. > Even merely generating a set of (suitably "average", > "random", and suitably "worst case") datasets might > turn out to be a major undertaking. > If the documentation stated the order-of-magnitude > behavior of those basic operations up front, then > I (and *anyone* else who ever wanted to use those > operations on large lists / large sets) could do > a quick order-of-magnitude estimation of how > a certain program design will behave, performance > wise. > *Experimenting* is not necessarily as easy to > do as you seem to believe. How do you, for example, > hit upon the worst-case behavior with your test > data? - Without knowing *anything* about the > implementation it might a matter sheer luck. > If you *know* something about the implementation > then, of course, you might be able to figure it > out. (But note that if you know *that* much about > the implementation, you usually have an order-of- > magnitude estimate anyway and don't need to do > *any* experimenting in order to answer my question.) > You are, of course, either assuming that there's a single implementation of Python, or that all implementations have the same behaviour. Or alternatively you are asking all implementers to do what you seem to consider so difficult (i.e. identify worst-case scenarios and then estimate order-of-magnitude behaviour for them). Test results with known test data are relatively easy to extrapolate from, and if your test data are reasonably representative of live data then so will your performance estimates. Anyway, aren't you more interested in average behaviour than worst-case? Most people are. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From davids at webmaster.com Sun Oct 23 14:43:44 2005 From: davids at webmaster.com (David Schwartz) Date: Sun, 23 Oct 2005 11:43:44 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> Message-ID: "Steven D'Aprano" wrote in message news:pan.2005.10.23.01.46.50.621450 at REMOVETHIScyber.com.au... >> No, not at all. It is the gravest act of self-contradiction to >> maintain >> that one should be allowed to pursue one's own interest while denying >> that >> same right to others. > This is perhaps the most ignorant thing I've seen written down by somebody > educated for a long, long long time. An individual's self-interest may > very well include theft, murder or rape, to mention just a few examples. You are dishonest, lying sack of shit. DS From tjue1 at sussex.ac.uk Thu Oct 6 05:42:53 2005 From: tjue1 at sussex.ac.uk (tjue1 at sussex.ac.uk) Date: Thu, 06 Oct 2005 10:42:53 +0100 Subject: Compile as static Message-ID: <1128591773.4344f19d7b429@webmail.sussex.ac.uk> Hello List Has anyone had any luck with this? Im trying to compile python 2.4.2 on Slackware 10.1 into one large executable. One which contains everything required to run python (as static). So python doesn't look for dynamically shared objects like libpthread.so.0. I have tried ./configure --disable-dynamic --enable-dynamic=NO --enable-static However the executable size is always the same :/ Please assist. Thank You Matt From bonono at gmail.com Sun Oct 16 10:20:25 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 16 Oct 2005 07:20:25 -0700 Subject: subtle side effect of generator/generator expression In-Reply-To: References: <1129470158.623786.135010@g14g2000cwa.googlegroups.com> Message-ID: <1129472425.591880.11500@g14g2000cwa.googlegroups.com> That is exactly what I meant, in fact. These IO thing are expected to have side effects so they are not subtle. Generator on the other hand, is sort of "clever iteratables". Now that I notice that, Of course I can be sure I would be careful. But what about the following situation : I import some function from some third party module which said, "oh, my function returns a iteratable". Then I can only list(o) if I want to pass it around or I consume it in only one and only one place. turning it into a list completely negate what generator is intended for(generate as much as you need) and using it in only one and only one place(like your fread example) would IMO means its usage is pretty limited. Beside, I can do a fseek to rewind a file handle but not a generator object. Fredrik Lundh wrote: > > > As when the program/system goes beyond a single module, this behaviour > > can cause subtle bugs ? > > sure, in the same way as > > >>> f = open(filename) > >>> f.read() > 'hello world\n' > >>> f.read() # oops! > '' > > causes subtle bugs (that is, almost never) > > From mwm at mired.org Mon Oct 3 01:03:59 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 03 Oct 2005 01:03:59 -0400 Subject: Will python never intend to support private, protected and public? References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xd5mstqab.fsf@ruckus.brouhaha.com> <7xzmpwuxd0.fsf@ruckus.brouhaha.com> <20050930075313.67b9b676.jk@ospaz.ru> <7xbr2a6dlz.fsf@ruckus.brouhaha.com> <7xk6gyoibc.fsf@ruckus.brouhaha.com> <433f56a3.2969039483@news.oz.net> <7x1x34f85u.fsf@ruckus.brouhaha.com> <867jcvmz06.fsf@bhuda.mired.org> <7x8xxbi8lw.fsf@ruckus.brouhaha.com> Message-ID: <86achrkx8g.fsf@bhuda.mired.org> Paul Rubin writes: > Mike Meyer writes: >> Which brings me to my point. Rather than trying to bandage Python to >> do what you want - and what, based on this thread, a lot of other >> people *don't* want - you should be building a system from the ground >> up to support the kind of B&D environment you want. > Heh, that goes against the principle that Python is supposed to be > good for everything. And where did you run into that principle? I've certainly never heard it before. It's pretty silly principle, as no language is good for everything. Python is general-purpose, meaning that it's not limited to a small set of problem areas, and that it probably won't be to bad for most uses. But that's not the same thing as being "good" for everything. Now, one of Python's strengths is that it can glue other applications together. So you can, for instance, write your application-specific code in a language suitable for that problem domain, then wrap those objects for use in a python interpreter - which is very popular in scientific circles - and optionally embed the interpeter in your application so you can invoke scripts as a fundamental part of your application. This makes it possible to deal with that application area with Python - but it doesn't mean Python is good for writing code for that application; just that it's good for wrapping other languages. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From lee at example.com Fri Oct 28 20:18:10 2005 From: lee at example.com (Lee Harr) Date: Sat, 29 Oct 2005 00:18:10 GMT Subject: ? Pythoncard References: <1130530479.983395.118810@f14g2000cwb.googlegroups.com> <1130534636.368702.277230@g49g2000cwa.googlegroups.com> Message-ID: <6dz8f.669$lg.121@news01.roc.ny> On 2005-10-28, LenS wrote: > Never mind I figured out my on stupid mistake > How about posting a very simple explanation of what you did wrong and how you fixed it, instead of leaving the next person who has this problem with a dead end? Thanks. From programmer.py at gmail.com Fri Oct 7 13:52:58 2005 From: programmer.py at gmail.com (Jaime Wyant) Date: Fri, 7 Oct 2005 12:52:58 -0500 Subject: Matching zero only once using RE In-Reply-To: <1128706522.319929.75310@g49g2000cwa.googlegroups.com> References: <1128706522.319929.75310@g49g2000cwa.googlegroups.com> Message-ID: On 7 Oct 2005 10:35:22 -0700, GregM wrote: > Hi, > > I've looked at a lot of pages on the net and still can't seem to nail > this. Would someone more knowledgeable in regular expressions please > provide some help to point out what I'm doing wrong? > > I am trying to see if a web page contains the exact text: > You have found 0 matches > Shouldn't your regular expression be "You have found 0 matches". If you're looking for that exact string, then you should use that. This works for me: >>> s = "asdfasfdfs You have found 0 matches asdfasdfasdf" >>> import re >>> re.search("You have found 0 matches", s) <_sre.SRE_Match object at 0x00B21800> ALso, it looks like your pattern is off. The pattern you use is given below... SecondarySearchTerm = 'You found (0){1} matches' However, you state that you are looking for 'You have found 0 matches' * Notice the 'have' in the string you are searching for and it's absence in your search term ;) HTH, jw From john at castleamber.com Tue Oct 18 14:02:53 2005 From: john at castleamber.com (John Bokma) Date: 18 Oct 2005 18:02:53 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <1129491006.021102.43920@g14g2000cwa.googlegroups.com> <86zmp8zsjk.fsf@bhuda.mired.org> <3rjvdaFk0l1sU1@individual.net> Message-ID: Eike Preuss wrote: > John Bokma wrote: > [snip] >> >> I see little difference with other big companies. You're right that >> there is no excuse for such behaviour, but if MS isn't doing it, >> another company will take their place. > > And if companies are allowed to behave this way (because of your > 'nice,fatalistic' argument), this will never change. > Showing companies that you don't excuse such behavior would include > not buying there products, using other products, whatever. To say that > they are just playing the evil part that somebody *has* to play, is to > excuse their behavior, IMO. If you think you can direct the development of human behaviour by not buying a Microsoft product, be my guest. I rather waste my time on other things. I think your "this will never change" is wrong, but it certainly will not change in my lifetime, and I doubt if this kind of human behaviour is going to change in many centuries to come. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From davids at webmaster.com Sun Oct 23 18:47:42 2005 From: davids at webmaster.com (David Schwartz) Date: Sun, 23 Oct 2005 15:47:42 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <86k6g59ke6.fsf@bhuda.mired.org> <3EI6f.43974$MF6.5922@fe1.news.blueyonder.co.uk> <86irvo861u.fsf@bhuda.mired.org> Message-ID: "Matt Garrish" wrote in message news:EVT6f.1507$ki7.59085 at news20.bellglobal.com... >> A right is a scope of authority. That is, a sphere within which one's >> decision is sovereign. > Then why were you claiming that a government can infringe on a person's > rights if those rights are not codified or even accepted by those people? > The idea of inalienable rights for anyone in a Western society only exists > if you believe that the rights of Western societies are inalienable and > should be respected everywhere. There is a huge arrogance in that > assumption, though, and once you enter a jurisdiction that does not hold > your rights to be inalienable they are no longer your rights. > > You can have generally agreed upon rights, but as you note, those rights > can only be hoped for if the systems exist to enforce them. Once those > systems erode, you no longer have rights only hopes. The more you allow > those systems to be eroded, the less you can expect your rights to exist. This would suggest that rogue governments can't infringe on the rights of their people because those people have no rights since their societies don't recognize any. This is another principle I reject at its roots. Your rights exist whether or not others choose to respect them. DS From matt.walsh at gmail.com Fri Oct 21 01:00:31 2005 From: matt.walsh at gmail.com (MBW) Date: 20 Oct 2005 22:00:31 -0700 Subject: TK question In-Reply-To: References: <1129860960.909273.68840@g43g2000cwa.googlegroups.com> Message-ID: <1129870831.440710.125870@f14g2000cwb.googlegroups.com> thank you very much, I have one more question that is tk related, I've use tkfileopendialog or whatever that name is to select files is there also a dialog for creating files, well not really creating them but allowing the same look and feel as many porgrams give for saving files? is there also a way/dialog whereby a user can specify a directory (if the application wanted to save multiple files into a 'project' folder) Thanks agian for the quick and accurate response to my first question, a small follow-up.. is it considered bad style to include main methods(and if __name__== "__main__") in all user defined classes, I realize it's usefulness when testing individual classes. thanks very much Matt Totally aside PyDEV is so much better then trustudio it runs smooth and isn't such a resource hog.. not to mention free From apardon at forel.vub.ac.be Mon Oct 3 03:10:41 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 3 Oct 2005 07:10:41 GMT Subject: Will python never intend to support private, protected and public? References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xll1gvk7w.fsf@ruckus.brouhaha.com> <1128001308.905398.321670@g44g2000cwa.googlegroups.com> <311b5ce105092908332c12164c@mail.gmail.com> Message-ID: Op 2005-09-30, Steven D'Aprano schreef : > On Fri, 30 Sep 2005 06:52:50 +0000, Antoon Pardon wrote: > >> Op 2005-09-29, Bill Mill schreef : >>> >>> But, if your users can't figure out that they shouldn't be changing >>> the variable called t._test__i without expecting side effects, what do >>> you think of the users of your class? >>> >>> Python is for consenting adults. >> >> No it is not. Consenting means you had the choice. Python doesn't >> give you the choice not to consent. > > Damn straight. I used to be a perfectly happy Pascal programmer, until > Guido and the Timbot kicked down my front door and forced me at gun point > to start programming in Python. I don't know about you, but when I hear someone saying, this is to be used between consenting adults, I don't expect the choice to be limited between using and not using. Those adults also have to consent on how to use it. If you limit this "consenting adults" to using python or not, you are making my point. -- Antoon Pardon From fredrik at pythonware.com Tue Oct 4 01:45:01 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 4 Oct 2005 07:45:01 +0200 Subject: Python Debug Build References: <20051003210217.88812.qmail@web30614.mail.mud.yahoo.com> Message-ID: "Celine & Dave" wrote: > What happens if I build Python with debug option > (--with-pydebug)? Do I see any changes in my program > output? What is --with-pydebug good for? from the README: --with-pydebug: Enable additional debugging code to help track down memory management problems. This allows printing a list of all live objects when the interpreter terminates. From steve at holdenweb.com Fri Oct 14 00:15:04 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 14 Oct 2005 05:15:04 +0100 Subject: A problem while using urllib In-Reply-To: <87r7apknym.fsf@pobox.com> References: <1129024641.113182.74420@g49g2000cwa.googlegroups.com> <1h49slu.1gaj0nnmdk5ghN%aleax@mail.comcast.net> <1129089078.852454.153800@f14g2000cwb.googlegroups.com> <1129102671.990994.43590@f14g2000cwb.googlegroups.com> <434CC861.2080805@holdenweb.com> <434CCFDE.7000409__24352.7919905775$1129107859$gmane$org@holdenweb.com> <87r7apknym.fsf@pobox.com> Message-ID: John J. Lee wrote: > Steve Holden writes: > [...] > >> File "/usr/lib/python2.4/urllib2.py", line 996, in do_open >> raise URLError(err) >>urllib2.URLError: >> >>Looking at that part of the course of urrllib2 we see: >> >> headers["Connection"] = "close" >> try: >> h.request(req.get_method(), req.get_selector(), req.data, >>headers) >> r = h.getresponse() >> except socket.error, err: # XXX what error? >> raise URLError(err) >> >>So my conclusion is that there's something in the Cygwin socket module >>that causes problems not seen under other platforms. >> >>I couldn't find any obviously-related error in the Python bug tracker, >>and I have copied this message to the Cygwin list in case someone there >>knows what the problem is. > > [...] > > I don't *think* this is related, but just in case: > > http://python.org/sf/1208304 > Good catch, John, I suspect this is a possibility so I've added the following note: """The Windows 2.4.1 build doesn't show this error, but the Cygwin 2.4.1 build does still have uncollectable objects after a urllib2.urlopen(), so there may be a platform dependency here. No 2.4.2 on Cygwin yet, so nothing conclusive as lsof isn't available.""" regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From steve at REMOVETHIScyber.com.au Sun Oct 30 07:42:52 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 30 Oct 2005 23:42:52 +1100 Subject: Automatic binding of **kwargs to variables References: <1130539752.667045.183460@g14g2000cwa.googlegroups.com> Message-ID: On Fri, 28 Oct 2005 15:49:12 -0700, lbolognini at gmail.com wrote: > I have a very long list of parameters coming from a web form to my > method foo(self, **kwargs) > > I would like to avoid manually binding the variables to the values > coming through the **kwargs dictionary, That's easy: Just Don't Do It. Instead of some horribly contorted code converting key,item in kwargs into self.key = item, just do the simple, obvious thing: self.kwargs = kwargs and then access the values with self.kwargs[key]. > just to keep the code cleaner, > I'd like to bind them automatically If you are worried about excessive use of quotation marks, you can always define some constants to use: NAME = 'name' EMAIL = 'email' NUM = 'num' if self.kwargs[NAME]is None: self.kwargs[NAME] = "Anonymous" The benefit of this is that when you change your web form to use "number" instead of "num", you only have to change your code in one place. -- Steven From bonono at gmail.com Tue Oct 18 21:50:02 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 18 Oct 2005 18:50:02 -0700 Subject: how best to split into singleton and sequence In-Reply-To: References: Message-ID: <1129686602.596866.172960@g43g2000cwa.googlegroups.com> what you wrote is the most readable to me: just asign the first 2 element to t, l respectively and forget about the rest. I assume that is what you want. I think perl may do it this way. A solution which I think looks uglier is : t, l = s.split('|')[:2] Randy Bush wrote: > >>> l = [] > >>> s = 'a|b' > >>> t, l = s.split('|') > >>> t > 'a' > >>> l > 'b' > >>> s = 'a|b|c|d' > >>> t, l = s.split('|') > Traceback (most recent call last): > File "", line 1, in ? > ValueError: too many values to unpack > >>> > > so, i imagine what is happening is the lhs, t,l, is really > (t, (l)), i.e. only two items. > > so how should i have done this readably and simply? > > randy From steve at holdenweb.com Wed Oct 5 06:54:24 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 05 Oct 2005 11:54:24 +0100 Subject: dictionary interface In-Reply-To: References: Message-ID: Antoon Pardon wrote: > Op 2005-10-05, Steve Holden schreef : [...] > > Anyway, I have searched the source of the test for all testing > with regards to < and after some browsing back and fore it seems > it all boils down to the following two tests. > > self.assert_(not {} < {}) > self.assert_(not {1: 2} < {1L: 2L}) > So there isn't much to do, then! That's good. Seems you can pretty much choose your own ordering. It would seem sensible to test a third case, namely self.assert_(not {1L: 2L} < {1: 2}) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From mwm at mired.org Fri Oct 28 14:43:57 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 28 Oct 2005 14:43:57 -0400 Subject: Typing tutor help script needed, please References: <1130507926.729061.125850@g43g2000cwa.googlegroups.com> Message-ID: <861x25fpn6.fsf@bhuda.mired.org> "Throw" writes: > G'day everyone! > > I would like to design typing tutor exercises for Afrikaans (and other > languages possibly). This is for a GPL project. For this, I need a > script that can extract words from a long list of words, based on which > letters those words contain, and write then write output to a file. > Does anyone know of an existing script for this, or can anyone write me > one, please? This sounds nearly trivial in Python. More specifics would help. > Preferably I must be able to extract words which contain only certain > letters (they need not contain all of those letters, but they may not > contain any other letters). It would be nice if I can also extract > words which do not contain certain letters. Again, this sounds nearly trivial in Python. For instance. to get a list of all words that don't contain 'a', you'd do something like: f = open(textfile) words = f.read().split() f.close() selected = [word for word in words if 'a' not in word] and then selected has the list of words that don't have an 'a' in them. Tweaking the test the other way - to select words with an 'a', remove the 'not'. You can combine the tests with 'and' and 'or'. But without a UI, that's pretty much useless - and you haven't said what you want the UI to be. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From fphsml at gmail.com Wed Oct 5 17:06:48 2005 From: fphsml at gmail.com (James) Date: 5 Oct 2005 14:06:48 -0700 Subject: Python Newbie In-Reply-To: <1128526724.904832.278270@z14g2000cwz.googlegroups.com> References: <1128526724.904832.278270@z14g2000cwz.googlegroups.com> Message-ID: <1128546408.526280.138670@g47g2000cwa.googlegroups.com> 1. What toolkit is best for Windows development? "Best" depends on your needs. wxPython seems to be the most popular one. 2. Which toolkits can I exclude from consideration? You haven't given enough exclusion criteria. But here are the possible issues to consider. Fox - Hasn't been updated with a binary release since the release for Python 2.2. OpenGL - not a toolkit for everyday windowing needs. But I don't know what you have in mind. FLTK - Light Weight but doesn't have a good "MS Windows" feel. pyQt - Be sure you check if the licensing bothers you. 3. What toolkit is most popular for Windows development? wxPython seems to be the most popular one for Python, not just on "MS Windows". I think it has more apps written with, than any other, and the toolkit has active support for MS Windows specific technologies. 4. Are there any impartial reviews of these packages anywhere? http://www.python.org/doc/faq/gui.html. Google for others. I personally prefer not to do Windows GUI development in Python. I prefer to use mainstream GUI dev tools for windows (Delphi, Visual Studio) and pull in Python as embedded or as COM. But that's just "my" preference. A lot of people here do it all in Python happily. From steve at REMOVETHIScyber.com.au Sat Oct 22 23:26:32 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 23 Oct 2005 13:26:32 +1000 Subject: best way to replace first word in string? References: <1129822003.246170.303920@f14g2000cwb.googlegroups.com> <861x2dbcwv.fsf@bhuda.mired.org> Message-ID: On Sat, 22 Oct 2005 14:54:24 -0400, Mike Meyer wrote: >> The string formatting is two orders of magnitude faster than the >> concatenation. The speed difference becomes even more obvious when you >> increase the number of strings being concatenated: > > The test isn't right - the addition test case includes the time to > convert the number into a char, including taking a modulo. I wondered if anyone would pick up on that :-) You are correct, however that only adds a constant amount of time to the time it takes for each concatenation. That's why I talked about order of magnitude differences. If you look at the vast increase in time taken for concatenation when going from 10**5 to 10**6 iterations, that cannot be blamed on the char conversion. At least, that's what it looks like to me -- I'm perplexed by the *vast* increase in speed in your version, far more than I would have predicted from pulling out the char conversion. I can think of three possibilities: (1) Your PC is *hugely* faster than mine; (2) Your value of x is a lot smaller than I was using (you don't actually say what x you use); or (3) You are using a version and/or implementation of Python that has a different underlying implementation of string concatenation. > I couldn't resist adding the .join idiom to this test: [snip code] >>>> tester(x) > 0.0551731586456 0.0251281261444 0.0264830589294 >>>> tester(x) > 0.0585241317749 0.0239250659943 0.0256059169769 >>>> tester(x) > 0.0544500350952 0.0271301269531 0.0232360363007 > > The "order of magnitude" now falls to a factor of two. The original > version of the test on my box also showed an order of magnitude > difference, so this isn't an implementation difference. [snip] >>>> tester(x * 10) > 1.22272014618 0.252701997757 0.27273607254 >>>> tester(x * 10) > 1.21779584885 0.255345106125 0.242965936661 >>>> tester(x * 10) > 1.25092792511 0.311630964279 0.241738080978 Looking just at the improved test of string concatenation, I get times about 0.02 second for n=10**4. For n=10**5, the time blows out to 2 seconds. For 10**6, it explodes through the roof to about 2800 seconds, or about 45 minutes, and for 10**7 I'm predicting it would take something of the order of 500 HOURS. In other words, yes the char conversion adds some time to the process, but for large numbers of iterations, it gets swamped by the time taken repeatedly copying chars over and over again. -- Steven. From ericwan78 at yahoo.com Fri Oct 14 17:35:47 2005 From: ericwan78 at yahoo.com (wanwan) Date: 14 Oct 2005 14:35:47 -0700 Subject: confusion between global names and instantiated object variable names In-Reply-To: References: <1129322411.776202.314290@g43g2000cwa.googlegroups.com> Message-ID: <1129325747.113619.23630@g44g2000cwa.googlegroups.com> oops, of course. Very careless mistake. thx From steve at REMOVEMEcyber.com.au Mon Oct 31 05:16:41 2005 From: steve at REMOVEMEcyber.com.au (Steven D'Aprano) Date: Mon, 31 Oct 2005 21:16:41 +1100 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <4363fdd4$0$2107$edfadb0f@dtext02.news.tele.dk> Message-ID: <4365EF09.7020709@REMOVEMEcyber.com.au> David Rasmussen wrote: > Steven D'Aprano wrote: > >> On Fri, 28 Oct 2005 06:22:11 -0700, pinkfloydhomer at gmail.com wrote: >> >>> Which is quite fast. The only problems is that the file might be huge. >> >> >> What *you* call huge and what *Python* calls huge may be very different >> indeed. What are you calling huge? >> > > I'm not saying that it is too big for Python. I am saying that it is too > big for the systems it is going to run on. These files can be 22 MB or 5 > GB or ..., depending on the situation. It might not be okay to run a > tool that claims that much memory, even if it is available. If your files can reach multiple gigabytes, you will definitely need an algorithm that avoids reading the entire file into memory at once. [snip] > print file("filename", "rb").count("\x00\x00\x01\x00") > > (or something like that) > > instead of the original > > print file("filename", "rb").read().count("\x00\x00\x01\x00") > > it would be exactly what I am after. I think I can say, without risk of contradiction, that there is no built-in method to do that. > What is the conceptual difference? > The first solution should be at least as fast as the second. I have to > read and compare the characters anyway. I just don't need to store them > in a string. In essence, I should be able to use the "count occurences" > functionality on more things, such as a file, or even better, a file > read through a buffer with a size specified by me. Of course, if you feel like coding the algorithm and submitting it to be included in the next release of Python... :-) I can't help feeling that a generator with a buffer is the way to go, but I just can't *quite* deal with the case where the pattern overlaps the boundary... it is very annoying. But not half as annoying as it must be to you :-) However, there may be a simpler solution *fingers crossed* -- you are searching for a sub-string "\x00\x00\x01\x00", which is hex 0x100. Surely you don't want any old substring of "\x00\x00\x01\x00", but only the ones which align on word boundaries? So "ABCD\x00\x00\x01\x00" would match (in hex, it is 0x41424344 0x100), but "AB\x00\x00\x01\x00CD" should not, because that is 0x41420000 0x1004344 in hex. If that is the case, your problem is simpler: you don't have to worry about the pattern crossing a boundary, so long as your buffer is a multiple of four bytes. -- Steven. From mrbmahoney at gmail.com Sat Oct 29 14:08:55 2005 From: mrbmahoney at gmail.com (B Mahoney) Date: 29 Oct 2005 11:08:55 -0700 Subject: Understanding the arguments for SubElement factory in ElementTree References: <1130567974.754511.66930@g14g2000cwa.googlegroups.com> Message-ID: <1130609335.112602.322180@g44g2000cwa.googlegroups.com> Your SubElement call is lacking the attrib argument, but you can't set text, anyway. The elementtree source makes it clear, you can only set element attrib attributes with SubElement def SubElement(parent, tag, attrib={}, **extra): attrib = attrib.copy() attrib.update(extra) element = parent.makeelement(tag, attrib) parent.append(element) return element From my_email_is_posted_on_my_website at munged.invalid Wed Oct 12 20:34:06 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Thu, 13 Oct 2005 00:34:06 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <868xx3m2ve.fsf@bhuda.mired.org> <86irw6l1mc.fsf@bhuda.mired.org> Message-ID: On Thu, 13 Oct 2005 09:12:46 +1000, Steven D'Aprano wrote or quoted : >Suppose I wanted to gather industrial espionage about, oh, say Roedy >Green. If my virus could impersonate him, I could tell everyone in sight >that his email has changed to rgreen at mydomain.ru (or wherever). I would >harvest his email I would say by extrapolating the problem of spam and snooping that the next level of email software needs to concentrate on the following: 1. routine and transparent encryption. 2. making spam no longer economic. Blocking all spam is, even in theory, impossible. I sometimes read a message and am ambivalent myself about whether I wanted to read or receive it. The key is to provide efficient, transparent spam solutions. They can be layered to filter higher and higher percentages of mail depending on how big your spam problem is. 3. prevent phishing. When PayPal sends you an email, you want to know for sure it really is from PayPal. This means corporate users at least will all have digital ids, and all emails will be digitally signed. 4. status tracking. Unless blocked by the receiver, the sender knows if his message has been receiveived/read. 5. making it impossible for any incoming email to mount any sort of attack. the only parts the email software processes are the data parts. Any enclosed programs must be explicitly installed. The email software would warn if any code were not digitally signed with proper certificate to identify the author. Especially with spam, there are no perfect solutions, but at least we could do many times better than what we are living with and put the spammers out of business. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From steve at holdenweb.com Wed Oct 19 04:46:37 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 19 Oct 2005 09:46:37 +0100 Subject: UI toolkits for Python In-Reply-To: <3rlj78Fjsu7mU1@individual.net> References: <7xslv56ud1.fsf@ruckus.brouhaha.com> <3ras6oFit2djU1@individual.net> <3rg3aiFjgc47U1@individual.net> <3rlj78Fjsu7mU1@individual.net> Message-ID: Claudio Grondi wrote: > "Steve Holden" schrieb im Newsbeitrag > news:mailman.2143.1129532422.509.python-list at python.org... > >>Claudio Grondi wrote: [...] >>>>>Do I miss here something? >>>>> >>>> >>>>While you are correct in saying (I paraphrase) that HTML interfaces >>>>nowadays can offer a rich graphical interface, it can be quite difficult >>>>to manage state maintenance between the two components (web server, web >>>>client) in the system. >>> >>> >>>The cause of confusion here is, that HTML interfaces don't necessary > > need a > >>>web server and HTTP to work. I mean, that Internet Browsers >>>have an API which allow access to them directly, so they can be used > > without > >>>a server as a kind of GUI library supporting widgets programmed >>>in HTML and JavaScript (I haven't used them yet in this form, but I > > think > >>>it should be no problem - right or not?). >>> >> >>You are perfectly correct that interfaces can be programmed in the >>browser. As has already been said, with the adoption of standards like >>CSS2, it's even possible to make such stuff run across multiple browser >>platforms (at the moment, though, just try writing an interface that >>makes table rows appear and disappear in a cross-browser fashion: you'll >>find the stylesheet techniques you need to use for Mozilla and IE are >>very different). But this doesn't help you at all if you are trying to >>interface to Python logic. >> >>>>A "proper" GUI runs all functionality inside a single process, and >>>>allows much easier control over complex interactions, creation of >>>>dynamic dialogues, and so on. >>> >>>Complex and dynamic is in my eyes possible with HTML and JavaScript, so > > I > >>>still don't see where is a problem with this approach. I have programmed >>>already a HTML and JavaScript driven server platform and know about (the >>>solvable) problems with the back-button and sessions (it is sure not the >>>easiest way of programming a GUI). >>>The only disadvantage of not using plugins or Java is, that real time >>>interactions are not possible, but this is in my eyes usually not the >>>requirement for a standard kind of GUI with no gaming, no Virtual > > Reality > >>>and no timing of user response down to milliseconds (but consider, that > > with > >>>a good speed of connection it is even possible to play blitz chess over > > the > >>>Internet). >>> >> >>So, back to the subject: with an HTML/Javascript interface, how do you >>propose to bolt Python logic into the same process? Or do you admit that >>the application that interacts with such an interface either has to be >>all JavaScript or in a separate process? > > I haven't used it in such configuration yet, but I mean, that it is not a > bad idea to use local DHTML files (i.e. HTML with JavaScript) combined with > a Python driven HTTP server like e.g. Karrigell which makes it possible to > access local files by executing Python scripts triggerred by demand raised > by submitting to it DHTML form data resulting from user input. > So mixing JavaScript in local DHTML files for performing what can be done > with JavaScript inside HTML and a HTTP server capable of executing Python > scripts will do the job which JavaScript alone can't because of lack of > access to the local file system and another parts of the computer system on > which such kind of UI is executed. Indeed. But this again partitions the problem into client functionality and server functionality residing in two separate processes, albeit on the same computer, with the previously-mentioned state maintenance problems. This issue isn't new, you know. > Another possible scenario I have in mind is to control the Internet browser > directly from a Python script using DHTML as a language for definition of > appearance and specification of necessary data processing of in the browser > displayed UI. This way the Internet browser and HTML with JavaScript can be > considered an UI toolkit for use in Python. > Hope with this above to have got Python back on topic. > That is, I suppose, a possibility, but you certainly can't claim it would be platform-independent. Unless you know of some common control interface respected by both Internet Exploder and Firefox ;-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From pmartin at snakecard.com Mon Oct 10 15:45:17 2005 From: pmartin at snakecard.com (Philippe C. Martin) Date: Mon, 10 Oct 2005 19:45:17 GMT Subject: how to capture key pressing References: Message-ID: Hi, Look at curses. Philippe billie wrote: > Hi all. I'm searching for a module that permit me to costantly log every > key pressed on the keyboard and eventually assign it a function (e.g. when > "esc" is pressed: exit program"). From cowie.rob at gmail.com Fri Oct 7 21:51:25 2005 From: cowie.rob at gmail.com (Rob Cowie) Date: 7 Oct 2005 18:51:25 -0700 Subject: GUI on Macintosh In-Reply-To: <1128717512.502956.45170@g49g2000cwa.googlegroups.com> References: <1128717512.502956.45170@g49g2000cwa.googlegroups.com> Message-ID: <1128736285.368230.228340@g49g2000cwa.googlegroups.com> FYI... the preinstalled python distributed with OS X 10.4 includes the Tk and wxPython GUI frameworks. I am unaware of how to get either of these installed on OS 9. From johnww at worldpath.net Sat Oct 15 11:55:14 2005 From: johnww at worldpath.net (John Wingate) Date: Sat, 15 Oct 2005 15:55:14 -0000 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: <11l29j29rq4jh18@corp.supernews.com> Peter T. Breuer wrote: > In comp.os.linux.misc Jeroen Wenting wrote: >> Without Microsoft 90% of us would never have seen a computer more powerful >> than a ZX-81 and 90% of the rest of us would never have used only dumb >> mainframe terminals. > > Uh - when microsoft produced dos 1.0, or whatever it was, I was sitting > at my Sun 360 workstation (with 4M of RAM, later upgraded to 8M), > running SunOS 3.8 or thereabouts. Peter, if you are serious, and not just pulling our legs, your memory is failing. MS-DOS 1.0 came out in August 1981; SunOS 3.0 in February 1986. Sun Microsystems was incorporated (with four employees) in February 1982. There never was a SunOS 3.8. (SunOS 3.5 was succeeded by 4.0.) And I'm not sure what you mean by "Sun 360"--a Sun 3/60, maybe? -- John Wingate Mathematics is the art which teaches johnww at worldpath.net one how not to make calculations. --Oscar Chisini From aleax at mail.comcast.net Sat Oct 15 04:54:56 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Sat, 15 Oct 2005 10:54:56 +0200 Subject: Problem splitting a string References: <20051015045208.28476.qmail@web35811.mail.mud.yahoo.com> <86u0fjs47c.fsf@bhuda.mired.org> Message-ID: <1h4gzkw.1mkaqo31e2d5w7N%aleax@mail.comcast.net> Mike Meyer wrote: ... > A third alternative is to split once, then split the substrings a > second time and stitch the results back together: > > >>> sum([x.split('_') for x in mystr.split()], []) > ['this', 'NP', 'is', 'VL', 'funny', 'JJ'] > > Which is probably slow. To bad extend doesn't take multiple arguments. Using sum on lists is DEFINITELY slow -- avoid it like the plague. If you have a list of lists LOL, DON'T use sum(LOL, []), but rather [x for x in y for y in LOL] Alex From codecraig at gmail.com Tue Oct 4 08:46:27 2005 From: codecraig at gmail.com (Java and Swing) Date: 4 Oct 2005 05:46:27 -0700 Subject: Swig and Python Message-ID: <1128429987.357140.111280@f14g2000cwb.googlegroups.com> I am trying to wrap some C code I have. Currently I have something like... defs.h ----------- typedef unsigned long MY_DIGIT; myapp.c ------------- void MakeDigits(MY_DIGIT digits[]) { .... } char* GetString(char *inMessage, MY_DIGIT *digit) { char *results; ... ... return results; } ...ok so my interface for swig looks like.. %module MyApp %{ #include "math.h" %} extern void MakeDigits(MY_DIGIT digits[]); extern char* GetString(char *inMessage, MY_DIGIT *digit); %include "cpointer.i" %pointer_functions(MY_DIGIT, digit_array); %include "cmalloc.i" %malloc(int); %free(int); ...Ok, so I have a couple questions. 1) How would I call MakeDigits from python? In the C code I would normally have something like... MY_DIGIT tmp[10]; MakeDigits(tmp); 2) How would I call GetString? Again, in C I would have... char *ptr; char msg[100] = "Hello World"; MY_DIGIT x = 98; ptr = GetString(msg, x); 3) Did I define MY_DIGIT correctly in my SWIG interface file? 4) If I try the following Python code... x = new_digit_array() print x then Python.exe dies...any idea? thanks for the help. I am trying to find my answers int he SWIG docs...either i haven't found it or I didn't understand when I came across it. thanks in the mean time. From shawn.kelley at oracle.com Thu Oct 20 17:46:08 2005 From: shawn.kelley at oracle.com (Shawn Kelley) Date: Thu, 20 Oct 2005 16:46:08 -0500 Subject: network installations Message-ID: <43581020.2020502@oracle.com> Hi All - I am working on a project that requires Python be installed on multiple Windows servers. I was wondering if anyone knew of a method/utility/script that can push the installation of Python to multiple networked servers from a centralized location. Thanks in advance! -shawn -------------- next part -------------- A non-text attachment was scrubbed... Name: shawn.kelley.vcf Type: text/x-vcard Size: 346 bytes Desc: not available URL: From *firstname*nlsnews at georgea*lastname*.com Mon Oct 17 23:11:24 2005 From: *firstname*nlsnews at georgea*lastname*.com (Tony Nelson) Date: Tue, 18 Oct 2005 03:11:24 GMT Subject: Stripping ASCII codes when parsing References: Message-ID: <*firstname*nlsnews-F61EFA.23113517102005@news.verizon.net> In article , David Pratt wrote: > This is very nice :-) Thank you Tony. I think this will be the way to > go. My concern ATM is where it will be best to unicode. The data after > this will go into dict and a few processes and into database. Because > input source if not explicit encoding, I will have to assume ISO-8859-1 > I believe but could well be cp1252 for most part ( because it says no > ASCII (0-30) but alright ASCII chars 128-254) and because most are > Windows users. Am thinking to unicode after stripping these characters > and validating text, then unicoding (utf-8) so it is unicode in dict. > Then when I perform these other processes it should be uniform and then > it will go into database as unicode. I think this should be ok. Definitely "".translate() then unicode(). See the docs for "".translate(). As far as charset, well, if you can't know in advance you'll want to have some way to configure it for when it's wrong. Also, maybe 255 is not allowed and should be checked for? ________________________________________________________________________ TonyN.:' *firstname*nlsnews at georgea*lastname*.com ' From fredrik at pythonware.com Mon Oct 31 09:36:29 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 31 Oct 2005 15:36:29 +0100 Subject: Tkinter problem References: <1130761580.552145.167340@z14g2000cwz.googlegroups.com> Message-ID: "dale cooper" wrote: > I've recently installed python2.4.2 on Fedora 4 (from downloaded > sources), but it appeared, that I can't use Tkinter module: > >>>> import Tkinter > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/local/lib/python2.4/lib-tk/Tkinter.py", line 38, in ? > import _tkinter # If this fails your Python may not be configured > for Tk > ImportError: libBLT24.so: cannot open shared object file: No such file > or directory this seems to indicate that the build process picked up the Tk BLT extension [1], but that you haven't installed that extension properly. 1) http://sourceforge.net/projects/blt/ From kent37 at tds.net Fri Oct 28 14:56:01 2005 From: kent37 at tds.net (Kent Johnson) Date: Fri, 28 Oct 2005 14:56:01 -0400 Subject: OEM character set issue In-Reply-To: References: <1130507709.2923814103422110fb7a08568f0eb060@meganetnews2> Message-ID: <43627216$1_3@newspeer2.tds.net> Dennis Lee Bieber wrote: > On Fri, 28 Oct 2005 15:55:56 +0200, "Ladv?nszky K?roly" > declaimed the following in comp.lang.python: > > >>On my hungarian Win2k, some of the accented characters of the file names >>appear incorrectly when Python is driven from the command line. However, >>they > > > The "MS-DOS" command window tends to use a different character > encoding than full "Windows" widgets. You can chaneg the encoding used by the command window with the chcp command. Kent From mcfletch at rogers.com Fri Oct 7 12:53:42 2005 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Fri, 07 Oct 2005 12:53:42 -0400 Subject: Merging sorted lists/iterators/generators into one stream of values... In-Reply-To: <1128667968.421469.180910@g47g2000cwa.googlegroups.com> References: <1128667968.421469.180910@g47g2000cwa.googlegroups.com> Message-ID: <4346A816.4080603@rogers.com> Lasse V?gs?ther Karlsen wrote: >Ok, that one looks more sleak than what I came up with. > >Couple of things I learn from your solution, please correct me if I >misunderstood something: > >1. list containing other lists will sort itself based on first element >on lists inside ? > > Correct, comparison is recursive for lists/tuples. >2. sort(), pop() is not costly operations > > They *can* be costly, but the algorithm reduces the number of times they are called to less-than-linear for all but pathological cases (i.e. they are only called when you need to switch streams). It also only requires sorting only the number of streams, rather than the whole set. >Other than that you seem to not use the cmp operator but that's easily >fixed. > > Sorry about that, revised version below: def firstIter( value ): it = iter( value ) try: return it.next(), it except StopIteration, err: return None, None def cmpFirstWith( comparison ): def compare( a,b ): return comparison(a[0],b[0]) return compare def inorder( comparison, *args ): iterators = [ [value,it] for (value,it) in [ firstIter( arg ) for arg in args ] if it is not None ] iterators.sort() while iterators: yield iterators[0][0] try: value = iterators[0][0] = iterators[0][1].next() except StopIteration, err: iterators.pop(0) else: if len(iterators) > 1 and comparison( value, iterators[1][0]) == 1: iterators.sort( cmpFirstWith( comparison ) ) continue if __name__ == "__main__": s1 = [10, 20, 30, 40, 50] s2 = [15, 25] s3 = [17, 27, 37] s4 = [] for value in inorder(cmp, s1, s2, s3, s4): print value s1 = [{'a':'b'}, {'a':'e'}] s2 = [{'a':'d'}, {'a':'z'}] def comp( a,b ): return cmp( a['a'],b['a']) for value in inorder(cmp, s1, s2 ): print value Have fun, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From frithiof.jensen at die_spammer_die.ericsson.com Tue Oct 25 05:04:08 2005 From: frithiof.jensen at die_spammer_die.ericsson.com (Frithiof Andreas Jensen) Date: Tue, 25 Oct 2005 11:04:08 +0200 Subject: more than 100 capturing groups in a regex References: <1130160675.270886.208420@z14g2000cwz.googlegroups.com> <1130225565.592108.197670@z14g2000cwz.googlegroups.com> Message-ID: "Joerg Schuster" wrote in message news:1130225565.592108.197670 at z14g2000cwz.googlegroups.com... > Some people, when confronted with a problem, think "I know, > I'll use regular expressions." Now they have two problems. > --Jamie Zawinski Thanks for the citation. If my goal had been to redesign my program, I would not ask questions about regular expressions. I do not have the time to redesign my program. And knowing that my situation would be better, if I had written other code in the past, does not help me at all. Experience shows that, in any project, there is always time redo what was not made properly the first time a deadline was dreamed up. I just want to use more than 100 capturing groups. If someone told me that it is very unlikely for Python to get rid of the said limitation, I would recode part of my program in C++ using pcre. See!? There *is* Time. From anil.pundoor at gmail.com Mon Oct 3 03:27:08 2005 From: anil.pundoor at gmail.com (anil.pundoor at gmail.com) Date: 3 Oct 2005 00:27:08 -0700 Subject: bwidget problem Message-ID: <1128324428.810654.157880@f14g2000cwb.googlegroups.com> hi i tried installing the bwidget lib . but while running the demo script am getting following error. python sam.py Traceback (most recent call last): File "sam.py", line 1, in ? import bwidget, Tkinter, sys, os File "/usr/local/lib/python2.2/site-packages/bwidget/__init__.py", line 149, in ? class _Frame: File "/usr/local/lib/python2.2/site-packages/bwidget/__init__.py", line 152, in _Frame getframe = makeswidget(getframe, Tkinter.Frame) File "/usr/local/lib/python2.2/site-packages/bwidget/__init__.py", line 74, in makeswidget return _wrap(w, f) File "/usr/local/lib/python2.2/site-packages/bwidget/__init__.py", line 59, in _wrap oldfunc.func_name, wrapper.func_defaults, wrapper.func_closure) TypeError: function() takes at most 4 arguments (5 given) can u plz help me From fredrik at pythonware.com Tue Oct 4 03:58:36 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 4 Oct 2005 09:58:36 +0200 Subject: cgi relay for python cgi script References: <1128411305.541560.90790@g44g2000cwa.googlegroups.com> Message-ID: Amir Michail wrote: > Is there an easy way to execute a python cgi script on a different > machine from the cgi server? http://www.google.com/search?q=reverse+proxy From steven.bethard at gmail.com Tue Oct 11 16:41:37 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Tue, 11 Oct 2005 14:41:37 -0600 Subject: Class property In-Reply-To: References: <42C7E766869C42408F0360B7BF0CBD9B01CD75BE@pnlmse27.pnl.gov> Message-ID: Laszlo Zsolt Nagy wrote: > class A(object): > cnt = 0 > a_cnt = 0 > def __init__(self): > A.cnt += 1 > if self.__class__ is A: > A.a_cnt += 1 > class B(A): > pass > print A.cnt,A.a_cnt # 0,0 > b = B() > print A.cnt,A.a_cnt # 1,0 > a = A() > print A.cnt,A.a_cnt # 2,1 > > But then, I may want to create read-only class property that returns the > cnt/a_cnt ratio. > This now cannot be implemented with a metaclass, because the metaclass > cannot operate on the class attributes: Huh? Every function in the metaclass takes the class object as the first parameter. So they can all operate on the class attributes: py> class A(object): ... cnt = 0 ... a_cnt = 0 ... def __init__(self): ... A.cnt += 1 ... if self.__class__ is A: ... A.a_cnt += 1 ... class __metaclass__(type): ... @property ... def ratio(cls): ... return cls.a_cnt/float(cls.cnt) ... py> class B(A): ... pass ... py> A.cnt, A.a_cnt (0, 0) py> A.ratio Traceback (most recent call last): File "", line 1, in ? File "", line 11, in ratio ZeroDivisionError: float division py> b = B() py> A.cnt, A.a_cnt, A.ratio (1, 0, 0.0) py> a = A() py> A.cnt, A.a_cnt, A.ratio (2, 1, 0.5) STeVe From *firstname*nlsnews at georgea*lastname*.com Sat Oct 29 17:42:23 2005 From: *firstname*nlsnews at georgea*lastname*.com (Tony Nelson) Date: Sat, 29 Oct 2005 21:42:23 GMT Subject: Any Pythonic GTK Undo library? References: <*firstname*nlsnews-62BA42.13375929102005@news.verizon.net> Message-ID: <*firstname*nlsnews-C26D19.17423729102005@news.verizon.net> In article , Dave Cook wrote: > On 2005-10-29, Tony Nelson <*firstname*nlsnews at georgea*lastname*.com> wrote: > > > I'm looking for a "pythonic" GTK Undo library/class. It would have a > > You might ask the authors of Kiwi if they plan to add undo/redo. Or help > them add it if you can. > > http://www.async.com.br/projects/kiwi/ > Well, after I implement it myself, if I do, I could give them the code to port to kiwi. > It would be great to have this feature in the Gtk C API, though. I do see > some relevant bugzilla entries: > > http://bugzilla.gnome.org/show_bug.cgi?id=316551 > > You might want to make a new request for a general undo/redo interface. Well, after I implement it myself, if I do, I could give them the code to translate to C. ________________________________________________________________________ TonyN.:' *firstname*nlsnews at georgea*lastname*.com ' From larry.bates at websafe.com Tue Oct 11 11:17:32 2005 From: larry.bates at websafe.com (Larry Bates) Date: Tue, 11 Oct 2005 10:17:32 -0500 Subject: how to execute .exe file ? In-Reply-To: <1129040197.719729.22460@g44g2000cwa.googlegroups.com> References: <1129040197.719729.22460@g44g2000cwa.googlegroups.com> Message-ID: <434BD78C.9030900@websafe.com> There are several ways. The easiest is to use os.system('program.exe') If you require more control on the output, etc. take a look at popen and the new subprocess modules. A more complex method that is mostly for Windows GUI applications and allows finer grain control over window size, environment, etc. is the win32process.CreateProcess module which is part of the win32 extensions by Mark Hammond. This requires a bit more work, but gives you control over almost every aspect of a Windows GUI application window at startup. -Larry Bates quiteblack at gmail.com wrote: > hi all~ > > i used to drive .exe file working by writing a simple batch file, i > thin python may do this as well bu i dunno how to, any help ? > From jepler at unpythonic.net Thu Oct 20 20:34:02 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Thu, 20 Oct 2005 19:34:02 -0500 Subject: nested escape chars in a shell command In-Reply-To: <1129841626.103053.104800@g47g2000cwa.googlegroups.com> References: <1129666159.791998.134880@g49g2000cwa.googlegroups.com> <1129841626.103053.104800@g47g2000cwa.googlegroups.com> Message-ID: <20051021003402.GA16725@unpythonic.net> I think you're mistaken about how 'sh -c' works. The next argument after "-c" is the script, and following arguments are the positional arguments. (what, you've never used -c in conjunction with positional arguments? me either!) Example: ------------------------------------------------------------------------ $ /bin/sh -c 'echo $#' a b c # i.e., a blank line $ /bin/sh -c 'echo $# 0=$0 1=$1 2=$2' a b c 2 0=a 1=b 2=c # i.e., a, b, c went to positional arguments ------------------------------------------------------------------------ Additionally, unless pexpect.spawn behaves differently than os.spawnv, "-c" is actually going to /bin/sh's argv[0], and you end up trying to execute /usr/bin/ssh as a shell script, which is probably not what you want! ------------------------------------------------------------------------ def shellquote(arg): # shell quoting technique I first read about on the 'git' development list # Everything is safely quoted inside a ''-quoted string, except a ' itself, # which can be written as '\'' (a backslash-escaped ' outside of the ''-quoted # string) return "'" + arg.replace("'", "'\\''") + "'" def shellquotelist(args): return " ".join([shellquote(arg) for arg in args]) # XXX: you may wish to assemle 'command' using shellquotelist too command1 = shellquotelist(['/bin/sh', '-c','/usr/bin/ssh','-t','-o', 'StrictHostKeyChecking no',host,command]) command2 = shellquotelist(['awk','{print %s:$0}'%host]) child = \ pexpect.spawn('/bin/sh', args=['/bin/sh', '-c', command1 + "|" + command2], timeout=30) ------------------------------------------------------------------------ Finally, in your case the use of awk would seem to be gratuitous. Instead, prepend the hostname to each line when you read the lines in. (this could easy or hard depending on the structure of the code where you read the output generated by child---if you do it with readline() or by iterating over the file, it is probably easy) Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From mwm at mired.org Fri Oct 21 13:20:58 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 21 Oct 2005 13:20:58 -0400 Subject: Set an environment variable References: <43573022$0$155$edfadb0f@dread16.news.tele.dk> <1129798724.366618.194650@g44g2000cwa.googlegroups.com> <43589205$0$125$edfadb0f@dread16.news.tele.dk> <11lhv31li8sgm0c@corp.supernews.com> Message-ID: <86ll0mu6px.fsf@bhuda.mired.org> Grant Edwards writes: > On 2005-10-21, Christian wrote: >>> >>> The closest thing you can do is that: >>> >>> -myScript.py-------------------------------------- >>> print 'export MY_VARIABLE=value' >>> -------------------------------------------------- >>> >>> -myScript.sh-------------------------------------- >>> python myScript.py > /tmp/chgvars.sh >>> . /tmp/chgvars.sh >>> -------------------------------------------------- > > Bullshit. Are people being intentionally misleading?? No. Are you being intentionally - never mind. > And even Google knows the correct answer > > http://www.google.com/search?hl=en&lr=&q=python+set+environment+variable > > Follow the first hit. The first hit is basically the solution presented above translated from Unix to Windows: your python script writes the appropriate shell commands into a file, then you get the command processor to process that file. The Windows version carries this a step further by wrapping it all up in a script to make it easy to run, but that's the only real difference. Maybe the results order has changed since you looked? Watch the recipe - I may add a Unix/sh solution. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From dave at pythonapocrypha.com Wed Oct 19 23:24:17 2005 From: dave at pythonapocrypha.com (Dave Brueck) Date: Wed, 19 Oct 2005 21:24:17 -0600 Subject: destroy your self???? In-Reply-To: <1129778080.444432.115690@g14g2000cwa.googlegroups.com> References: <1129776816.148308.210460@g44g2000cwa.googlegroups.com> <1129778080.444432.115690@g14g2000cwa.googlegroups.com> Message-ID: <43570DE1.7050701@pythonapocrypha.com> KraftDiner wrote: > Well I guess what I'm trying to achive is the invalidate the instance > of the object. > I have been using None to denote an invalide or uninitialized instance > of an object. > > There is a degenerate case in my code where a polygon has less than 3 > points and > I want to class to flag this instance of the object as invalid. > > so.. like super.self = None :) > In Python, variables don't "hold" values - variables are just named references to objects: x = 5 # x refers to the 5 integer object x = 'hi' # now x refers to the string object By reassigning a name to something else, that's all you're doing - ever other reference to that object will still be intact. If you were able to flag the degenerate case, code that uses the object would have to check for it, right? That being the case, the same code could just as easily test a member function. Better yet, if you can catch this case at the point when the object is created, just throw an exception or at least perform the test at that point only. From __peter__ at web.de Tue Oct 4 10:40:32 2005 From: __peter__ at web.de (Peter Otten) Date: Tue, 04 Oct 2005 16:40:32 +0200 Subject: email module, redirecting to stdout References: Message-ID: Just wrote: >> smtplib obtains a copy of stderr by >> from sys import stderr > Ouch. I'd consider this a bug. "from sys import stderr" should at least > be considered bad style. I'd rather say this is the low-tech equivalent to debug = logging.getLogger("smtplib").debug an approach which is currently only taken by the cookielib module. Peter From jepler at unpythonic.net Tue Oct 4 17:11:15 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Tue, 4 Oct 2005 16:11:15 -0500 Subject: how to get any available port In-Reply-To: References: Message-ID: <20051004211115.GC29124@unpythonic.net> Apparently, calling bind() with a zero "port" will choose some available port number, as demonstrated by this program: import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(("", 0)) print s.getsockname() Here's how it behaved over several runs: $ python soc.py ('0.0.0.0', 34205) $ python soc.py ('0.0.0.0', 34206) $ python soc.py ('0.0.0.0', 34207) I don't know for sure whether this is standard behavior for sockets, or whether it's a special behavior of linux. 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 at flash-gordon.me.uk Wed Oct 12 18:58:25 2005 From: spam at flash-gordon.me.uk (Flash Gordon) Date: Wed, 12 Oct 2005 23:58:25 +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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <036lk15rkocgpjjlbdl11vsr82tkrc4bmn@4ax.com> Message-ID: Roedy Green wrote: Can all of you please take comp.lang.c out of this thread (and all its sub-threads, since it is totaly off topic and NONE of the people on this thread are posting to anything else on comp.lang.c so I doubt any of you are reading it here. -- Flash Gordon Living in interesting times. Although my email address says spam, it is real and I read it. From mwm at mired.org Thu Oct 13 11:08:24 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 13 Oct 2005 11:08:24 -0400 Subject: Jargons of Info Tech industry References: <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <868xx3m2ve.fsf@bhuda.mired.org> <86irw6l1mc.fsf@bhuda.mired.org> <86r7aqugmk.fsf@bhuda.mired.org> Message-ID: <86irw1v4if.fsf@bhuda.mired.org> Roedy Green writes: > On Thu, 13 Oct 2005 01:32:03 -0400, Mike Meyer wrote > or quoted : >>That won't prevent phishing, that will just raise the threshhold a >>little. The first hurdle you have to get past is that most mail agents >>want to show a human name, not some random collection of symbols that >>map to a unique address. Even if you do that, most readers aren't >>going to pay attention to said random collection of symbols. Given >>that, there are *lots* of tricks that can be used to disguise the >>signed name, most of which phishers are already using. How many people >>do you think will really notice that mail from "John Bath, PayPal >>Customer Service Representative" (john.barth at paypa1.com) isn't really >>from paypal? > > I think it better than you imagine. > > First of all Mr. Phish will come in as a new communicant begging an > audience. That is your first big clue. PayPal is already allowed in. That's your first big clue. You've got two problems, though. 1) An as yet unspecified mechanism that magically approves everyone that you want to talk to. That's a big lump to swallow. It's also not an easy problem - all existing mechanisms for approving people require constant attention. Casual users aren't going to put up with that. 2) What makes you think your average user will realize this? It only takes a few percent to make it worth the phishers time. > Next if Thawte issues certs, they won't allow Phish names such as > Paypol.com just as now for other certs. So they'll do what their web sites do now, and sign their own certs. > Mr. Phish is coming in on a different account. Different from what? And how does the user get told about this, and what will make them care? > Next Mr. Phish had to present his passport etc when he got his Thawte > ID. Now Interpol has a much better handle on putting him in jail. Not if he didn't have to go to Thawte. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From gene.tani at gmail.com Thu Oct 20 07:05:52 2005 From: gene.tani at gmail.com (gene tani) Date: 20 Oct 2005 04:05:52 -0700 Subject: Python vs Ruby In-Reply-To: <1129801104.502548.300340@g47g2000cwa.googlegroups.com> References: <1129801104.502548.300340@g47g2000cwa.googlegroups.com> Message-ID: <1129806352.731422.183700@f14g2000cwb.googlegroups.com> http://blog.ianbicking.org/ruby-python-power.html 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://www.jvoegele.com/software/langcomp.html http://reflectivesurface.com/weblog/2004/12/19/why-rails http://martinfowler.com/bliki/CollectionClosureMethod.html http://onestepback.org/articles/10things http://www.cincomsmalltalk.com/userblogs/avi/blogView?showComments=true&entry=3284695382 http://www.tbray.org/ongoing/When/200x/2005/08/27/Ruby http://pleac.sourceforge.net/ http://dev.rubycentral.com/faq/rubyfaq-2.html beza1e1 wrote: > Depends on your experience. If you know C,C++,Java and the whole From chris.cavalaria at free.fr Fri Oct 7 06:46:01 2005 From: chris.cavalaria at free.fr (Christophe) Date: Fri, 07 Oct 2005 12:46:01 +0200 Subject: "no variable or argument declarations are necessary." In-Reply-To: References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <3qi8erFf252rU1@uni-berlin.de> <3qkdbrFfgga9U1@uni-berlin.de> <3qkn7qFffkl6U1@uni-berlin.de> <3qkr1hFfgj5uU1@uni-berlin.de> <7xr7ax690j.fsf@ruckus.brouhaha.com> <1128676408.129888.297840@g14g2000cwa.googlegroups.com> Message-ID: <434651f4$0$11145$626a14ce@news.free.fr> Roy Smith a ?crit : > There's more to it than just that. Python's type checking is not just not > done at compile time, it's done as late in run time as possible. One might > call it just-in-time type checking. It's more of a "Nearly too late" type checking I would say. Not that I complain but it would be great if there were also some automatic type checking to catch a few errors as soon as possible. From fredrik at pythonware.com Mon Oct 10 07:13:31 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 10 Oct 2005 13:13:31 +0200 Subject: Changing an AST References: <1128941690.030540.258790@g43g2000cwa.googlegroups.com> Message-ID: "beza1e1" wrote: > I have such a statement as string: "distance = x**2 + y**2" > x and y are undefined, so it is no executable Python code, but it is > parseable. Now i'd like traverse through the AST and change Name('x') > for the value i have elsewhere. And finally let Python resolve the > computation. you can use the parser class for this purpose: http://www.effbot.org/librarybook/parser.htm instead of manipulating the parse tree, you can use the AST to identify the variables, create a dictionary with the current values, and use exec or eval to evaluate it. or you can use a regular expression to dig out all variable names. or you can compile the expression and analyze the code object to find the variable names, and use the dictionary/exec approach: >>> expr = compile("distance = x**2 + y**2", "", "exec") >>> expr.co_varnames ('distance',) >>> list(set(expr.co_names) - set(expr.co_varnames)) ['y', 'x'] >>> context = {"x": 10, "y": 20} >>> exec expr in context >>> context["distance"] 500 (the regular expression approach is probably the only one that's guaranteed to work on all python implementations) From davbrow at gmail.com Thu Oct 13 02:33:21 2005 From: davbrow at gmail.com (davbrow at gmail.com) Date: 12 Oct 2005 23:33:21 -0700 Subject: how to make this code faster In-Reply-To: <1129183717.183243.100540@g49g2000cwa.googlegroups.com> References: <1129183717.183243.100540@g49g2000cwa.googlegroups.com> Message-ID: <1129185201.650334.262680@g47g2000cwa.googlegroups.com> It looks like you're using Numeric for your arrays, but you are then pulling sin from the math module and calculating one point at a time. Instead try using sin(whole array) where sin is a ufunc from the Numeric module. Also, it's usually not good practice to "import Numeric as *". Instead try import Numeric as N so it's clear which functions you are using. -- David From pmartin at snakecard.com Fri Oct 21 14:55:56 2005 From: pmartin at snakecard.com (Philippe C. Martin) Date: Fri, 21 Oct 2005 18:55:56 GMT Subject: how to modify text in html form from python Message-ID: <0Ra6f.5050$q%.616@newssvr12.news.prodigy.com> Hi, I am trying to change the data in a form field from python. The following code does not crash but has no effect as if "form" is just a copy of the original html form. Must I recreate the form order to do that ? My point is for the client to be able to re-read the modified data. Thanks, Philippe #!/usr/bin/python import cgi import os import sys import logging import cgi sys.stderr = sys.stdout print "Content-type: text/html\n" try: form = cgi.FieldStorage() #logging.warning (form) except: logging.exception("\nEXCEPTION 1") try: form['tosrv'].value = "TEST" except: logging.exception("\nEXCEPTION 2") pass Smart Logon

Smart Logon


TO SERVER:

FROM SERVER

From eternalsquire at comcast.net Mon Oct 17 11:33:46 2005 From: eternalsquire at comcast.net (The Eternal Squire) Date: 17 Oct 2005 08:33:46 -0700 Subject: can a cut-down Python still be Python? In-Reply-To: <1129563032.227240.106670@f14g2000cwb.googlegroups.com> References: <1129531249.605353.204280@f14g2000cwb.googlegroups.com> <1129548481.197637.122710@g47g2000cwa.googlegroups.com> <1129563032.227240.106670@f14g2000cwb.googlegroups.com> Message-ID: <1129563226.211176.6860@g43g2000cwa.googlegroups.com> Oops, I meant to say BDFL. Sorry about the transpose. From roy at panix.com Sun Oct 2 14:21:28 2005 From: roy at panix.com (Roy Smith) Date: Sun, 02 Oct 2005 14:21:28 -0400 Subject: Virgin keyword (Was: Will python never intend to support private, protected and public?) References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xd5mstqab.fsf@ruckus.brouhaha.com> <7xzmpwuxd0.fsf@ruckus.brouhaha.com> <20050930075313.67b9b676.jk@ospaz.ru> <7xbr2a6dlz.fsf@ruckus.brouhaha.com> <7xk6gyoibc.fsf@ruckus.brouhaha.com> <433f56a3.2969039483@news.oz.net> <1128274267.064255.306980@f14g2000cwb.googlegroups.com> Message-ID: "El Pitonero" wrote: > Python's lack of Java-style "private" surely has its drawback: name > collisions can happen. But, that's just one side. Name collisions are > allowed in many dynamic languages, where you can override the default > system behavior (in some languages, you can override/intercept the > assignment operator "=", or even the "if" statement and the "while" > loop.) Sure, in these very dynamic languages you can ACCIDENTALLY > override the default system behavior. How many Python programmers have > once upon a time done stupid things like: > > list = 3 > > , without realizing that list() is a Python function? This type of > accidental overriding DOES happen. Similarly, in large and complicated > Python projects, name collision (even for "self._x" type of private > members) CAN happen, and I am sure it has happened for some people. I think everybody would agree that accidentally overwriting a name because you didn't realize it was defined in an enclosing context is a Bad Thing. The classic (C++/Java) solution has been to have classes protect their members from outside exposure. I wonder if a better solution would be to have the protection applied from the other end? Imagine if we had a "virgin" keyword which could modify the assignment statement to assert that the name being assigned to was not currently in use. Thus virgin x = y would be treated sort of as if it had been written (ignore, for the moment, the possible side effects of the extra eval of x) try: x except NameError: throw ChastityError else: x = y This would provide you protection from stomping on names by accident, but it would allow you to stomp all you wanted if you wanted to. From kay.schluehr at gmx.net Sat Oct 8 05:03:04 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 8 Oct 2005 02:03:04 -0700 Subject: Merging sorted lists/iterators/generators into one stream of values... References: <1128667968.421469.180910@g47g2000cwa.googlegroups.com> <1128691708.c6930b5cb9f3673ed3abe8755178d163@teranews> <1128692196.410209.252100@g14g2000cwa.googlegroups.com> <1128695317.c6a5acb3e62787f011310c96f0c7cc35@teranews> <1h439qe.pz7c451jcec6hN%aleax@mail.comcast.net> Message-ID: <1128762184.908604.267760@g14g2000cwa.googlegroups.com> Alex Martelli wrote: > try it (and read the Timbot's article included in Python's sources, and the > sources themselves)... Just a reading advise. The translated PyPy source pypy/objectspace/listsort.py might be more accessible than the corresponding C code. Kay From jgrahn-nntq at algonet.se Wed Oct 12 13:43:18 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 12 Oct 2005 17:43:18 GMT Subject: Converting C++ array into Python References: Message-ID: On Wed, 12 Oct 2005 11:13:52 -0500, Larry Bates wrote: > Like others, without more information on what you have tried we are > just guessing. Many times I've used the struct.unpack() module to > unpack C "arrays" into python objects. In that case, it sounds like you make yourself depend on the memory layout of those C arrays -- generally a very bad thing to do. > Don't know if this will help, > but thought I'd pass it along. Post some code and we can help more. Yes. Or at least tell us what the /type/ of that array is. I assume it's 'Foo thearray[]', in which case you usually would return it as a Python list of whatever Python data structure you encode a Foo into -- might be a tuple, or an integer, or a full-blown class of some kind, or ... /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From robin at reportlab.com Mon Oct 17 13:52:19 2005 From: robin at reportlab.com (Robin Becker) Date: Mon, 17 Oct 2005 18:52:19 +0100 Subject: override a property Message-ID: <4353E4D3.4090507@chamonix.reportlab.co.uk> Is there a way to override a data property in the instance? Do I need to create another class with the property changed? -- Robin Becker From chris.cavalaria at free.fr Thu Oct 13 11:21:33 2005 From: chris.cavalaria at free.fr (Christophe) Date: Thu, 13 Oct 2005 17:21:33 +0200 Subject: passing variable arguments to a function In-Reply-To: <1129216706.981025.17750@o13g2000cwo.googlegroups.com> References: <1129216706.981025.17750@o13g2000cwo.googlegroups.com> Message-ID: <434e7b70$0$21056$636a55ce@news.free.fr> Ryan Wilcox a ?crit : > Hello all, > > I want to be able to pass a variable number of parameters into a Python > function. Now, I know how to _receive_ variable arguments, but I don't > know how to _send_ them. > > def myFunction(*args): > print args > > myList = [1, 2, 3, 4] > myFunction(myList) > > this function will print out ([1, 2, 3, 4]). > > Except that's not what I want. I want the equivalent to: > > myFunction(1, 2, 3, 4) > > So, given an array, how can I unpack the array and pass all of the > elements into a Python function as parameters? > > Thanks in advance!, > _Ryan Wilcox > myFunction(*myList) From aleax at mail.comcast.net Mon Oct 31 10:07:26 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Mon, 31 Oct 2005 08:07:26 -0700 Subject: 'super' to only be used for diamond inheritance problems? References: Message-ID: <1h5aedq.ctneln1h28tdfN%aleax@mail.comcast.net> Alex Hunsley wrote: > I've seen a few discussion about the use of 'super' in Python, including > the opinion that 'super' should only be used to solve inheritance > diamond problem. (And that a constructor that wants to call the > superclass methods should just call them by name and forget about super.) > What is people's opinion on this? Does it make any sense? No, it makes no sense whatsoever. Any situation where multiple inheritance is possible, diamonds or no diamonds, can benefit from cooperative superclass calling where needed (e.g., __init__). Consider: class A(B, C): ... should A know or care at all whether B and C share common bases? Of course not -- why should A have to be burdened with that knowledge?! To ensure __init__ is called on each base once and only once, systematically using super(A, self) is the best and simplest way. Another way to put it: there's ALWAYS "meshes" (diamonds or more complicated forms), whenever multiple inheritance occurs, because (in the newstyle object model, and the other one only exists for legacy reasons and shouldn't be used in new code) object is always among the ancestors of EVERY class. So, again: use super. Alex From max at alcyone.com Mon Oct 3 17:36:29 2005 From: max at alcyone.com (Erik Max Francis) Date: Mon, 03 Oct 2005 14:36:29 -0700 Subject: Python based unacceptable language filter In-Reply-To: References: <11k13a57dtm2u0d@news.supernews.com> Message-ID: Andrew Gwozdziewycz wrote: > I think he may be referring to "bad" words, and 'filthy' language. At > least that's what i got from the question. > There are many PHP implementations on the web, which could be adapted > to python fairly easily. Most of which are probably not the most > ideal solution and > involve alot of stuff like > > for n in badwords: > texttofilter.replace(n, '') > > If that's all you need though, maybe it's not so bad. This is a no-op, since it replaces the text, but then discards it. You meant: for badWord in badWords: textToFilter = textToFilter.replace(badWord, '<)!&%(#&)%>') -- 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 anything is sacred, the human body is sacred. -- Walt Whitman From jmeile at hotmail.com Wed Oct 26 15:42:32 2005 From: jmeile at hotmail.com (Josef Meile) Date: Wed, 26 Oct 2005 21:42:32 +0200 Subject: Double replace or single re.sub? In-Reply-To: <1130322073.666179.49350@g44g2000cwa.googlegroups.com> References: <1130322073.666179.49350@g44g2000cwa.googlegroups.com> Message-ID: <435FDC28.7050308@hotmail.com> Hi Iain, > Would this be a quicker/better way of doing it? I don't know if this is faster, but it is for sure more elegant: http://groups.google.ch/group/comp.lang.python/msg/67b8767c793fb8b0 I really like it because of its simplicity an easy use. (Thanks to Fredrik Lundh for the script). However, I suggested it once to replace the approach you suggested in a web application we have, but it was rejected because the person, who benchmarked it, said that it was OK for small strings, but for larger ones performance were an issue. Anyway, for my own applications, performance isn't an issue, so, I use it some times. By the way, the benchmarking, from which I don't have any information, was done in python 2.1.3, so, for sure you will get a better performance with 2.4. Regards, Josef Iain King wrote: > I have some code that converts html into xhtml. For example, convert > all tags into . Right now I need to do to string.replace calls > for every tag: > > html = html.replace('','') > html = html.replace('','') > > I can change this to a single call to re.sub: > > html = re.sub('<([/]*)i>', r'<\1em>', html) > > > Iain > From bonono at gmail.com Thu Oct 20 23:33:02 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 20 Oct 2005 20:33:02 -0700 Subject: fun with lambdas In-Reply-To: References: Message-ID: <1129865582.751679.32440@g44g2000cwa.googlegroups.com> You are asking it to return a list of lambda, not its evaluated value. map(lambda x: f(x,0), [0,1,2]) works. [ f(o) for o in [0,1,2] ] works too. Juan Pablo Romero wrote: > Hello! > > given the definition > > def f(a,b): return a+b > > With this code: > > fs = [ lambda x: f(x,o) for o in [0,1,2]] > > or this > > fs = [] > for o in [0,1,2]: > fs.append( lambda x: f(x,o) ) > > I'd expect that fs contains partial evaluated functions, i.e. > > fs[0](0) == 0 > fs[1](0) == 1 > fs[2](0) == 2 > > But this is not the case :( > > What is happening here? > > > Nevertheless, this code does work > > fs = [ eval("lambda x: f(x,%d)" % o) for o in [0,1,2,3]] > > Thanks. > > Juan Pablo From aahz at pythoncraft.com Mon Oct 10 15:47:53 2005 From: aahz at pythoncraft.com (Aahz) Date: 10 Oct 2005 12:47:53 -0700 Subject: Python's garbage collection was Re: Python reliability References: <7xll11twc2.fsf@ruckus.brouhaha.com> Message-ID: In article , Tom Anderson wrote: > >Has anyone looked into using a real GC for python? I realise it would be a >lot more complexity in the interpreter itself, but it would be faster, >more reliable, and would reduce the complexity of extensions. > >Hmm. Maybe it wouldn't make extensions easier or more reliable. You'd >still need some way of figuring out which variables in C-land held >pointers to objects; if anything, that might be harder, unless you want to >impose a horrendous JAI-like bondage-and-discipline interface. Bingo! There's a reason why one Python motto is "Plays well with others". -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." --Red Adair From lasse at vkarlsen.no Thu Oct 13 10:32:41 2005 From: lasse at vkarlsen.no (=?UTF-8?B?TGFzc2UgVsOlZ3PDpnRoZXIgS2FybHNlbg==?=) Date: Thu, 13 Oct 2005 16:32:41 +0200 Subject: Perl-Python-a-Day: Sorting In-Reply-To: <3r6in8Fi486aU1@uni-berlin.de> References: <1128937897.500935.254770@o13g2000cwo.googlegroups.com> <1129170241.274868.45680@g43g2000cwa.googlegroups.com> <3r6in8Fi486aU1@uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > Diez > > [1] http://xahlee.org/PageTwo_dir/Personal_dir/mi_pixra.html Oh man... Talk about ... bummer. Seriously, who do we call to get someone with a straightjacket to show up at his home? -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From ndbecker2 at gmail.com Tue Oct 11 10:41:25 2005 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 11 Oct 2005 10:41:25 -0400 Subject: Can module access global from __main__? References: Message-ID: Everything you said is absolutely correct. I was being lazy. I had a main program in module, and wanted to reorganize it, putting most of it into a new module. Being python, it actually only took a small effort to fix this properly, so that in B.py, what were global variables are now passed as arguments to class constructors and functions. Still curious about the answer. If I know that I am imported from __main__, then I can do access X as sys.modules[__main__].X. In general, I don't know how to determine who is importing me. From iainking at gmail.com Tue Oct 25 08:17:52 2005 From: iainking at gmail.com (Iain King) Date: 25 Oct 2005 05:17:52 -0700 Subject: more than 100 capturing groups in a regex In-Reply-To: References: <1130160675.270886.208420@z14g2000cwz.googlegroups.com> <1130225565.592108.197670@z14g2000cwz.googlegroups.com> Message-ID: <1130242672.024469.324530@g47g2000cwa.googlegroups.com> Fredrik Lundh wrote: > Joerg Schuster wrote: > > > I just want to use more than 100 capturing groups. > > define "more" (101, 200, 1000, 100000, ... ?) > > The Zero-One-Infinity Rule: http://www.catb.org/~esr/jargon/html/Z/Zero-One-Infinity-Rule.html Iain From chris2k01 at hotmail.com Thu Oct 13 01:56:07 2005 From: chris2k01 at hotmail.com (Chris Head) Date: Thu, 13 Oct 2005 05:56:07 GMT Subject: Jargons of Info Tech industry In-Reply-To: <11krdosli1jgla7@corp.supernews.com> References: <1124804082_1011@spool6-east.superfeed.net> <8q0rk1tiktr86ksdu55mgsqffpkf2uus1c@4ax.com> <11kr5p3hstor935@corp.supernews.com> <11krdosli1jgla7@corp.supernews.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello? I don't think that should make any difference. I should be able to visit absolutely any website on the Internet without any danger to my computer or the data stored on it. Any browser which allows otherwise has a bug. Javascript is not inherently a virus vector. Flawed implementations might be; the language itself is not. Similarly for anything else. In reality, with a properly-configured, good quality operating system (probably a UNIX-type system), one ought to be able to run full native code without any danger to one's computer or data (think: under the NOBODY account on Linux). Just my 1/50th of a dollar. Chris Gordon Burditt wrote: [snip] > Browsers don't read unsolicited web sites. Email readers do, however, > read unsolicited email, and email from downright hostile correspondents. > And I consider "web bugs" and similar tracking methods to be a danger > for something that's supposed to be ONLY "formatted text". [snip] -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (MingW32) Comment: GnuPT 2.7.2 Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDTfb26ZGQ8LKA8nwRAo53AJ4gt1VeSkonnRC0f2eSdwLaJt85CACcDP5+ xVO8Y8uWFRzwY26H4EmmKDo= =178i -----END PGP SIGNATURE----- From mwm at mired.org Thu Oct 27 17:19:44 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 27 Oct 2005 17:19:44 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <66u633-etj.ln1@news.it.uc3m.es> <7xbr1aewtq.fsf@ruckus.brouhaha.com> <86acgulv5z.fsf@localhost.localdomain> <7xvezi8ypy.fsf@ruckus.brouhaha.com> Message-ID: <86y84ehd3j.fsf@bhuda.mired.org> Paul Rubin writes: >> Sorry to be pedantic, but I think it's an important point that no court >> ever found that Microsoft illegally acquired a monopoly. So to characterize >> the monopoly itself as "illegal" is simply erroneous. > > Who is paying you to tell these ridiculous crap? The monopoly is illegal > if maintained by anticompetitive means regardless of how it was acquired. > From http://cyber.law.harvard.edu/msdoj/conclusions-l.html: > > Section 2 of the Sherman Act declares that it is unlawful for a person > or firm to "monopolize . . . any part of the trade or commerce among > the several States, or with foreign nations . . . ." 15 U.S.C. ? 2. > This language operates to limit the means by which a firm may lawfully > either acquire or perpetuate monopoly power. Specifically, a firm > violates sec. 2 if it attains or preserves monopoly power through > anticompetitive acts. > > The threshold element of a sec 2 monopolization offense being "the > possession of monopoly power in the relevant market... Which means that the successful exercise of monopoly power is sufficient to demonstrate the existence of a monopoly. A claim that David Schwartz has never bothered to answer. > David Schwartz, I have a direct question for you: are you on > Microsoft's payroll? I've noticed something strange that makes me wonder the same thing. Everytime someone compares MS's behavior with that of any other criminals, he responds about MS's activity being "equated to that of criminals with guns", and refuses to discuss the issue. Ironically, while no one else has so much as compared MS to criminals with guns - after all, they're white collar criminals - David Schwartz called the DOJ official who were investigating MS "criminals with guns pointed out [MS officers] heads". It seems like he's trying to avoid (further) tarnishing MS's reputation by avoiding having MS associated with other criminals. You have to wonder what could caause that kinnd of behavior. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From fredrik at pythonware.com Mon Oct 17 03:06:02 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 17 Oct 2005 09:06:02 +0200 Subject: can a cut-down Python still be Python? References: <1129531249.605353.204280@f14g2000cwb.googlegroups.com> Message-ID: "The Eternal Squire" wrote: > Regardless of the technical difficulties involved (and I know they are > legion), I am considering developing a very limited subset of Python > fit to run on embedded systems using 80188 or 68332 microchips. My > main question regarding this is: even if I am successful, would the > results be rejected out of hand by y'all as not meeting the Zen of > Python? some blabbermouths will probably reject it, but no matter how you twist words, a subset of Python is indeed a subset of Python. magnus lie hetland's mini-python is a good base to build upon: http://hetland.org/python/mini-python.php From matt.hammond at rd.bbc.co.uk Tue Oct 4 07:06:22 2005 From: matt.hammond at rd.bbc.co.uk (Matt Hammond) Date: Tue, 04 Oct 2005 12:06:22 +0100 Subject: Thread's, async_chat and asyncore References: <1128392080.485892.287770@g43g2000cwa.googlegroups.com> Message-ID: Hi Jos, Have you looked at Kamaelia? Its a project I'm involved in to create a framework for highly concurrent systems, geared particularly for suitability for network server/client applications. A system is built out of many small components, each with their own pseudo-thread of execution (implemented as python generators). They communicate with each other by reading from and sending to local inboxes and outboxes. These are then linked together, causing messages to be passed from component to component. We're hopefully going to be making a new release soon, with some more interesting facilities. A Kamaelia system doing something similar could look something like this: ----code snippet starts---- #!/usr/bin/env python from Axon.Component import component import time import random class PulseGenerator(component): def __init__(self, msg): super(PulseGenerator,self).__init__() self.msg = msg def main(self): # microprocess (generator) t=time.time() while 1: while time.time() < t: yield 1 # hand back control to scheduler t += random.random() self.send( self.msg, "outbox") if __name__ == "__main__": from Kamaelia.Util.Splitter import Plug, PlugSplitter from Kamaelia.Chassis.ConnectedServer import SimpleServer from Kamaelia.Util.passThrough import passThrough from Axon.Scheduler import scheduler producer = PlugSplitter(PulseGenerator("hello!\n")).activate() def newClientHandler(): return Plug(producer, passThrough()).activate() SimpleServer( protocol = newClientHandler, port = 1601 ).activate() scheduler.run.runThreads() ----code snippet ends---- The SimpleServer component uses the factory function 'newClientHandler' to create a component to handle the new client connection. In this case, its a 'plug' component that connects to a splitter component. The purpose of the splitter is to copy output to multiple destinations. In this case, the output comes from a PulseGenerator component. In the above system there's only one producer. To deal with multiple games, I guess you'd have to write a component that handles the initial 'conversation' with the client to establish which game they want to connect to, before then creating the 'plug' component to connect to the appropriate game server. This is of course only one way to do it, and the 'plug' arrangement might not be the best eventual solution. We've also got a lookup-service, called the Co-ordinating Assistant Tracker. It translates name to references to inboxes or outboxes on components. You could, for example, use this service to look up components handling specific games. I'd encourage you to take a look at our project site on sourceforge ( http://kamaelia.sf.net/ ). There's some more introductory material and a tutorial or two which should give you a better idea about the system. We'd be interested to know what you think, and whether you think you could build your application using it. regards Matt -- | Matt Hammond | R&D Engineer, BBC Research & Development, Tadworth, Surrey, UK. | http://kamaelia.sf.net/ | http://www.bbc.co.uk/rd/ From vasilijepetkovic at yahoo.com Fri Oct 21 13:59:23 2005 From: vasilijepetkovic at yahoo.com (vasilijepetkovic at yahoo.com) Date: 21 Oct 2005 10:59:23 -0700 Subject: Help with language, dev tool selection In-Reply-To: <1129915422.693950.97000@g43g2000cwa.googlegroups.com> References: <1129915422.693950.97000@g43g2000cwa.googlegroups.com> Message-ID: <1129917563.001216.294150@g43g2000cwa.googlegroups.com> Further clarification: The pages will have to be pure static html pages (so no datasource will be driving generation of the pages). Therefore, I'd have to create 30,000 files. It's my understanding that almost every host should be able to serve a simple and static html code. Best, Vasa From graham.fawcett at gmail.com Tue Oct 4 11:22:14 2005 From: graham.fawcett at gmail.com (Graham Fawcett) Date: 4 Oct 2005 08:22:14 -0700 Subject: ssh or other python editor In-Reply-To: <1128432388.417194.323400@g44g2000cwa.googlegroups.com> References: <1128430526.531749.68600@g47g2000cwa.googlegroups.com> <1128431721.153846.236930@g43g2000cwa.googlegroups.com> <1128432388.417194.323400@g44g2000cwa.googlegroups.com> Message-ID: <1128439334.705980.311500@g44g2000cwa.googlegroups.com> martijn at gamecreators.nl wrote: > >So you're using Putty to telenet/ssh into the FreeBSD server, but what > >editor on you using on the FreeBSD server? > > I use pico for that. > That Samba isn't available but I can install it. > > Or are there other editors for FreeBSD that I can run with putty ? I use Emacs on my win32 workstation to edit files on my Linux servers via SSH. There are at least two Emacs third-party modules ("modes") -- Tramp and Hobo -- that allow you to edit files over SSH. I use Hobo (never tried Tramp, I think it's for XEmacs anyway). There is a bit of setup. You'll need to use "pageant" and authenticate by RSA/DSA key. See PuTTY's Web site; you may also need to do some Googling to set up agent-based authentication. Note that pageant will make PuTTY authenticate automatically as well, so it's easy to test whether your pageant setup is correct, apart from any Emacs-related issues. You might also need to configure Hobo slightly; email me if you want my configuration details (though I can't help you with the pageant/authentication stuff, so get that done first :-). Once you're done, you can load, edit and save files quite transparently. Not everybody's cup of tea, but there you are. :-) Graham From karczma at info.unicaen.fr Wed Oct 19 05:00:05 2005 From: karczma at info.unicaen.fr (Jerzy Karczmarczuk) Date: Wed, 19 Oct 2005 11:00:05 +0200 Subject: Microsoft Hatred FAQ In-Reply-To: <6u1cl1dvqaac21klrqsoumsoh0ugrbom9e@4ax.com> References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <11l48meji6u4e69@corp.supernews.com> <6u1cl1dvqaac21klrqsoumsoh0ugrbom9e@4ax.com> Message-ID: Roedy Green wrote: > On Wed, 19 Oct 2005 07:10:55 GMT, Alan Connor > wrote or quoted : > > >>To all the shit-for-brains trolls that are polluting these groups >>with this crap, which I haven't even bothered to read: > > > A single thread does not pollute a group. It is trivially easy to > ignore a thread. If your newsreader does not support that feature, > try an different newsreader. The pollution *is* there, despite the possibility of individual screening. The subject and the contents violates some basic nsgroup principles, such as topicality. One to ten irrelevant postings do no harm. More than hundred - become annoying. Cross-posting to 5 groups is bad. Please go away. Claiming that this is an interesting, "great" thread is utterly silly in this context. Shall Python newsgroup discuss the trial of Saddam Hussein as well? Jerzy Karczmarczuk From nephish at xit.net Thu Oct 20 14:12:31 2005 From: nephish at xit.net (nephish at xit.net) Date: 20 Oct 2005 11:12:31 -0700 Subject: need some advice on x y plot In-Reply-To: <4357d998$1_2@newspeer2.tds.net> References: <1129823043.104864.73750@f14g2000cwb.googlegroups.com> <11lfgebn85liq1b@corp.supernews.com> <1129825379.218308.242010@g47g2000cwa.googlegroups.com> <4357d998$1_2@newspeer2.tds.net> Message-ID: <1129831950.926154.196420@g47g2000cwa.googlegroups.com> ok, yeah, thats exactly what i am looking for. i will give it a go. thanks a whole lot. putt this off is a typo, pull this off is what i was meaning to type. this is cool. From martin.kuner at thomson.net Thu Oct 20 12:10:48 2005 From: martin.kuner at thomson.net (mku) Date: 20 Oct 2005 09:10:48 -0700 Subject: Accessing a dll from Python In-Reply-To: <1129814361.130127.255990@f14g2000cwb.googlegroups.com> References: <1129814361.130127.255990@f14g2000cwb.googlegroups.com> Message-ID: <1129824648.628284.52960@g14g2000cwa.googlegroups.com> I used ctypes. It works really fine with DLLs. have a lool at http://starship.python.net/crew/theller/ctypes Martin From http Fri Oct 7 04:47:10 2005 From: http (Paul Rubin) Date: 07 Oct 2005 01:47:10 -0700 Subject: "no variable or argument declarations are necessary." References: <7xu0fucuhi.fsf@ruckus.brouhaha.com> Message-ID: <7xmzll67e9.fsf@ruckus.brouhaha.com> Brian Quinlan writes: > > There is no proposal on the table. There's a discussion of how this > > stuff can work, and whether it's useful. As for how the compiler > > deals with imported modules, see for example Common Lisp or Haskell or > > ML--how do they do it? > > Except that you are providing neither useful input on how it could > work nor on whether it would be useful. All you are doing is telling > people to do research on other languages (that resumably do things in > a way more to your liking). Nah. I just see the import statement as a solved problem. Do it the same way those other languages do. From steve at holdenweb.com Tue Oct 4 05:28:59 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 04 Oct 2005 10:28:59 +0100 Subject: Reply-To header In-Reply-To: <43423EAA.9060600@REMOVEMEcyber.com.au> References: <2ECA6FE9-3C8F-4C60-9E89-70CC078B14EF@gmail.com> <7rc0f.11261$Un.585792@phobos.telenet-ops.be> <86oe66jpfj.fsf@bhuda.mired.org> <43423EAA.9060600@REMOVEMEcyber.com.au> Message-ID: Steven D'Aprano wrote: > Mike Meyer wrote: > > >>When I notice that a list is broken (RFC 2822 says that >>reply-to is for the *author* of the message; anyone else setting it is >>doing so in violation of the RFC, and hence broken, no matter how >>useful it may be), > > > Since when did obeying the RFC become important in and > of itself? If there was a RFC that said that passwords > should be limited to one alphanumeric character, would > we slavishly follow it? > The day such an RFC is published will be the day RFCs stop being useful. Until that time the RFCs are pretty much the guide to desired behaviour on the Internet, and anyone willfully disobeying them is asking for trouble. If an RFC was published saying you should give yourself a kick in the head for such inanity would you do it? ;-) > I have been known to change the reply-to address from > the address I am sending from (me at work for example) to > the address I want the reply to go to (me at home). There > are many times I'm emailing people I know can't cope > with the complicated task of changing the To address of > their reply, so I change the reply-to header so that > their reply goes where I want it to go to (which might > be another email address of mine, or a different > person, or a mailing list). > This is an entirely sensible use of the Reply-To address, and indeed many mail clients nowadays will allow you to set a Reply-To for each of the accounts you create. Having in the past used accounts where the Reply-To was different from the originating address I am only too well aware, though, that there are several email clients and mailing systems that *don't* correctly action Reply-To, and instead respond to the originating address directly. > That's what reply to means, surely? What is the point > of a reply-to header that must be the sender, since you > already have a header that gives you the sender. > Quite. > If the RFC says that the reply-to header doesn't > actually mean the address the reply should go to, but > only the sender, then the RFC is broken. "Where the > reply goes to" is a *human* decision, not a technical > one. If I send you an email saying "Please reply to > president at whitehouse.gov" then your mailer should > honour that (although, since we are all adults, you > should have the freedom to ignore my request and make a > nuisance of yourself by emailing your reply to a > different address). > Of course, few users actually bother to even check whether the address their mailer generates corresponds to anything in the original message, instead blindly relying on their software's behaviour for correctness (see above). > Likewise, if I set the reply address to the list, then > your mailer should reply to the list. Perhaps you can > argue that *my decision* to have replies go to the list > is a bad one, but that's a social issue, not a > technical one. > Most mailers will indeed do this. Except the ones that don't (see above ...). > > >>I tell my mailer to ignore reply-to on mail from >>that list. Similarly, I no longer try and explain to people how long >>lines violate RFCs and are a pain to read in well-behave mail readers, > [...] Having a mailer that can vary its behaviour from one list to another is something that's way beyond 90% of Internet mail users nowadays. Sadly we are talking about a problem that the majority of users don't even understand, happily sending their rich-text and HTML emails to mailing lists/newsgroups as well as individuals. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From nyamatongwe+thunder at gmail.com Fri Oct 7 01:41:10 2005 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Fri, 07 Oct 2005 05:41:10 GMT Subject: When someone from Britain speaks, Americans hear a "British accent"... In-Reply-To: <11kbp7eogjniq4c@corp.supernews.com> References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kbgj7421kd560@corp.supernews.com> <867jcqoxgk.fsf@bhuda.mired.org> <11kbp7eogjniq4c@corp.supernews.com> Message-ID: Grant Edwards: > Where exactly did you see all these > sub-titled British TV/movies? I've noticed this too when travelling but can't recall precise details. Perhaps it is on the international versions of American channels such as CNN which are commonly watched by people with less English and hence less ability to handle accents. Neil From usenet at DavidFilmer.com Wed Oct 26 03:49:03 2005 From: usenet at DavidFilmer.com (usenet at DavidFilmer.com) Date: 26 Oct 2005 00:49:03 -0700 Subject: a Haskell a Day In-Reply-To: <1130312303.713737.160830@g44g2000cwa.googlegroups.com> References: <1130312303.713737.160830@g44g2000cwa.googlegroups.com> Message-ID: <1130312943.717481.217200@g44g2000cwa.googlegroups.com> Xah Lee wrote: > I hope you will join me in learning Haskell. I think the folks here are more interested in Perl. There's a reason why this newsgroup is called lc("comp.lang.PERL.misc"). From rbt at athop1.ath.vt.edu Sat Oct 8 08:36:34 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Sat, 08 Oct 2005 08:36:34 -0400 Subject: socketServer questions In-Reply-To: <7xoe61yoa2.fsf@ruckus.brouhaha.com> References: <1128699247.9040.15.camel@athop1.ath.vt.edu> <7xll15paha.fsf@ruckus.brouhaha.com> <1128718708.7800.2.camel@athop1.ath.vt.edu> <7xoe61yoa2.fsf@ruckus.brouhaha.com> Message-ID: <1128774994.14078.2.camel@athop1.ath.vt.edu> On Fri, 2005-10-07 at 15:07 -0700, Paul Rubinhttp: wrote: > rbt writes: > > The server just logs data, nothing else. It's not private or important > > data... just sys admin type stuff (ip, mac addy, etc.). I just don't > > want some script kiddie discovering it and trying to 'hack' it. By doing > > so, they'd fill the log up with crap. So, If the data doesn't contain x, > > y, and z and if the data is too big or too small, I record it to a > > 'tamper' log and tell the leet hacker to 'go away'. > > Well, rather than this x,y,z stuff, it's best to do it properly and > authenticate the records with the hmac module. Off-topic here, but you've caused me to have a thought... Can hmac be used on untrusted clients? Clients that may fall into the wrong hands? How would one handle message verification when one cannot trust the client? What is there besides hmac? Thanks, rbt From engineuity at gmail.com Tue Oct 4 11:23:47 2005 From: engineuity at gmail.com (Matt Chan) Date: Tue, 4 Oct 2005 11:23:47 -0400 Subject: Python script to install network printers Message-ID: Hi, I am trying to create a python script to install a set of network printers. I have had success using an os.popen statement, using rundll32 and printui.dll. This takes way too long. Can someone point me in a quicker direction? thanks, Matt From gdamjan at gmail.com Tue Oct 25 08:42:21 2005 From: gdamjan at gmail.com (Damjan) Date: Tue, 25 Oct 2005 14:42:21 +0200 Subject: Confused on Kid References: <1128957144_131989@spool6-east.superfeed.net> Message-ID: > I was > investigating each subproject individually and could not, for the life > of me figure out how Kid worked. I understand that it takes a > well-formed XML document and transforms it, but I could not figure out > where it transforms it, or how to transform a document. They have > plenty of template examples, but I'm left say, "What do I do with this?" > I know I can't just pop in it a browser because it has no sort of style > sheet or anything so it would just render as an XML document. What do > you do after you have a kid template? KID is a pythonic template system. The KID templates are well-formed XML files but the generated document can be HTML or even plain text (this should be supported in some of the latest versions). The KID templates have some simple control structures like 'if' and 'for' which are modeled to be similar to python. The way it works is you feed the template some data and it generates HTML documents. The document can have a reference to a CSS file just like any other HTML page. -- damjan From noway at sorry.com Sun Oct 30 14:12:03 2005 From: noway at sorry.com (Giovanni Bajo) Date: Sun, 30 Oct 2005 19:12:03 GMT Subject: Understanding the arguments for SubElement factory in ElementTree References: <1130567974.754511.66930@g14g2000cwa.googlegroups.com> Message-ID: <7W89f.15842$65.462321@twister1.libero.it> mirandacascade at yahoo.com wrote: > > xyz > > > rather than: > root = Element('root') > subroot = SubElement(root, 'subroot') > subroot.text = 'xyz' > > Was wondering whether this code accomplish that > root = Element('root') > subroot = SubElement(root, 'subroot', text='xyz') No, this creates: I believe the text ought to be set in a separate statement. Giovanni Bajo From deets at web.de Fri Oct 7 07:58:52 2005 From: deets at web.de (Diez B. Roggisch) Date: 7 Oct 2005 04:58:52 -0700 Subject: "no variable or argument declarations are necessary." In-Reply-To: References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <3qi8erFf252rU1@uni-berlin.de> <3qkdbrFfgga9U1@uni-berlin.de> <3qkn7qFffkl6U1@uni-berlin.de> <3qkr1hFfgj5uU1@uni-berlin.de> <3qmrd2Ffocu8U1@uni-berlin.de> Message-ID: <1128686332.212150.275360@g43g2000cwa.googlegroups.com> Antoon Pardon wrote: > Then argue against my ideas, and not your makings of it. > > If I just use 'ANY' and you fill that in with C void* like > implementation and argue against that, then you are arguing > against your own ghosts, but not against what I have in mind. Well, you didn't tell us what you had in mind. You just said "let's introduce something like any". I showed you existing implementations of such a concept that have problems. You say "thats not what _I_ have in mind, so your criticism doesn't apply." Guess what, I can't read your mind. But you did not tell me in what your idea is different from existing concepts. > You have not counterd my idea with criticism. You have decorated my > idea with how you think it would be implemented (C void*) and argued > against that. I don't need to give an implementation to notice, that > you jumped to a particular implementation and basicly just countered > that implementation, not the idea in general. Again - where is your idea layed out in (more) detail, so that one can discuss them? That was all that I'm asking - which of course you carefully avoided... > As far as I'm concerned that was just meant as a matter of fact remark, > with no snide intentions. Where exactly come the facts? All I see is some vague "there should be something better, by introducing ANY". But no details how typechecking then would work. I showed you that existing type systems can't properly cope with ANY so far and allow for much errors. Just saying "but mine won't" is a little bit thin, don't you think?l Diez From grante at visi.com Thu Oct 20 13:50:09 2005 From: grante at visi.com (Grant Edwards) Date: Thu, 20 Oct 2005 17:50:09 -0000 Subject: need some advice on x y plot References: <1129823043.104864.73750@f14g2000cwb.googlegroups.com> <11lfltdrulivj6b@corp.supernews.com> Message-ID: <11lfm6hfno9c5ee@corp.supernews.com> On 2005-10-20, Grant Edwards wrote: >> and insert None (or whatever value is used by charting >> package) for times where observations were not taken. This >> will mean that you have to preprocess your data by determining >> a time step step value that will fit your data. If you get 3 >> observations each 10 minutes apart then one an hour later, you >> will need to insert 5 empty observations in the list before >> the last observation. [...] > > That's completely unnecessary. Just pass a set of time,value > pairs and they'll get plotted as desired. For example, here's how gnuplot plots the data 2 12 3 10 4 9 101 8 102 6 103 9 20 ++----------+-----------+-----------+----------+-----------+----------++ + + + + + "foo.dat" A + | | | | | | 15 ++ ++ | | | | |A | | | 10 ++A ++ | A A | | A | | | | A | 5 ++ ++ | | | | | | + + + + + + + 0 ++----------+-----------+-----------+----------+-----------+----------++ 0 20 40 60 80 100 120 Isn't that what you're asking for? -- Grant Edwards grante Yow! ... I have read the at INSTRUCTIONS... visi.com From piet at cs.uu.nl Thu Oct 13 15:49:15 2005 From: piet at cs.uu.nl (Piet van Oostrum) Date: Thu, 13 Oct 2005 21:49:15 +0200 Subject: [Info] PEP 308 accepted - new conditional expressions References: <3q4ro9Fd770nU3@individual.net> <3q6oo1Fddg7eU3@individual.net> <7xr7b5zq31.fsf@ruckus.brouhaha.com> <1129129852.92dc41cf1bd445c448e00bd42ec59500@teranews> Message-ID: >>>>> iddw at hotmail.com (Dave Hansen) (DH) wrote: >DH> So lose the "if." >DH> R = C then A else B >DH> I don't think python uses the question mark for anything. Throw that >DH> in, if it makes parsing easier: >DH> R = C ? then A else B We have already had this discussion several times. I don't think it is going to add anything new to it. Besides after the BDFL has decided it is useless. -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From nephish at xit.net Sun Oct 30 21:48:30 2005 From: nephish at xit.net (nephish at xit.net) Date: 30 Oct 2005 18:48:30 -0800 Subject: need start point for getting html info from web In-Reply-To: <86br16bef2.fsf@bhuda.mired.org> References: <1130724071.688187.59230@g47g2000cwa.googlegroups.com> <86br16bef2.fsf@bhuda.mired.org> Message-ID: <1130726910.798179.248770@g49g2000cwa.googlegroups.com> yeah, i know i am going to have to write a bunch of stuff because the values i want to get come from several different sites. ah-well, just wanting to know the easiest way to learn how to get started. i will check into beautiful soup, i think i have heard it referred to before. thanks shawn From codecraig at gmail.com Tue Oct 4 15:23:37 2005 From: codecraig at gmail.com (Java and Swing) Date: 4 Oct 2005 12:23:37 -0700 Subject: SWIG - python.exe crash Message-ID: <1128453817.543212.320830@g43g2000cwa.googlegroups.com> When I try to print an object in Python, python.exe crashes. Below are my files. defs.h ------------------------------------------------------------------------------------------------------ typedef unsigned long MY_DIGIT; myapp.c ------------------------------------------------------------------------------------------------------ void MakeDigits(MY_DIGIT digits[]) { .... } char* GetString(char *inMessage, MY_DIGIT *digit) { char *results; ... ... return results; } MyApp.i ------------------------------------------------------------------------------------------------------ %module MyApp %{ #include "math.h" %} extern void MakeDigits(MY_DIGIT digits[]); extern char* GetString(char *inMessage, MY_DIGIT *digit); /* allows for the creation of a MY_DIGIT array */ %inline %{ MY_DIGIT *my_digit_array(int size) { return (MY_DIGIT *) malloc(size * sizeof(int)); } %} ...I have two questions. 1) One, I call MakeDigits which should populate the "digits" array with some values. It seems the first time I try it the digits array is populated. Then if I try to re-use the digits array i get some garbage output. But if I recall MakeDigits...I can then re-use the digits array over and over without anymore problems? Any idea? here is how I was trying it... digits = my_digit_array(10) MakeDigits(digits) 2) When I try to print the "my_digit_array" object, python.exe crashes...below is the code I use to cause this problem: (within python) digits = my_digit_array(10) print digits I am using Python 2.4.1, Swig 1.3.25 on Win XP Pro. I tried sending a message on the SWIG mailing list...but so far it hasn't shown up on the list...I've sent it three times now. I'll keep trying. From fqueirolo at gmail.com Tue Oct 4 18:00:26 2005 From: fqueirolo at gmail.com (fqueirolo at gmail.com) Date: 4 Oct 2005 15:00:26 -0700 Subject: Boost.python mingw install on XP Message-ID: <1128463226.753667.157140@z14g2000cwz.googlegroups.com> Hello all I am trying to install boost.python on my XP box. Boost: 1.33.0 Python: 2.4.2 (Final) MinGw: 4.1.1 I try: D:\Dev\boost_1_33_0\libs\python\build>bjam "--prefix=D:\Dev\boosttarget" "-sTOOLS=mingw" "--with-python-root=D:\Dev\Python24" "--with-python" install from a DOS command prompt. Where: D:\Dev\boosttarget is an existing directory mingw/bin is in my System path D:\Dev\Python24 is my python root My pexports output: Python24.a is in C:\WINDOWS\system32 The bjam output is: --------------------------------------------------------------------- *** If you don't need Boost.Python, you can ignore this section *** *** pass --without-python to suppress this message in the future *** skipping Boost.Python library build due to missing or incorrect configuration couldn't find Python.h in "c:/tools/python/include" You can configure the location of your python installation by setting: PYTHON_ROOT - currently "c:/tools/python" PYTHON_VERSION - The 2-part python Major.Minor version number (e.g. "2.2", NOT "2.2.1") - currently "2.2" The following are automatically configured from PYTHON_ROOT if not otherwise set: PYTHON_LIB_PATH - path to Python library object; currently "c:/tools/python/libs" --------------------------------------------------------------------- don't know how to make install ...found 1 target... ...can't find 1 target... I can give you any other system or set up parameters. BTW I specified where my python root is so I have no idea why it can't find Python.h! Thank you very much, Francesco From michael at stroeder.com Tue Oct 25 12:02:47 2005 From: michael at stroeder.com (=?ISO-8859-15?Q?Michael_Str=F6der?=) Date: Tue, 25 Oct 2005 18:02:47 +0200 Subject: Documentation for iteration in mappings In-Reply-To: <435e49b8$1@news.uni-ulm.de> References: <435e49b8$1@news.uni-ulm.de> Message-ID: <7i1233-qcv.ln1@nb2.stroeder.com> Dennis Benzinger wrote: > > I must be blind because I didn't find anything in the documentation > which says iterating over an dictionary iterates over its keys. > > For example > > a_dictionary = {0: "zero", 1: "one"} > for x in a: > print x > > gives you > > 0 > 1 > > Where is this information hidden? :) You should examine your program. Simply pasting the code above to the Python shell fails as expected: $ python Python 2.4.2 (#1, Oct 1 2005, 14:32:09) [GCC 3.3.5 20050117 (prerelease) (SUSE Linux)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a_dictionary = {0: "zero", 1: "one"} >>> for x in a: ... print x ... Traceback (most recent call last): File "", line 1, in ? NameError: name 'a' is not defined >>> Ciao, Michael. From kwright at free-comp-shop.com Wed Oct 19 01:07:42 2005 From: kwright at free-comp-shop.com (Programmer in Chief) Date: 18 Oct 2005 22:07:42 -0700 Subject: Don't bother to read this, it's just Xah Lee again In-Reply-To: <1129675636.740977.151760@z14g2000cwz.googlegroups.com> References: <1129672592.328278.41490@g14g2000cwa.googlegroups.com> <1129675636.740977.151760@z14g2000cwz.googlegroups.com> Message-ID: <1129698462.233695.80860@g14g2000cwa.googlegroups.com> Xah Lee wrote: > Xah Lee wrote: > > > this is of interest to me, That's why you are replying to yourself > I have written a full > page of criticism but the human animal fuckers handily censored it too. Who would have predicted that? Maybe you should boycott them. To those who came to this message looking for pornography, I am sorry for the misleading keywords. Try adding "pictures" to your search terms. There is nothing to see here; just another keyboard wanker. Python, Perl, Lisp, and Scheme all have one thing in common --- the people who use them do not need any more of this drivel. -- Programmer in Chief From darkpaladin79 at hotmail.com Sun Oct 2 12:10:53 2005 From: darkpaladin79 at hotmail.com (Ivan Shevanski) Date: Sun, 02 Oct 2005 12:10:53 -0400 Subject: Class Help In-Reply-To: Message-ID: Thanks everyone for helping me out and tolerating the noob question =D The last part was confusing to me and thanks for explaining it so I get it! -Ivan _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ From my_email_is_posted_on_my_website at munged.invalid Thu Oct 27 08:39:56 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Thu, 27 Oct 2005 12:39:56 GMT Subject: Microsoft Hatred FAQ References: <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> Message-ID: <20i1m19cup3s8hb4ikqti1monvtf9nb3dv@4ax.com> On Thu, 27 Oct 2005 04:06:16 -0700, "David Schwartz" wrote, quoted or indirectly quoted someone who said : > Well shit, how surprising that they wouldn't want to do business with >you if you broke your agreements with them. I am going to summarise this then drop out. My blood pressure is at a boil. I was a computer retailer. We built custom computers. I had 8 people working for me. This was in the time prior to Win95 when IBM had a clearly technically superior solution with OS/2 to MS's Windows 3.1 I had no contract of any kind with MS. I never bought anything from them directly. I was far too small a fish. I bought the components including software through dozens of wholesale suppliers. MS threatened to put any retailer out of business who would not co-operate with them in extorting money from people who had no use for MS Windows who explicitly for various reasons did not want to buy MS windows. To me that is no different from a popsicle manufacturer demanding I sell $200 popsicles with every machine I sold. The machines needed MS Windows no more than they needed a popsicle. The particular way MS threatened to put me out of business was by threatening to arm twist all wholesalers to refuse to sell MS product to me, which any retailer needed to survive in those days. It was obviously quasi legal or the threats would have had paper to back them up so I could go to court now to sue the fuckers. -- Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching. From msoulier at digitaltorque.ca Mon Oct 31 15:46:44 2005 From: msoulier at digitaltorque.ca (Michael P. Soulier) Date: Mon, 31 Oct 2005 16:46:44 -0400 Subject: Python Linked list? In-Reply-To: <001f01c5de4b$65e18880$0201a8c0@LOKI> References: <001f01c5de4b$65e18880$0201a8c0@LOKI> Message-ID: On 10/31/05, Simon Roses Femerling wrote: > I'm looking for a linked list class or lib ? Any suggestions ? I'm not sure anyone would bother making one for Python. Why do you feel that you need one? Are dictionaries and lists not enough? Can you not simply make one via references in a class? class MyNode(object): next = None Should do it, no? Mike -- Michael P. Soulier From harddong at 21cn.net Sun Oct 23 11:09:46 2005 From: harddong at 21cn.net (Gonnasi) Date: Sun, 23 Oct 2005 23:09:46 +0800 Subject: How to separate directory list and file list? Message-ID: <0e9nl1tvvgqlhkahkmrrfc810b3ed1unb6@4ax.com> With >glob.glob("*") or >os.listdir(cwd) I can get a combined file list with directory list, but I just wanna a bare file list, no directory list. How to get it? Tons of thanks in advance! Gonnasi From nephish at xit.net Thu Oct 27 13:26:58 2005 From: nephish at xit.net (nephish at xit.net) Date: 27 Oct 2005 10:26:58 -0700 Subject: how do i run another script from my python script In-Reply-To: References: <1130431172.443751.230730@o13g2000cwo.googlegroups.com> Message-ID: <1130434018.752481.8900@z14g2000cwz.googlegroups.com> man, thats just too easy. thanks much ! From gjohannes at gmail.com Sun Oct 2 11:52:53 2005 From: gjohannes at gmail.com (gjohannes at gmail.com) Date: 2 Oct 2005 08:52:53 -0700 Subject: IDLE dedent/unindent key bindings for non-us keybord? Message-ID: <1128268373.613214.102500@g44g2000cwa.googlegroups.com> Hi. I use Idle 1.1.1 on Python 2.4.1. The "Ctrl-[" and "Ctrl-]" key bindings for indenting do not work on non-us keyboards where brackets are accessed by the "Alt Gr" key. The Tab key seem to work for indenting a selected textblock on my swedish keyboard, but Shift-tab does not dedent as you would have expected. If I try to redefine key bindings in "options->Configure IDLE->Keys" so that Shift-Tab is bound to dedent, things seem to get really weird. After creating a "Custom key set" - the "Ok"-button does not close the options window, I have to use "Cancel" to get out. - Tab does not longer indent selected text, but replaces it with a tab character instead. - Shift->Tab does nothing. - F5 for Run module does nothing and so on. What could be wrong here, and do you have any other suggestions for a "dedent" key binding that may work on a non-us/swedish keyboard (or maybe an alternative editor for python code). Thanks. From m.hadfield at niwa.co.nz Tue Oct 18 06:55:12 2005 From: m.hadfield at niwa.co.nz (m.hadfield at niwa.co.nz) Date: Tue, 18 Oct 2005 18:55:12 +0800 Subject: =?gb2312?B?1NrP+8+iICJ0ZXN0ItbQt6LP1rKhtr4=?= Message-ID: <20051018105536.CD7FC1E4159@bag.python.org> The message contains Unicode characters and has been sent as a binary attachment. From fredrik at pythonware.com Fri Oct 7 10:22:54 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 7 Oct 2005 16:22:54 +0200 Subject: Python interpreter bug References: <1128686833.994339.295780@f14g2000cwb.googlegroups.com><1128692705.964188.5720@z14g2000cwz.googlegroups.com> <1128694071.902605.201440@o13g2000cwo.googlegroups.com> Message-ID: alainpoint at yahoo.fr wrote: > Why is it that a membership test needs to call the __cmp__ method? because the membership test has to check if the tested item is a member of the sequence. if it doesn't do that, it's hardly qualifies as a membership test. from the reference manual: For the list and tuple types, x in y is true if and only if there exists an index i such that x == y[i] is true. From aleax at mail.comcast.net Sat Oct 8 04:28:23 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Sat, 8 Oct 2005 01:28:23 -0700 Subject: Merging sorted lists/iterators/generators into one stream of values... References: <1128667968.421469.180910@g47g2000cwa.googlegroups.com> <1128691708.c6930b5cb9f3673ed3abe8755178d163@teranews> <1128692196.410209.252100@g14g2000cwa.googlegroups.com> <1128695317.c6a5acb3e62787f011310c96f0c7cc35@teranews> Message-ID: <1h439qe.pz7c451jcec6hN%aleax@mail.comcast.net> George Sakkis wrote: > "Lasse V?gs?ther Karlsen" wrote: > > > Thanks, that looks like Mike's solution except that it uses the > > built-in heapq module. > > This make a big difference for the algorithmic complexity; replacing an > item in a heap is much more efficient than sorting the whole list. In the most general case, yes. However, Python's sort ("timsort") is preternaturally fast when sorting sequences that are mostly sorted except for maybe one element being in the wrong place... try it (and read the Timbot's article included in Python's sources, and the sources themselves)... I suspect that heapq will still be faster, but by nowhere as much as one might think. > Yes, it's a little inconvenient that the builtin heap doesn't take a > comparison operation but you can easily roll your own heap by transforming > each item to a (key,item) tuple. Now that I'm thinking about it, it might > be a good addition to the cookbook. I believe Python 2.5 adds a key= argument to heapq's functions... Alex From davids at webmaster.com Thu Oct 27 08:53:28 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 05:53:28 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <1130417205.892409.230580@g14g2000cwa.googlegroups.com> Message-ID: Iain King wrote: > Don't you see how your metaphor doesn't work? No. > It would only be > fitting if Microsoft OWNED the outlet. Huh? > Places which sell Whoppers > are Burger King franchises, so of course they aren't going to sell > Big Mac's. Right. The Burger King corporate franchising agent only sells Whoppers wholesale to franchisees, and to be a franchisee you must agree not to sell competing products. > PC hardware stores do not belong to microsoft. 91% of Burger King restaurants are independently owned and operated. Burger King doesn't own the stores either. > There > just isn't any correlation. Huh? DS From Florian.Lindner at xgm.de Mon Oct 3 12:12:37 2005 From: Florian.Lindner at xgm.de (Florian Lindner) Date: Mon, 03 Oct 2005 18:12:37 +0200 Subject: Graphical debugger/code explorer Message-ID: Hello, in order to understand python code from a larger project (Zope 3) I'm looking for a tool that helps me with that. It should also help What (graphical) application running on Linux can you recommend? Thanks, Florian From sam at email-scan.com Sat Oct 8 19:26:34 2005 From: sam at email-scan.com (Sam) Date: Sat, 08 Oct 2005 18:26:34 -0500 Subject: Daisy Daisy, give me your answer do References: <1128802217.156887.234490@g43g2000cwa.googlegroups.com> <1128807595.122982.310790@o13g2000cwo.googlegroups.com> Message-ID: Xah Lee writes: > Dear Michael Goettsche, > > why don't you lead the pack to be on-topic for a change, huh? Why don't you: 1. Learn how to properly format messages for posting to Usenet, so that your scribblings don't read like stream-of-consciousness babbling (see http://en.wikipedia.org/wiki/Top-posting). 2. Explain why such an important and famous ubergeek like yourself (judging by your web site) has to beg others to write code for him. 3. Make sure the door handle doesn't hit your ass on the way out. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From fredrik at pythonware.com Sun Oct 23 05:22:22 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 23 Oct 2005 11:22:22 +0200 Subject: Syntax across languages References: <1130052687.396109.145420@o13g2000cwo.googlegroups.com> <1130055226.967456.266220@z14g2000cwz.googlegroups.com> Message-ID: bearophileHUGS at lycos.com wrote: > >if you can define the semantics, it's a few lines of code. if you're not > sure about the semantics, a built-in won't help you...< > > I think the language needs a fast built-in version of it. If something > is both inside Mathematica and Ruby, then probably it can be useful in > Python too :-) numpy already has one: http://numeric.scipy.org/numpydoc/numpy-9.html#pgfId-36512 (it's probably there in scipy too, but the scipy docs don't appear to be freely available. hmm...) PIL also has one: http://www.effbot.org/imagingbook/image.htm#image-getdata-method there's also one in Tkinter: >>> import Tkinter >>> Tkinter._flatten(["abc", 1, 2, (3, 4, 5), None, [6, 7, 8, (9,)]]) ('abc', 1, 2, 3, 4, 5, 6, 7, 8, 9) to create a generic version, you have to decide which sequences to treat like sequences, and which sequences you don't want to treat like sequences... From steve at holdenweb.com Sat Oct 8 05:35:18 2005 From: steve at holdenweb.com (Steve Holden) Date: Sat, 08 Oct 2005 10:35:18 +0100 Subject: When someone from Britain speaks, Americans hear a "British accent"... In-Reply-To: <200510071643.11162.hancock@anansispaceworks.com> References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <200510071528.25305.hancock@anansispaceworks.com> <200510071643.11162.hancock@anansispaceworks.com> Message-ID: Terry Hancock wrote: > On Friday 07 October 2005 03:44 pm, Steve Holden wrote: > >>Precisely because there *is* such a thing as a saving. If I buy a $100 >>gumball for $80 I have achieved a saving of 20%. > > > Nope, that's incorrect American. ;-) > > You can say "I bought a $100 gumball for $80, saving 20%," or > "If I buy a $100 gumball for $80, I have achieved a savings of 20%." > > (Although, you lose points for style with "achieved", and those > are awfully expensive gumballs). ;-) > I must have been working at NASA at the time; they are well known for embiggening prices. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From lbolognini at gmail.com Sat Oct 29 21:03:22 2005 From: lbolognini at gmail.com (lbolognini at gmail.com) Date: 29 Oct 2005 18:03:22 -0700 Subject: Automatic binding of **kwargs to variables In-Reply-To: <1130539752.667045.183460@g14g2000cwa.googlegroups.com> References: <1130539752.667045.183460@g14g2000cwa.googlegroups.com> Message-ID: <1130634202.937957.244220@g44g2000cwa.googlegroups.com> Thanks everybody for their reply. I'll see what solution is best for my case and maybe follow up here. Thanks again, Lorenzo From david at jotax.com Tue Oct 25 00:53:14 2005 From: david at jotax.com (David Poundall) Date: 24 Oct 2005 21:53:14 -0700 Subject: Importing at runtime Message-ID: <1130215994.502926.99190@g43g2000cwa.googlegroups.com> I have several .py files in a directory that I would like to import at run time. Each file contains a state machine that requires to be run in its own thread. The first problem I have is how can I import the code in all of the .py files without knowing the file names in advance. Can this be done ?? TIA From martin.witte at gmail.com Sun Oct 2 09:50:23 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 2 Oct 2005 06:50:23 -0700 Subject: how to send a SIGINT to a Python process? In-Reply-To: <1128146541.001784.85350@z14g2000cwz.googlegroups.com> References: <1128146541.001784.85350@z14g2000cwz.googlegroups.com> Message-ID: <1128261023.748355.252190@g14g2000cwa.googlegroups.com> AFAIK there isn't. You could browse through this http://starship.python.net/crew/tmick/ to get an idea on how to kill on both platforms. From *firstname*nlsnews at georgea*lastname*.com Sat Oct 29 13:37:46 2005 From: *firstname*nlsnews at georgea*lastname*.com (Tony Nelson) Date: Sat, 29 Oct 2005 17:37:46 GMT Subject: Any Pythonic GTK Undo library? Message-ID: <*firstname*nlsnews-62BA42.13375929102005@news.verizon.net> I'm looking for a "pythonic" GTK Undo library/class. It would have a framework for Undo/Redo, and would provide Undo/Redo for TextView, Entry, and containers and other classes. In a "batteries included" fashion, just instantiating a "UndoableTextView" or "UndoableEntry" or "UndoableContainer" would provide Undo and Redo in the right-click menu; simply connecting such an object to an "UndoableUIManager" would take care of the stock items in the menus and toolbar; and there would be a simple connection to some sort of "UndoableDocument" interface or mix-in for more global sequencing of Undo/Redo. Does something like this exist for Python or GTK? Googling didn't turn up anything useful. I'm disappointed that GTK doesn't do this already. Making my own seems doable, but a fair amount of work. If there isn't some such thing already, is there interest in using one that I make? I know about GUndo, which doesn't implement any actual undo operations; the actual operations would need to be coded for TextView and Entry and anything else. ________________________________________________________________________ TonyN.:' *firstname*nlsnews at georgea*lastname*.com ' From peter at engcorp.com Mon Oct 3 20:12:45 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 03 Oct 2005 20:12:45 -0400 Subject: Where to find python c-sources In-Reply-To: <43417009$0$15070$ed2619ec@ptn-nntp-reader02.plus.net> References: <433e7898$0$49766$ed2e19e4@ptn-nntp-reader04.plus.net> <43417009$0$15070$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: Michael wrote: > John J. Lee wrote: >>You believe that Tor is dumb enough not to think of searching for >>"socketmodule.c" when, um, searching for socketmodule.c? > > He said he had tried google - OK, not in the first post but early in this > thread - I don't equate that with being dumb - just dumb luck :-) > > Message-ID: > > After all Peter Hansen suggested the search terms "python socketmodule.c" > rather than just "socketmodule.c" > > Message-ID: <5N-dnZny3YyaA6HenZ2dnUVZ_tKdnZ2d at powergate.ca> > > To you the obvious search term was "socketmodule.c" which to me simply means > you're more aligned with Google than Tor :-) Sorry, but this defense is less than weak. Using "python socketmodule.c" you actually get the right answer as the third result, while with the even-more-obvious-to-a-rookie "socketmodule.c" you get it as the *first* result. It would perhaps be fun to experiment to see just how hard it would be to use "socketmodule.c" plus anything else and *not* get the result one was looking for. ;-) (note the wink...) Clearly "Tor" did not try searching Google with two of the most obvious results, but I think at this point he should be considered to be soundly thrashed over the matter and we can all move on. This isn't getting any more interesting... -Peter From jstroud at mbi.ucla.edu Mon Oct 24 22:21:11 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 24 Oct 2005 19:21:11 -0700 Subject: namespace dictionaries ok? In-Reply-To: References: Message-ID: <200510241921.11994.jstroud@mbi.ucla.edu> Here it goes with a little less overhead: py> class namespace: ... def __init__(self, adict): ... self.__dict__.update(adict) ... py> n = namespace({'bob':1, 'carol':2, 'ted':3, 'alice':4}) py> n.bob 1 py> n.ted 3 James On Monday 24 October 2005 19:06, Ron Adam wrote: > Hi, I found the following to be a useful way to access arguments after > they are passed to a function that collects them with **kwds. > > > class namespace(dict): > def __getattr__(self, name): > return self.__getitem__(name) > def __setattr__(self, name, value): > self.__setitem__(name, value) > def __delattr__(self, name): > self.__delitem__(name) > > def foo(**kwds): > kwds = namespace(kwds) > print kwds.color, kwds.size, kwds.shape etc.... > > foo( color='red', size='large', shape='ball', .... etc..) > > > It just seems awkward to have to use "string keys" in this situation. > This is easy and still retains the dictionary so it can be modified and > passed to another function or method as kwds again. > > Any thoughts? Any better way to do this? > > Cheers, Ron -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From onurb at xiludom.gro Wed Oct 12 04:30:05 2005 From: onurb at xiludom.gro (bruno modulix) Date: Wed, 12 Oct 2005 10:30:05 +0200 Subject: Python's Performance In-Reply-To: References: <20051008040614.47429.qmail@web30607.mail.mud.yahoo.com> <43495259$0$29124$626a14ce@news.free.fr> Message-ID: <434cc98e$0$8933$626a14ce@news.free.fr> Alex Stapleton wrote: > > On 9 Oct 2005, at 19:04, Bruno Desthuilliers wrote: > > >> Laszlo Zsolt Nagy a ?crit : (snip) >>> Do you want to know how many internal string operations are done inside >>> the Python interpreter? I believe it is not a useful information. There >>> are benchmarks testing the *real performance* of Python. >>> >>> For example: http://www.osnews.com/story.php?news_id=5602 >>> >> >> A benchmark stating that Python is interpreted is bullshit. >> > Except it is interpreted. What is your point? Nope. It's byte-compiled, just like Java. What do you think those .pyc files are exactly ? -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From aahz at pythoncraft.com Fri Oct 7 19:22:43 2005 From: aahz at pythoncraft.com (Aahz) Date: 7 Oct 2005 16:22:43 -0700 Subject: Matching zero only once using RE References: <1128706522.319929.75310@g49g2000cwa.googlegroups.com> <86ll15nri1.fsf@bhuda.mired.org> Message-ID: In article <86ll15nri1.fsf at bhuda.mired.org>, Mike Meyer wrote: > >I think it's time to form a Committee for the Prevention of Regular >Expression Abuse. 'Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.' --Jamie Zawinski -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." --Red Adair From johnandsarah at estragon.freeserve.co.uk Sun Oct 2 12:37:03 2005 From: johnandsarah at estragon.freeserve.co.uk (John Perks and Sarah Mount) Date: Sun, 2 Oct 2005 17:37:03 +0100 Subject: Will python never intend to support private, protected and public? References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xd5mstqab.fsf@ruckus.brouhaha.com> <7xzmpwuxd0.fsf@ruckus.brouhaha.com> <20050930075313.67b9b676.jk@ospaz.ru> <7xbr2a6dlz.fsf@ruckus.brouhaha.com> <7xk6gyoibc.fsf@ruckus.brouhaha.com> <433f56a3.2969039483@news.oz.net> <7x1x34f85u.fsf@ruckus.brouhaha.com> Message-ID: > 1) Something that fixes the broken name mangling in the current > system, but still doesn't try to defeat intentional unmangling. > Currently, if you have a class with the same name as one of its > superclasses, the name mangling can fail even its existing purpose of > preventing accidental collisions. None of what follows offers any protection against malice, but at least "normal" use will be safe. Are there any other idioms where __dict__s are used as dumping grounds for strange objects, in particular superclasses of that object? (For this to work the instance needs a __dict__; fully __slots__'d objects won't be amenable to it) Instead of mangling in the class name: class C: def __init__(self, x): self.__x = x One could mangle in the class itself: class C: def __init__(self, x): self.__dict__[C, 'x'] = x (and retrieve similarly). Now classes with the same name are still regarded as distict. A variation on this is to have a single __dict__ entry for the class, which refers to another dict, so we would have something like def __init__(self, ...): privates = { } self.__dict__[C] = privates # ... def f(self...): privates = self.__dict__[C] # ... and then get or set privates[varName] as needed. (Or possibly use it lazily via setdefault if you have a good idea of the what the defaults should be.) However this means non-strings end up in dir() which may cause things like map str.upper, dir(C())) to fail. Thus instead of C as the key we could use `id(C)`. The only chance for collision I can see in the `id` solution is if an object changes its __class__, then the old class is GC'd, a new one is loaded with the same address as the old, and the __class__ is changed to (a subclass of) this new one. Frankly __class__ reassignment is fairly esoteric, and already has the question of how well the __dict__ from the old type masquerades as a new one. Other scope for collision: if the classes in question are instances of some mad metaclass which defines == to mean something other than identity testing (is). This would only be needed if the objects weren't just used as types, but also something else as well (e.g. collections of all their instances, implemented via weakrefs). Note that this won't quite work for private data in new classes, as their __dict__ is read-only, but I offer the following peculiar hack: class K(object): __dict__ = {} # ... Any normal accesses to K.__dict__ will reach the wrapping dictproxy object, but K.__dict__['__dict__'] is all yours to play with. If you start by assigning __dict__ to locals() in the class initializer, then writes to K.__dict__['__dict__'] will be visible just through K.__dict__. Whether that's desirable or not depends on you. (locals() isn't what you want if you're creating truly dynamic types via type(names, bases, dict), though.) Paranoid/super-open-minded types might wish to replace accesses to __dict__ here with calls to object.__getattribute__(...,'__dict__') in case any subclasses have strange semantics (which may make perfect sense as far as they're concerned, but still potentially be a problem for you having to second-guess them.) Hope this helps John PS Only slightly relevant: when checking out the possibilties for private attrs on types, I ran up against dictproxies. What need did they meet over plain dicts, why are they read-only (at the Python and CPython level), why are they not instantiable directly (though you can always just create a temporary type and steal its __dict__), and why is type's __dict__ is read-only but a class's isn't? I just have down'n'dirty type dict munging to do, and it seems retrograde that it only works with old (and nominally less flexible) classes. From davids at webmaster.com Wed Oct 26 14:33:28 2005 From: davids at webmaster.com (David Schwartz) Date: Wed, 26 Oct 2005 11:33:28 -0700 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> <3s6l8mFmj3fjU1@individual.net> <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> Message-ID: "Peter T. Breuer" wrote in message news:5am333-iia.ln1 at news.it.uc3m.es... > In comp.os.linux.misc David Schwartz wrote: >> "Peter T. Breuer" wrote in message >> news:0hm233-0ut.ln1 at news.it.uc3m.es... >> I don't know what drugs you're on, but the McDonald's corporation >> most >> certainly is in the business of the wholesale distribution of burger >> patties. One key reason to become a franchisee is to access their >> wholesale >> distribution network. > Then they are not in the wholesale business. So lock the drugs cabinet. > (What they are marketting is a "brand", complete with clowns and > arches, and a secret formula for making up patties in buns). So is Microsoft, except the clowns write the software. When a shop sells machines that ship with Microsoft Windows, it is to some extent the power of Microsoft's brand that brings them into the shop. All I'm saying is that if Microsoft had insisted on exclusive deals to offer Windows at wholesale, that would have been entirely reasonable. Microsoft actually insisted on something less than this. The Windows name is a valuable brand, and advertising it and promoting it got you business. Microsoft doesn't want to see customers drawn in by the power of its brand being switched to competing products. How would the McDonald's corporation feel if you walked into a store because of the pretty golden arches (that in McDonald's opinion, assure the customer of getting quality McDonald's food) and the person at the counter said, "try a Whopper, it's cheaper and tastes better too". There is nothing unusual about wholesale agreements that restrict your ability to sell competing products. DS From qwweeeit at yahoo.it Mon Oct 10 19:54:11 2005 From: qwweeeit at yahoo.it (qwweeeit at yahoo.it) Date: 10 Oct 2005 16:54:11 -0700 Subject: Works only in interactive mode In-Reply-To: <1128985455.433816.8710@g43g2000cwa.googlegroups.com> References: <1128978917.143125.68230@g43g2000cwa.googlegroups.com> <1128985455.433816.8710@g43g2000cwa.googlegroups.com> Message-ID: <1128988451.318485.291240@f14g2000cwb.googlegroups.com> Hi Sam, thank you very much. Your diagnosis was perfect! Bye. From chris at kateandchris.net Mon Oct 24 13:46:40 2005 From: chris at kateandchris.net (Chris Lambacher) Date: Mon, 24 Oct 2005 13:46:40 -0400 Subject: python gc performance in large apps In-Reply-To: <43594BD5.7050104@u20.org> References: <43594BD5.7050104@u20.org> Message-ID: <20051024174640.GB17848@kateandchris.net> A couple of strategic gc.collect() calls can be useful. You can also tweak how the garbage collector gets run by changing settings in the gc module. -Chris On Fri, Oct 21, 2005 at 04:13:09PM -0400, Robby Dermody wrote: > > Hey guys (thus begins a book of a post :), > > I'm in the process of writing a commercial VoIP call monitoring and > recording application suite in python and pyrex. Basically, this > software sits in a VoIP callcenter-type environment (complete with agent > phones and VoIP servers), sniffs voice data off of the network, and > allows users to listen into calls. It can record calls as well. The > project is about a year and 3 months in the making and lately the > codebase has stabilized enough to where it can be used by some of our > clients. The entire project has about 37,000 lines of python and pyrex > code (along with 1-2K lines of unrelated java code). > > Now, some disjointed rambling about the architecture of this software. > This software has two long-running server-type components. One > component, the "director" application, is written in pure python and > makes use of the twisted, nevow, and kinterbasdb libraries (which I > realize link to some C extensions). The other component, the > "harvester", is a mixture of python and pyrex, and makes use of the > twisted library, along with using the C libs libpcap and glib on the > pyrex end. Basically, the director is the "master" component. A single > director process interacts with users of the system through a web and/or > pygtk client application interface and can coordinate 1 to n harvesters > spread about the world. The harvester is the "heavy lifter" component > that sniffs the network traffic and sifts out the voice and signalling > data. It then updates the director of call status changes, and can > provide users of the system access to the data. It records the data to > disk as well. The scalibility of this thing is really cool: given a > single director sitting somewhere coordinating the list of agents, > multiple harvester can be placed anywhere there is voice traffic. A user > that logs into the director can end up seeing the activity of all of > these seperate voice networks presented like a single giant mesh. > > Overall, I have been very pleased with python and the 3rd party > libraries that I use (twisted, nevow, kinterbasdb and pygtk). It is a > joy to program with, and I think the python community has done a fine > job. However, as I have been running the software lately and profiling > its memory usage, the one and only Big Problem I have seen is that of > the memory usage. Ideally, the server application(s) should be able to > run indefinitely, but from the results I'm seeing I will end up > exhausting the memory on a 2 GB machine in 2 to 3 days of heavy load. > > Now normally I would not raise up an issue like this on this list, but > based on the conversations held on this list lately, and the work done > by Evan Jones (http://evanjones.ca/python-memory.html), I am led to > believe that this memory usage -- while partially due to some probably > leaks in my program -- is largely due to the current python gc. I have > some graphs I made to show the extent of this memory usage growth: > > http://public.robbyd.fastmail.fm/iq-graph1.gif > > http://public.robbyd.fastmail.fm/iq-graph-director-rss.gif > > http://public.robbyd.fastmail.fm/iq-graph-harv-rss.gif > > The preceding three diagrams are the result of running the 1 director > process and 1 harvester process on the same machine for about 48 hours. > This is the most basic configuration of this software. I was running > this application through /usr/bin/python (CPython) on a Debian 'testing' > box running Linux 2.4 with 2GB of memory and Python version 2.3.5. > During that time, I gathered the resident and virtual memory size of > each component at 120 second intervals. I then imported this data into > MINITAB and did some plots. The first one is a graph of the resident > (RSS) and virtual memory usage of the two applications. The second one > is a zoomed in graph of the director's resident memory usage (complete > with a best fit quadratic), and the 3rd one is a zoomed in graph of the > harvester's resident memory usage. > > To give you an idea of the network load these apps were undergoing > during this sampling time, by the time 48 hours had passed, the > harvester had gathered and parsed about 900 million packets. During the > day there will be 50-70 agents talking. This number goes to 10-30 at night. > > In the diagrams above, one can see the night-day separation clearly. At > night, the memory usage growth seemed to all but stop, but with the > increased call volume of the day, it started shooting off again. When I > first started gathering this data, I was hoping for a logarithmic curve, > but at least after 48 hours, it looks like the usage increase is almost > linear. (Although logarithmic may still be the case after it exceeds a > gig or two of used memory. :) I'm not sure if this is something that I > should expect from the current gc, and when it would stop. > > Now, as I stated above, I am certain that at least some of this > increased memory usage is due to either un-collectable objects in the > python code, or memory leaks in the pyrex code (where I make some use of > malloc/free). I am working on finding and removing these issues, but > from what I've seen with the help of gc UNCOLLECTABLE traces, there are > not many un-collectable reference issues at least. Yes, there are some > but definitely not enough to justify growth like I am seeing. The pyrex > side should not be leaking too much, I'm very good about freeing what I > allocate in pyrex/C land. I will be running that linked to a memory leak > finding library in the next few days. Past the code reviews I've done, > what makes me think that I don't have any *wild* leaks going on at least > with the pyrex code is that I am seeing the same type of growth patterns > in both apps, and I don't use any pyrex with the director. Yes, the > harvester is consuming much more memory, but it also does the majority > of the heavy lifting. > > I am alright with the app not freeing all the memory it can between high > and low activity times, but what puzzles me is how the memory usage just > keeps on growing and growing. Will it ever stop? > > What I would like to know if others on this list have had similar > problems with python's gc in long running, larger python applications. > Am I crazy or is this a real problem with python's gc itself? If it's a > python gc issue, then it's my opinion that we will need to enhance the > gc before python can really gain leverage as a language suitable for > "enterprise-class" applications. I have surprised many other programmers > that I'm writing an application like this in python/pyrex that works > just as well and even more efficiently than the C/C++/Java competitors. > The only thing I have left to show is that the app lasts as long between > restarts. ;) > > > Robby > -- > http://mail.python.org/mailman/listinfo/python-list From list at notmyisp.pl Wed Oct 5 06:54:13 2005 From: list at notmyisp.pl (Tomasz Lisowski) Date: Wed, 05 Oct 2005 12:54:13 +0200 Subject: bug or feature? In-Reply-To: <1128508770.727391.313300@f14g2000cwb.googlegroups.com> References: <1128508770.727391.313300@f14g2000cwb.googlegroups.com> Message-ID: <4343b0d5$1@news.home.net.pl> beza1e1 wrote: > Coming back from a bug hunt, i am not sure what to think of this python > behaviour. Here is a demo program: > > class A: > def __init__(self, lst=[]): > self.lst = lst > > a = A() > b = A() > b.lst.append("hallo") > print a.lst # output: ["hallo"] > > The point seems to be, that lst=[] creates a class attribute (correct > name?), which is shared by all instances of A. So a.lst ist the same > object as b.lst, despite the fact, that object a is different to object > b. > It is an *instance attribute* by nature, since it does not reside in the class object, but only in its instances. The truth is, that a.lst and b.lst point to the same memory object, so it seems to behave much like the class attribute :) It is no more different from the simple fact, that two variables (attributes) may point to the same memory object, like you see below: a = b = [] a.append("hallo") print b #output: ["hallo"] In fact, it is usually a bad practice to assign instance attributes a reference to the compound variable, existing in an external scope. Example: aList = [] class A: def __init__(self, lst): #no default attribute! self.lst = lst a = A(aList) aList.append("hallo") print a.lst #output: ["hallo"] and your default value (, lst=[]) IS such an variable! The bad thing is, that the value of the instance attribute 'lst' (example above) depends on the external variable, which may be independently modified, thus modifying unexpectedly the instance attribute. The safer approach, of course is to write: class A: def __init__(self, lst): #no default attribute! self.lst = lst[:] #take a copy Summing up, is it an error, or a feature? I would say - a feature. Everyone should be aware, that the argument default values are evaluated once, and the same value (memory object) is reused at each instance creation. Best regards, Tomasz Lisowski From fredrik at pythonware.com Tue Oct 11 08:46:22 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 11 Oct 2005 14:46:22 +0200 Subject: Function decorator that caches function results References: <7x4q7rt3yl.fsf@ruckus.brouhaha.com> Message-ID: Tom Anderson wrote: > Okay, a crack at a definition: a closure is a function in which some of > the variable names refer to variables outside the function. And i don't > mean global variables - i mean somebody else's locals; call them 'remote > variables'. in Python, the global variables are someone else's locals. From vvoipio at kosh.hut.fi Sun Oct 9 16:00:04 2005 From: vvoipio at kosh.hut.fi (Ville Voipio) Date: Sun, 9 Oct 2005 23:00:04 +0300 (EEST) Subject: Python reliability Message-ID: I would need to make some high-reliability software running on Linux in an embedded system. Performance (or lack of it) is not an issue, reliability is. The piece of software is rather simple, probably a few hundred lines of code in Python. There is a need to interact with network using the socket module, and then probably a need to do something hardware- related which will get its own driver written in C. Threading and other more error-prone techniques can be left aside, everything can run in one thread with a poll loop. The software should be running continously for practically forever (at least a year without a reboot). Is the Python interpreter (on Linux) stable and leak-free enough to achieve this? - Ville -- Ville Voipio, Dr.Tech., M.Sc. (EE) From my_email_is_posted_on_my_website at munged.invalid Tue Oct 18 22:49:44 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 19 Oct 2005 02:49:44 GMT Subject: Microsoft Hatred FAQ References: <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <867jcbzdw9.fsf@bhuda.mired.org> Message-ID: <4vcbl1dkek9kr86embmgrj70vk945t99ho@4ax.com> On Tue, 18 Oct 2005 11:53:29 -0700, "David Schwartz" wrote or quoted : >The only obligation Microsoft has is to their shareholders. >> >> If you genuinely believe that, you are a psychopath. > > That's almost as convincing as "that's what you think". Taken literally, you think MS has no obligation to obey the law, to its customers, to its employees. I don't think you will find many CEOs espousing those sentiments, though you will in alt.politics.bush from those who have just read their first book outside of school reading and picked an Ayn Rand novel. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From apardon at forel.vub.ac.be Fri Oct 28 05:17:52 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 28 Oct 2005 09:17:52 GMT Subject: Would there be support for a more general cmp/__cmp__ References: Message-ID: Op 2005-10-28, Antoon Pardon schreef : > Op 2005-10-26, Ron Adam schreef : >> > > These are the results. > >: 1000 repeats, 1000 long, 10.061425 secs >: 1000 repeats, 1000 long, 9.544035 secs >: 1000 repeats, 1000 long, 10.450864 secs >: 1000 repeats, 1000 long, 15.566061 secs >: 1000 repeats, 1000 long, 15.776443 secs > > Results on a longer sequence were: > >: 1000 repeats, 10000 long, 146.722443 secs >: 1000 repeats, 10000 long, 139.480863 secs >: 1000 repeats, 10000 long, 152.623424 secs >: 1000 repeats, 10000 long, 224.630926 secs >: 1000 repeats, 10000 long, 228.663825 secs > > The most interesting result of this test is the difference between > cld and cle. IMO this difference is an indication of the cost > that my idea would have on sorting, should it be implemented. > That would be around 2%. I think that is bearable. Especially > since this were very simple routines. The moment the comparison > calculation become heavier, the relative contribution of the > try: except will diminuish. > > If you are concerned about sorting times, I think you should > be more concerned about Guido's idea of doing away with __cmp__. > Sure __lt__ is faster. But in a number of cases writing __cmp__ > is of the same complexity as writing __lt__. So if you then > need a __lt__, __le__, __eq__, __ne__, __gt__ and __ge__ it > would be a lot easier to write a __cmp__ and have all rich > comparisons methods call this instead of duplicating the code > about six times. So you would be more or less forced to write > your class as class cld or cle. This would have a bigger > impact on sorting times than my suggestion. And as an afterthought: Adding __slots__ increased the sorting speed between 7.5 and 9.0% -- Antoon Pardon From gandalf at designaproduct.biz Sat Oct 8 03:49:05 2005 From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy) Date: Sat, 08 Oct 2005 09:49:05 +0200 Subject: Python's Performance In-Reply-To: <20051008040614.47429.qmail@web30607.mail.mud.yahoo.com> References: <20051008040614.47429.qmail@web30607.mail.mud.yahoo.com> Message-ID: <434779F1.9080508@designaproduct.biz> Dave wrote: > Hello All, > > I would like to gather some information on Python's runtime > performance. As far as I understand, it deals with a lot of string > objects. Does it require a lot string processing during program > execution? How does it handle such time-consuming operations? Is there > a way to find out how many string operations (perhaps in the > underlying system) ) it does during program execution? Do you want to know how many internal string operations are done inside the Python interpreter? I believe it is not a useful information. There are benchmarks testing the *real performance* of Python. For example: http://www.osnews.com/story.php?news_id=5602 Les From peter at engcorp.com Thu Oct 27 15:05:28 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 27 Oct 2005 15:05:28 -0400 Subject: help with sending data out the parallel port In-Reply-To: References: Message-ID: David wrote: > I'm wondering if python is capable of fairly precise timing and also sending > data out the parallel port. > > For example ; making a 7.5 KHz square wave come out of one of the data pins > on the printer port. > > I've tried to help myself with this one but searching in the "Python Library > Reference" that installed with my version, [ Python 2.4.1. ] yielded > nothing on the subject of either timing or parallel port. What are you trying to use this for? What kind of jitter does your specification allow? (That is, since you can't get the edge transitions exactly 66.6 microseconds apart all the time, how much variation are you able to handle?) What will happen if, say, once every five or ten seconds the OS hiccups and prevents your task from running for a full second? Doing this kind of high-speed realtime control on a non-realtime operating system is generally difficult or impossible, but it does depend on how precise you need to be, and how "soft" your realtime requirements are. My gut feeling is that you cannot achieve what you want using Python on Windows (or Linux!), but it depends on your needs, not my gut. :-) -Peter From dezmodue at gmail.com Mon Oct 17 03:52:01 2005 From: dezmodue at gmail.com (Simone) Date: Mon, 17 Oct 2005 09:52:01 +0200 Subject: Repost: Text not showing up In-Reply-To: <434FADFA.8050302@gmail.com> References: <434FADFA.8050302@gmail.com> Message-ID: <43535821.20108@gmail.com> Simone wrote: >Hi all, I am new to python and trying to write a simple GUI that would >call 2 growisofs processes (dvd burning) at the same time, and retrive >the exit code to be printed on a text box (couldn't find any program >that could use multiple dvd burners, not even k3b). Excuse me if this is >really a simple problem, but two days of googling didn't help. > The program is really simple, I developed the GUI using glade and it >works. >The only thing I would like to improve is that I'd like it to show in >the text boxes messages like "Waiting for use input" or "Burning dvd >please wait", but it looks like even though I don't have any error, the >message won't show up until the burning process is finished (showing >either "burning successfully" or "an error occurred"). >I am not sure I made myself clear on this, but I will post the relevant >code trying to explain it: > >import os, sys >import gtk.glade > >class DVD: > > > def __init__(self): > print "Initializing the Graphic User Interface: This may take >some time" > self.xml=gtk.glade.XML("./dvd2.xml") > self.window=self.xml.get_widget("dvd") > self.xml.signal_connect('on_quit_clicked', self.Quit) > self.xml.signal_connect('on_burn_clicked', self.Burn) > >self.OrdKeys=["comboentry1","entry1","spinbutton1","entry2","esitotext","esitotext1"] ># here esitotext is the box I want the text to show up > > > > def Quit(self, *args): > gtk.mainquit() > > def Burn(self, *args): > > comand="" > comand2="" > > name=self.xml.get_widget("entry1").get_text() #name >for the dvd > path=self.xml.get_widget("comboentry1").get_text() #path to >dvd AUDIO_TS and VIDEO_TS > num=self.xml.get_widget("spinbutton1").get_text() #chosing >the number of dvd to burn > pub=self.xml.get_widget("entry2").get_text() >#publisher > self.xml.get_widget("esitotext").set_text("Waiting for >input") # THIS NEVER SHOWS UP > > > dvd1="/dev/hda" # this is the first dvd >burner, edit as needed > dvd2="/dev/hdc" # this is the second dvd >burner, edit as needed > > > > comand+="growisofs -dvd-compat -Z "+dvd1+" -dvd-video -V >"+name+" -publisher "+pub+" "+path > comand2+="growisofs -dvd-compat -Z "+dvd2+" -dvd-video -V >"+name+" -publisher "+pub+" "+path > > > if num == "1": > self.xml.get_widget("esitotext").set_text("Burning the dvd, >please wait") # THIS NEVER SHOWS UP, unless i have an error and >the program > > # quits >before executing the command > self.xml.get_widget("esitotext").show() > # don't know if this is correct, >but it doesn't work either > f = os.popen(comand, 'r') > line = f.readline() > > error_in_prog = f.close() > if error_in_prog: > error=str(error_in_prog) > self.xml.get_widget("esitotext").set_text("An error >occurred. Burn not completed") # THIS COMES UP as it should > self.xml.get_widget("esitotext").show() > else: > self.xml.get_widget("esitotext").set_text("Burn >completed successfully") # THIS COMES UP as it should > self.xml.get_widget("esitotext").show() > > >if __name__=='__main__': > main=DVD() > gtk.main() > > >Any comment, help, url, really appreciated. > >Have a nice day >Simone > > > > > From larry.bates at websafe.com Mon Oct 3 17:05:37 2005 From: larry.bates at websafe.com (Larry Bates) Date: Mon, 03 Oct 2005 16:05:37 -0500 Subject: Convert hex to string In-Reply-To: <1128370840.468590.27030@o13g2000cwo.googlegroups.com> References: <1128370840.468590.27030@o13g2000cwo.googlegroups.com> Message-ID: It contains non-printing and non-ASCII characters so it can't be printed lie you want. The best Python can do is to show you the hexadecimal of those bytes (as it has done). Printable ASCII characters lie in the range 32 decimal (20 hex) to 125 decimal (7F hex). Those characters in that range are shown properly. Example: There is no printable ASCII character for the first character which is \x01. My ASCII table shows that this character represents an ASCII SOH (start of heading) character. -Larry Bates Java and Swing wrote: > I have some output stored in a string that looks like.. > > >>>x > > '\x01\xee\x1eo\xc3+\x8b\x83\xfad\xf6E\xaa\x0ea/I\x96\x83\xf5G\xa3\rQ\xfcH\xee\r' > > > According to, http://docs.python.org/lib/typesseq-strings.html, this is > "Unsigned Hexidecimal (lowercase)". How can I get this into normal > Ascii so that I can read it? > > thanks. > From andreas.zwinkau at googlemail.com Sun Oct 23 09:00:03 2005 From: andreas.zwinkau at googlemail.com (beza1e1) Date: 23 Oct 2005 06:00:03 -0700 Subject: Syntax across languages In-Reply-To: References: <1130052687.396109.145420@o13g2000cwo.googlegroups.com> Message-ID: <1130072403.157932.147930@z14g2000cwz.googlegroups.com> >>> id("blub") -1210548288 This is not identity in a mathematical view. def identity(x): return x It has is uses. I had some kind of parser and had a dict like this: {case: function, ...} It had to be a dict, because i wanted to dynamically add and remove cases. In some cases nothing had to be done. To represent this in the dict a identity function is needed. There surely are other ways, but identity was the most expressive in my eyes. Nice read, by the way. Thanks for sharing ;) From lidenalex at yahoo.se Tue Oct 11 01:56:39 2005 From: lidenalex at yahoo.se (Alex) Date: 10 Oct 2005 22:56:39 -0700 Subject: Batteries Included? Message-ID: <1129010199.291968.142720@g47g2000cwa.googlegroups.com> One of the first things I wanted to do when I start learning Python was to produce a simple standalone application that I could distribute to my users (windows users). Python's moto is "Batteries Included", but where are the batteries for making exe files and making an installer file? I had to download, install and use py2exe and Inno Setup in order to accomplish this. I might be wrong expecting that a language whose moto is "Batteries Included" would be able to produce exe files. Are there plans to do this in the future version of Python? Alex From rschroev_nospam_ml at fastmail.fm Mon Oct 17 07:14:43 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Mon, 17 Oct 2005 11:14:43 GMT Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: John Bokma wrote: > Roel Schroeven wrote: >>But that's not the point; the point is that they have the choice. >>If MS had it its way, they wouldn't have that choice. > > > I doubt that. But even if you're right, do you really think that MS is > the only evil company on earth working like this? Do you really think > that companies like Disney, Sony, Intel, AMD, Apple, etc work any > different? No, I do not think that MS is the only company that uses shady tactics. Also I didn't use the word 'evil', since I think it is too strong for what even MS does. But the fact is that MS is convicted for abusing its monopoly position. >>>>- An application works in IE, Firefox, Konqueror, Safari, Lynx, >>>>Links, Opera, ... -> users can use it with any browser on any OS >>> >>>I think that we both understand that one browser will be more >>>compatible then an other. It will only happen if all use exactly the >>>same render engine, or all web recommendations are frozen. >> >>Thousands and thousands of website work perfectly in all of the >>aforementioned websites right now. > > > Maybe you define perfectly different then me, but have a look at the > Acid tests for example. Even between minor versions of for example > Firefox, or Opera there are differences in rendering. I won't call that > perfectly, but maybe because I am a programmer. Differences in rendering are perfectly acceptable on the World Wide Web. That's one point where web graphics differ from graphics in press. >>>Look at processors: which one would you buy at the moment? AMD? >>>Intel? and if you pick a brand, which type? >> >>Depends on my needs, budget and the specs and price of the available >>offers. Plus I always have a small, admittedly perhaps unjustified, >>preference for the underdog; in the past that was AMD, in the future >>that may very well be Intel. But I don't see the point of that >>question. > > > Others just pick Intel, because it's Intel. The same is happening for > MS. People just buy MS, they don't care that it's cheaper (or maybe > "cheaper") to install Linux + OpenOffice (for example). MS, so it's > good. Popularity is not the same as quality. I still fail to see your point. The original issue was the browser wars. Tim Roberts wondered why Microsoft went through the efforst of dominating the browser market, even if they don't make any money on IE. David Schwartz gave the answer: MS did it to prevent the OS from becoming a commodity, since that would allow users to freely choose their own OS. You seem to be saying that that is not their intention, since users will always prefer Windows as their OS anyhow. Well I don't think so, but just maybe you're right. But I'm pretty sure MS didn't want to take the chance, and did what it did for the reason David gave. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From steve at REMOVETHIScyber.com.au Wed Oct 12 19:12:46 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Thu, 13 Oct 2005 09:12:46 +1000 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <868xx3m2ve.fsf@bhuda.mired.org> <86irw6l1mc.fsf@bhuda.mired.org> Message-ID: On Wed, 12 Oct 2005 21:46:12 +0000, Tim Tyler wrote: > Viruses can mail out change of address messages to everyone in the > compromised machine's address book today. > > Of course, viruses don't bother doing that - since it's stupid and > pointless. > > If you've compromised someone's machine there are typically lots more > rewarding things to do with it than spoof change-of-address notices. Yes. But erasing hard drives is stupid and pointless, and viruses written by digital vandals do exactly that. Viruses *these days* are mostly written by criminals looking to make money, not criminals looking to do the equivalent of smashing your windows and running away. Suppose I wanted to gather industrial espionage about, oh, say Roedy Green. If my virus could impersonate him, I could tell everyone in sight that his email has changed to rgreen at mydomain.ru (or wherever). I would harvest his email, forward it on to him so he doesn't even notice, and sell the data to the highest bidder. Or use it for blackmail. Or sell it to companies who want to buy demographic and purchasing information ("I see he has bought seven books from Amazon this month..."). If you think this is too ridiculous for words, think of this: how valuable to Steve Ballmer and Bill Gates do you think Google's internal emails would be? Information is power, and power makes money. -- Steven. From jwentingathornetdotdemondotnl Sat Oct 15 01:52:57 2005 From: jwentingathornetdotdemondotnl (Jeroen Wenting) Date: Sat, 15 Oct 2005 07:52:57 +0200 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> Message-ID: <11l16dst501kjdd@corp.supernews.com> >> >> Q: Microsoft's Operating System is used over 90% of PCs. If that's >>not monopoly, i don't know what is. > > They got where they are by CHEATING. That is why they are evil, not > because they have a large market share. no, they got their by clever marketing and generally having a product that was easier to use for the average user than anything the competition made and a lot more powerful than other products created for their main target market. Microsoft isn't evil, they're not a monopoly either. If they were a monopoly they'd have 100% of the market and there'd be no other software manufacturers at all. Prices would be far far higher than they are today, like they were back in the days before Microsoft started competing with the likes of Ashton Tate and WordPerfect corporation by offering similar products at 20% the price (which is the real reason they got to be top dog, they delivered a working product for a fraction of the price their competition did, and the competition couldn't drop their prices that much and remain profitable). Without Microsoft 90% of us would never have seen a computer more powerful than a ZX-81 and 90% of the rest of us would never have used only dumb mainframe terminals. IBM's prediction that there would be 5 computers (not counting game computers like the Comodores and Spectrums) by 2000 would likely have come true. From steve at REMOVEMEcyber.com.au Tue Oct 4 05:05:57 2005 From: steve at REMOVEMEcyber.com.au (Steven D'Aprano) Date: Tue, 04 Oct 2005 19:05:57 +1000 Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> Message-ID: <434245F5.6060500@REMOVEMEcyber.com.au> Mike Meyer wrote: > Steven D'Aprano writes: > >>Declared variables have considerable labour costs, and only marginal >>gains. Since the steps you take to protect against other errors will also >>protect against mistyping variables, declarations of variables is of >>little practical benefit. > > > As far as I can tell, this is as much hearsay and personal experience > as the alternate claim that not having them costs you lots of > debugging time and errors. If anyone has pointers to real research > into this area (I've heard the TRAK folks did some, but haven't been > able to turn any up), I'd love to hear it. Sorry, I have no hard research to point to. If I did, I would have referenced it. > My gut reaction is that it's a wash. The time taken to declare > variables in well-written code in a well-designed language - meaning > the declarations and use will be close together - isn't all that > great, but neither are the savings. It isn't the typing time to declare variables, it is the context switching. You're focused on implementing an algorithm, realise you need to declare another variable, your brain does a mini-context switch, you scroll up to the declaration section, you declare it, you scroll back to where you were, and now you have to context switch again. You've gone from thinking about the implementation of the algorithm to thinking about how to satisfy the requirements of the compiler. As context switches go, it isn't as big as the edit-compile-make-run method of testing, but it is still a context switch. Or you just code without declaring, intending to go back and do it later, and invariably forget. [snip] > If I'm going to get compiler support for semantic checking like this, > I want it to serious levels. I want function pre/post conditions > checked. I want loop and class invariant checked. I want subsumption > in my inheritance tree. Nuts - I want a complete, well-designed > inheritance tree. Duck typing is great stuff, but if I'm going to be > doing the work to declare everything, I want *everything* that can be > checked checked. We like to think of programming as a branch of engineering. It isn't, not yet. I've worked for architects who were involved in some major engineering projects. One of the things I learnt is that there are times when you need to specify objects strictly. When only a 5% titanium stainless steel alloy will do, then *only* a 5% titanium stainless steel alloy will do. That's when you want strict type-checking. But the rest of the time, just about any stainless steel will do, and sometimes you don't even care if it is steel -- iron will do the job just as well. If the nail is hard enough to be hammered into the wood, and long enough to hold it in place, it is good enough for the job. That's the real-world equivalent of duck typing. Static typed languages that do all those checks are the equivalent of building the space shuttle, where everything must be specified in advance to the nth degree: it must not just be a three inch screw, but a three inch Phillips head anti-spark non-magnetic corrosion-resistant screw rated to a torque of such-and-such and capable of resisting vaccuum welding, extreme temperatures in both directions, and exposure to UV radiation. For that, you need a compiler that will do what Mike asks for: check *everything*. I don't know whether there are languages that will check everything in that way. If there aren't, then perhaps there should be. But Python shouldn't be one of them. Specifying every last detail about the objects making up the space shuttle is one of the reasons why it costs umpty-bazillion dollars to build one, and almost as much to maintain it -- and it still has a safety record worse than most $10,000 cars. That level of specification is overkill for most engineering projects, and it's overkill for most programming projects too. It is all well and good to tear your hair and rip your clothes over the possibility of the language allowing some hidden bug in the program, but get over it: there is always a trade off to be made between cost, time and risk of bugs. Python is a language that makes the trade off one way (fast development, low cost, high flexibility, moderate risk) rather than another (slow development, high cost, low flexibility, low risk). We make the same trade offs in the real world too: the chair you sit on is not built to the same level of quality as the space shuttle, otherwise it would cost $100,000 instead of $100. Consequently, sometimes chairs break. Deal with it. -- Steven. From deets at web.de Thu Oct 13 08:20:57 2005 From: deets at web.de (Diez B. Roggisch) Date: 13 Oct 2005 05:20:57 -0700 Subject: Setdefault bypasses __setitem__ In-Reply-To: References: <3r6hsnFi3qb8U1@uni-berlin.de> <3r6p5oFhvtg1U1@uni-berlin.de> Message-ID: <1129206057.333744.161010@g47g2000cwa.googlegroups.com> > Are we talking about the same setdefault()? > > > D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D > > There is no per-instance default value just on per call: Oh. You're right. I was somehow under the impression that setdefault is per-instance, so that I can avoid d.get(key, default) and write d[key] instead, for all keys, and get no more KeyErrors. But then you are right of course. Regards, Diez From jstroud at mbi.ucla.edu Sat Oct 8 21:55:06 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sat, 8 Oct 2005 18:55:06 -0700 Subject: Daisy Daisy, give me your answer do In-Reply-To: References: <1128802217.156887.234490@g43g2000cwa.googlegroups.com> <1128807595.122982.310790@o13g2000cwo.googlegroups.com> Message-ID: <200510081855.06066.jstroud@mbi.ucla.edu> On Saturday 08 October 2005 16:26, Sam wrote: > Xah Lee writes: > > Dear Michael Goettsche, > > > > why don't you lead the pack to be on-topic for a change, huh? > > Why don't you: > > 1. Learn how to properly format messages for posting to Usenet, so that > your scribblings don't read like stream-of-consciousness babbling > (see http://en.wikipedia.org/wiki/Top-posting). > Sam: His scribblings *are* babbling, as I am sure you are quite aware. (Your predisposition for congeniality is showing through here.) Formatting would not help...unless, of course, he marks it up with "Rich Backspace Formatting" (RBF). Ideally, he would backspace once for every character. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From peter at engcorp.com Sun Oct 30 23:33:22 2005 From: peter at engcorp.com (Peter Hansen) Date: Sun, 30 Oct 2005 23:33:22 -0500 Subject: Message about not deleted folders using Inno Setup In-Reply-To: References: Message-ID: Martin wrote: > I would like to place a message in an uninstaller window which will > inform the user that some folders haven't been deleted. Is that possible > using > Inno Setup? Probably, but this newsgroup is for discussion of Python. Unless you have some kind of Python angle to your question, a mailing list or something for InnoSetup would be a more appropriate place to ask. -Peter From deets at nospam.web.de Mon Oct 17 15:27:31 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 17 Oct 2005 21:27:31 +0200 Subject: ordered keywords? In-Reply-To: References: Message-ID: <3ric96Fjni97U1@uni-berlin.de> Ron Adam wrote: > > Is there a way to preserve or capture the order which keywords are given? > > >>> def foo(**kwds): > ... print kwds > ... > >>> foo(one=1, two=2, three=3) > {'three': 3, 'two': 2, 'one': 1} > > > I would love to reverse the *args, and **kwds as well so I can use kwds > to set defaults and initiate values and args to set the order of > expressions. > > > def foo(**__dict__, *args): > print args > > print foo(x=10, y=20, x, y, x+y) > [10, 20, 30] This is not simply about reversing the order of kwargs and args - this would require that keyword args would create bindings to variable names in the scope of the caller. Which is an enterily different beast. And a major semantic change in python, so it's not possible or at least not happening before Python 3K. Regards, Diez From pmartin at snakecard.com Wed Oct 26 10:00:09 2005 From: pmartin at snakecard.com (Philippe C. Martin) Date: Wed, 26 Oct 2005 14:00:09 GMT Subject: tool for syntax coloring in html References: <1130330426.059794.282450@g49g2000cwa.googlegroups.com> Message-ID: I use gvim. regards, Philippe Xah Lee wrote: > in some online documentations, for examples: > > http://perldoc.perl.org/perlref.html > http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z-H-17.html > http://www.haskell.org/hawiki/HaskellDemo > > the codes are syntax colored. > > Is there a tool that produce codes in html with syntax coloring? > > Thanks. > > Xah > xah at xahlee.org > ? http://xahlee.org/ From luismgz at gmail.com Tue Oct 4 13:46:10 2005 From: luismgz at gmail.com (Luis M. Gonzalez) Date: 4 Oct 2005 10:46:10 -0700 Subject: New project coming up...stay with Python, or go with a dot net language??? Your thoughts please! In-Reply-To: <1128446202.858491.240700@o13g2000cwo.googlegroups.com> References: <1128428885.390019.304730@g43g2000cwa.googlegroups.com> <1128432576.708995.19060@f14g2000cwb.googlegroups.com> <1128436552.877409.296480@g47g2000cwa.googlegroups.com> <1128446202.858491.240700@o13g2000cwo.googlegroups.com> Message-ID: <1128447970.707787.50050@g47g2000cwa.googlegroups.com> > that Boo isn't enough like Python to > be a kind of Python - not necessarily a criticism, though, but an > observation. This is correct. I completely agree with you and I'm not saying that boo is python. Again, I just said that it could be considered "almost" a static python implementation for .NET. It has many similarities, but also some fundamental differences, therefore, it is a different language. However, I think its similarities make it "pythonic" enough (or closely related to python) to be considered, commented and appreciated by the people in this mailing list. Unfortunately, others disagree with this idea, and insist (over and over again) that Boo is not python or that it has nothing to do with it. From mrbmahoney at gmail.com Fri Oct 21 01:47:21 2005 From: mrbmahoney at gmail.com (B Mahoney) Date: 20 Oct 2005 22:47:21 -0700 Subject: Expat - how to UseForeignDTD References: <1129786744.782887.80130@z14g2000cwz.googlegroups.com> Message-ID: <1129873641.859405.78190@o13g2000cwo.googlegroups.com> I needed to set Entity Parsing, such as parser.SetParamEntityParsing( expat.XML_PARAM_ENTITY_PARSING_ALWAYS ) From anenem at gmail.com Sun Oct 30 14:38:56 2005 From: anenem at gmail.com (robert) Date: Sun, 30 Oct 2005 20:38:56 +0100 Subject: MySQLdb and cgi Message-ID: Dear group, I have a problem with importing MySQLdb in a cgi-script. The code fragment at the beginning: 1 #!/usr/bin/env python 2 3 print "Content-Type: text/html\n\n" 4 5 import re 6 import cgi 7 import MySQLdb 8 print "something" but the print statement in line 8 will never be executed. The Apache error log says: "No module named MySQLdb, referer: http://localhost/sqlForm.html" But when executing the import statement outside of an cgi-script, for example at the command line, the import works fine. I assume, it has something to do with the apache. Why does the python interpreter not find the MySQLdb module when executed in apache context? thanks, roebi -------------- next part -------------- An HTML attachment was scrubbed... URL: From donn at drizzle.com Tue Oct 25 11:29:12 2005 From: donn at drizzle.com (Donn Cave) Date: Tue, 25 Oct 2005 15:29:12 -0000 Subject: Read/Write from/to a process References: <1130163642.868252.148070@g44g2000cwa.googlegroups.com> <1130174259.472124.114790@f14g2000cwb.googlegroups.com> <1130242940.918480.65020@f14g2000cwb.googlegroups.com> <1130245185.304132.110840@g43g2000cwa.googlegroups.com> Message-ID: <1130254148.192702@yasure> Quoth "jas" : | Steve Holden wrote: |> Look at how you might do it in other languages. Then you'll realise this |> isn't (just) a Python problem. | | Yea your right. However, for example, in Java, one can use the Process | class, and then read from the stream until its the end (i.e. -1 is | returned). However, with Python when reading from | subprocess.Popen.stdout ...I don't know when to stop (except for | looking for a ">" or something). Is there a standard, like read until | "-1" or something? Sure, end of file is '', a string with 0 bytes. That means the other end of the pipe has closed, usually due to exit of the other process that was writing to it. Not much help for you there, nor would the Java equivalent be, I presume. Even on UNIX, where pipes are a mainstay of ordinary applications, this one would very likely need a pseudotty device instead, to prevent C library block buffering, and it would still be difficult and unreliable. Ironically the best support I've seen came from a platform that didn't use pipes much at all, VAX/VMS (I put that in the past tense because for all I know it may have evolved in this respect.) The pipe-like VMS device was called a "mailbox", and the interesting feature was that you could be notified when a read had been queued on the device. Donn Cave, donn at drizzle.com From programmer.py at gmail.com Mon Oct 17 11:22:23 2005 From: programmer.py at gmail.com (Jaime Wyant) Date: Mon, 17 Oct 2005 10:22:23 -0500 Subject: Installing Python at Work In-Reply-To: <1129561955.452114.53290@g44g2000cwa.googlegroups.com> References: <1129561955.452114.53290@g44g2000cwa.googlegroups.com> Message-ID: The python interpreter doesn't do anything other than what you tell it. That is, the standard python installation does not install any `secret programs' that run in the background. Like most tools, Python is as benign as it's user. However, unlike most tools even benign users can be powerful. Wow, I just stated somewhat conflicting statements ;) jw On 17 Oct 2005 08:12:35 -0700, Nikola wrote: > I'm currently learning Python for my own use. > I'm considering installing it on a work laptop, knowing that it is > non-licensed, distributable software. > > However, does it access communication ports? I know the company checks > their ports regularly for activity. > > I won't be doing anything very serious; I'm just trying out Python, > learning the basics from 'Learning Python' by O'Reilly. > > -- > http://mail.python.org/mailman/listinfo/python-list > From ncoghlan at gmail.com Wed Oct 26 06:49:20 2005 From: ncoghlan at gmail.com (NickC) Date: 26 Oct 2005 03:49:20 -0700 Subject: Log rolling question References: <1130259387.787107.120740@g14g2000cwa.googlegroups.com> Message-ID: <1130323760.319391.83900@g43g2000cwa.googlegroups.com> If you're on Python 2.4, then consider whether or not you can use a TimedRotatingLogFileHandler from the logging module to handle this for you: http://www.python.org/doc/2.4.1/lib/node344.html Of course, that only works if defining a "month" as 30 days is acceptable. If you genuinely need calendar months, then you still need to do it manually. From mwm at mired.org Sat Oct 29 01:38:21 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 29 Oct 2005 01:38:21 -0400 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <3sf070Fo0klqU1@individual.net> <3sg8hiFmvbo7U1@individual.net> Message-ID: <864q70evci.fsf@bhuda.mired.org> "Paul Watson" writes: > Here is a better one that counts, and not just detects, the substring. This > is -much- faster than using mmap; especially for a large file that may cause > paging to start. Using mmap can be -very- slow. > > #!/usr/bin/env python > import sys > > fn = 't2.dat' > ss = '\x00\x00\x01\x00' > > be = len(ss) - 1 # length of overlap to check > blocksize = 64 * 1024 # need to ensure that blocksize > overlap > > fp = open(fn, 'rb') > b = fp.read(blocksize) > count = 0 > while len(b) > be: > count += b.count(ss) > b = b[-be:] + fp.read(blocksize) > fp.close() > > print count > sys.exit(0) > > Did you do timings on it vs. mmap? Having to copy the data multiple times to deal with the overlap - thanks to strings being immutable - would seem to be a lose, and makes me wonder how it could be faster than mmap in general. Thanks, http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From grante at visi.com Mon Oct 10 14:34:27 2005 From: grante at visi.com (Grant Edwards) Date: Mon, 10 Oct 2005 18:34:27 -0000 Subject: convert char to byte representation References: <434AB205.8000304@websafe.com> Message-ID: <11kld1jrulcri13@corp.supernews.com> On 2005-10-10, Larry Bates wrote: >> I am trying to xor the byte representation of every char in a string with >> its predecessor. But I don't know how to convert a char into its byte >> representation. This is to calculate the nmea checksum for gps data. > ord(c) gives you decimal representation of a character. While ord(c) is what the OP needs, it doesn't give a decimal represention -- which I guess would be a string like "65" for the ASCII characer "A". What ord() gives you is an integer object with the value of the character [which the hardware stores in binary on all of the platforms I'm aware of]. -- Grant Edwards grante Yow! Hmmm... A hash-singer at and a cross-eyed guy were visi.com SLEEPING on a deserted island, when... From xah at xahlee.org Tue Oct 11 18:58:27 2005 From: xah at xahlee.org (Xah Lee) Date: 11 Oct 2005 15:58:27 -0700 Subject: Python Doc Problem Example: sort() (reprise) In-Reply-To: <1129033426.009136.256600@g47g2000cwa.googlegroups.com> References: <1128937897.500935.254770@o13g2000cwo.googlegroups.com> <1129033426.009136.256600@g47g2000cwa.googlegroups.com> Message-ID: <1129071507.829655.252340@g44g2000cwa.googlegroups.com> Addendum, 200510 Here's further example of Python's extreme low quality of documentation. In particular, what follows focuses on the bad writing skill aspect, and comments on some language design and quality issues of Python. >From the Official Python documentation of the sort() method, at: http://python.org/doc/2.4.2/lib/typesseq-mutable.html, Quote: ?The sort() method takes optional arguments for controlling the comparisons.? It should be ?optional parameter? not ?optional argument?. Their difference is that ?parameter? indicates the variable, while ?argument? indicates the actual value. ?... for controlling the comparisons.? This is a bad writing caused by lack of understanding. No, it doesn't ?control the comparison?. The proper way to say it is that ?the comparison function specifies an order?. ?The sort() and reverse() methods modify the list in place for economy of space when sorting or reversing a large list. To remind you that they operate by side effect, they don't return the sorted or reversed list. ? This is a example of tech-geeking drivel. The sort() and reverse() methods are just the way they are. Their design and behavior are really not for some economy or remind programers of something. The Python doc is bulked with these irrelevant drivels. These littered inanities dragged down the whole quality and effectiveness of the doc implicitly. ?Changed in version 2.4: Support for key and reverse was added.? ?In general, the key and reverse conversion processes are much faster than specifying an equivalent cmp function. This is because cmp is called multiple times for each list element while key and reverse touch each element only once.? When sorting something, one needs to specify a order. The easiest way is to simply list all the elements as a sequence. That way, their order is clearly laid out. However, this is in general not feasible and impractical. Therefore, we devised a mathematically condensed way to specify the order, by defining a function f(x,y) that can take any two elements and tell us which one comes first. This, is the gist of sorting a list in any programing language. The ordering function, being a mathematically condensed way of specifying the order, has some constraints. For example, the function should not tell us x < y and y < x. (For a complete list of these constraints, see http://xahlee.org/perl-python/sort_list.html ) With this ordering function, it is all sort needed to sort a list. Anything more is interface complexity. The optional parameters ?key? and ?reverse? in Python's sort method is a interface complexity. What happened here is that a compiler optimization problem is evaded by moving it into the language syntax for programers to worry about. If the programer does not use the ?key? syntax when sorting a large matrix (provided that he knew in advance of the list to be sorted or the ordering function), then he is penalized by a severe inefficiency by a order of magnitude of execution time. This situation, of moving compiler problems to the syntax surface is common in imperative languages. ?Changed in version 2.3: Support for None as an equivalent to omitting cmp was added.? This is a epitome of catering towards morons. ?myList.sort()? is perfect but Pythoners had to add ?myList.sort(None)? interface complexity just because idiots need it. The motivation here is simple: a explicit ?None? gives coding monkeys a direct sensory input of the fact that ?there is no comparison function?. This is like the double negative in black English ?I ain't no gonna do it!?. Logically, ?None? is not even correct and leads to bad thinking. What really should be stated in the doc, is that ?the default ordering function to sort() is the ?cmp? function.?. ?Starting with Python 2.3, the sort() method is guaranteed to be stable. A sort is stable if it guarantees not to change the relative order of elements that compare equal -- this is helpful for sorting in multiple passes (for example, sort by department, then by salary grade).? One is quite surprised to read this. For about a decade of a language's existence, its sort functionality is not smart enough to preserve order?? A sort that preserves original order isn't something difficult to implement. What we have here is sloppiness and poor quality common in OpenSource projects. Also note the extreme low quality of the writing. It employes the jargon ?stable sort? then proceed to explain what it is, and the latch on of ?multiple passes? and the mysterious ?by department, by salary?. Here's a suggested rewrite: ?Since Python 2.3, the result of sort() no longer rearrange elements where the comparison function returns 0.? ----------- This post is archived at: http://xahlee.org/perl-python/python_doc_sort.html Xah xah at xahlee.org ? http://xahlee.org/ From simon.brunning at gmail.com Wed Oct 19 15:57:00 2005 From: simon.brunning at gmail.com (Simon Brunning) Date: Wed, 19 Oct 2005 20:57:00 +0100 Subject: Yes, this is a python question, and a serious one at that (moving to Win XP) In-Reply-To: <200510191222.14334.jstroud@mbi.ucla.edu> References: <1129574592.754495.72530@g43g2000cwa.googlegroups.com> <1129642964.690532.242710@g49g2000cwa.googlegroups.com> <200510191222.14334.jstroud@mbi.ucla.edu> Message-ID: <8c7f10c60510191257p7e6b936bv@mail.gmail.com> On 19/10/05, James Stroud wrote: > The OP is obviously a troll. Hey - let's not throw the T word around quite so freely. The OP did say that he was switching to Windows "for unfortunate reasons", and that OSX was "not as bad" as Windows. Besides, it is possible to prefer Windows. Odd, but possible. Having moved from Windows to Mac recently myself, I know *I* won't be switching back, but reasonable men can differ. -- Though-clearly-not-differ-with-me-ly y'rs, Simon B. From sam at email-scan.com Sat Oct 1 10:51:26 2005 From: sam at email-scan.com (Sam) Date: Sat, 01 Oct 2005 09:51:26 -0500 Subject: [Info] PEP 308 accepted - new conditional expressions References: <3q4ro9Fd770nU3@individual.net> Message-ID: Leif K-Brooks writes: > Sam wrote: >> And "foo if bar" is Perl-ish; yet, even Perl has the ? : operators. > > What _isn't_ Perl-ish? BASIC? -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From franz.steinhaeusler at gmx.at Wed Oct 5 04:50:00 2005 From: franz.steinhaeusler at gmx.at (Franz Steinhaeusler) Date: Wed, 05 Oct 2005 10:50:00 +0200 Subject: IDLE dedent/unindent key bindings for non-us keybord? References: <1128268373.613214.102500@g44g2000cwa.googlegroups.com> Message-ID: On 2 Oct 2005 08:52:53 -0700, gjohannes at gmail.com wrote: >Hi. > >I use Idle 1.1.1 on Python 2.4.1. > >The "Ctrl-[" and "Ctrl-]" key bindings for indenting do not work on >non-us keyboards where brackets are accessed by the "Alt Gr" key. > >The Tab key seem to work for indenting a selected textblock on my >swedish keyboard, but Shift-tab does not dedent as you would have >expected. > >If I try to redefine key bindings in "options->Configure IDLE->Keys" so >that Shift-Tab is bound to dedent, things seem to get really weird. > >After creating a "Custom key set" >- the "Ok"-button does not close the options window, I have to use >"Cancel" to get out. > I'v seen this also: this must be a bug. Exception in Tkinter callback Traceback (most recent call last): File "C:\Python24\lib\lib-tk\Tkinter.py", line 1345, in __call__ return self.func(*args) File "C:\Python24\lib\idlelib\configDialog.py", line 1197, in Apply self.ActivateConfigChanges() File "C:\Python24\lib\idlelib\configDialog.py", line 1185, in ActivateConfigCh anges instance.ResetKeybindings() File "C:\Python24\lib\idlelib\EditorWindow.py", line 585, in ResetKeybindings self.apply_bindings() File "C:\Python24\lib\idlelib\EditorWindow.py", line 837, in apply_bindings text.event_add(event, *keylist) File "C:\Python24\lib\lib-tk\Tkinter.py", line 1299, in event_add self.tk.call(args) TclError: bad event type or keysym "tab" Exception in Tkinter callback Traceback (most recent call last): File "C:\Python24\lib\lib-tk\Tkinter.py", line 1345, in __call__ return self.func(*args) File "C:\Python24\lib\idlelib\configDialog.py", line 1192, in Ok self.Apply() File "C:\Python24\lib\idlelib\configDialog.py", line 1197, in Apply self.ActivateConfigChanges() File "C:\Python24\lib\idlelib\configDialog.py", line 1185, in ActivateConfigCh anges instance.ResetKeybindings() File "C:\Python24\lib\idlelib\EditorWindow.py", line 585, in ResetKeybindings self.apply_bindings() File "C:\Python24\lib\idlelib\EditorWindow.py", line 837, in apply_bindings text.event_add(event, *keylist) File "C:\Python24\lib\lib-tk\Tkinter.py", line 1299, in event_add self.tk.call(args) TclError: bad event type or keysym "tab" next time, I start: C:\Python24\Lib\idlelib>idle.py error reading package index file C:/Python24/tcl/tix8.1/pkgIndex.tcl: invalid co mmand name "lt}]}" Traceback (most recent call last): File "C:\Python24\Lib\idlelib\idle.py", line 21, in ? idlelib.PyShell.main() File "C:\Python24\lib\idlelib\PyShell.py", line 1355, in main if not flist.open_shell(): File "C:\Python24\lib\idlelib\PyShell.py", line 275, in open_shell self.pyshell = PyShell(self) File "C:\Python24\lib\idlelib\PyShell.py", line 793, in __init__ OutputWindow.__init__(self, flist, None, None) File "C:\Python24\lib\idlelib\OutputWindow.py", line 16, in __init__ EditorWindow.__init__(self, *args) File "C:\Python24\lib\idlelib\EditorWindow.py", line 108, in __init__ self.apply_bindings() File "C:\Python24\lib\idlelib\EditorWindow.py", line 837, in apply_bindings text.event_add(event, *keylist) File "C:\Python24\lib\lib-tk\Tkinter.py", line 1299, in event_add self.tk.call(args) _tkinter.TclError: bad event type or keysym "tab" (On Windows) I discovered, looking in C:\.idlerc\config-keys.cfg there was the entry dedent-region = with an editor you can change it to uppercase: dedent-region = then it works again. HTH -- Franz Steinhaeusler From mwm at mired.org Sun Oct 9 06:43:35 2005 From: mwm at mired.org (Mike Meyer) Date: Sun, 09 Oct 2005 06:43:35 -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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> <7xvf07a1ro.fsf@ruckus.brouhaha.com> <86ll13mlpn.fsf@bhuda.mired.org> Message-ID: <86vf07km20.fsf@bhuda.mired.org> "Dr.Ruud" writes: > Let procmail make all those decisions and transformations for you. I prefer qmail dot-commands. It provides an architecture for controlling the delivery of email, and lets you write the smarts of the mail processing in whatever language you want. > I have a maildir called 'raw' where I keep a copy of all non-spammish > mail. I call mine archives. I also remove duplicate email before it gets to the mailbox. > Copies of the same messages also get delivered in the right mailboxes, > by procmail. Yup, qmail does that for me. > A message that contains only html, is piped though lynx -dump -stdin. I build a bounce message explaing that it wasn't read, and send that back to the sender. > A message containing both HTML and a plain/text-part, is de-mime-d, > leaving only the plain/text-part (unless that part contains only a silly > remark). > Footers and long signatures are limited or even deleted. Etc., etc. (I > like my mail cooked.) I don't do those things. Then again - my mail reader makes deals with them on request. > One of the reasons that I started with Perl, is that I want to rewrite > procmail in Perl. Try qmail - it may solve the problem with a lot less work. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From lasse at vkarlsen.no Fri Oct 28 04:20:01 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Fri, 28 Oct 2005 10:20:01 +0200 Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <1130417205.892409.230580@g14g2000cwa.googlegroups.com> Message-ID: David Schwartz wrote: > Lasse V?gs?ther Karlsen wrote: > > >>David Schwartz wrote: > > >>> Burger King won't let you sell Whoppers or buy their burger >>>patties wholesale no matter what you want to call your store unless >>>you take the whole franchise deal. It's an all-or-nothing package. >>>With very few limits, companies do get to choose how their products >>>are branded, marketed, and sold. > > >>Yes, and that's not what Microsoft has ever done. There have always >>been lots of shops selling Microsoft merchandise without being a >>Microsoft franchise in the sense Burger King shops are. > > > Right, Microsoft imposed a lesser restriction. They allowed you to sell > competing products, but charged you a fee. > > >>That's why I still say your comparison is a bad one. > > > It shows that Microsoft's purportedly draconian restrictions are much > less than restrictions that people don't even bat an eye at. > > DS > > Ok, let me just make my opinion very clear on this and then I'll just leave this thread altogether. I think you are comparing apples and oranges so whatever conclusion you manage to draw from that is in my eyes invalid. It doesn't matter, in my opinion, if you managed to conclude that Microsoft was the saints themselves because, in my opinion, your reasoning is not valid. I'm not saying one way or the other, I'm just picking at your reasoning. To me it sounds like concluding that the prices of RAM will drop because the swallows are flying high this fall. But enough, I'll just leave it. -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From whzhao at gmail.com Wed Oct 5 04:52:41 2005 From: whzhao at gmail.com (Wenhua Zhao) Date: Wed, 05 Oct 2005 16:52:41 +0800 Subject: How to create temp file in memory??? Message-ID: A.T.T Thanks a lot. From bobrien18 at yahoo.com Sat Oct 22 21:25:31 2005 From: bobrien18 at yahoo.com (KraftDiner) Date: 22 Oct 2005 18:25:31 -0700 Subject: Question about inheritance... In-Reply-To: <_My6f.1423$Zd.1063@tornado.tampabay.rr.com> References: <1130017209.078943.119990@g43g2000cwa.googlegroups.com> <_My6f.1423$Zd.1063@tornado.tampabay.rr.com> Message-ID: <1130030731.105360.92200@o13g2000cwo.googlegroups.com> This is what I've got so far: class Shape(object): def __init__(self): pass def render(self): print 'Shape render' self.outline() def outline(self): pass class Rect(Shape): def __init__(self): super(self.__class__, self).__init__() def render(self): super(self.__class__, self).render() def outline(self): print 'Rect outline' r = Rect() r.render() The output: Shape render Rect outline Cool.. I guess its working.. From ron at vnetworx.net Fri Oct 14 12:44:46 2005 From: ron at vnetworx.net (Ron Guerin) Date: Fri, 14 Oct 2005 12:44:46 -0400 Subject: NYLUG meeting: The Python Object Model with Alex Martelli & Google (open bar and food!) Message-ID: <434FE07E.9070005@vnetworx.net> The New York Linux User's Group invites you to a special presentation by Alex Martelli of Google, on the Python Object Model. This presentation will be held at P.J. Clarke's Sidecar, rather than our usual location, and Google is picking up the tab for an hour and a half of open bar and food. Additionally, if you're looking for a job as a Python developer, bring your resume. Please RSVP at http://rsvp.nylug.org to attend, as seating is limited. - Ron (announcement follows) The New York Linux User's Group Presents Alex Martelli - on - The Python Object Model Held at P.J. Clarke's Sidecar 915 Third Avenue @ 55th Street - NY Python is a multi-paradigm programming language, but, out of the paradigms it supports, there is no doubt that OOP (Object Oriented Programming) is the paradigm that forms Python's core. If you have done any substantial programming with Python, you have, most likely, used some of its OOP features. But -- have you ever stopped to really think about those OOP features, the mechanisms that Python uses (and exposes!) to implement them, and how best to make use of the possibilities this state of things offers? This subject is generally known as the "Object Model" of a language. This talk stops a bit short of examining every level of Python's Object Model -- in particular, it does not get into metatypes (metaclasses) and similar levels of "Black Magic". Rather, the talk sticks to the most practically interesting aspects of Python's Object Model as seen from the point of view of a programmer using Python -- understanding exactly what's going on in all kind of everyday OOP-usage situation, what alternatives and trade-offs these mechanisms imply (for example, when should you use closures, and when should you use functors instead? when to inherit, and when to delegate instead?), and how Design Patterns play into the mix (Python subsumes and build-ins some classic DPs, and makes a few others irrelevant due to its highly dynamic typing, but other classic DPs yet remain extremely relevant and important for optimal day to day use of OOP in Python). About Alex Martelli ------------------- Alex Martelli is Uber Technical Lead at Google, in Production Software. He wrote Python in a Nutshell and co-edited the Python Cookbook, and is a member of the Python Software Foundation. Before joining Google, Martelli spent 8 years with IBM, 12 with think3 inc, and 3 as a Python freelance consultant, mostly for AB Strakt (Sweden). P. J. Clarke's Sidecar ---------------------- 915 Third Avenue @ 55th Street - NY Sidecar is PJ Clarkes handsome semiprivate upstairs dining room. You enter Sidecar through a distinct yet discreet door on East 55th Street. Subway: Take the E, V or 6 Subways to 51st Street, cut over to Third Avenue and walk north 4 blocks. Take the 4, 5 or 6 Trains to 59th Street, cut over to Third and walk 4 blocks south. Bus: Take the 101, 102 or 103 Buses to 55th. If you're coming downtown on Lexington, cut across to Third. If you're coming up on Third, it's right across the street. http://pjclarkes.com/htm/sidecar.htm About NYLUG ----------- NYLUG is the New York Linux Users Group, which has met every month without fail for the last six years. Meetings are free and open to the public, but require advance RSVP due to fire code and security requirements at our usual meeting space at the IBM Building. Our announcements mailing list at http://nylug.org/mailman/listinfo/nylug-announce provides a low-volume but steady stream of Linux, Free and Open Source, and related community and other user group announcements for the tri-state area. Our technical discussion list is a moderate-volume list featuring a diverse group that from home users to enterprise security experts. http://nylug.org/mailman/listinfo/nylug-talk http://www.nylug.org/ From qwweeeit at yahoo.it Mon Oct 10 07:10:10 2005 From: qwweeeit at yahoo.it (qwweeeit at yahoo.it) Date: 10 Oct 2005 04:10:10 -0700 Subject: dcop module under Python 2.4 References: <1128639872.036312.76620@g44g2000cwa.googlegroups.com> <3qmopvFfstbiU1@uni-berlin.de> Message-ID: <1128942610.451519.113330@g49g2000cwa.googlegroups.com> Hi Diez, thank you for your replay, but I didn't succeed (I am almost a newbye). So I solved the problem in another manner: I changed distribution from kubuntu to SUSE 9.3 (base installation). Now I can import dcop and also pcop. Bye. From junhua.deng at ericsson.com Thu Oct 27 11:34:45 2005 From: junhua.deng at ericsson.com (Junhua Deng (AL/EAB)) Date: Thu, 27 Oct 2005 17:34:45 +0200 Subject: socket.error: (32, 'Broken pipe'): need help Message-ID: Hi, I have a simple server-client application with threading. It works fine when both server and client on the same machine, but I get the following error message if the server is on another machine: ... ... self.socket.send(outgoingMsg) socket.error: (32, 'Broken pipe') I do not know where to start with? Thanks Junhua From bonono at gmail.com Sun Oct 23 05:48:35 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 23 Oct 2005 02:48:35 -0700 Subject: execution order in list/generator expression In-Reply-To: References: <1130059544.215010.318610@g44g2000cwa.googlegroups.com> Message-ID: <1130060915.165468.241980@o13g2000cwo.googlegroups.com> Ah, no wonder. I test with p=[5,4]. thanks. so basically, I still need to expand it first given this behaviour. Robert Kern wrote: > bonono at gmail.com wrote: > > Hi, > > > > I am wondering how this is evaluated. > > > > a=(x for x in [1,2,3,4]) > > p=[4,5] > > > > c=[x for x in p if x in list(a)] > > > > c is [] > > No it isn't. > > In [1]: a=(x for x in [1,2,3,4]) > > In [2]: p=[4,5] > > In [3]: c=[x for x in p if x in list(a)] > > In [4]: c > Out[4]: [4] > > I'm willing to bet that you used up the 'a' iterator before you ran that > list comprehension, though. > > In [5]: c=[x for x in p if x in list(a)] > > In [6]: c > Out[6]: [] > > Note that "x in list(a)" gets executed on each iteration, but the > iterator is used up on the first time. > > In [7]: a=(x for x in [1,2,3,4]) > > In [8]: p = [4, 5, 2, 3] > > In [9]: c=[x for x in p if x in list(a)] > > In [10]: c > Out[10]: [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 zhu_dave at yahoo.com Tue Oct 11 18:36:05 2005 From: zhu_dave at yahoo.com (Dave) Date: Tue, 11 Oct 2005 15:36:05 -0700 (PDT) Subject: Python name lookups / Interning strings In-Reply-To: <20051010224702.GB31497@unpythonic.net> Message-ID: <20051011223606.89640.qmail@web30611.mail.mud.yahoo.com> --- jepler at unpythonic.net wrote: > lookdict_string is used for most lookups of the form > obj.attr > because they are never found to have non-string keys > entered or searched. > > Furthermore, most of these string keys are > "interned", > which I believe makes the check > if (ep->me_key == NULL || ep->me_key == key) > return ep; > return a result without comparing the contents of > the strings. What exactly does it mean to "intern" a string? Thanks! __________________________________ Yahoo! Music Unlimited Access over 1 million songs. Try it free. http://music.yahoo.com/unlimited/ From my_email_is_posted_on_my_website at munged.invalid Wed Oct 12 17:50:22 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 12 Oct 2005 21:50:22 GMT Subject: Jargons of Info Tech industry References: <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <41hhk195gcipfarnqu85ggs606aqi89ea1@4ax.com> <2dadnfArEfWwvdTeRVnzvA@telenor.com> <0trik1ldrtvuhsdvoai4a7h34q7la1pehl@4ax.com> Message-ID: <8v0rk1hjh0k6q2estgqc19i0da59fgurse@4ax.com> On Sun, 9 Oct 2005 21:53:52 +0200, "Dr.Ruud" wrote or quoted : >Don't think that that is true for everybody. For example not for people >that are behind central filters that already cope with common spam. The variants of the Nigerian spam are getting cleverer and cleverer to get though the filters. I can't always immediately recognise them. No wonder the spam filter gets fooled too. We victims of spam collectively are about the silliest of victims imaginable. We provide a FREE service to the spammers to torment us with. WE SUBSIDISE THEM. It costs them almost nothing to send a spam, and even at the weakest response percentages they still make money. It is almost like providing ladders and setting out cookies and milk for the burglars. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From tdwdotnet at gmail.com Sat Oct 8 09:35:50 2005 From: tdwdotnet at gmail.com (Tim Williams (gmail)) Date: Sat, 8 Oct 2005 14:35:50 +0100 Subject: socketServer questions In-Reply-To: <1128699247.9040.15.camel@athop1.ath.vt.edu> References: <1128699247.9040.15.camel@athop1.ath.vt.edu> Message-ID: <9afea2ac0510080635n304c2589l@mail.gmail.com> On 07/10/05, rbt wrote: > I have written a python socketServer program and I have a few questions This is a multithreaded non-blocking version of your server (not tested), with a basic attempt to hande errors. from socket import * from SocketServer import * import time, threading, sys class tr_server(ThreadingMixIn, TCPServer): def some_function(self): pass class tr_handler(StreamRequestHandler): global write_to_file, file_path def handle(self): print "Current Connection count:", threading.activeCount() -1 public_ip = self.client_address[0] serv_date = time.strftime('%Y-%m-%d', time.localtime()) serv_time = time.strftime('%H:%M:%S', time.localtime()) try: data = self.rfile.readline(300) data = str.strip(data) bytes = str(len(data)) # Note that 'data; comes from the client. fp = file('/home/rbt/Desktop/tr_report.txt', 'a') fp.write(data+"\t"+serv_date+"\t"+serv_time+"\t"+public_ip+"\t"+bytes+"\n") fp.close() except: print "unknown error", sys.exc_info()[0] def StartServer(): setdefaulttimeout( 30 ) # timeout incoming connections server = tr_server(('', 55503 ), tr_handler) server.serve_forever() if __name__ == '__main__': StartServer() Consider putting the writing to file function in its own class or thread. Then opening the file once and appending the data to it from each connection. Yoou would need to use fp.flush() after each fp.write() so that the data survives a program fail. HTH :) From fredrik at pythonware.com Wed Oct 26 03:13:09 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 26 Oct 2005 09:13:09 +0200 Subject: XML Tree Discovery (script, tool, __?) References: <1130183060.195730.178330@g47g2000cwa.googlegroups.com><1130193322.138313.320480@o13g2000cwo.googlegroups.com> <1130261709.136041.144110@f14g2000cwb.googlegroups.com> Message-ID: eric.pederson at gmail.com wrote: > just namespace + tag here's an ElementTree-based example: # http://effbot.org/tag/elementtree import elementtree.ElementTree as ET FILE = "example.xml" path = () path_map = {} for event, elem in ET.iterparse(FILE, events=("start", "end")): if event == "start": path = path + (elem.tag,) else: path_map.setdefault(path, []).append(elem) path = path[:-1] elem.clear() # won't need the contents any more for path in path_map: print "/".join(path), len(path_map[path]) given this document: chapter 1 chapter 2 the above script prints document 1 document/chapter 2 document/chapter/title 2 the script uses universal names for tags that live in a namespace. for information on how to decipher such names, see: http://www.effbot.org/zone/element.htm#xml-namespaces hope this helps! From mwm at mired.org Wed Oct 19 16:49:26 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 19 Oct 2005 16:49:26 -0400 Subject: UI toolkits for Python References: <7xslv56ud1.fsf@ruckus.brouhaha.com> <3ras6oFit2djU1@individual.net> <4350dd34$0$6774$9b4e6d93@newsread4.arcor-online.net> <863bn12k6i.fsf@bhuda.mired.org> <7xslv02aoj.fsf@ruckus.brouhaha.com> <87psq39aur.fsf@wilson.rwth-aachen.de> <7xwtkbud5q.fsf@ruckus.brouhaha.com> <1h4mhm2.1rmv4fh1czi843N%aleaxit@yahoo.com> <86r7aiyg4g.fsf@bhuda.mired.org> <1h4n6ag.5uhq7a7xe1v4N%aleaxit@yahoo.com> <86ach6y6ta.fsf@bhuda.mired.org> <1h4o6eo.4gi3s6xgesmzN%aleaxit@yahoo.com> Message-ID: <86k6g9w7u1.fsf@bhuda.mired.org> aleaxit at yahoo.com (Alex Martelli) writes: > Mike Meyer wrote: >> aleaxit at yahoo.com (Alex Martelli) writes: >> > Mike Meyer wrote: >> >> What surprises me is that marketing types will accept turning away - >> >> what's the current internet user base? 200 million? - 10 million >> >> potential customers without a complaint. Or maybe they just don't get >> >> told that that's what's going on. >> > In firms where marketing has lots of power, they may indeed well decide >> > to pursue those "10 millions" by demanding an expenditure of effort >> > that's totally out of proportion >> What makes you think that the expenditure of effort is "totally out of >> proportion"? In my experience, that isn't the case - at least if you >> go into it planning on doing things that way. Retrofitting a site that >> was built without any thought but "make it work in my favoriter >> browser in my favorite configuration" can be a radically different >> thing. > We ARE talking about moving from supporting 95% to supporting > (*supposedly*!) 100%, after all -- very much into the long, *LONG* tail > of obscure buggy versions of this browser or that, which SOME users > within those last centiles may have forgotten to patch/upgrade, etc. I'm talking about supporting standards instead of clients, which is how you get interoperability. You clearly can't support all the buggy browsers that exist, especially not when even commercial browsers are releasing betas to the public. Reality is that you *have* to support the most popular browser(s) - except for the betas, anyway. Other browsers that have bugs - well, you can patch around them if it's trivial enough, and identify where the browser is out of spec otherwise in hopes the author will fix it. Unless you're out of spec, in which case you fix your code. >> > Maybe that's part of the explanation for the >> > outstanding success of some enterprises founded by engineers, led by >> > engineers, and staffed overwhelmingly with engineers, competing with >> > other firms where marketing wield power...? >> You mean like google? Until recently, they're an outstanding example >> of doing things right, and providing functionality that degrades >> gracefully as the clients capabilities go down. > I'm not sure what you mean by "until recently" in this context. AFAIK, > we've NEVER wasted our efforts by pouring them into the quixotic task of > supporting *100%* of possible browsers that may hit us, with the near > infinite number of combinations of browsers, versions and disabled > feature that this would require. Google's sites have been very good about working with many browsers and configurations, especially when compared with the run of the mill on the web. If that's unintentional - well, that's simply a shame. > One may quibble whether the target percentage should be, say, 93%, > 95%, or 97%, and what level of degradation can still be considered > "graceful" around various axes, but the 100% goal which you so > clearly imply above would, in my personal opinion, be simply foolish > now, just as it would have been 3 years ago. I never meant to imply that you should try and support 100% of all browsers, merely that they should try and support every browser that follows the specifications (and IE). I can see how what I said might be construed to mean the latter, and I'm sorry about that. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From steve.horsley at gmail.com Mon Oct 31 15:37:39 2005 From: steve.horsley at gmail.com (Steve Horsley) Date: Mon, 31 Oct 2005 20:37:39 +0000 Subject: Problem With Insert with MySQLdb In-Reply-To: References: Message-ID: David Mitchell wrote: > Hello, > > I am a complete beginner with Python. I've managed to get mod_python up and > running with Apache2 and I'm trying to a simple insert into a table in a > MySQL database. > > I'm using the MySQLdb library for connectivity. I can read from the database > no problem, but when I do an insert, the value never gets added to the > database, even though there is no error, and the SQL is fine (I print out > the SQL statement in the function). When I copy and paste the sql from my > browser and insert directly into MySQL, it works fine. > > Here is the function in question: > > def add(req): > db = MySQLdb.connect(host="intranet", user="root", passwd="", > db="intranet") > # create a cursor > cursor = db.cursor() > # execute SQL statement > > sql = "INSERT INTO category (category_name) VALUES ('" + > req.form['category'] + "')" > cursor.execute(sql) > return sql > > > The SQL it is outputting is: > > INSERT INTO category (category_name) VALUES ('Test') > > Am I doing something obviously incorrect here? > > Thanks, > > Dave > Try either executing this first: cursor.execute("set autocommit = 1") or this afterwards: cursor.execute("commit") The idea is that transactions are not committed into the database until you "commit" them - and if you hit problems halfway through a sequence of updates that really shouldn't be left half finished, you can execute "abort" instead (or just close the connection), and none of them will be done. Steve From http Thu Oct 13 17:56:10 2005 From: http (Paul Rubin) Date: 13 Oct 2005 14:56:10 -0700 Subject: Python's garbage collection was Re: Python reliability References: <3r6i0uFi3qb8U2@uni-berlin.de> <7xfyr5kfgm.fsf@ruckus.brouhaha.com> <3r6osdFhsfjgU1@uni-berlin.de> <7xvf0168nq.fsf@ruckus.brouhaha.com> <434e7967$1@nntp0.pdx.net> <7xr7apqw1y.fsf@ruckus.brouhaha.com> <434ea2ad$1@nntp0.pdx.net> <7x3bn5s1dm.fsf@ruckus.brouhaha.com> <3r83a5Fi1rt6U1@uni-berlin.de> Message-ID: <7xfyr5qdxh.fsf@ruckus.brouhaha.com> "Diez B. Roggisch" writes: > > Yes, that would describe just about every cpu for the past 30 years > > that's a plausible Python target. > > No. The later 68K (>68020) could address on odd adresses. And AFAIK > all x86 can because of their 8080 stemming. Yes, "could" but not "does" in terms of what any reasonable actual compiler implmementations do. You get a huge performance hit for using unaligned data. The one exception is you could conceivably have character strings starting at odd addresses but it's no big deal to start them all on 4-byte (or even 2-byte) boundaries. From llothar at web.de Tue Oct 25 12:22:37 2005 From: llothar at web.de (llothar) Date: 25 Oct 2005 09:22:37 -0700 Subject: How is the python path build ? Message-ID: <1130257357.684848.260180@g14g2000cwa.googlegroups.com> Hello, i must add my own python.exe and a little patched runtime library with my product. How can i setup the python path, so that the directories are not taken from the registry values for Python2.4 but something relative to my own python.exe ? With PYTHONPATH i can only add new items in front of sys.path but i want start with a clean sys.path without any pre added directories. From steve at REMOVETHIScyber.com.au Fri Oct 7 09:11:56 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Fri, 07 Oct 2005 23:11:56 +1000 Subject: Python recipes: list mixin, improved timeit, etc References: <1128687060.102240.56040@g44g2000cwa.googlegroups.com> Message-ID: On Fri, 07 Oct 2005 05:11:00 -0700, Michele Simionato wrote: > Well, suppose you have a class MyObject and you want to add to it some > methods to make its instances into a database. You could put these > methods into another class called Storable (the mixin class). > Then you can mix MyObject with Storable and get what you want, > a class StorableObject inheriting both from Storable and MyObject. > Of course you can reuse Storable to make storable even other > classes, for instance you could define a StorableOtherObject > inheriting from OtherObject and Storable. So mixins are just a sub-class [pun intended] of sub-classing? I've just found this: [quote] A mixin class is a parent class that is inherited from - but not as a means of specialization. Typically, the mixin will export services to a child class, but no semantics will be implied about the child "being a kind of" the parent. [end quote] from http://c2.com/cgi/wiki?MixIn Is that all they are? It is amazing how you can take the simplest concept, and by using appropriate terminology, make it as confusing and opaque as you want... *wink* -- Steven. From steve at holdenweb.com Wed Oct 5 05:59:27 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 05 Oct 2005 10:59:27 +0100 Subject: "no variable or argument declarations are necessary." In-Reply-To: <4343996E.8010201@sweetapp.com> References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> <434245F5.6060500@REMOVEMEcyber.com.au> <7xr7b14lk0.fsf@ruckus.brouhaha.com> <7xu0fx9l7y.fsf@ruckus.brouhaha.com> <4343996E.8010201@sweetapp.com> Message-ID: Brian Quinlan wrote: > Paul Rubin wrote: > >>Brian Quinlan writes: >> >> >>>Have those of you who think that the lack of required declarations in >>>Python is a huge weakness given any thought to the impact that adding >>>them would have on the rest of the language? I can't imagine how any >>>language with required declarations could even remotely resemble >>>Python. >> >> >>Python already has a "global" declaration; > > > Which is evaluated at runtime, does not require that the actual global > variable be pre-existing, and does not create the global variable if not > actually assigned. I think that is pretty different than your proposal > semantics. > I believe that "global" is the one Python statement that isn't actually executable, and simply conditions the code generated during compilation (to bytecode). Hard to see why someone would want to use a global declaration unless they were intending to assign to it, given the sematnics of access. > [...] regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From my_email_is_posted_on_my_website at munged.invalid Sat Oct 8 16:44:44 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sat, 08 Oct 2005 20:44:44 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> Message-ID: <0ubgk190ncu25dki8h0ddd3s4fd13bj76k@4ax.com> On Wed, 05 Oct 2005 09:38:49 +1000, Steven D'Aprano wrote or quoted : >Even more invariably, they set the point size directly rather than in >relative terms, and they are on Windows, where point sizes are about 20% >oversized. that is like giving up Java because there was a bug in the Windows JVM. FIX THE BUG. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From dudufigueiredo at gmail.com Mon Oct 31 20:58:51 2005 From: dudufigueiredo at gmail.com (Dudu Figueiredo) Date: 31 Oct 2005 17:58:51 -0800 Subject: Rename files with numbers In-Reply-To: References: <1130776390.085587.116270@g43g2000cwa.googlegroups.com> <1130784747.373637.108040@g14g2000cwa.googlegroups.com> <1130789205.862429.10090@g43g2000cwa.googlegroups.com> <20051031220841.GF2575@kitchen.client.attbi.com> Message-ID: <1130810331.052918.75650@g14g2000cwa.googlegroups.com> Oh, forget what i've just said, i didn't read the __debug__ part. It worked perfectly =] Realy good Python classes! ____________________ Eduardo Figueiredo http://dudufigueiredo.com From bonono at gmail.com Mon Oct 24 04:21:31 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 24 Oct 2005 01:21:31 -0700 Subject: testing '192.168.1.4' is in '192.168.1.0/24' ? In-Reply-To: References: <1130131120.695320.180030@z14g2000cwz.googlegroups.com> Message-ID: <1130142091.327886.163710@g44g2000cwa.googlegroups.com> thanks, that is basically what I am doing and since it is a recipe, I would assume there is no standard library module for it. Peter Hansen wrote: > bonono at gmail.com wrote: > > Is there standard library modules handling this ? currently I need to > > turn it into a long integer and do the shift and compare. > > A little Googling turned up this: > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440560 > > -Peter From ptb at oboe.it.uc3m.es Tue Oct 25 08:21:31 2005 From: ptb at oboe.it.uc3m.es (Peter T. Breuer) Date: Tue, 25 Oct 2005 14:21:31 +0200 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: In comp.os.linux.misc David Schwartz wrote: > "Peter T. Breuer" wrote in message news:okh133-n3l.ln1 at news.it.uc3m.es... >> 3) there are plenty of other OSs that are developed or could be >> developed but which cannot get a foothold or even manage to be put on >> the shelves because the majority product producer insists on charging >> hardware manufacturers for every box produced, whether or not it carries >> their o/s, and does other nasty things like sabotaging their own >> products so they won't work with a clone o/s. > How could he resell an OS that "could be developed"? Is it relevant? Why? Can you sell a voip solution that could be developed? Is that relevant? No. No. No. No. > If nobody wants > these operating systems, False premise, indeed, irrelevant premise, therefore rest of statememt junked. No dumb client cares what o/s they are running. Do you care if your mobile phone runs symbios of javalite? That's simply not the point - the point is that the makers of symbios don't charge your mobile phone manufacturer for every phone sold, whether symbios is on there or not. Doing so is "restraint of trade", because, uh, it restrains the manufactrers of mobile phones from exercising their market choices. > then it doesn't hurt him not to be able to sell Who cares? It's to the advantage of sellers to create a monopoly! It's not in YOUR, the customer's, advantage to have one, which is why there are laws against it! Go away! Peter From apardon at forel.vub.ac.be Mon Oct 3 07:22:37 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 3 Oct 2005 11:22:37 GMT Subject: [Info] PEP 308 accepted - new conditional expressions References: <3q4ro9Fd770nU3@individual.net> Message-ID: Op 2005-09-30, Sam schreef : > This is a MIME GnuPG-signed message. If you see this text, it means that > your E-mail or Usenet software does not support MIME signed messages. > The Internet standard for MIME PGP messages, RFC 2015, was published in 1996. > To open this message correctly you will need to install E-mail or Usenet > software that supports modern Internet standards. > > --=_mimegpg-commodore.email-scan.com-32420-1128120829-0002 > Content-Type: text/plain; format=flowed; charset="US-ASCII" > Content-Disposition: inline > Content-Transfer-Encoding: 7bit > > Reinhold Birkenfeld writes: > >> Hi, >> >> after Guido's pronouncement yesterday, in one of the next versions of Python >> there will be a conditional expression with the following syntax: >> >> X if C else Y >> >> which is the same as today's >> >> (Y, X)[bool(C)] > > What's wrong with "C ? X:Y"? > > Aside from ":" being overloaded? Nothing, but afaiu Guido dislikes it. -- Antoon Pardon From apardon at forel.vub.ac.be Wed Oct 5 03:55:10 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 5 Oct 2005 07:55:10 GMT Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> Message-ID: Op 2005-10-04, Ron Adam schreef : > Antoon Pardon wrote: >> Op 2005-10-03, Steven D'Aprano schreef : >>> >>>And lo, one multi-billion dollar Mars lander starts braking either too >>>early or too late. Result: a new crater on Mars, named after the NASA >>>employee who thought the compiler would catch errors. >> >> >> Using (unit)tests will not guarantee that your programs is error free. >> >> So if sooner or later a (unit)tested program causes a problem, will you >> then argue that we should abondon tests, because tests won't catch >> all errors. > > Maybe you need to specify what kind of errors you want to catch. > Different types of errors require different approaches. I want to catch all errors of course. I know that nothing will ever guarantee me this result, but some things may help in getting close. So if a language provides a feature that can help, I generally think that is positive. That such a feature won't solve all problems shouldn't be considered fatal as some counter arguments seem to suggest. -- Antoon Pardon From mwm at mired.org Wed Oct 5 09:53:07 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 05 Oct 2005 09:53:07 -0400 Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86u0fxi7gf.fsf@bhuda.mired.org> Message-ID: <863bnghxz0.fsf@bhuda.mired.org> Antoon Pardon writes: >>> They also relieve a burden from the run-time, since all variables >>> are declared, the runtime doesn't has to check whether or not >>> a variable is accesible, it knows it is. >> Not in a dynamic language. Python lets you delete variables at run >> time, so the only way to know if a variable exists at a specific >> point during the execution of an arbitrary program is to execute the >> program to that point. > It is not perfect, that doesn't mean it can't help. How much code > deletes variables. It's not perfect means it may not help. Depends on the cost of being wrong - which means we need to see how things would be different if the code was assuming that a variable existed, and then turned out to be wrong. Actually, I'd be interested in knowing how you would improve the current CPython implementation with knowledge about whether or not a variable existed. The current implementation just does a dictionary lookup on the name. The lookup fails if the variable doesn't exist. So checking on the existence of the variable is a byproduct of finding the value of the variable. So even if it was perfect, it wouldn't help. >>> And if you provide type information with the declaration, more >>> efficient code can be produced. >> Only in a few cases. Type inferencing is a well-understood >> technology, and will produce code as efficient as a statically type >> language in most cases. > I thought it was more than in a few. Without some type information > from the coder, I don't see how you can infer type from library > code. There's nothing special about library code. It can be anaylyzed just like any other code. >>> I think language matters shouldn't be setlled by personal preferences. >> I have to agree with that. For whether or not a feature should be >> included, there should either be a solid reason dealing with the >> functionality of the language - meaning you should have a set of use >> cases showing what a feature enables in the language that couldn't be >> done at all, or could only be done clumsily, without the feature. > I think this is too strict. Decorators would IMO never made it. >From the impressions I get here, a lot of people would have been happy with that result. > I think that a feature that could be helpfull in reduction > errors, should be a candidate even if it has no other merrits. Yes, but that doesn't mean it should be accepted. Otherwise, every language would be Eiffel. You have to weigh the cost of a feature against the benefit you get from it - and different people come to different conclusions. Which is why different languages provide different levels of bondage. >> Except declarations don't add functionality to the language. They >> effect the programing process. > It would be one way to get writable closures in the language. > That is added functionality. Except just adding declerations doesn't give you that. You have to change the language so that undeclared variables are looked for up the scope. And that's the only change you need to get writable variables - some way to indicate that a variable should be checked for up the scope. There are more lightweight ways to do that than tagging every *other* variable. Those have been proposed - and rejected. >> And we have conflicting claims about >> whether that's a good effect or not, all apparently based on nothing >> solider than personal experience. Which means the arguments are just >> personal preferences. > Whether the good effect is good enough is certainly open for debate. > But the opponents seem to argue that since it is no absolute guarantee, > it is next to useless. Well I can't agree with that kind of argument > and will argue against it. You're not reading the opponents arguments carefully enough. The argument is that the benefit from type declerations is overstated, and in reality doesn't outweigh the cost of declerations. >> Antoon, at a guess I'd say that Python is the first time you've >> encountered a dynamnic language. Being "horrified" at not having >> variable declarations, which is a standard feature of such languages >> dating back to the 1950s, is one such indication. > No I'm not horrified at not having variable declarations. I'm in > general very practical with regard to programming, and use what > features a language offers me. However that doesn't stop me from > thinking: Hey if language X would have feature F from language Y, > that could be helpfull. I'm sorry - I thought you were the OP, who said he was horrified by that lack. >> Dynamic languages tend to express a much wider range of programming >> paradigms than languages that are designed to be statically >> compiled. Some of these paradigms do away with - or relegate to the >> level of "ugly performance hack" - features that someone only >> experienced with something like Pascal would consider >> essential. Assignment statements are a good example of that. > I think we should get rid of thinking about a language as > static or dynamic. It is not the language which should determine > a static or dynamic approach, it is the problem you are trying > to solve. And if the coder thinks that a static approach is > best for his problem, why shouldn't he solve it that way. Except that languages *are* static or dynamic. They have different features, and different behaviors. Rather than tilting at the windmill of making a dynamic language suitable for static approaches, it's better to simply use the appropriate tool for the job. Especially if those changes make the tool *less* suitable for a dynamic approach. > That a language allows a static approach too, doesn't contradict > that it can work dynamically. Everytime a static feature is > suggested, some dynamic folks react as if the dynamic aspect > of python is in perril. The problem is that such changes invariably have deep impact that isn't visible until you examine things carefully knowing you're dealing with a dynamic language. For instance, just as Python can delete a variable from a name space at run time, it can add a variable to some name spaces at run time. So the compiler can't reliably determine that a variable doesn't exist any more than it can reliably determine that one does. This means that you can't flag using undeclared variables in those namespaces at compile time without a fundamental change in the language. >> Given these kinds of differences, prior experience is *not* a valid >> reason for thinking that some difference must be wrong. Until you have >> experience with the language in question, you can't really decide that >> some feature being missing is intolerable. You're in the same position >> as the guy who told me that a language without a goto would be >> unusable based on his experience with old BASIC, FORTRAN IV and >> assembler. > There seems to be some misunderstanding, I don't remember stating that > missing declarations are intolerable, I certainly dont think so. I > wouldn't be programming in python for over five years now if I > thought so. But that doesn't mean having the possibilty to > declare is useless. Again, I was apparently confusing you and the OP. My apologies. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From jason at pengale.com Wed Oct 19 23:11:56 2005 From: jason at pengale.com (Jason Stitt) Date: Wed, 19 Oct 2005 22:11:56 -0500 Subject: Python vs Ruby In-Reply-To: References: <1129776956.254389.188040@z14g2000cwz.googlegroups.com> Message-ID: <89DF2CF9-408E-4D9E-8E43-003D23006C24@pengale.com> On Oct 19, 2005, at 10:01 PM, Roy Smith wrote: > In article <1129776956.254389.188040 at z14g2000cwz.googlegroups.com>, > "jean-marc" wrote: > >> I'd believe that would be Lua, but then again what is common to one >> might not be to another ;-) >> > > Dang, you're right! Lua's got Ruby beat two-fold! And lack of vowels is definitive proof that PHP is not-so-good, right? How can we improve Python's competitiveness in this arena? "Pie"? Or can we do even better than Lua? Ptooey! - Jason From davids at webmaster.com Tue Oct 25 07:21:45 2005 From: davids at webmaster.com (David Schwartz) Date: Tue, 25 Oct 2005 04:21:45 -0700 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: "Roedy Green" wrote in message news:g6srl15c24s1b7ed22rc1hqqt0d2dh8ktp at 4ax.com... > On Mon, 24 Oct 2005 21:06:36 -0700, "David Schwartz" > wrote, quoted or indirectly quoted someone who > said : >> Do you think it would be immoral if Microsoft said, "we will only sell >>Windows wholesale to dealers who don't sell other operating systems?" > I had an existing independent business. I was not as though I were an > MS franchise. They imposed this extortion well into my business's > life. My choice was comply or go out of business. > It was not as if I had a choice of sell Hondas or sell Kias if I did > like the franchise deal. Okay, I give up. As far as I can see it, there are only two realistic possibilties: 1) There is no other operating system worth selling. In this case, you are right, you have no choice but to sell the Microsoft OS, but the deal they're offering you harms you in no way. (Unless you intended to sell PCs with no OS at all.) 2) There are other realistic competing operating systems. In this case, you were foolish to agree to Microsoft's deal. You lost out on the realistic competing markets. That is, unless Windows only really was a better deal, in which case you were wise to take the deal and have no reason to be upset. > To my way of thinking what MS did was similar to a the only magasine > wholesaler in town telling retailers it had to sell kiddie porn under > the table or pay full retail for all magazines. Of course you pick an analogy where MS analogically peddles kiddie porn. I can play the same game, watch this: What MS did was similar to the major magazine wholesaler in a town telling retailers they must carry gay and lesbian publications if they want to carry its mainstream magazines. > I broke my own ethical code rather than go out of business. I will > never forgive MS for putting me in that position. You certainly have a legitimate personal grudge against MS. DS From martin.witte at gmail.com Fri Oct 7 10:18:53 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 7 Oct 2005 07:18:53 -0700 Subject: Python interpreter bug In-Reply-To: <1128692705.964188.5720@z14g2000cwz.googlegroups.com> References: <1128686833.994339.295780@f14g2000cwb.googlegroups.com> <1128692705.964188.5720@z14g2000cwz.googlegroups.com> Message-ID: <1128694733.576909.16560@g49g2000cwa.googlegroups.com> Your __cmp__ method will always return 0, so all objects will be equal when you add the method, as Simon and Steve pointed out. The result is all objects will pass the test of being a member of excluded. If you do not add a __cmp__ method objects will be compared on identy - call the id() function to see the identity of an object. An alternative would be Steve's proposal to compare on the id attribute instead of the allocated attribute From oshecho at gmail.com Thu Oct 13 20:48:52 2005 From: oshecho at gmail.com (Echo) Date: Thu, 13 Oct 2005 20:48:52 -0400 Subject: Hidden string formatting bug Message-ID: <910885da0510131748y16dd9603n4e013553e28797df@mail.gmail.com> Hello, I have been trying to figure out the problem with this string formatting: sql = 'INSERT INTO tc_themes (name,user_made,hour12,time_loc,background_color_r,' + \ 'background_color_g,background_color_b,clock_color_r,clock_color_g,' + \ 'clock_color_b,clock_background_color_r,clock_background_color_g,' + \ 'clock_background_color_b,clock_points_color_r,clock_points_color_g,' + \ 'clock_points_color_b,clock_hour_color_r,clock_hour_color_g,' + \ 'clock_hour_color_b,clock_min_color_r,clock_min_color_g,' + \ 'clock_min_color_b,clock_sec_color_r,clock_sec_color_g,' + \ 'clock_sec_color_b,clock_font_facename,clock_font_size,' + \ 'clock_font_style,clock_font_underlined,clock_font_weight,' + \ 'clock_font_color_r,clock_font_color_g,clock_font_color_b,' + \ 'time_font_facename,time_font_size,time_font_style,' + \ 'time_font_underlined,time_font_weight,time_font_color_r,' + \ 'time_font_color_g,time_font_color_b) VALUES (' + \ "%s,%i,%i,%s,%i," + \ "%i,%i,%i,%i," + \ "%i,%i,%i," + \ "%i,%i,%i," + \ "%i,%i,%i," + \ "%i,%i,%i," + \ "%i,%i,%i," + \ "%i,%s,%i," + \ "%i,%i,%i," + \ "%i,%i,%i," + \ "%s,%i,%i," + \ "%i,%i,%i," + \ "%i,%i)" % ("'Simple Clock'", 0, 1, "'Top'", 200, 200, 200, 100, 100, 100, 255, 255, 255, 100, 100, 100, 0, 0, 0, 0, 0, 0, 255, 0, 0, "'Arial'", 18, 90, 0, 90, 0, 0, 0, "'Arial'", 32, 90, 0, 90, 0, 0, 0) when it executes, I get this error: "inv argument required". I have checked and rechecked both the string and the tuple. I cant figure out what the problem is. After playing around with it, i found out if change the last line to: "%s,%i) %(... I get a different error. The error is "not all arguments converted during string formatting". So I am baffled and confused as of why this wont work. Is anyone able to shed some light on my hidden bug? Using: Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] -- -Echo -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Tue Oct 11 13:54:06 2005 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 11 Oct 2005 10:54:06 -0700 Subject: Wrapper function In-Reply-To: <1129052312.444144.142950@g44g2000cwa.googlegroups.com> References: <1129052312.444144.142950@g44g2000cwa.googlegroups.com> Message-ID: Java and Swing wrote: > I am having trouble with a wrapper function... > > My C code looks like > ----------------------- > #include > #include > #include "Python.h" > > int doStuff(const char *input, const char *d) {...} > > PyObject *wrap_doStuff(PyObject *, PyObject *args) { PyObject *wrap_doStuff(PyObject *self, PyObject *args) { > ...when I try to compile this I get > "error C2055: expected formal parameter list, not a type list" and it > points to line 31...which is the line "PyObject *wrap_doStuff(...)". -- 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 oliver.andrich at gmail.com Sat Oct 22 17:49:40 2005 From: oliver.andrich at gmail.com (Oliver Andrich) Date: Sat, 22 Oct 2005 23:49:40 +0200 Subject: Question about inheritance... In-Reply-To: <1130017209.078943.119990@g43g2000cwa.googlegroups.com> References: <1130017209.078943.119990@g43g2000cwa.googlegroups.com> Message-ID: <6f7b52d0510221449x28a027b6n@mail.gmail.com> Hi, 22 Oct 2005 14:40:09 -0700, KraftDiner : > I have a base class called Shape > And then classes like Circle, Square, Triangle etc, that inherit from > Shape: > > My quesiton is can a method of the Shape class call a method in Circle, > or Square etc...? even there would exist a way to accomplish that, I would suggest to rethink your class hierachy. Such requirements can show serious design problems. Best regards, Oliver -- Oliver Andrich --- http://roughbook.de/ From steve at holdenweb.com Tue Oct 11 00:42:25 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 11 Oct 2005 05:42:25 +0100 Subject: Python name lookups In-Reply-To: <20051010220230.98030.qmail@web30607.mail.mud.yahoo.com> References: <20051010220230.98030.qmail@web30607.mail.mud.yahoo.com> Message-ID: Dave wrote: > Hello All, > > As far as I understand, Python deals with a lot of > string objects, i.e. it looks up all names. Is there a > way to find out how many name lookup operations take > place in a Python program? Is it the name lookup > operation or hash operation that degrades performance? > What function does Python use for name lookup > operations? Is it the lookdict function in > Objects/dictobject.c? > > Thank you for your help! > Be aware that it doesn't "look up all names" if by that you mean that all variable accesses are symbolic. Function-local variables are referred to by a pre-computed offset in the stack frame, and so are much more quickly accessed than others, where the name-based access is typically used. The only way I can think of to get the number you want is to instrument the interpreter once you have determined what you are really asking. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From mapisto at gmail.com Tue Oct 18 11:27:45 2005 From: mapisto at gmail.com (Mapisto) Date: 18 Oct 2005 08:27:45 -0700 Subject: Writing an immutable object in python In-Reply-To: References: <1129562898.812915.238430@g14g2000cwa.googlegroups.com> Message-ID: <1129649265.168515.306010@o13g2000cwo.googlegroups.com> Ok, I've understood my mistake. Now, my list contains a shared entry of an empty object. When an entry is needed to be changed, I check if the entry is the shared empty object; in that case I create a new unique instance. If the entry is already a unique instance, I use it, so the empty object isn't touched. Thanks, Guy. From http Wed Oct 5 04:03:53 2005 From: http (Paul Rubin) Date: 05 Oct 2005 01:03:53 -0700 Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> <434245F5.6060500@REMOVEMEcyber.com.au> <7xr7b14lk0.fsf@ruckus.brouhaha.com> <7xu0fx9l7y.fsf@ruckus.brouhaha.com> Message-ID: <7xy85875li.fsf@ruckus.brouhaha.com> Duncan Booth writes: > If you think variable declarations should be required, I don't think they should be required. I think there should optional declarations along with a compiler flag that checks for them if the user asks for it, like Perl has. > then you presumably want that to cover class attributes as well as > local and global variables. After all assigning to 'x.i' when you > meant 'x.j' is at least as bad as assigning to 'i' Yes, lots of people mistakenly use __slots__ for exactly that purpose. Maybe the function they think __slots__ is supposed to implement is a legitimate one, and having a correct way to do it is a good idea. > But unless you know the type of 'x', how do you know whether it > has attributes 'i' or 'j'? If the compiler knows (through declarations, type inference, or whatever) that x is a certain type of class instance, then it knows what attributes x has. From MrJean1 at gmail.com Sun Oct 2 21:40:55 2005 From: MrJean1 at gmail.com (MrJean1) Date: 2 Oct 2005 18:40:55 -0700 Subject: what does 0 mean in MyApp(0) In-Reply-To: <1128089733.684329.101320@o13g2000cwo.googlegroups.com> References: <1128089733.684329.101320@o13g2000cwo.googlegroups.com> Message-ID: <1128303655.924894.127190@g49g2000cwa.googlegroups.com> See the documentation for the __init__() method here Btw, this is wxPython 2.6, AFAIK. /Jean Brouwers From paul at boddie.org.uk Sun Oct 9 12:26:55 2005 From: paul at boddie.org.uk (paul at boddie.org.uk) Date: 9 Oct 2005 09:26:55 -0700 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <8ohgk1p9s6pgaq8d67bgpjg7i8i22ngiul@4ax.com> <1128820635.056326.87380@f14g2000cwb.googlegroups.com> Message-ID: <1128875215.566389.194590@g43g2000cwa.googlegroups.com> Tim Tyler wrote: > Javascript can be turned off in *mail readers* - by their manufacturers. Yes, mail readers, browsers, combined mail reading and Web browsing "suites", or whatever combination of functions you care to consider. In any case, in the not-exactly-unknown mail reader I use, I can't seem to find a setting that will turn JavaScript on. Meanwhile, HTML mail is flagged and presented as plain text with a prominent warning about viewing the message as HTML - an acceptable tradeoff which only slightly delays the viewing of the very few legitimate messages I get sent in that format. Of course, the most excitable manufacturers of mail readers with respect to enabling a "rich experience" are those pitching "enterprise functionality", although a full treatment of their mistakes (amplifying my previous rant) would take this discussion even further away from the tenuous connection it has with Python, related discussions on type safety, private/protected/public, using Python in Mozilla, and the disappearance of the Bastion module notwithstanding. Paul From no.offline.contact.please at nospam.com Sat Oct 15 12:56:05 2005 From: no.offline.contact.please at nospam.com (Rhino) Date: Sat, 15 Oct 2005 12:56:05 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: <7wa4f.9275$vD4.567542@news20.bellglobal.com> "Real Gagnon" wrote in message news:Xns96F0827ADD1F8realhowtowwwrgagnonc at 140.99.99.130... > > I'd be VERY surprised if IBM predicted that there would be only 5 > > COMPUTERS in *2000* - perhaps you mean 5 *manufacturers* of computers? > > - unless the prediction was made a VERY long time ago. I think you are > > giving a badly-mangled version of something I saw when I worked at > > IBM. > > "I think there is a world market for maybe five computers." ~ IBM Chairman > Thomas Watson, 1943. > > ref : http://en.wikiquote.org/wiki/Computers > > Bye. I stand corrected; I understated the world market by 2 units and was 4 years late in my guesstimate for the timing of the quote :-) Oh well, not bad for something I read 10 years ago.... Rhino From robin at reportlab.com Tue Oct 11 06:07:27 2005 From: robin at reportlab.com (Robin Becker) Date: Tue, 11 Oct 2005 11:07:27 +0100 Subject: strange import error with Python-2.4.1 Message-ID: <434B8EDF.3060905@chamonix.reportlab.co.uk> Whilst testing the excellent xlrd http://www.python.org/pypi/xlrd/0.3a1 I came across the following strangeness when trying to add an import of os to assist with debugging/tracing. At line 66 I replaced import sys with import sys, os and then ran python runxlrd.py --help and got this error which is not a real syntax problem Traceback (most recent call last): File "runxlrd.py", line 5, in ? import xlrd File "C:\python24\lib\site-packages\xlrd\__init__.py", line 552 if DEBUG: print >> self.logfile, "SST Processing" if I remove the , os then the run produces the expected usage: runxlrd.py [options] command input-file-patterns options: -h, --help show this help message and exit -l LOGFILENAME, --logfilename=LOGFILENAME contains error messages -v VERBOSITY, --verbosity=VERBOSITY level of information and diagnostics provided I also am able to change the line to import sys import os without error. This behaviour doesn't occur with 2.4.2 or 2.4 only with 2.4.1. I looked for some bug fix in the recently released 2.4.2 that related, but couldn't find anything obvious. My system doesn't have psyco so xlrd's attempted psyco use shouldn't be an issue. Thanks for 2.4.2, but is this one of the fixed bugs or has it just got harder to induce? -- Robin Becker From arotem at juniper.net Mon Oct 17 03:52:15 2005 From: arotem at juniper.net (arotem) Date: 17 Oct 2005 00:52:15 -0700 Subject: TypeError: unbound method PrintInput() must be called with test instance as first argument (got test instance instead) References: <1129481319.436107.16950@f14g2000cwb.googlegroups.com> <3rffl4Fjc0n2U1@uni-berlin.de> Message-ID: <1129535535.922908.257720@g49g2000cwa.googlegroups.com> Thanks... it solves the problem :-) From jstroud at mbi.ucla.edu Thu Oct 20 22:50:53 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Thu, 20 Oct 2005 19:50:53 -0700 Subject: TK question In-Reply-To: <1129860960.909273.68840@g43g2000cwa.googlegroups.com> References: <1129860960.909273.68840@g43g2000cwa.googlegroups.com> Message-ID: <200510201950.53800.jstroud@mbi.ucla.edu> Forgot to answer the "better" part: class optFrame(Frame): def __init__(self, *args, **kwargs): Frame.__init__(self, *args, **kwargs) self.pack() self.make_widgets() def make_widgets(self): """ Put widgets here. """ pass def main(): tk = Tk() optWin = optFrame(tk) tk.mainloop() if __name__ == "__main__": main() James On Thursday 20 October 2005 19:16, MBW wrote: > I have a class that is a windows in a GUI > > the following is the code: > > class optWin: > > def __init__(self): > return None > > def __call__(self): > self.root = tk() > self.root.title("My title") > self.root.mainloop() > return None > > 1)Why doesn't this work when I go to call optWin > 2)What is a better way to do this > > Thanks in advance -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From steve at holdenweb.com Fri Oct 21 03:40:48 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 21 Oct 2005 08:40:48 +0100 Subject: Set an environment variable In-Reply-To: <43589205$0$125$edfadb0f@dread16.news.tele.dk> References: <43573022$0$155$edfadb0f@dread16.news.tele.dk> <1129798724.366618.194650@g44g2000cwa.googlegroups.com> <43589205$0$125$edfadb0f@dread16.news.tele.dk> Message-ID: Christian wrote: >>The closest thing you can do is that: >> >>-myScript.py-------------------------------------- >>print 'export MY_VARIABLE=value' >>-------------------------------------------------- >> >>-myScript.sh-------------------------------------- >>python myScript.py > /tmp/chgvars.sh >>. /tmp/chgvars.sh >>-------------------------------------------------- > > > Can I write a .py script that calls a .sh script that executes the > export command and then calls another .py script (and how would the > first .py script look)? > > That would be much more what is my basic problem. > You can do what you suggest without shell scripting, unless I misunderstand your intention: just set the environment variables you want your Python script to see and then run it using os.system(): :::::::::::::: one.py :::::::::::::: import os os.environ['STEVE'] = "You are the man" os.system("python two.py") print "Ran one" :::::::::::::: two.py :::::::::::::: import os print "STEVE is", os.environ['STEVE'] print "Ran two" [sholden at headrat tmp]$ python one.py STEVE is You are the man Ran two Ran one [sholden at headrat tmp]$ Hope this helps. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From luismgz at gmail.com Fri Oct 7 21:03:20 2005 From: luismgz at gmail.com (Luis M. Gonzalez) Date: 7 Oct 2005 18:03:20 -0700 Subject: When someone from Britain speaks, Americans hear a "British accent"... References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kbgj7421kd560@corp.supernews.com> Message-ID: <1128733400.812671.304850@g43g2000cwa.googlegroups.com> Grant Edwards ha escrito: > While we're off this topic again topic, I was watching a BBC > series "Space Race" the other night. The British actors did a > passable job with the American accents in the scenes at Fort > Bliss in Texas, but the writers wrote British English lines for > them to speak in their American accents... Continuing with this off-topic thread about british accent and movies... I've always asked myself why do Hollywood movies about the Roman Empire show the Emperors and all the nobles speaking with british accent? They were italians for God's sake! Anyway, I can't imagine Julius Caesar speaking like Vito Corleone... From kbk at shore.net Sat Oct 8 00:34:33 2005 From: kbk at shore.net (Kurt B. Kaiser) Date: Sat, 8 Oct 2005 00:34:33 -0400 (EDT) Subject: Weekly Python Patch/Bug Summary Message-ID: <200510080434.j984YXHG031113@bayview.thirdcreek.com> Patch / Bug Summary ___________________ Patches : 341 open ( +4) / 2953 closed ( +6) / 3294 total (+10) Bugs : 884 open (-28) / 5321 closed (+43) / 6205 total (+15) RFE : 196 open ( +1) / 187 closed ( +0) / 383 total ( +1) New / Reopened Patches ______________________ Make fcntl work properly on AMD64 (2005-09-30) http://python.org/sf/1309352 opened by Brad Hards A wait4() implementation (2005-09-30) http://python.org/sf/1309579 opened by chads httplib error handling and HTTP/0.9 fix (2005-10-04) http://python.org/sf/1312980 opened by Yusuke Shinyama Speedup PyUnicode_DecodeCharmap (2005-10-05) http://python.org/sf/1313939 opened by Walter D?rwald os.makedirs - robust against partial path (2005-10-05) http://python.org/sf/1314067 opened by Jim Jewett ensure lock is released if exception is raised (2005-10-06) http://python.org/sf/1314396 opened by Eric Blossom ToolTip.py: fix main() function (2005-10-06) http://python.org/sf/1315161 opened by sebastien blanchet Py_INCREF/Py_DECREF with magic constant demo (2005-10-07) http://python.org/sf/1316653 opened by Adam Olsen Patches Closed ______________ pyexpat.c: Two line fix for decoding crash (2005-09-29) http://python.org/sf/1309009 closed by nnorwitz patch IDLE to allow running anonymous code in editor window (2005-05-13) http://python.org/sf/1201522 closed by kbk BSD-style wait4 implementation (2004-07-29) http://python.org/sf/1000267 closed by nnorwitz Patch for (Doc) bug #1219273 (2005-06-25) http://python.org/sf/1227568 closed by nnorwitz Greatly enhanced webbrowser.py (2003-06-13) http://python.org/sf/754022 closed by birkenfeld Patch for [ 1163563 ] Sub threads execute in restricted mode (05/17/05) http://python.org/sf/1203393 closed by sf-robot New / Reopened Bugs ___________________ linechache module returns wrong results (2005-09-30) http://python.org/sf/1309567 opened by Thomas Heller 2.4.2 make problems (2005-10-03) http://python.org/sf/1311579 opened by Paul Mothersdill broken link in sets page (2005-10-03) CLOSED http://python.org/sf/1311674 opened by Fernando Canizo python.exe 2.4.2 compiled with VS2005 crashes (2005-10-03) http://python.org/sf/1311784 opened by Peter Klotz Python breakdown in windows (uses apsw) (2005-10-03) CLOSED http://python.org/sf/1311993 opened by Benjamin Hinrichs mac_roman codec missing "apple" codepoint (2005-10-04) http://python.org/sf/1313051 opened by Tony Nelson urlparse "caches" parses regardless of encoding (2005-10-04) http://python.org/sf/1313119 opened by Ken Kinder bisect C replacement doesn't accept named args (2005-10-04) CLOSED http://python.org/sf/1313496 opened by Drew Perttula Compile fails for configure "--without-threads" (2005-10-05) CLOSED http://python.org/sf/1313974 opened by seidl Issue in unicode args in logging (2005-10-05) CLOSED http://python.org/sf/1314107 reopened by tungwaiyip Issue in unicode args in logging (2005-10-05) CLOSED http://python.org/sf/1314107 opened by Wai Yip Tung crash in longobject (invalid memory access) (2005-10-05) CLOSED http://python.org/sf/1314182 opened by Jon Nelson logging run into deadlock in some error handling situation (2005-10-05) CLOSED http://python.org/sf/1314519 opened by Wai Yip Tung Trailing slash redirection for SimpleHTTPServer (2005-10-05) http://python.org/sf/1314572 opened by Josiah Carlson inspect.getsourcelines() broken (2005-10-07) http://python.org/sf/1315961 opened by Walter D?rwald gzip.GzipFile.seek missing second argument (2005-10-07) http://python.org/sf/1316069 opened by Neil Schemenauer Segmentation fault with invalid "coding" (2005-10-07) http://python.org/sf/1316162 opened by Humberto Di?genes Bugs Closed ___________ Datagram Socket Timeouts (2005-09-29) http://python.org/sf/1308042 closed by nnorwitz Unsatisfied symbols: _PyGILState_NoteThreadState (code) (2005-09-29) http://python.org/sf/1307978 closed by mwh subprocess.Popen locks on Cygwin (2005-09-29) http://python.org/sf/1307798 closed by jlt63 test_posix fails on cygwin (2005-04-10) http://python.org/sf/1180147 closed by jlt63 can't import thru cygwin symlink (2005-04-08) http://python.org/sf/1179412 closed by jlt63 popen4/cygwin ssh hangs (2005-01-13) http://python.org/sf/1101756 closed by jlt63 2.3.3 tests on cygwin (2003-12-22) http://python.org/sf/864374 closed by jlt63 Datagram Socket Timeouts (2005-09-28) http://python.org/sf/1307357 closed by nnorwitz log() on a big number fails on powerpc64 (2005-07-26) http://python.org/sf/1245381 closed by nnorwitz __getnewargs__ is in pickle docs but not in code (2005-09-30) http://python.org/sf/1309724 closed by nnorwitz Win registry problem (2005-07-15) http://python.org/sf/1239120 closed by birkenfeld unknown encoding -> MemoryError (2003-07-17) http://python.org/sf/772896 closed by nnorwitz 'Expression' AST Node not documented (2005-06-12) http://python.org/sf/1219273 closed by nnorwitz segfault if redirecting directory (2004-01-30) http://python.org/sf/887946 closed by nnorwitz Acroread aborts printing PDF documentation (2004-05-30) http://python.org/sf/963321 closed by hgolden Python hangs up on I/O operations on the latest FreeBSD 4.10 (2004-06-09) http://python.org/sf/969492 closed by birkenfeld empty raise after handled exception (2004-06-15) http://python.org/sf/973103 closed by nnorwitz Unhelpful error message when mtime of a module is -1 (2004-06-21) http://python.org/sf/976608 closed by nnorwitz compile of code with incorrect encoding yields MemoryError (2004-06-25) http://python.org/sf/979739 closed by nnorwitz os.access reports true for read-only directories (2004-07-15) http://python.org/sf/991735 closed by nnorwitz seg fault when calling bsddb.hashopen() (2004-07-19) http://python.org/sf/994100 closed by montanaro os.major() os.minor() example and description change (2004-08-12) http://python.org/sf/1008310 closed by nnorwitz test_pep277 fails (2004-09-16) http://python.org/sf/1029561 closed by nnorwitz broken link in sets page (2005-10-03) http://python.org/sf/1311674 closed by fdrake Python breakdown in windows (uses apsw) (2005-10-03) http://python.org/sf/1311993 closed by birkenfeld Missing sk_SK in windows_locale (2005-07-13) http://python.org/sf/1237015 deleted by luks bisect C replacement doesn't accept named args (2005-10-05) http://python.org/sf/1313496 closed by rhettinger Compile fails for configure "--without-threads" (2005-10-06) http://python.org/sf/1313974 closed by perky Issue in unicode args in logging (2005-10-05) http://python.org/sf/1314107 closed by vsajip Issue in unicode args in logging (2005-10-05) http://python.org/sf/1314107 closed by vsajip crash in longobject (invalid memory access) (2005-10-05) http://python.org/sf/1314182 closed by tim_one logging run into deadlock in some error handling situation (2005-10-06) http://python.org/sf/1314519 closed by vsajip A command history for the idle interactive shell (2005-09-23) http://python.org/sf/1302267 closed by kbk New / Reopened RFE __________________ Add os.path.relpath (2005-09-30) http://python.org/sf/1309676 opened by Reinhold Birkenfeld From steve at REMOVETHIScyber.com.au Sun Oct 23 04:32:06 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 23 Oct 2005 18:32:06 +1000 Subject: downloading web images References: Message-ID: On Sun, 23 Oct 2005 06:52:26 +0000, Joe wrote: > I'm just wandering if I'm doing this correct way I'm trying to download an > image and store it into a file this does the job, but created file does not > apear to be an image, it works fine and I can open image, I'm just > wandering if there is a better way of doing this. What do you mean that the file does not appear to be an image? If it works fine and you can open the image, then what is the problem? -- Steven. From tim.golden at viacom-outdoor.co.uk Wed Oct 26 10:20:56 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Wed, 26 Oct 2005 15:20:56 +0100 Subject: Windows vs Linux [was: p2exe using wine/cxoffice] Message-ID: <9A28C052FF32734DACB0A288A3533991044D22A6@vogbs009.gb.vo.local> [Tim Golden] > Just occasionally you read posts from people who say (synthesised) > "The Windows command line is rubbish", [Sybren Stuvel] > It is. Let me give an example. I have the following files: [.. snip example of finding .somefile when you type som ..] Well, fair enough. Although I don't think that on its own this constitutes "rubbish". However, the rest of your points... > There is also no proper terminal support in the "DOS" box Not quite sure what this means. As in ANSI support? (Perfectly true - definitely lacking there). Or something else? > You can't resize it horizontally Well, peculiarly, you can do this (as you're probably aware) from the Properties menu and it'll work immediately, albeit without advising the running programs that it's resized, so only new lines will take advantage of the new width. Now, why they didn't let you do the same thing by grabbing the border and pulling, I don't know! > and the TAB key can only do dubm filename completion > (no smart option completion like only completing with > directory names after a "cd" command) Ummm. Not quite true, at least not on my XP machine, which, given: python.txt python alternates between the two when I do "dir p" but only offers me the directory when I do "cd p". In addition (and to no real advantage that I can see), Windows offers two keystrokes, by default Ctrl-F and Ctrl-D if enabled, to do file (and directory) completion and directory completion only. > > "All Windows machines are overrun with adware and generate spam > > willy-nilly". > Not all, indeed. There are _lots_ of Windows zombie machines, though. > Then again, when I was moving, I didn't pay enough attention to my > Linux box, was too late in patching a leak, and it started spamming > too. I'm sure you're right: given moderately naive users, a Windows box is *extremely* likely to be zombified. It's just that it doesn't have to be that way with the proper care and attention. And more recent versions of Windows are a bit better off this way. But I'm quite sure they're still worse off than Linux. 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 helge.stenstrom.NOSPAM at NOSPAMericsson.com Tue Oct 18 06:48:49 2005 From: helge.stenstrom.NOSPAM at NOSPAMericsson.com (Helge Stenstroem) Date: 18 Oct 2005 12:48:49 +0200 Subject: unittest of file-reading function Message-ID: Say I have a function def f(filename): result = openFileAndProcessContents(filename) return result Can that function be unit tested without having a real file as input? Something along the lines of import unittest class tests(unittest.TestCase): def test1(self): fileContents = "bla bla bla\nmore bla bla bla" ??? # make f read this string instead of opening a file expected = expectedResult result = f(filename) self.assertEqual(result, expected) One possibility would be to make the unit test write to a temporary file. Are there better alternatives? -- Helge Stenstr?m From nil at dev.nul Tue Oct 18 01:27:50 2005 From: nil at dev.nul (Christian Stapfer) Date: Tue, 18 Oct 2005 07:27:50 +0200 Subject: Comparing lists References: <1128930699.799657.146210@g47g2000cwa.googlegroups.com> <1128952417.0544cc73190bbbd4e683448c137969c8@teranews> <434ba977@nntp0.pdx.net> <1129216693.445956.155490@g47g2000cwa.googlegroups.com> <1h4knvy.41r7fw1k4bge7N%aleaxit@yahoo.com> <1h4lfof.1jirgzd1rpwucsN%aleaxit@yahoo.com> Message-ID: "Alex Martelli" wrote in message news:1h4lfof.1jirgzd1rpwucsN%aleaxit at yahoo.com... > Christian Stapfer wrote: > >> "Alex Martelli" wrote in message >> news:1h4knvy.41r7fw1k4bge7N%aleaxit at yahoo.com... >> > Christian Stapfer wrote: >> > >> >> This is why we would like to have a way of (roughly) >> >> estimating the reasonableness of the outlines of a >> >> program's design in "armchair fashion" - i.e. without >> >> having to write any code and/or test harness. >> > >> > And we would also like to consume vast amounts of chocolate, while >> > similarly reclining in comfortable armchairs, >> >> Maybe some of my inclination towards design >> based on suitable *theories* (instead of >> self-conditioning through testing) goes back >> to the fact that I tend to think about the >> design of my programs when no computer happens >> to be near at hand to do some such experimenting, >> or self-conditioning... > > Oh, I am as prone as anybody I know to do SW architecture and design in > bed when the lights are off and I'm sliding into sleep -- just about the > only case in which no computer is handy, or, rather, in which it's > generally unwise to turn the computer on (since it would interfere with > the sleep thing;-). Back before laptops were really affordable and > usable, I used to have a long bus commute, and did a lot of design with > pen and paper; and whiteboards are a popular group-design tool at > Google, no matter how many laptops or desktops happen to be around -- > whiteboards are simply more suitable for "socialization" around a draft > design's sketch, than any computer-based tool I've ever seen. > > But that's *design*, and most often in pretty early stages, too -- quite > a ways from *coding*. At that stage, one doesn't even generally commit > to a specific programming language or other for the eventual > implementation of the components one's considering! Rough ideas of > *EXPECTED* run-times (big-Theta) for various subcomponents one is > sketching are *MUCH* more interesting and important than "asymptotic > worst-case for amounts of input tending to infinity" (big-O) -- for > example, where I sketch-in (mentally, on paper, or on whiteboard) a > "hash table" subcomponent, I consider the *expected* (Theta) performance > (constant-time lookups), definitely NOT the big-O "linear time" lookups > which just MIGHT occur (if, say, all inputs just happened to hash to the > same value)... otherwise, I'd never use hash tables, right?-) Well, Big-Oh, Big-Theta: these both are asymptotic complexity measures, arent' they. So that's ok with me. >> > without getting all fat and flabby. >> >> Well, thinking can be hard work. There is no need >> to suggest an image of laziness. Thought experiments >> are also quite often successful. Hardware engineers >> can design very often entire gadgets without doing >> a great deal of testing. They usually need to resort >> to testing only if they know (or feel?) not to have >> a sufficiently clear *theoretical* grasp of the >> behavior of some part of their design. > > Having been a hardware designer (of integrated circuits, for Texas > Instruments, and later briefly for IBM), before switching to software, I > can resolutely deny this assertion: only an utter madman would approve a > large production run of an IC who has not been EXTENSIVELY tested, in > simulations and quite possibly in breadboards and later in limited > pre-production runs. Whoa, yet another straw-man attack! First, remember, I do *not* advocate doing without testing *altogether*: so here you are just attacking a straw-man of your own making: that's *not* me. What I wanted to say here is just that, in my experience, as a close observer of "average hardware designers", I believe that their testing *usually* doesn't turn up major gotchas, and this can only be because the theory they have about their hardware will operate, is sufficiently powerful. - "Usually": which means that exceptions are possible, of course. > And any larger "gadget" USING ICs would be > similarly crazy to skimp on prototyping, simulation, and other testing > -- because, as every HW engineer KNOWS (SW ones often have to learn the > hard way), the distance between theory and practice, in practice, is > much larger than the distance between practice and theory should be in > theory;-). > >> > Unfortunately, what we would like and what reality affords >> > are often pretty uncorrelated. No matter how much theoreticians may >> > love big-O because it's (relatively) easy to compute, it still has two >> > failings which are often sufficient to rule out its sufficiency for any >> > "estimate [of] the reasonableness" of anything: [a] as we operate on >> > finite machines with finite wordsize, we may never be able reach >> > anywhere even remotely close to the "asymptotic" region where big-O has >> > some relationship to reality; [b] in many important cases, the >> > theoretical worst-case is almost impossible to characterize and hardly >> > ever reached in real life, so big-O is of no earthly use (and much >> > harder to compute measures such as big-Theta should be used for just >> > about any practical purpose). >> >> But the fact remains that programmers, somewhat >> experienced with the interface a module offers, >> have a *rough*idea* of that computational complexity >> attaches to what operations of that interface. >> And having such a *rough*idea* helps them to >> design reasonably performing programs much more >> quickly. > > A rough idea helps, particularly a rough idea of EXPECTED performance. > >> Big-Oh and other asymptotic complexity measures >> really do have *this* advantage over having >> acquired, by way of conditioning experiences, >> some such *rough*idea* of computational complexity: > > No: big-O is NOT AT ALL a measure, rough or otherwise, of EXPECTED > performance. Another straw-man attack. Do you really read what others write? What I have written? Big-Oh is not the real bone of contention at all, nor is worst-case characterizations, but the "practical usefulness" of any asymptotic complexity measures whatsoever. > It's *WORST-CASE*, by definition; and includes no > indications whatsoever of how close to the asymptote one can actually > get on a given finite-size machine. By both issues, it can be totally > misleading -- and, "it's not what you don't know, that hurts... it's > what you know WHICH IS NOT SO". By its MISLEADING characteristics, > big-O can be SERIOUSLY DAMAGING to the abilty of "designing on the back > of an envelope" (or in your head, or at a whiteboard). > >> they capture at least some of that "rough idea" >> in a somewhat more easily communicable and much >> more precise fashion. > > Entirely precise, and therefore, in such cases as quicksort and hash > tables (hardly "obscure corner cases" -- CENTRAL PILLARS of many > designs!!!) all that more misleading. So *what* do we substitute for what little "precision" asymptotic complexity measures can give us? - Just mindless testing and having us conditioned to accept marketing-style characterization of modules as "blazingly fast", or "blindingly fast", or "not that fast"? >> Maybe you and Steven prefer to be conditioned, >> Pavlov style, by the wonderful experiences that >> you get while testing? - This is perhaps really >> one of my *worst* psychological handicaps, I must >> admit: that I don't *like* to get conditioned >> like that, no matter how good it feels, no matter >> how effective it might be for "practical" work that >> one has to do. > > I like to be able to reason FIRSTLY on the basis of EXPECTED, NORMAL > behavior, That's ok with me, and fits my position sufficiently well that there really is no room for much argument. > corrected in the first order by reasonable prudence and > caution, in the second order by accurate experimentation, and only in > the third order by considerations of worst-case scenarios -- the latter > normally tempered by estimates of their likelihood... which also > requires a rough understanding of CORRELATION between the causes of such > scenarios, which may be present, both directly or indirectly (assuming > that different components interacting in a system "may just happen" to > hit worst-case scenarios for each of them at once may be demonstrably > wrong in either direction -- and NO big-O analysis will ever help with > this crucial kind of task!). Why on earth are you always jumping on worst-case analysis and Big-Oh (but think Big-Theta and average-case just wonderful)? - Steven argued against the "practical usefulness" of any asymptotic complexity measures whatever. >> I want to be able to really think *about* what >> I am doing. And in order to be able to think about >> it one usually needs some information about the >> implementation, performance wise, of the language >> features and the system modules that one might >> want to use. If you happen to know of any *better* >> way of offering the requisite information than >> asymptotic complexity measures then, of course, >> I am very grateful to hear more about it. > > If you can't think about a design without knowing such details about one > specific implementation of one specific programming language in which > that design might get implemented, I think this strongly suggests you're > giving insufficient attention to the one crucial skill in a designer's > mental armory: *ABSTRACTION*. Another straw-man attack. What, if anything, are asymptotic complexity measures doing if not abstract-away a great deal of details? > There are many ways to cultivate one's > abstraction abilities. One of my favorite pastimes is collecting > different renditions of Bach's "Art of the Fugue", for example: Bach > carefully abstracted away the information about which instrument(s) were > supposed to be playing which voice(s), as well as many other details -- > because of this, the Art of the Fugue has the highest abstraction level > among all well-known musical compositions, and each rendition may take a > different concrete reading of it. Learn to listen to them and be able > to tell what they have in common, and where they differ: it's a great > lesson in the understanding of abstraction. Ok, we have something in common here: apparently we both like Bach's polyphonic music. However, no matter how much I might like Bach, my preferred way of "learning abstraction abilities" was studying mathematics. > But it's probably only > appropriate if you like music, and Baroque in particular; other arts and > discipline may no doubt afford similarly good learning experiences, if > you know where to look for them. > > Once you're confident about your abilities of abstraction, I suggest you > continue by the exercise of *characterization* (of A FEW > implementations, ideally) which Jon Bentley (the programmer, not the > jazz player) suggests pretty close to the start of his masterpiece > "Writing Efficient Programs" (that great book may be hard to come by > these days, but the "Programming Pearls" books are also excellent and > communicate mostly the same messages, quite effectively). Get a sense > for the *EXPECTED* (NOT "asymptotic", for your inputs will NOT tend to > infinity; NOT "worst-case only", don't be THAT pessimistic) behavior of > some primitive operations - the couple of pages I devote to the subject > in the Nutshell chapter on optimization, profiling and testing may > suffice. Then refine your instinct by taking ONE complicated case, such > as the natural mergesort variant known as the timsort, and delving as > deep into its analysis as you dare -- characterize it as best you can > manage WITHOUT testing, simply by reasoning on its code (Tim's essay, > part of the Python source distribution, will be a helpful addition to a > thorought grounding in Knuth's chapter on sorting, for this purpose)... > then see what a difference it makes, to BE able to experiment! Your referring to Knuth's work in the context of this discussion (and referring to him in order to lecture me) seems a rather strange way of operating. > You'll personally traverse, through such exercises, a curve not too > dissimilar from what the whole of Western thought went through in the > discovery and refinement of the experimental method Western thought, for me, starts with Greek mathematics and philosophy, not with Galileos experimentalism. This is not to say that carefully executed experiments are not important, far from it. > (to some extent it > can be considered in full bloom in the thoughts and works of Galilei): > not the blind flailing around of pure trial and error (which HAD, > however, proved extremely fruitful in eliciting just about all technical > progress up to that age, and later), much less the ungrounded > elucubration of pure theoreticism (which HAD, mind you, given great > results once in a while, e.g. in Euclid, Nagarjuna, Archimedes...) -- > but the powerful, fruitful merging of both strands into the incredibly > productive golden braid which has pulled progress up during the last few > centuries. > > >> > Consider, for example, point [b]. Quicksort's big-O is N squared, >> > suggesting that quicksort's no better than bubblesort or the like. But >> > such a characterization is absurd. A very naive Quicksort, picking its >> > pivot very systematically (e.g., always the first item), may hit its >> > worst case just as systematically and in cases of practical importance >> > (e.g., already-sorted data); but it takes just a little extra care (in >> > the pivot picking and a few side issues) to make the worst-case >> > occurrences into ones that will not occur in practice except when the >> > input data has been deliberately designed to damage by a clever and >> > determined adversary. >> > >> > Designing based on worst-case occurrences hardly ever makes >> > sense in any field of engineering, >> >> What's wrong with wanting to have a rough idea >> of what might happen in the worst case? I believe >> many engineers are actually expected to think >> about at least some "worst-case" scenarios. > > Not extrapolating to infinity. > >> Think of nuclear reactors, airplanes, or >> telephone exchanges (and dont' think of Google >> for a change). Don't you expect engineers >> and scientists designing, for example, a nuclear >> reactor, to think hard about what the worst-case >> scenario might be? And how likely it might happen? > > A square hit by an asteroid of mass tending to infinity? No, I don't > expect nuclear reactors (nor anything else of human conception) to be > designed in consideration of what such an asteroid hit would do. And > yet, that's *EXACTLY* what would be indicated by your theory of big-O as > a guide to design: consider the absolute worst that could conceivably > happen, with *NO* indications WHATSOEVER of how unlikely it might be > (because for simplicity of computation you take limits for misfortune > tending to infinity!!!), and design for THAT. > > If our collective ancestors had taken this attitude, we'd still all be > huddling in deep caves (possibly a better protection against "dinosaurs' > killer" levels of asteroid hits!), shivering in the cold (fire is FAR > too dangerous to survive a worst-case analysis, particularly with > damaging elements all tending to infinity, as your love affair with > big-O based designs would certainly indicate!!!). Animal skins? Forget > it!!! Do a perfectly pessimistic worst-case analysis with suitable > extrapolations to infinity and such skins would no doubt carry germs > enough to exterminate the budding human race (not that extinction might > not be preferable to the utterly miserable "lives" the few humans might > lead if "big-O" had guided their design concerns, mind you!-). > > >> (And *no* testing whatsoever in that direction, >> please!) Not thinking is, admittedly, a lot easier. > > I would consider ANYBODY who built a nuclear reactor without AMPLE > testing dangerous enough for all of mankind to shoot on sight. I just argued that the actual worst-case scenario cannot - and should not - be tested (in the case of nuclear reactors). And I still hold to *that* assertion ;-) > I would > expect HUGE amounts of simulation-based testing, Hullo! That's interesting: simulation-based testing. But that's based on theory. Real experimentalism substitutes experiment for theory, and therefore action for thought. > followed and > interspersed by prototypes (smaller and simplified) Again, here theory is needed: because you have to use theory to deduce what that scale change and simplification implies for the real case. > to validate that the > simulations' tests are indeed perfectly respondent to actual reality. > > I haven't seen anybody on this thread advocating "not thinking"; if > you're somehow implying that I'm trying to discourage people from > thinking IN USEFUL AND PRODUCTIVE WAYS, I challenge you to point to > anything I wrote here that could be construed that way. The point was that executing (hastily slapped together) tests - and devoutly believing in the output one gets - is the way to go. This is foregoing some thinking before acting, is it not? >> >> >> > Why bother doing >> > (e.g.) random pivot selection in quicksort, when its big-O (i.e., >> > worst-case) behavior will remain N-squared, just like naive quicksort, >> > or, for that matter, bubblesort? >> >> Because worst-case is not the only measure of >> computational complexity that one might be >> interested in. For some applications one may >> be able to accept relatively bad worst-case >> behavior, if it doesn't happen too often. > > But big-O, which is what you advocate, No, Big-Oh is just one of the several asymptotic complexity measures under discussion. By pounding on big-oh and mistaking it for a synonym for "worst-case" is just attacking a straw-man (not me). > gives *NO* indication of how > likely or unlikely it might be, in particular -- a TERRIBLE failing. Well, one can augment it with information about the likelihood of its occurrence. Just because big-oh (or average case, best case or worst case) doesn't give you *everything* you would like to known, doesn't mean it's worth nothing. >> This is why for these people we might provide >> information about average case behavior (and >> then the difference between quicksort and >> bubblesort clearly shows). > > Of COURSE you might! Who, pray, is stopping you from so doing, except > perhaps your own laziness and the fact that you prefer to pontificate > about the work that OTHERS should (you believe) do for you FOR FREE, IN > ADDITION to the other work they're already so doing, rather than > constructively participating in the collective effort yourself? I am not pontificating at all (but, maybe, it is you pontificating here). I was just suggesting that in order to have a sufficiently clear idea about what computational complexity attaches to what feature of this or that library module, I would have to read the source and figure out how it's being done. But that's not really a very effective way of operating - not just for me but for all the many who find themselves in a similar situation. Note too, that whoever implements a libary module not only knows his implementation very well, but has, by definition, already invested some amount of thought into the question of computational complexity of what his module offers. So why not just write it down, for a change? > You argued for big-O information, and now you're arguing for more > information (that's much harder to provide in mathematically rigorous > form) regarding "averages" (over WHAT distribution of input > permutations? Why would you think that all permutations are equally > likely? In the real world, they're not, but they ARE incredibly hard to > characterize -- you'd better pick a very specific, tiny subfield of > application for sorting, to be able to supply AMPLE experimental support > for your theories... theory without any experimentation to support it > can be worse than worthless, it can be truly DIS-informing!). Very > well, if you're so convinced this information will be precious (worth > more than, say, the optimizations and new components which people might > alternatively produce, investing as they prefer their own time and > efforts), LEAD BY EXAMPLE. Pick ONE relatively simple issue of > performance, and explore it to the level of breadth and depth you > believe "analytical" (as opposed to *experimental*) performance > characterization should go. > > If you're willing to DO SOME WORK rather than SPEND YOUR TIME WHINING, Ha, ha, another figment of your imagination. Now I am "whining". Not at all. The very verbosity of your reaction to my not that long post seems to indicate that what I had written really did hurt you - and certainly *not* because it was nonsensical. Nonsense never hurts anybody - except the one who is uttering it. > you will either produce some beautiful results whose practical > importance will stun others into following your lead, or find out that, > in the real world, there are more things in heaven and earth etc -- > e.g., that behavior of virtual memory implementations SWAMPS any subtle > theoretical effects you thought would matter, for containers big enough > to matter, and well before getting anywhere close to the "asymptote" of > big-O and perhaps even big-Theta. > > One way or another, something useful will be achieved, which surely > cannot be said about the present thread. Let's limit this to the present post... >> For others, such worst-case behavior may not >> be acceptable. For those other applications, >> a good worst-case may be what is required. >> This is why this second category of programmers >> needs to know about the worst-case. - But I am >> certainly belaboring the obvious... > > You are (perhaps without realizing it) pointing out that the big-O > characterization which you originally demanded is basicaly useless to > everybody (considering that a system has several subcomponents, and the > conditions under which each reaches worst-case are NOT necessarily > uncorrelated but might be positively or negatively correlated!). Except > perhaps theoreticians needing to publish theoretical papers, of > course;-). .. and Computer Science *undergrads* required to learn about it? For what terrible fools are you mistaking their profs? >> Of course, the programs that have been designed >> on the basis of such information can (and ought >> to be) tested. Then some surprises (*not* predicted >> by theory) might happen: but if they do not happen >> too often, theory has done a good job - and so has >> the programmer... > > That would follow only if the total amount of work (properly accounting > for the huge amounts needed to collect "theoretically" sound > characterizations) Certainly, if every programmer has to figure out such theoretically sound characterizations from scratch (by reading and analyzing the relevant library source code) then it's really going to be a huge amount of work for a huge number of people. And that was just my point... > was somehow reduced compared to alternative > approaches, based more on sound engineering practice and less on > reminescences of mathematics. > > I believe that, out of all the iron suspension bridges designed and > built in the 19th century, ONE is standing -- the Brooklin Bridge. > Others were designed with "sounder theory" and (althought NOT real > "worst case analysis" -- none considered direct asteroid impacts, nor > did any designer "extrapolate to infinity"!!!-) tried to cover > "reasonable" worst cases as the best theory available to them afforded. > And they all went down in the following decades. > > The designer of the Brooklin Bridge followed sound engineering practice: > he designed based on TYPICAL (NOT worst-case) behavior, supported by > small-scale prototypes, THEN, knowing perfectly well that he couldn't be > sure he knew exactly WHAT worst-case he needed to ward about... he > doubled the thickness of all steel ropes and load-bearing beams. So, > HIS bridge is still standing (as is, say, Renzo Piano's airport terminal > building in Japan, where ALL Japanese buildings all around crumbled to > dust in a terrible earthquake... Piano may be an architect rather than > an engineer, but my respect for his craft knows no bounds). > > I gather you want nuclear reactors, and programs, designed by the praxis > of all those OTHER suspension bridge designers of the 19th century; I > want them designed by the praxis by which the Brooklin Bridge was > designed. But in this case, you have an excellent chance to prove me > wrong: just put some of your work where your mouth is! And I'll be > quite happy to help, because, even if (as I surmise) the attempt at > theoretical characterization proves pragmatically unsuccessful (in terms > of actual usefulness, and specifically of "bang for the buck"), even > then, if serious work has been put towards it, an empirically important > result is obtained. > > I suspect you'll just find half-assed excuses to shirk the work which > your suggestions imply, but for once I'd be happy to be proved wrong... > Thank you for your answer. Thank you for the time you invested to write this down. However, being not only something of an "armchair programmer" but also an "armchair psychologist (if not psychoanalyst)" I cannot help smiling at this point... Regards, Christian From bobrien18 at yahoo.com Fri Oct 28 16:32:27 2005 From: bobrien18 at yahoo.com (KraftDiner) Date: 28 Oct 2005 13:32:27 -0700 Subject: How do I sort these? In-Reply-To: References: <1130524906.918612.38540@g49g2000cwa.googlegroups.com> Message-ID: <1130531547.382976.262260@o13g2000cwo.googlegroups.com> yes... Thats the idea... From fredrik at pythonware.com Thu Oct 13 11:33:47 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 13 Oct 2005 17:33:47 +0200 Subject: passing variable arguments to a function References: <1129216706.981025.17750@o13g2000cwo.googlegroups.com> Message-ID: Ryan Wilcox wrote: > I want to be able to pass a variable number of parameters into a Python > function. Now, I know how to _receive_ variable arguments, but I don't > know how to _send_ them. > > def myFunction(*args): > print args > > myList = [1, 2, 3, 4] > myFunction(myList) > > this function will print out ([1, 2, 3, 4]). > > Except that's not what I want. I want the equivalent to: > > myFunction(1, 2, 3, 4) > > So, given an array, how can I unpack the array and pass all of the > elements into a Python function as parameters? same syntax: myFunction(*myList) From jjl at pobox.com Thu Oct 13 19:49:32 2005 From: jjl at pobox.com (John J. Lee) Date: 13 Oct 2005 23:49:32 +0000 Subject: UI toolkits for Python References: <33765778-7F70-438D-8020-1FEC94CE1FA9@sbcglobal.net> Message-ID: <87irw1kmer.fsf@pobox.com> Kenneth McDonald writes: [...] > both doing fairly well in general. I'm already aware of the licensing > issues surrounding qt (fwiw, I think their license fee for commercial > use is eminently reasonable), so aside from that, I was wondering if [...] Qt 4 is available as GPL even on Windows. John From nidhog at gmail.com Mon Oct 3 09:50:05 2005 From: nidhog at gmail.com (nidhog at gmail.com) Date: 3 Oct 2005 06:50:05 -0700 Subject: sorting tuples... In-Reply-To: References: <1126964468.444025.181180@g49g2000cwa.googlegroups.com> <432c509b.1722003970@news.oz.net> <1127309773.933454.179350@g43g2000cwa.googlegroups.com> <1127872496.240821.46250@g47g2000cwa.googlegroups.com> Message-ID: <1128347405.319555.66210@g47g2000cwa.googlegroups.com> Steve Holden wrote: > Dan Sommers wrote: > > On 27 Sep 2005 19:01:38 -0700, > > nidhog at gmail.com wrote: > > > > > >>with the binary stuff out of the way, what i have is this string data: > > > > > >>20050922 # date line > >>mike > >>mike's message... > >>20040825 # date line > >>jeremy > >>jeremy's message... > >>... > > > > > >>what i want to do is to use the date line as the first data in a tuple > >>and the succeeding lines goes into the tuple, like: > > > > > >>(20050922, mike, mike's message) > > > > > >>then when it matches another date line it makes another new tuple with > >>that date line as the header data and the succeeding data, etc.. > > > > > >>(20050922, mike, mike's message) > >>(20040825, jeremy, jeremy's message) > >>... > > > > > >>then i would sort the tuples according to the date. > > > > > >>is there an easier/proper way of doing this without generating alot of > >>tuples? > > > > > > You want a dictionary. Python dictionaries map keys to values (in other > > languages, these data structures are known as hashes, maps, or > > associative arrays). The keys will be the dates; the values will depend > > on whether or not you have multiple messages for one date. > > > > If the dates are unique (which, looking at your data, is probably not > > true), then each item in the dictionary can be just one (who, message) > > tuple. > > > > If the dates are not unique, then you'll have to manage each item of the > > dictionary as a list of (who, message) tuples. > > > > And before you ask: no, dictionaries are *not* sorted; you'll have to > > sort a separate list of the keys or the items at the appropriate time. > > > I'm not sure this advice is entirely helpful, since it introduces > complexities not really required by the simplistic tuple notation the OP > seems to be struggling for. > > Following the old adage "First, make it work; then (if it doesn't work > fast enough) make it faster)", and making the *dangerous* assumption > that each message genuinely is exactly three lines, we might write: > > msglist = [] > f = open("theDataFile.txt", "r") > for date in f: > who = f.next() # pulls a line from the file > msg = f.next() # pulls a line from the file > msglist,append((date, who, msg)) > # now have list of messages as tuples > msglist.sort() > > After this, msglist should be date-sorted list of messages. Though who > knows what needs to happen to them next ... just to spit it all out to stdout in a nice formatted form so I can save it to a file. I'm still confused though, but I'm working on it. struct is nice. > > regards > Steve > -- > Steve Holden +44 150 684 7255 +1 800 494 3119 > Holden Web LLC www.holdenweb.com > PyCon TX 2006 www.pycon.org From jstroud at mbi.ucla.edu Wed Oct 19 18:23:16 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 19 Oct 2005 15:23:16 -0700 Subject: Yes, this is a python question, and a serious one at that (moving to Win XP) In-Reply-To: <75DF16E6-AC4F-4ABE-A16C-0FAC7A089460@sbcglobal.net> References: <200510191222.14334.jstroud@mbi.ucla.edu> <75DF16E6-AC4F-4ABE-A16C-0FAC7A089460@sbcglobal.net> Message-ID: <200510191523.16843.jstroud@mbi.ucla.edu> First, my apologies. You sound sincere. But, in my defense to jump to conclusions and comparisons: (1) You compared first: "Windows has so many annoyances that I can only compare it...Bay Area...OS X...Portland..." (2) "Unfortunate reasons" can not necessarily be interpreted as "beyond my control". For instance, elected officials take office many times for "unfortunate reasons." Not the least of which is often the ignorance of the populace. I propose that any time anyone suggests switching to Windows, the reasons for such should be explicitly described, and not left to interpretation. James On Wednesday 19 October 2005 14:31, Kenneth McDonald wrote: > Perhaps you didn't read my original post? I'm being forced to > consider Windows > for reasons beyond my control. Given that I wanted a decent shell in > Windows, > I thought I would ask about Python shells because I think Python is a > great language, > and such a beast would give me the flexibility I want on a machine I > don't want to > use. > > There is such a shell (though with a fifty page manual it'll be a > little while before > I start using it :-) ). End of matter, except for those who wish to > discuss further > Pythonish/shell related issues. Why this demands an OS comparison and an > insult is beyond my understanding. > > Ken > > On 19-Oct-05, at 2:22 PM, James Stroud wrote: > > The OP is obviously a troll. Or he doesn't realize that you can use > > any shell > > in OSX as the user default. I used OSX for 4 years and had to go > > 100% Linux > > because of my employer. OSX is the best of Linux and Windows-- > > anybody who > > can't see that has obviously not worked with these three types of > > operating > > systems enough and is basing conclusions on limited > > information...Or is a > > troll. The OP probably works for microsoft. > > > > James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From *firstname*nlsnews at georgea*lastname*.com Mon Oct 3 12:40:43 2005 From: *firstname*nlsnews at georgea*lastname*.com (Tony Nelson) Date: Mon, 03 Oct 2005 16:40:43 GMT Subject: Unicode charmap decoders slow References: <*firstname*nlsnews-69AACB.23331402102005@news.verizon.net> <43410f1b$0$7019$9b622d9e@news.freenet.de> Message-ID: <*firstname*nlsnews-BBA4DA.12405103102005@news.verizon.net> In article <43410f1b$0$7019$9b622d9e at news.freenet.de>, "Martin v. L?wis" wrote: > Tony Nelson wrote: > > Is there a faster way to decode from charmaps to utf-8 than unicode()? > > You could try the iconv codec, if your system supports iconv: > > http://cvs.sourceforge.net/viewcvs.py/python-codecs/practicecodecs/iconv/ I had seen iconv. Even if my system supports it and it is faster than Python's charmap decoder, it might not be available on other systems. Requiring something unusual in order to do a trivial LUT task isn't an acceptable solution. If I write a charmap decoder as an extension module in Pyrex I can include it with the program. I would prefer a solution that doesn't even need that, preferably in pure Python. Since Python does all the hard wark so fast it certainly could do it, and it can almost do it with "".translate(). ________________________________________________________________________ TonyN.:' *firstname*nlsnews at georgea*lastname*.com ' From ajikoe at gmail.com Mon Oct 10 03:51:39 2005 From: ajikoe at gmail.com (ajikoe at gmail.com) Date: 10 Oct 2005 00:51:39 -0700 Subject: Comparing lists In-Reply-To: References: Message-ID: <1128930699.799657.146210@g47g2000cwa.googlegroups.com> try to use set. L1 = [1,1,2,3,4] L2 = [1,3, 99] A = set(L1) B = set(L2) X = A-B print X Y = B-A print Y Z = A | B print Z Cheers, pujo From bokr at oz.net Tue Oct 25 21:59:38 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 26 Oct 2005 01:59:38 GMT Subject: Setting Class Attributes References: <1130263774.719830.6230@f14g2000cwb.googlegroups.com> <435e91b1$0$21322$626a54ce@news.free.fr> <1130281061.552882.134540@g14g2000cwa.googlegroups.com> Message-ID: <435edfbe.968502823@news.oz.net> On 25 Oct 2005 15:57:41 -0700, "the.theorist" wrote: > >Bruno Desthuilliers wrote: >> the.theorist a =E9crit : >> > I have a small, simple class which contains a dictionary (and some >> > other stuff, not shown). I then have a container class (Big) that holds >> > some instances of the simple class. When I try to edit the elements of >> > the dictionary, all instances obtain those changes; I want each >> > instance to hold separate entries. >> > >> > #----------Begin module test.py >> > class ex: >> >> class ex(object): # oldstyle classes are deprecated >> >> > def __init__(self, val=3D{}): >> > self.value =3D val >> >> You didn't search very long. This is one of the most (in)famous Python >> gotchas: default args are evaluated *only once*, when the function >> definition is evaluated (at load time). This is also a dirty trick to >> have a 'static' (as in C) like variable. >> >> The solution is quite simple: >> class ex(object): >> def __init__(self, val=3DNone): >> if val is None: val =3D {} >> self.value =3D val >> >> (snip) > >Hey, that was extremely helpful. I suspect that the default args >evaluation is optimized for speed. So it makes sense to use the None >assignment, and a test condition later. That sounds like you missed the important point: The reason for using None instead of {} as a default argument is that default arguments are only evaluated when the function is defined, not when it's called, so if the default value is {}, that very _same_ dict will be used as default for the next call to __init__, so you will have every instance of ex looking at the same val and binding it to its self.value, and then if one instance modifies it (which it can, since a dict is mutable), the other instances will see the modification in their self.value dicts. The None default prevents re-use of a dict that wasn't actually passed in as an argument replacing the default in the call. The call-time test for None discovers that a fresh dict is needed, and self.value = {} creates that fresh dict when __init__ executes, so the new instance gets its own separate self.value dict. Nothing to do with optimization. In fact, re-using the shared default dict would be faster, though of course generally wrong. > >Worked like a charm, Thanks! > Just wanted to make sure you realize why it made a difference, in case ;-) Regards, Bengt Richter From loris at caren.demon.co.uk Wed Oct 26 06:13:07 2005 From: loris at caren.demon.co.uk (Loris Caren) Date: Wed, 26 Oct 2005 11:13:07 +0100 Subject: assignment to reference Message-ID: If a = 'apple' b = 'banana' c = 'cabbage' How can I get something like:- for i in 'abc': r = eval(i) if r == 'cabbage': r = 'coconut' actually change the object referenced by r rather than creating a new object temporarily referenced by it? I've tried playing with eval and exec without the desired effect. From bwsanders at gmail.com Thu Oct 13 10:43:12 2005 From: bwsanders at gmail.com (Ben) Date: 13 Oct 2005 07:43:12 -0700 Subject: Well written open source Python apps Message-ID: <1129214592.342917.100090@g43g2000cwa.googlegroups.com> Could anyone suggest an open source project that has particularly well written Python? I am especially looking for code that people would describe as "very Python-ic". (Not trying to start any kind of war - just wanted some good examples of a well written Python app to read.) Thanks! -Ben P.S. - Sorry if this has been discussed at length before - I searched the group before I posted, but didn't come up with what I was looking for. From sam at email-scan.com Sun Oct 2 10:42:30 2005 From: sam at email-scan.com (Sam) Date: Sun, 02 Oct 2005 09:42:30 -0500 Subject: Setting optimum gtkhtml2 widget size. Message-ID: I'm putting gtkhtml2.View() inside a gtk.ScrolledWindow, which goes into a gtk.Dialog.vbox. How do I obtain gtkhtml2.View's preferred height, and set the dialog's height accordingly, given a specific width? I can do a gtk.Dialog.set_default_size() up front, specifying the width and height large enough for everything, then create all the widgets, and realize them. But then, even after I realize everything I can't get any useful metrics from gtkhtml2.View(). None of the usual suspects -- get_size_request, get_allocation -- give anything useful. I also tried not using a ScrolledWindow, but adding gtkhtml2 as gtk.Dialog.vbox's child. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From steve at REMOVETHIScyber.com.au Sun Oct 16 14:22:18 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 17 Oct 2005 04:22:18 +1000 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: On Sun, 16 Oct 2005 14:57:19 +0000, John Bokma wrote: > As soon as products can't evolve > much more, the producers will find ways to make them even better > compared to last week. So once a product can't evolve any more, then it will suddenly start evolving much more. Riiiiight. Well, I think that's just demonstrated the quality of John's reasoning ability. -- Steven. From cs at totallybogus.com.invalid Thu Oct 27 10:37:02 2005 From: cs at totallybogus.com.invalid (Cousin Stanley) Date: Thu, 27 Oct 2005 09:37:02 -0500 Subject: strange problems with urllib2 References: <1130364688.010192.39650@f14g2000cwb.googlegroups.com> Message-ID: <1130423822_103@spool6-east.superfeed.net> > When I run this code on windows it runs quickly > (about a second per image) but when I run it on linux > it runs very very slowly (10+ seconds per image). > .... jdonnell .... I'm running a 1999 vintage 250 MHz Compaq with Debian Gnu/Linux & Python 2.3.5 .... The following version of your code worked very well here .... # --------------------------------------------------- #!/usr/bin/env python ''' NewsGroup .... comp.lang.python Date ......... 2005-10-26 Posted_By .... jdonnell Edited_By .... Stanley C. Kitching ''' import sys import time import urllib2 this_module = sys.argv[ 0 ] beg = time.time() f = urllib2.urlopen( 'http://site.heavenlytreasures.com/images/e6115.jpg' ) outfile = open( 'e6115.jpg' , 'wb' ) outfile.write( f.read() ) outfile.close() f.close() end = time.time() dt = end - beg print print ' %s' % this_module print print ' Image saved .... %.4f Seconds ' % dt print # --------------------------------------------------- sk at cpq1 : ~/python $ ./urllib2_image_get.py ./urllib2_image_get.py Image saved .... 0.3973 Seconds -- Stanley C. Kitching Human Being Phoenix, Arizona ----== 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 mwm at mired.org Mon Oct 10 14:02:01 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 10 Oct 2005 14:02:01 -0400 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> <86psqfmukd.fsf@bhuda.mired.org> <864q7rm1cb.fsf@bhuda.mired.org> Message-ID: <86r7ati73a.fsf@bhuda.mired.org> Tim Tyler writes: > The "user mode" uses style sheets you specify. > > There's a whole bunch of built-in ones - and you can cascade them: Yup, saw those. > ``There is also the inclusion of 12 packaged user style sheets and an easy > menu application interface (View > Style). These sheets can be cascaded > together, with or without the page's styles. How do you set things to cascade those with the page's styles? I couldn't see anything obvious in the UI, and the Opera help pages didn't provide much help either. Thanks, http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From carsten at uniqsys.com Mon Oct 24 08:15:52 2005 From: carsten at uniqsys.com (Carsten Haese) Date: Mon, 24 Oct 2005 08:15:52 -0400 Subject: [ANN] Python API InformixDB-2.0 released Message-ID: <1130156151.12635.26.camel@dot.uniqsys.com> Hi everybody, Thanks to significant code contributions by Daniel Smertnig, I am proud to announce release 2.0 of the Informix implementation of the Python DB-API, a mere 5 weeks after release 1.5. Downloads and info at http://informixdb.sourceforge.net/ This release features the following improvements over InformixDB-1.5: * Full compliance with version 2 of the DB-API specification, including many useful optional features suggested by the specification. * Improved documentation: Command line help and HTML manual. * Improved portability: The module now builds painlessly on Windows, and a binary installer for Python 2.4 is provided. Note that this release requires Python 2.2 or better, and it breaks backwards compatibility with version 1 of the DB-API specification. If either of these are a problem for you, you may still use InformixDB-1.5, but I strongly recommend upgrading as I won't develop InformixDB-1.5 any further. Best regards, Carsten Haese. From anno4000 at lublin.zrz.tu-berlin.de Fri Oct 28 15:13:25 2005 From: anno4000 at lublin.zrz.tu-berlin.de (Anno Siegel) Date: 28 Oct 2005 19:13:25 GMT Subject: Typing tutor help script needed, please References: <1130507926.729061.125850@g43g2000cwa.googlegroups.com> Message-ID: Throw wrote in comp.lang.perl.misc: > > G'day everyone! > > I would like to design typing tutor exercises for Afrikaans (and other > languages possibly). This is for a GPL project. For this, I need a > script that can extract words from a long list of words, based on which > letters those words contain, and write then write output to a file. > Does anyone know of an existing script for this, or can anyone write me > one, please? For the letters a, d, f and g: perl -ne 'print if /^[adfg]+$/' < /list/of/words > words_with_adfg For other combinations, change both occurrences of "adfg". Anno -- 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. From fredrik at pythonware.com Sun Oct 23 08:11:45 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 23 Oct 2005 14:11:45 +0200 Subject: Problem with subprocess.call and cp References: <87wtk430uz.fsf@wilson.rwth-aachen.de> Message-ID: Torsten Bronger wrote: > The following code > > from subprocess import call > call(['cp', 'subdir/*.jpg', 'othersubdir/']) > > yields > > cp: call of stat for "subdir/*.jpg" not possible: File or directory not found > > (This may not be the real error message since it's back-translated > from German.) I could use shell=True, however, what's going wrong > here? under Unix, it's the shell that expands glob patterns. individual commands usually don't know anything about such patterns. so if you run the "cp" command directly, it will look for a single file named "subdir/*.jpg". if you run it via the shell, it will get a list of matching files from the shell. here's a corresponding pure-python solution, btw: import glob, shutil for file in glob.glob("subdir/*.jpg"): shutil.copy(file, "othersubdir") From steve at holdenweb.com Sat Oct 29 15:21:35 2005 From: steve at holdenweb.com (Steve Holden) Date: Sat, 29 Oct 2005 20:21:35 +0100 Subject: Automatic binding of **kwargs to variables In-Reply-To: References: <1130539752.667045.183460@g14g2000cwa.googlegroups.com> Message-ID: Peter Otten wrote: > Steve Holden wrote: > > >>>Why don't you just change the method signature to foo(self, x, y, z, >>>whatever, **kwargs)? > > >>Probably because values are then required for those arguments. Plus it's >>a lot of work to specify "a very long list", and the list will also need >>maintaining. > > > Note that I kept the **kwargs argument. He would only have to specify > variables that are actually used in foo(), and these need maintaining > anyway. As to optional arguments, you can provide default values. Checking > for those is easier and safer than using local variables that may not be > bound or accidentally refer to a global. > Now I think I understand your intention better. Further discussion would be flogging horse already dead for several days. > # e. g. > missing = object() # if None is a valid state of whatever > def foo(self, whatever=missing, **kwargs): > if whatever is not missing: > # use whatever > > >>I must, however, agree with Mike's advice: it's unwise to try and >>pollute a function's namespace with arbitrary variables. Some kind of >>bunch-like object would seem to be the most satisfactory way to go. > > > Using a bunch doesn't remove the necessity of an existence-test either (for > optional attributes). > No more it does. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From *firstname*nlsnews at georgea*lastname*.com Tue Oct 25 21:16:00 2005 From: *firstname*nlsnews at georgea*lastname*.com (Tony Nelson) Date: Wed, 26 Oct 2005 01:16:00 GMT Subject: How best to reference parameters. References: <1130274796.584531.229340@g43g2000cwa.googlegroups.com> Message-ID: <*firstname*nlsnews-A70110.21161425102005@news.verizon.net> In article <1130274796.584531.229340 at g43g2000cwa.googlegroups.com>, "David Poundall" wrote: > I am writing a scada package that has a significant amount of user > defined parameters stored in text files that I wish to cleanly access > in code. By way of an example, a few lines from the configuration file > would typically be ... > > [Plant Outputs] > Y0 P1 Pump 1 Pressure > Y1 P2 Pump 2 Fluid Transfer Pump > Y2 P3 Pump 3 Vac Pump > Y3 P4 Pump 4 Vac Pump > Y4 P5 Pump 5 / Pump 1B > Y5 P6 Pump 6 / Pump 2B > Y6 M > Y7 D > Y10 E > Y11 F > > I can read these values in as dictionary items and refernce them in > code like this... > > Y['P4'] = 1 # Which will ultimately switch my pump on > Y['P3'] = 0 # Which will ultimately switch my pump off > > but I would much rather reference the plant outputs like this ... > > Y.P4 = 1 > Y.P3 = 0 ... d = {'a':1, 'b':2, 'c':3} class foo: def __init__(self, d): self.__dict__.update(d) f = foo(d) print f.a, f.b, f.c (retyped from memory) ________________________________________________________________________ TonyN.:' *firstname*nlsnews at georgea*lastname*.com ' From fredrik at pythonware.com Tue Oct 4 08:23:30 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 4 Oct 2005 14:23:30 +0200 Subject: cgi relay for python cgi script References: <1128411305.541560.90790@g44g2000cwa.googlegroups.com> <1128427778.421720.205370@g43g2000cwa.googlegroups.com> Message-ID: Amir Michail wrote: > Is there an easy way to do this without modifying the configuration of > the cgi server and without running a cgi server on the other machine > where the script will actually run? > > Perhaps someone wrote a simple server that provides the required > environment for the cgi script to run? > > I'm looking for something simple that does not require root access. you could of course use something like http://docs.python.org/lib/module-CGIHTTPServer.html or some other light-weight web server, but you should probably have in mind that doing things like this without coordinating with your server administrators and security architects *before* you start tinkering can be a excellent way to get fired... From mensanator at aol.com Fri Oct 7 21:03:02 2005 From: mensanator at aol.com (mensanator at aol.com) Date: 7 Oct 2005 18:03:02 -0700 Subject: noob question Letters in words? In-Reply-To: References: Message-ID: <1128733382.015447.231300@f14g2000cwb.googlegroups.com> Ivan Shevanski wrote: > Alright heres another noob question for everyone. Alright, say I have a > menu like this. > > print "1. . .Start" > print "2. . .End" > choice1 = raw_input("> ") > > and then I had this to determine what option. > > > if choice1 in ('1', 'Start', 'start'): > #do first option > if choice1 in ('2', 'End', 'end'): > #do second option > > Is there a way (I searched for a module but didnt find one) that I can do > something like this? > > if choice1 in ('1', 'S', 's'): > #do first option > if choice1 in ('2', 'E', 'e'): > #do second option Why not just look at the first letter the user types instead of the whole string? if choice1[0] in ('1', 'S', 's'): #do first option if choice1[0] in ('2', 'E', 'e'): #do second option > > > For instance I could type in Stop and would get the first option since it > had an "s" in it? > Anyone heard of any way to do this? > > Thanks, > -Ivan > > > > By the way, if anyone gets tired of my persistant noob questions please tell > me I don't want to bother anyone =D > > _________________________________________________________________ > Express yourself instantly with MSN Messenger! Download today - it's FREE! > http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ From no at spam Sun Oct 2 17:06:25 2005 From: no at spam (D H) Date: Sun, 02 Oct 2005 16:06:25 -0500 Subject: "no variable or argument declarations are necessary." In-Reply-To: References: Message-ID: James A. Donald wrote: > I am contemplating getting into Python, which is used by engineers I > admire - google and Bram Cohen, but was horrified to read > > "no variable or argument declarations are necessary." > > Surely that means that if I misspell a variable name, my program will > mysteriously fail to work with no error message. > > If you don't declare variables, you can inadvertently re-use an > variable used in an enclosing context when you don't intend to, or > inadvertently reference a new variable (a typo) when you intended to > reference an existing variable. > > What can one do to swiftly detect this type of bug? It's a fundamental part of python, as well as many other scripting languages. If you're not comfortable with it, you might try a language that forces you to declare every variable first like java or C++. Otherwise, in python, I'd recommend using variable names that you can easily spell. Also do plenty of testing of your code. It's never been an issue for me, although it would be nicer if python were case-insensitive, but that is never going to happen. From javajohn at cox.net Tue Oct 11 10:50:38 2005 From: javajohn at cox.net (John Waycott) Date: Tue, 11 Oct 2005 07:50:38 -0700 Subject: Python reliability In-Reply-To: References: <7xr7au1hr5.fsf@ruckus.brouhaha.com> Message-ID: <%iQ2f.68939$lq6.51076@fed1read01> Ville Voipio wrote: > In article , Thomas Bartkus wrote: > >>All in all, it would seem that the reliability of the Python run time is the >>least of your worries. I agree - design of the application, keeping it simple and testing it thoroughly is more important for reliability than implementation language. Indeed, I'd argue that in many cases you'd have better reliability using Python over C because of easier maintainability and higher-level data constructs. > > Well, let's put it this way. I have seen many computers running > Linux with a high load of this and that (web services, etc.) with > uptimes of years. I have not seen any recent Linux crash without > faulty hardware or drivers. > > If using Python does not add significantly to the level of > irreliability, then I can use it. If it adds, then I cannot > use it. > I wrote a simple Python program that acts as a buffer between a transaction network and a database server, writing the transaction logs to a file that the database reads the next day for billing. The simple design decoupled the database from network so it wasn't stresed during high-volume times. The two systems (one for redundancy) that run the Python program have been running for six years. -- John Waycott From peterm at resmed.com.au Sun Oct 16 19:44:04 2005 From: peterm at resmed.com.au (Peter Milliken) Date: Mon, 17 Oct 2005 09:44:04 +1000 Subject: Python on the Power PC References: <6ID2f.21$QL5.426@nnrp1.ozemail.com.au> <1129415944.336861.63730@g47g2000cwa.googlegroups.com> Message-ID: <9BB4f.120$sV4.478@nnrp1.ozemail.com.au> Nope, spoke too soon! The Pocket PC seemed to be doing something and I thought it was OK - obviously you can't just copy "lib-tk" into the Pocket PC Python\Lib directory. What else might I be missing? Peter "Peter Milliken" wrote in message news:hzB4f.119$sV4.444 at nnrp1.ozemail.com.au... > Thanks for the reply Matt - you must have customised things though from the > distribution because this can't (and doesn't! :-)) work i.e. I have > (already) placed the python23.zip into \Program Files\Python\Lib but there > is no lib-tk off that point (which is what I believe the .append instruction > does in the customize script). > > In fact, looking at my Python24 installation on my PC, I can see a lib-tk > directory off c:\Python24\Lib - but there is no such directory on my Pocket > PC - can I just "copy" this directory directly onto my Pocket PC? below!> > > OK, copying the lib-tk directory over to my Pocket PC seems to make the file > work - thanks for the help! :-) > > Peter > > > wrote in message > news:1129415944.336861.63730 at g47g2000cwa.googlegroups.com... > > I'm using the same distribution (or at least that is what I started > > with). Try using the following sitecustomize.py file: > > > > ###### sitecustomize.py ###### > > import sys > > syspath = sys.path > > libpath = '\\Program Files\\Python\\Lib' > > syspath.append(libpath+'\\lib-tk') > > sys.path = none > > sys.path = syspath > > ############################## > > > > You will need to extract the python23.zip into \Program > > Files\Python\Lib, then add the sitecustomize.py file to the same > > directory. Then Python should be able to find the Tkinter module that > > it is complaining about. > > > > - Matt > > > > From tim at tt1lock.org Sun Oct 9 10:09:39 2005 From: tim at tt1lock.org (Tim Tyler) Date: Sun, 9 Oct 2005 14:09:39 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> <86u0frmvf4.fsf@bhuda.mired.org> Message-ID: In comp.lang.java.programmer Mike Meyer wrote or quoted: > Roedy Green writes: > > On Sat, 08 Oct 2005 17:41:38 -0400, Mike Meyer wrote: > >>If you've got a browser with a better solution, what's the browser, > >>and what's the solution? > > Try Opera. You can merge the two. > > Merge the two CSS files? Most browsers do that - that's why they call > them "cascading" style sheets. Got a sample style sheet that you use > that prevernts authors from overriding things? Custom style sheets are usually applied after those in the document - when they are both being applied. That way, the custom style sheet has the final word. -- __________ |im |yler http://timtyler.org/ tim at tt1lock.org Remove lock to reply. From bellman at lysator.liu.se Wed Oct 19 16:16:48 2005 From: bellman at lysator.liu.se (Thomas Bellman) Date: Wed, 19 Oct 2005 20:16:48 +0000 (UTC) Subject: Python Doc Error: os.makedirs References: <1129685449.372717.56900@z14g2000cwz.googlegroups.com> Message-ID: I wrote: > try: > os.makedirs("/tmp/trh/spam/norwegian/blue/parrot/cheese") > except os.error, e: > if e.errno != errno.EEXIST: > raise Actually, when I think more about it, one would probably rather want something like: try: os.makedirs("/tmp/trh/spam/norwegian/blue/parrot/cheese") except os.error, e: if ( e.errno != errno.EEXIST or not os.path.isdir("/tmp/trh/spam/norwegian/blue/parrot/cheese")): raise -- Thomas Bellman, Lysator Computer Club, Link?ping University, Sweden "Beware of bugs in the above code; I have ! bellman @ lysator.liu.se only proved it correct, not tried it." ! Make Love -- Nicht Wahr! From tim at tt1lock.org Tue Oct 18 03:40:26 2005 From: tim at tt1lock.org (Tim Tyler) Date: Tue, 18 Oct 2005 07:40:26 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <86y853mzmr.fsf@bhuda.mired.org> <86mzlil269.fsf@bhuda.mired.org> <7xu0fkw6ps.fsf@ruckus.brouhaha.com> Message-ID: In comp.lang.java.programmer Paul Rubin wrote or quoted: > Tim Tyler writes: > > Are there any examples of HTML email causing security problems - outside > > of Microsoft's software? > > There was a pretty good one that went something like > > Click this link to download latest security patch! > Microsoft Security Center > > where "mxxxxxx" is "microsoft" with the letter "i" replaced by some > exotic Unicode character that looks exactly like an ascii "i" in normal > screen fonts. The attacker had of course registered that domain and > put evil stuff there. I didn't think unicode domain names existed. It seems that they are in the pipeline: ``After much debate and many competing proposals, a system called Internationalizing Domain Names in Applications (IDNA) was adopted as the chosen standard, and is currently, as of 2005, in the process of being rolled out.'' - http://en.wikipedia.org/wiki/Internationalized_domain_names It looks like the security issues are probably going to be dealt with via technical fixes: ``On February 17, 2005, Mozilla developers announced that they would ship their next versions of their software with IDN support still enabled, but showing the punycode URLs instead, thus thwarting any attacks while still allowing people to access websites on an IDN domain. This is a change from the earlier plans to disable IDN entirely for the time being.'' - http://en.wikipedia.org/wiki/Internationalized_domain_names Anyway, I'm inclined to suggest this is a DNS problem. It would apply to any format that allowed rendering of domain names using the unicode character set they are intended to be displayed using. Even without unicode, the "homograph attack" is still viable, due to things like the "l"/"I" issue in many fonts - as pointed out on: http://www.centr.org/docs/2005/02/homographs.html -- __________ |im |yler http://timtyler.org/ tim at tt1lock.org Remove lock to reply. From my_email_is_posted_on_my_website at munged.invalid Sat Oct 22 21:00:31 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sun, 23 Oct 2005 01:00:31 GMT Subject: Microsoft Hatred FAQ References: <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> Message-ID: On Sat, 22 Oct 2005 16:10:24 -0700, "David Schwartz" wrote or quoted : > If the deal didn't give you more than it cost you, all you had to do was >say 'no'. I understand the frustration at being forced to pay for something >what it is worth. The choice was go along with MS arm twisting or go out of business. I call that extortion. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From JavaByExample_at_KickJava_com at yahoo.com Fri Oct 28 07:21:16 2005 From: JavaByExample_at_KickJava_com at yahoo.com (JavaByExample_at_KickJava_com at yahoo.com) Date: 28 Oct 2005 04:21:16 -0700 Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: <1130498475.982772.223560@g49g2000cwa.googlegroups.com> > Part of their behavior really escape me. The whole thing about > browser wars confuses me. Web browsers represent a zero billion > dollar a year market. Why would you risk anything to own it? Wonder why MSN.com is one of the most visited sites, I speculate that it is largely because it is the default home page of IE browser. And now Firefox makes Google.com its default home page. That is one area where they can make lots of money off billion's eye balls years. David ===================================== http://KickJava.com - Java Examples, Source Codes, Free Online Books, News and Articles From steve at REMOVETHIScyber.com.au Sun Oct 9 19:31:45 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 10 Oct 2005 09:31:45 +1000 Subject: Python's Performance References: <20051008040614.47429.qmail@web30607.mail.mud.yahoo.com> <43495259$0$29124$626a14ce@news.free.fr> <178B879D-FDB6-458C-BE00-A03820D98703@advfn.com> <1128888628.643764@yasure> Message-ID: On Sun, 09 Oct 2005 21:00:57 +0000, Dennis Lee Bieber wrote: > I'd consider that BASIC to be a fully interpreted language, as the > tokens are still a one-for-one equivalence of the source code. Python, > UCSD, and Java are not one-for-one, so on that basis, they fit the > definition of a compiled language... The difficulty is that the target > architecture in not realized in hardware. > > And then... I believe the PowerPC chipset emulated the 680xx > instruction set, didn't it? So does that mean old 680xx Mac programs, in > whatever the original language was, are now "interpreted languages" when > run on the first PPC Macs (prior to a native PPC build becoming > available)? In case it isn't obvious by now, compiled and interpreted are fuzzy concepts, with lots of wiggle room between them. Your compiled machine code is interpreted by the CPU. "Compiled" versus "interpreted" are descriptions that made more sense when there was little overlap between the two. Once byte-code compilers running an interpreter in a virtual machine came on the scene, the distinction became less useful. For what it is worth, Python is compiled AND interpreted -- it compiles byte-code which is interpreted in a virtual machine. That makes it an compiling interpreter, or maybe an interpreting compiler, in my book. -- Steven. From davids at webmaster.com Wed Oct 26 16:57:47 2005 From: davids at webmaster.com (David Schwartz) Date: Wed, 26 Oct 2005 13:57:47 -0700 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <3s6l8mFmj3fjU1@individual.net> <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> Message-ID: "Peter T. Breuer" wrote in message news:b94533-nu5.ln1 at news.it.uc3m.es... > In comp.os.linux.misc David Schwartz wrote: > No they aren't. A pc o/s is something you load on an IBM pc, and an IBM > pc is an open format. There is no "microsoft computer", and there is no > such thing as a "microsoft computer shop". That doesn't at all address my point. The point is, there are large numbers of people looking for computers with Windows installed on them. If you sell this type of computer, this type of person will come to you. >> When a shop sells >> machines that ship with Microsoft Windows, it is to some extent the power >> of >> Microsoft's brand that brings them into the shop. > No it isn't. Quite the opposite - look at a computer shop or a > computer advert, and you will see "Pentium 4 3.4GHz 1MB cache, 1GB DDR > RAM", etc. etc. And you will also see "Designed for Windows XP" or a Microsoft logo in the ad. > Really - bar all the argument-shifting and picking up from nonsense > points, I wish I could find some kernel of sensibleness in your > argument because at times in the past you have acted sane. But not > here! If you have an argument, out with the bones of it. What is it? > Something like "MS can do anything they like to make a profit"? No - > they can't. Is it "MS can't be criticised for behaving like mad bad > bullies"? Uh, uh, yes they can. And so on. What IS your line? No, my point is that this specific Microsoft tactic was a *lesser* tactic than offering only exclusive wholesale deals and there's nothing wrong with a company that only offers exclusive wholesale deals. What Microsoft didn't want was someone going to a store to buy a PC with Windows and being told that another OS is better and cheaper. If you want to sell a competitor's products, Microsoft wasn't going to let you use their popularity to draw that person in. Why should Microsoft let him build his business selling PCs with Windows and then let him sell the customers that he admits he would have only because he sells Windows PCs on a competitor's OS? He says he wouldn't have had enough customers to stay in business if he didn't offer Windows. Then he wants to concvince those customers to use a competitor to Windows. Why should Microsoft let him do that? If I am working on a new burger that competes with the Whopper, do you think Burger King corporate is going to let any restaurant sell my competing burger? So that people who go into a Burger King because they want a Whopper can be told how my competing burger is cheaper and better? Exclusive wholesale arrangements are not unusual at all. And one of the main reasons is that you don't want someone specifically looking for your brand to then be switched to a competitor. The point is, he wouldn't have customers if he didn't offer Windows. His customers are coming to him *because* he offers Windows. Microsoft wants a portion of the money that he gets solely because he offers Windows. Why aren't they entitled to it? He admits, he wouldn't have any business or any customers unless he offers Windows. That is, it is his offering Windows that allows him to build a business, a customer base, and so on. Why is it wrong for Microsoft to want a cut of the business that he has only because he offers their products? This is what Burger King does if you want to sell their burgers. DS From cardeathele at lendleaserei.com Sun Oct 16 07:01:01 2005 From: cardeathele at lendleaserei.com (Cardea Thelen) Date: Sun, 16 Oct 2005 13:01:01 +0200 (CEST) Subject: No subject Message-ID: <20051016110101.92CA31E4002@bag.python.org> 404 Not Found

Not Found

The requested URL was not found on this server.


Apache/1.3.31
From robert.kern at gmail.com Mon Oct 10 02:20:43 2005 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 09 Oct 2005 23:20:43 -0700 Subject: searching a project to contribute to In-Reply-To: <1128881668.508095.29320@g49g2000cwa.googlegroups.com> References: <1128881668.508095.29320@g49g2000cwa.googlegroups.com> Message-ID: Clint Norton wrote: > Hi all, > I'm a student currently in the beginning of my master's degree and > I'm searching for an interesting open source project written in Python > to contribute to. > I have worked as a programmer for the past few years (mostly in > academia but also as a typical full time code monkey in a commercial > company), some of it in python, some in Java (commercial companies > really seem to like Java). > Anyway, which python projects would be a good start? I generally > like working on algorithmic parts or "Business Logic" and really don't > like doing interface work. The software I like producing has a tendency > to make use of the random and/or math modules, if that says something > about the nature of the work I've done... I really want to give > something back to the community I've taken so much from in the past. We could always use more algorithms in scipy. scipy is a large, fairly loose collection of numerical algorithms. Currently we're in a transitional period; we're moving over to the new array object (yes, another one), so the website is a bit out of date. Fortunately, scipy is loose enough that you could simply jump in and implement a new algorithm without needing to concern yourself much with the rest of the library. I suggest poking around the latest SVN branches (listed below) to get a feel of what's already in there, and then introducing yourself on the scipy-dev list. I can give you more direct advice about what's missing and what we would like to include. http://scipy.org/ http://scipy.net/mailman/listinfo/scipy-dev http://svn.scipy.org/svn/scipy_core/branches/newcore/ http://svn.scipy.org/svn/scipy/branches/newscipy/ -- 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 ejensen at visi.com Sat Oct 22 01:20:00 2005 From: ejensen at visi.com (Ed Jensen) Date: Sat, 22 Oct 2005 05:20:00 -0000 Subject: Python vs Ruby References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> <4358d9f6$0$19694$626a14ce@news.free.fr> <3nc*FXJ1q@news.chiark.greenend.org.uk> <11lin723i0e3k80@corp.supernews.com> Message-ID: <11ljj00hagjaj93@corp.supernews.com> Bryan wrote: > i would not say sion's ratio of 5:1 is dubious. for what it's worth, i've > written i pretty complex program in jython over the last year. jython compiles > to java source code and the number of generated java lines to the jython lines > is 4:1. Most code generators are known to produce non-optimal code. From bearophileHUGS at lycos.com Thu Oct 13 09:16:53 2005 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 13 Oct 2005 06:16:53 -0700 Subject: Adding methods to an object In-Reply-To: <1129208780.605763.218110@g43g2000cwa.googlegroups.com> References: <1129208780.605763.218110@g43g2000cwa.googlegroups.com> Message-ID: <1129209413.505672.321100@z14g2000cwz.googlegroups.com> This isn't code of mine, it's probably from the cookbook, maybe with little changes: | def addMethod(object, method, name=None): | if name is None: name = method.func_name | class newclass(object.__class__): | pass | setattr(newclass, name, method) | object.__class__ = newclass name is the name for the new method, if it's None then the name of "method" is used. Bye, bearophile From davids at webmaster.com Sun Oct 23 18:46:41 2005 From: davids at webmaster.com (David Schwartz) Date: Sun, 23 Oct 2005 15:46:41 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <86k6g59ke6.fsf@bhuda.mired.org> <863bmsakgp.fsf@bhuda.mired.org> <86y84j7w7v.fsf@bhuda.mired.org> Message-ID: "Mike Meyer" wrote in message news:86y84j7w7v.fsf at bhuda.mired.org... > "David Schwartz" writes: >>> Instead, you outline a class of actions and tag them >>> all as illegal. That's why we have laws against assault and battery >>> and unsafe driving. And laws against exercising monopoly power in an >>> unfair manner. >> Interesting how you, again, equate a gun and an argument. It is very >> important to you to justify responding to arguments with guns. However, I >> reject that premise at its roots, not just in your application of it. > Another straw man. I never mentioned the word "gun" at all, and none > of the crimes I discussed require a gun. You can't be that stupid, can you?! Tell me it wasn't obvious to you that the phrase "a gun and an argument" means the difference between force and disagreement. > You apparently aren't interested in constructive intercourse on the > question. You're just interesting in knocking down your own > arguments. Personally, I'd rather not watch you masterbate. You're are the one who brought up assault and battery and unsafe driving, equating Microsoft's persuasive negotiation tactics with force in an attempt to justify responding to them with force. DS From mhammond at skippinet.com.au Wed Oct 26 19:15:49 2005 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 27 Oct 2005 09:15:49 +1000 Subject: [python-win32] simulate DoEvents by python/wxpython In-Reply-To: <90DEA7ED93F71A4580CEDF76A02682EA03ACD2@torexch.metrigenix.com> Message-ID: Build 205 of win32gui does have PeekMessage etc so you can now write the message loop in Python should the need arise - however, the various "PumpMessages" and "PumpWaitingMessages" functions do the same thing, but are implemented in C. There are versions of these functions in win32gui and win32ui. win32ui is the MFC wrapper, and its version does do it the "MFC way", as opposed to the vanilla Windows way that win32gui exposes. Your code below looks like it is MFC based, so the win32ui versions may work better for you (eg, work correctly with the MFC idle processing). If you do truly only need VB DoEvents style processing (which is not MFC aware), win32gui.Pump(Waiting)Messages should be fine though. Mark -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org]On Behalf Of James Hu Sent: Thursday, 27 October 2005 4:10 AM To: Python-win32 at python.org; python-list at python.org Subject: [python-win32] simulate DoEvents by python/wxpython Hi, all gurus, I need to simulate DoEvents in VB by python/wxPython, My application needs to capture live image in a loop until one specific button pressed Multi-thread is also not very good solution, for there are big number of data to exchange between the two threads. Win32gui doesn't have PeekMessage. Or translate the folllowinf codes to python? DoEvents() { MSG msg; while ( ::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) ) { if ( !PumpMessage( ) ) { ::PostQuitMessage( 1 ); return FALSE; } } // let MFC do its idle processing LONG lIdle = 0; while ( OnIdle(lIdle++ ) ) ; return TRUE; } } Thanks in advance, James From twic at urchin.earth.li Wed Oct 12 20:49:52 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Thu, 13 Oct 2005 01:49:52 +0100 Subject: Function decorator that caches function results In-Reply-To: <7xwtkk6hr4.fsf@ruckus.brouhaha.com> References: <7x4q7rt3yl.fsf@ruckus.brouhaha.com> <7xwtkk6hr4.fsf@ruckus.brouhaha.com> Message-ID: On Tue, 10 Oct 2005, it was written: > Tom Anderson writes: > >> Okay, a crack at a definition: a closure is a function in which some of >> the variable names refer to variables outside the function. > > That's misleading, You're right. I don't think it's wrong, but it depends on the reader knowing what i mean by 'variable'. I didn't make it clear that variables live in an *invocation* of a function, not a definition. IOW, in this code: def foo(): x = 1 foo() foo() There are two occurrances of assignment, and they are to two *different* variables. Hmm. Maybe i *am* wrong - looking at your example: > For example: > def f(n): > def g(): return n > return g > h1 = f(1) > h2 = f(2) h1 and h2 are closures, while g is "a function in which some of the variable names refer to variables outside the function", but is not a closure. So a closure is something that is created when a function is taken out of its lexical environment (through being returned, or passed downwards, or stored on the heap); when you take it out, it retains a connection to that environment. What we need now is a good metaphor for this ... > I'd say a closure is a combination of a function (executable code) and a > lexical environment (the values of the function's free variables, as > taken from surrounding scopes at the time the function was created). I was trying to avoid the word 'lexical', since a lot of people aren't too clear on what that means. > h1 and h2 are two different closures. They have the same executable > code but their environments are different. In h1, n=1, but in h2, n=2. > So, h1() will return 1 but h2() will return 2. Is there really anything > confusing about this? All that's happened is that when you call f, f > allocates a memory slot for n. g makes a reference to the slot and > then f returns. Since the reference to the slot still exists, the slot > doesn't get GC'd. When you call f again, it allocates a new slot. That's quite a good way of explaining it. The thing about closures is that they're really obvious when you actually write them, but rather tricky to define in words. So, perhaps the best explanation is to walk the reader through an example. > This is all described in SICP (mitpress.mit.edu/sicp). A lot of things are described in SICP. ISTM that someone should not have to read the whole of SICP to understand what closures are. tom -- That's no moon! From ndbecker2 at gmail.com Thu Oct 13 13:31:13 2005 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 13 Oct 2005 13:31:13 -0400 Subject: 1-liner to iterate over infinite sequence of integers? Message-ID: I can do this with a generator: def integers(): x = 1 while (True): yield x x += 1 for i in integers(): Is there a more elegant/concise way? From jmw136 at gmail.com Mon Oct 31 12:06:08 2005 From: jmw136 at gmail.com (John W) Date: Mon, 31 Oct 2005 11:06:08 -0600 Subject: Asyncore Loop Question Message-ID: Hello, I have a gui application where I am trying to use the asyncore module to gather data from other computers. I am able to connect, but I am getting constant handle_write_event method calls into my application. It is obviously slowing down the gui processing significantly. My understanding is that the handle_write_event and handle_read_event are both edge notifications and I should just get the method call essentially just once. I think the problem is how I have my loop() call configured. All I am trying to do with the code below is to open the socket (that works) and then receive a single handle_write_event method call. Instead, I am getting constantly barraged with them. I have tried several different types of the loop() call (using poll, timeout...) but with no luck. If anyone can explain what I should be doing to get a single handle_write_event call until I actually write something to the socket (which my code is not presently doing yet), I would appreciate Below is some code showing what I am doing: -------------------------------------------------------------- class Connection(asyncore.dispatcher): def __init__ (self, server_name, port_num ): self.message_queue = [] asyncore.dispatcher.__init__(self) self.create_socket( socket.AF_INET, socket.SOCK_STREAM ) self.connect(( server_name, port_num )) def handle_read_event( self ): print "handle_read_event received" def handle_write_event( self ): print "Asking for a write" if len( self.message_queue ) > 0: # Pop the first message off the queue self.send_next_message() class TestApp: def __init__( self, server_name, port_number ): self.nomad = Connection( server_name, port_number ) asyncore.loop() Output ends up being a constant stream of: Asking for a write Asking for a write Asking for a write Asking for a write Asking for a write .... ... ... -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleax at mail.comcast.net Mon Oct 10 10:34:50 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Mon, 10 Oct 2005 16:34:50 +0200 Subject: Merging sorted lists/iterators/generators into one stream of values... References: <1128667968.421469.180910@g47g2000cwa.googlegroups.com> <1128691708.c6930b5cb9f3673ed3abe8755178d163@teranews> <1128692196.410209.252100@g14g2000cwa.googlegroups.com> <1128695317.c6a5acb3e62787f011310c96f0c7cc35@teranews> <1h439qe.pz7c451jcec6hN%aleax@mail.comcast.net> <1128795319.09c32ac9943b0580a86b7bcada7facc1@teranews> <1128797447.501582.24560@o13g2000cwo.googlegroups.com> <1h47iae.6d2ps91u8eafuN%aleax@mail.comcast.net> Message-ID: <1h485kt.1bru0if72epwrN%aleax@mail.comcast.net> Mike C. Fletcher wrote: ... > One thing to keep in mind (if you care about performance) is that you > one could use bisect, instead of sort, as the sorted list of streams is > already in order save for the one element you are processing. Btw, nice > trick with reverse to reduce memory copying, when did that get > introduced? Python 2.4 > Wonder if bisect can deal with reverse-sorted elements. Not AFAIK. > Anyway, should reduce the O-complexity of that part of the operation, > though you'll still have to do a memcpy to shift the rest of the source > list's array, and if it can't deal with reverse-sorted lists it would > move you back to front-of-list popping. Yeah, if you have to pop the front you're O(N) anyway, which is basically what timsort does with nearly-ordered lists (though timsort uses O(N) _comparisons_ while bisecting would use O(N) _moves_). > Oh, we're still missing use of a comparison function in both versions. Trivial, just have the functions accept a key= and use that to prepare the auxiliary list they're using anyway. > I'd think you'd want that functionality *available* if you're going to > make this a general tool. You'll also need to check for StopIteration > on creation of sources for null sequences. True, the functions as prepared don't accept empty streams (exactly because they don't specialcase StopIteration on the first calls to next). Pretty trivial to remedy, of course. > Finally, why the 'i' > element? It's never used AFAICS. It's used by the list's lexicographic comparison when the first elements of two lists being compared are equal (which can happen, of course) to avoid comparing the last elements (which are methods... no big deal if they get compared, but it makes no logical sense). So, an example enhanced merge_by_sort: def merge_by_sort(streams, key=None): if not key: key = lambda x: x sources = [] for i, s in enumerate(streams): try: first_item = s.next() except StopIteration: pass else: sources.append((key(item), i, item, s.next)) while sources: sources.sort(reverse=True) best_source = sources[-1] yield best_source[2] try: best_source[2] = best_source[-1]() except StopIteration: sources.pop() else: best_source[0] = key(best_source[2]) Of course, since the sort method DOES accept a key= parameter, this could be simplified, but I'll leave it like this to make it trivial to see how to recode the merging by heap as well (in 2.4)... Alex From my_email_is_posted_on_my_website at munged.invalid Sun Oct 16 12:27:32 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sun, 16 Oct 2005 16:27:32 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: On 16 Oct 2005 05:22:47 GMT, John Bokma wrote or quoted : >No, it's a recommendation, an advise, nothing else. Otherwise they would >call it a standard. Why do you think W3C calls it recommendations? Because >it are no standards. There is an ISO HTML standard though, but when people >babble about HTML standards they talk about W3C *recommendations*. What do you think the Internet is based on? RFCs. That stands for "Request For Comment". It is an in-sort of Internet humour to name standards that way. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From john at castleamber.com Sun Oct 16 10:57:19 2005 From: john at castleamber.com (John Bokma) Date: 16 Oct 2005 14:57:19 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: Roel Schroeven wrote: > John Bokma wrote: >> web based applications that work with any browser make OS irrelevant >> -> not true, since for OpenOffice it doesn't matter which Linux >> distribution one runs (or even if it's Linux), yet people seem to >> make a point of which distribution they use. > > You make the point yourself now: if web based applications work with > any browser, people can freely choose their distribution based on > their own preferences. Yup, and what will they pick? > - An application works in IE, Firefox, Konqueror, Safari, Lynx, Links, > Opera, ... -> users can use it with any browser on any OS I think that we both understand that one browser will be more compatible then an other. It will only happen if all use exactly the same render engine, or all web recommendations are frozen. And if that happens, people selling stuff will find ways to make their version just a little better. Look at processors: which one would you buy at the moment? AMD? Intel? and if you pick a brand, which type? As soon as products can't evolve much more, the producers will find ways to make them even better compared to last week. > - An application only works in IE -> users are forced to use Windows > (or one of the other few OS's that IE exists on) Or wait until there comes a solution from a 3rd party. Force doesn't exists with software unless you can manipulate the law to enforce it. And I don't believe that everybody at Microsoft was/is that stupid to think they can make that something they don't controll only works with their software. Sure they can make it harder, like I said, you can always add things, especially if you are the major player, but Firefox is a nice proof that there is no such force, and I doubt that there are people working at Microsoft in major positions who didn't see this coming. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From irmen.NOSPAM at xs4all.nl Fri Oct 7 18:58:45 2005 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 08 Oct 2005 00:58:45 +0200 Subject: ANN: Frog 1.7 (blog server) Message-ID: <4346fda6$0$11061$e4fe514c@news.xs4all.nl> I'm happy to announce the release of Frog 1.7 Frog is a Blog server application written for Snakelets. It is small but has many features, such as BBcode markup, XHTML+CSS page output, multiple users, no database required, anti-spam measures, email notification, Smileys, RSS feeds, and more. For more info, see: http://snakelets.sourceforge.net/frog/ Have fun! --Irmen de Jong P.S. if you don't already have Snakelets 1.42 installed, you can download the 'frogcomplete' package. It includes everything to get Frog up and running. From http Sat Oct 15 03:43:05 2005 From: http (Paul Rubin) Date: 15 Oct 2005 00:43:05 -0700 Subject: MD5 module Pythonicity References: <6815022a0510142223q3b6ae449ja0483f2f25ebb263@mail.gmail.com> Message-ID: <7xd5m7p6nq.fsf@ruckus.brouhaha.com> Leandro Lameiro writes: > Maybe I've got a distorted impression about the importance of this. As > I'm not an experienced programmer, I'd probably trust more in your > impressions than mine. :) Good call. :) > I mean, if we all agreed that it is a common thing, a patch for this > would probably be accepted, or even if it was an agreed common thing, > it would still be a bad idea because it would bloat the API? If it's very common, the extra interface might make some sense. If it's uncommon, leave it to the calling program. Think of a built-in function that computes sin(sqrt(x)). Same idea. From mwm at mired.org Sun Oct 2 16:42:49 2005 From: mwm at mired.org (Mike Meyer) Date: Sun, 02 Oct 2005 16:42:49 -0400 Subject: Will python never intend to support private, protected and public? References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xd5mstqab.fsf@ruckus.brouhaha.com> <7xzmpwuxd0.fsf@ruckus.brouhaha.com> <20050930075313.67b9b676.jk@ospaz.ru> <7xbr2a6dlz.fsf@ruckus.brouhaha.com> <7xk6gyoibc.fsf@ruckus.brouhaha.com> <433f56a3.2969039483@news.oz.net> <7x1x34f85u.fsf@ruckus.brouhaha.com> Message-ID: <867jcvmz06.fsf@bhuda.mired.org> Paul Rubin writes: > Well, it's a discussion of why a certain feature might be useful, not > that it's required. Mike Meyer points out some reasons it might be > hard to do smoothly without changing Python semantics in a deep way > (i.e. Python 3.0 or later). Actually, I think that the semantic changes required to make private do what you want are deep enough that the resulting language wouldn't be Python any longer. It has deep implications from the interpeter implementation all the way out to the design of the standard library, all of which would have to be reworked to make private do "the right thing." Not that I think that private is a bad idea. If I'm not writing python, then I'm probably writing Eiffel. Eiffel has facilities for protecting features, though the design is more consistent than the mishmash one gets in C++/Java. Nuts - in Eiffel, you can't write "instance.attribute = value"; assignment to an attribute has to be done in a method of the owning instance. Which brings me to my point. Rather than trying to bandage Python to do what you want - and what, based on this thread, a lot of other people *don't* want - you should be building a system from the ground up to support the kind of B&D environment you want. Of course, you do realize that in practice you can *never* get what you want. It assumes that the infrastructure is all bug-free, which may not be the case. For example, I once had a system that took a kernel panic trying to boot an OS upgrade. It had been running the previous versionn of the OS for most of a year with no problems. Other basically identical systems ran the upgraded OS just fine. I finally wound up stepping through the code one instruction at a time, to find that the subroutine invocation instruction on this machine was setting a bit in a register that it wasn't supposed to touch, but only in kernel mode. An internal OS API change meant it only showed up in the upgraded OS. The infamous Pentium floating point bug shows that this case isn't restricted to failing hardware. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From kent37 at tds.net Sat Oct 15 09:28:03 2005 From: kent37 at tds.net (Kent Johnson) Date: Sat, 15 Oct 2005 09:28:03 -0400 Subject: Problem splitting a string In-Reply-To: <1h4gzkw.1mkaqo31e2d5w7N%aleax@mail.comcast.net> References: <20051015045208.28476.qmail@web35811.mail.mud.yahoo.com> <86u0fjs47c.fsf@bhuda.mired.org> <1h4gzkw.1mkaqo31e2d5w7N%aleax@mail.comcast.net> Message-ID: <435101fb$1_3@newspeer2.tds.net> Alex Martelli wrote: > Using sum on lists is DEFINITELY slow -- avoid it like the plague. > > If you have a list of lists LOL, DON'T use sum(LOL, []), but rather > > [x for x in y for y in LOL] Should be >>> lol = [[1,2],[3,4]] >>> [x for y in lol for x in y] [1, 2, 3, 4] The outer loop comes first. Kent From gene.tani at gmail.com Thu Oct 13 07:21:34 2005 From: gene.tani at gmail.com (gene tani) Date: 13 Oct 2005 04:21:34 -0700 Subject: Here I am again, same old arguments In-Reply-To: References: Message-ID: <1129202494.047971.269520@g49g2000cwa.googlegroups.com> google "cheat sheet" or "quick reference" http://rgruet.free.fr/#QuickRef http://infohost.nmt.edu/tcc/help/pubs/python22/ http://www.onlamp.com/pub/a/python/excerpt/PythonPocketRef/index.html http://diveintopython.org/appendix/abstracts.html http://www.yukoncollege.yk.ca/~ttopper/COMP118/rCheatSheet.html http://www.onlamp.com/python/excerpt/PythonPocketRef/examples/python.pdf http://www.petefreitag.com/item/455.cfm http://diveintopython.org/appendix/tips.html > 3) Where do I find a command list, with syntax and all that fun stuff for Python? I've explored > the python site to no end, but I can't seem to find a list. > From gandalf at designaproduct.biz Thu Oct 6 10:09:22 2005 From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy) Date: Thu, 06 Oct 2005 16:09:22 +0200 Subject: Class property In-Reply-To: References: <42C7E766869C42408F0360B7BF0CBD9B01CD75BE@pnlmse27.pnl.gov> Message-ID: <43453012.1000401@designaproduct.biz> Peter Otten wrote: >Laszlo Zsolt Nagy wrote: > > > >>I was trying for a while, but I could not implement a 'classproperty' >>function. Is it possible at all? >> >> > >You could define a "normal" property in the metaclass: > > The only way I could do this is: class MyXMetaClass(type): _x = 0 def get_x(cls): print "Getting x" return cls._x def set_x(cls,value): cls._x = value print "Set %s.x to %s" % (cls.__name__,value) x = property(get_x,set_x) class A(object): __metaclass__ = MyXMetaClass print A.x A.x = 8 Results in: Getting x 0 Set A.x to 8 But of course this is bad because the class attribute is not stored in the class. I feel it should be. Suppose we want to create a class property, and a class attribute; and we would like the property get/set methods to use the values of the class attributes. A real example would be a class that keeps track of its direct and subclassed instances: class A(object): cnt = 0 a_cnt = 0 def __init__(self): A.cnt += 1 if self.__class__ is A: A.a_cnt += 1 class B(A): pass print A.cnt,A.a_cnt # 0,0 b = B() print A.cnt,A.a_cnt # 1,0 a = A() print A.cnt,A.a_cnt # 2,1 But then, I may want to create read-only class property that returns the cnt/a_cnt ratio. This now cannot be implemented with a metaclass, because the metaclass cannot operate on the class attributes: class A(object): cnt = 0 a_cnt = 0 ratio = a_class_property_that_returns_the_cnt_per_a_cnt_ratio() # ???? def __init__(self): A.cnt += 1 if self.__class__ is A: A.a_cnt += 1 Any ideas? Les From john at castleamber.com Mon Oct 17 22:07:40 2005 From: john at castleamber.com (John Bokma) Date: 18 Oct 2005 02:07:40 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: "Mike Schilling" wrote: > > "John Bokma" wrote in message > news:Xns96F1E574E6873castleamber at 130.133.1.4... >> Roedy Green wrote: >> >>> On 16 Oct 2005 05:22:47 GMT, John Bokma wrote >>> or quoted : >>> >>>>No, it's a recommendation, an advise, nothing else. Otherwise they >>>>would call it a standard. Why do you think W3C calls it >>>>recommendations? Because it are no standards. There is an ISO HTML >>>>standard though, but when people babble about HTML standards they >>>>talk about W3C *recommendations*. >>> >>> What do you think the Internet is based on? RFCs. >> >> Yup, I know. Hence no standards. >> >> Like I said: there is ISO HTML, and there is a w3c HTML 4.01 >> recommendation. The former is a standard, the latter is a defacto >> standard. >> For some the difference does matter. > > What matters in generating HTML is which browsers you want to support > and what they understand. Standards and recommendations are both > irrelevant. So how do you develop a browser? I assume you have some experience with programming, or is that trial and error programming? Hack until it works? -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From just at xs4all.nl Tue Oct 4 10:25:04 2005 From: just at xs4all.nl (Just) Date: Tue, 04 Oct 2005 16:25:04 +0200 Subject: email module, redirecting to stdout References: Message-ID: In article , Peter Otten <__peter__ at web.de> wrote: > Laszlo Zsolt Nagy wrote: > > > I have this code: > > > > s = smtplib.SMTP() > > s.set_debuglevel(1) > > s.connect(host=smtp_host) > > s.set_debuglevel(0) > > log("Connected, sending e-mail") > > sys.stdout.flush() > > s.sendmail( > > consts.EMAIL_FROMADDRESS, > > [to], > > msg.as_string() > > ) > > log("E-mail sent OK") > > s.quit() > > > > The problem is that whenever I set the debuglevel to 1, messages will go > > to stderr. I would like them to go to stdout. Using > > > > sys.stderr = sys.stdout > > > > has no effect. Redirecting stderr to stdout from the shell is not an > > option for me, because I need to use stderr for other messages. > > smtplib obtains a copy of stderr by > > from sys import stderr > > Therefore you have to do > > smtplib.stderr = sys.stdout > > to get the desired effect. Ouch. I'd consider this a bug. "from sys import stderr" should at least be considered bad style. Just From rrr at ronadam.com Sat Oct 22 18:10:02 2005 From: rrr at ronadam.com (Ron Adam) Date: Sat, 22 Oct 2005 22:10:02 GMT Subject: Question about inheritance... In-Reply-To: <1130017209.078943.119990@g43g2000cwa.googlegroups.com> References: <1130017209.078943.119990@g43g2000cwa.googlegroups.com> Message-ID: <_My6f.1423$Zd.1063@tornado.tampabay.rr.com> KraftDiner wrote: > I have a base class called Shape > And then classes like Circle, Square, Triangle etc, that inherit from > Shape: > > My quesiton is can a method of the Shape class call a method in Circle, > or Square etc...? This looks familiar. :-) Yes, it can if it has references to them. Could you explain a little better what you are doing. Since I'm working on the same (or similar) thing maybe we can share our results, (or efforts). Cheers, Ron From tengo at DELETEMEecc.lu Sun Oct 9 10:42:02 2005 From: tengo at DELETEMEecc.lu (Stefaan A Eeckels) Date: Sun, 9 Oct 2005 16:42:02 +0200 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> Message-ID: <20051009164202.70f4d3f5.tengo@DELETEMEecc.lu> On Sun, 9 Oct 2005 13:44:42 GMT Tim Tyler wrote: > In comp.lang.java.programmer Roedy Green > wrote or quoted: > > > Read my essay. > > http://mindprod.com/projects.html/mailreadernewsreader.html It's gone :-) > FYI, this bit: > > ``Like ICQ, someone cannot send you mail without your prior > permission. They can't send you mail because they don't have your > public key to encrypt the mail.'' > > ...is pretty confusing - because "public key" is a term with a > technical meaning in cryptography - and a public key really *is* > public. > > If you want to allow email only from a list of senders, then you use > a simple white list. Cryptography is not needed or desirable if this > is the intended goal. But what is desirable is the possibility to authenticate the sender of the message as genuine, given the ease with which SMTP headers can be spoofed. Maybe this is suggested in Mr Green's essay, but cryptographically signed email (using the originator's _private_ key), where the signature and hence the originator of the mail can be verified independently, would be very useful. The problem is to get everyone to use digital signatures, and to ensure that such a signature can be linked to an individual or business. I've no illusions here. Take care, -- Stefaan -- As complexity rises, precise statements lose meaning, and meaningful statements lose precision. -- Lotfi Zadeh From nicksjacobson at yahoo.com Tue Oct 18 02:33:18 2005 From: nicksjacobson at yahoo.com (nicksjacobson at yahoo.com) Date: 17 Oct 2005 23:33:18 -0700 Subject: bug in os.system? Message-ID: <1129617198.528491.125830@g44g2000cwa.googlegroups.com> The following code fails (pythonbugtest.exe takes one parameter, a string): import os result = os.system('"pythonbugtest.exe" "test"') assert(result == 0) The error message is: 'pythonbugtest.exe" "test' is not recognized as an internal or external command, operable program or batch file. Traceback (most recent call last): File "C:\Nick\!My Programs\Python\bugtest\python1.py", line 8, in ? assert(result == 0) AssertionError If I remove the quote marks around "pythonbugtest.exe" or "test", it works fine. But sometimes I need those quote marks, if e.g. there are spaces in filenames. I think this is a bug? I'm running Python 2.4.1 on Windows XP Pro. From aleax at mail.comcast.net Sun Oct 16 03:24:14 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Sun, 16 Oct 2005 09:24:14 +0200 Subject: Some set operators References: <1129408019.100885.323870@g47g2000cwa.googlegroups.com> <1h4hwtl.np9wjhchw3duN%aleax@mail.comcast.net> Message-ID: <1h4ipj6.z65uja1mk94z9N%aleax@mail.comcast.net> Giovanni Bajo wrote: > Alex Martelli wrote: > > > I still vaguely hope that in 3.0, where backwards incompatibilities > > can be introduced, Python may shed some rarely used operators such as > > these (for all types, of course). > > I hope there is no serious plan to drop them. There is nothing wrong in having > such operators, and I wouldn't flag bit operations as "rarely used". They are > very common when calling C-based API and other stuff. I know I use them very > often. They have a clear and well-understood meaning, as they appear identical > in other languages, including the widely-spread C and C++. Well, C and C++ don't have unbounded-length integers, nor built-in sets, so the equivalence is slightly iffy; and the precedence table of operators in Python is not identical to that in C/C++. As for frequency of use, that's easily measured: take a few big chunks of open-source Python code, starting with the standard library (which does a lot of "calling C-based API and other stuff") and widespread applications such as mailman and spambayes, and see what gives. But the crux of our disagreement lies with your assertion that there's nothing wrong in having mind-boggling varieties and numbers of operators, presumably based on the fact that C/C++ has almost as many. I contend that having huge number of operators (and other built-ins) goes against the grain of Python's simplicity, makes Python substantially harder to teach, and presents no substantial advantages when compared to the alternative of placing that functionality in a built-in module (possibly together with other useful bit-oriented functionality, such as counts of ones/zeros, location of first/last one/zero bit, formatting into binary, octal and hexadecimal, etc). As for "serious plans", it's been a while since I checked PEP 3000, but I don't think it addresses this issue one way or another -- yet. Alex From Terji78 at gmail.com Sun Oct 30 00:27:39 2005 From: Terji78 at gmail.com (Terji78 at gmail.com) Date: 29 Oct 2005 21:27:39 -0700 Subject: Examples of Python code compared to other languages In-Reply-To: <20051030004310.7d30b682@linuxcestcomplique.fr> References: <20051030004310.7d30b682@linuxcestcomplique.fr> Message-ID: <1130646459.375480.190350@g14g2000cwa.googlegroups.com> http://pleac.sourceforge.net/ probably is what you're looking for. It shows how to to stuff from the perl cookbook in a plethora of other languages, including Python. Kind regards Terji Petersen From bh at intevation.de Fri Oct 28 09:40:02 2005 From: bh at intevation.de (Bernhard Herzog) Date: Fri, 28 Oct 2005 15:40:02 +0200 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <87y84dix2r.fsf@ieee.org> Message-ID: Jorge Godoy writes: > How about iterating through the file? You can read it line by line, two lines > at a time. Pseudocode follows: > > line1 = read_line > while line2 = read_line: > line_to_check = ''.join([line1, line2]) > check_for_desired_string > line1 = line2 > > With that you always have two lines in the buffer and you can check all of > them for your desired string, no matter what the size of the file is. This will fail if the string to search for is e.g. "\n\n\n\n" and it actually occcurs in the file. Bernhard -- Intevation GmbH http://intevation.de/ Skencil http://skencil.org/ Thuban http://thuban.intevation.org/ From mg.mailing-list at laposte.net Fri Oct 14 08:14:41 2005 From: mg.mailing-list at laposte.net (mg) Date: Fri, 14 Oct 2005 14:14:41 +0200 Subject: Compilation of _tkinter, tcl/tk bindings Message-ID: <434FA131.6060106@laposte.net> Hello, First, I installed Python on a traditionnal default linux-x86 platform (tk.h is located in /usr/include) and I did not meet any problem. I can write the following instruction without error in my python interpreter: ./configure --prefix=/usr/local/python make make install /usr/local/python/bin/python >>> import Tkinter >>> Second, I tried to install python on IBM-Aix5.1 with tk bindings too. Because of tcl/tk doesn't exist on my default platform, I have installed tcl8.4.11 in /usr/local/tcl8.4.11. Now, I ran the compilation of Python and tried to import Tkinter : ./configure --prefix=/usr/local/python make make install /usr/local/python/bin/python >>> import Tkinter Traceback (most recent call last): File "", line 1, in ? File "/usr/local/python/lib/python2.5/lib-tk/Tkinter.py", line 38, in ? import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named _tkinter >>> In fact, when Python is compiled, the shared library _tkinter.so should be compiled (Tkinter.py is just a Python script which import _tkinter.so) if tk is detected on the platform. So, my questions are : - Must I install tcl/tk in the default directories give by the distribution to compile python and Tkinter (_tkinter) ? - or can I specify the tcl/tk installation to compile Python and Tkinter (_tkinter) ? Regards, Mathieu. From duncan.booth at invalid.invalid Thu Oct 20 03:30:41 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Oct 2005 07:30:41 GMT Subject: Would there be support for a more general cmp/__cmp__ References: Message-ID: Antoon Pardon wrote: > The problem now is that the cmp protocol has no way to > indicate two objects are incomparable, they are not > equal but neither is one less or greater than the other. If that is the case then you implement __eq__ and __ne__ to return True/False and make cmp throw an exception. I don't see any need to extend the cmp protocol. From aleaxit at yahoo.com Sun Oct 23 12:43:45 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 23 Oct 2005 09:43:45 -0700 Subject: How to separate directory list and file list? References: <0e9nl1tvvgqlhkahkmrrfc810b3ed1unb6@4ax.com> Message-ID: <1h4vpi8.uylzvq1on43zeN%aleaxit@yahoo.com> Gonnasi wrote: > With > >glob.glob("*") > > or > >os.listdir(cwd) > > I can get a combined file list with directory list, but I just wanna a > bare file list, no directory list. How to get it? I see everybody's suggesting os.path.* solutions, and they're fine, but an interesting alternative is os.walk: __, thedirs, thefiles = os.walk('.').next() thefiles is the list of filenames (and thedirs is the list of directory names), and each is sorted alphabetically. (I'm assigning to '__' the absolute path of the current directory, meaning I intend to ignore it). An expression that just provides the filename list is os.walk('.').next()[2] although this may be a tad too obscure to recommend it!-) Alex From gerrit at nl.linux.org Fri Oct 14 12:09:56 2005 From: gerrit at nl.linux.org (Gerrit Holl) Date: Fri, 14 Oct 2005 18:09:56 +0200 Subject: Problems with properties In-Reply-To: References: Message-ID: <20051014160956.GA15053@topjaklont.student.utwente.nl> Michael Schneider wrote: > Could someone please point out my error, I have dents in my forehead > for this one. > ------------------------------------------------------------------ > > from unittest import TestCase > import unittest Here you need to add: __metaclass__ = type this will make your classes new-style. Gerrit. -- Temperature in Lule?, Norrbotten, Sweden: | Current temperature 05-10-14 17:59:48 7.9 degrees Celsius ( 46.3F) | -- Det finns inte d?ligt v?der, bara d?liga kl?der. From bokr at oz.net Fri Oct 14 23:33:12 2005 From: bokr at oz.net (Bengt Richter) Date: Sat, 15 Oct 2005 03:33:12 GMT Subject: [Info] PEP 308 accepted - new conditional expressions References: <3q4ro9Fd770nU3@individual.net> <87irw3l0qb.fsf@bigfoot.com> Message-ID: <435075c8.23872336@news.oz.net> On Wed, 12 Oct 2005 02:15:40 -0400, Chris Smith wrote: >>>>>> "Sebastian" == Sebastian Bassi writes: > > Sebastian> On 9/30/05, Reinhold Birkenfeld wrote: > >> after Guido's pronouncement yesterday, in one of the next > >> versions of Python there will be a conditional expression with > >> the following syntax: X if C else Y > > Sebastian> I don't understand why there is a new expression, if > Sebastian> this could be accomplished with: > > Sebastian> if C: X else: Y > > Sebastian> What is the advantage with the new expression? > >One very frequent use case is building a string. But what you show doesn't require choice of which to _evaluate_, since you are merely choosing between immutable constants, and there is no side effect or computation overhead to avoid by not evaluating the unselected expression. So "the answer is " + ('no', 'yes')[X==0] would do as well. >Instead of: > >if X==0: > filler="yes" >else: > filler="no" >return "the answer is %s" % filler > > >What I really want to do is take four lines of conditional, and put >them into one, as well as blow off dealing with a 'filler' variable: > >return "the answer is " + "yes" if X==0 else "no" As has been pointed out, though legal there is some doubt as to whether you meant what you wrote ;-) > > >Or whatever the final release syntax is. >Conditional expressions are a nice way to shim something in place, on >an acute basis. Chronic use of them could lead to a full-on plate of >spaghetti, where you really wanted code. >They can be impenitrable. Whenever I'm dealing with them in C/C++, I >always line the ?, the :, and the ; characters vertically, which may >seem a bit excessive in terms of whitespace, but provides a nice >hieroglyph over on the right side of the screen, to make things >obvious. >Best, >Chris Regards, Bengt Richter From spammers-go-here at spam.invalid Wed Oct 19 12:12:28 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Wed, 19 Oct 2005 12:12:28 -0400 Subject: Converting 2bit hex representation to integer ? Message-ID: <4356703e$0$41144$14726298@news.sunsite.dk> Hi I am using binascii.b2a_hex to convert some binary data to hex. The result is a two bit hex representation (i. e., without the leading 0x). How do I convert the resulting two bit representation into an integer ? Thanks. From christopher.saunter at durham.ac.uk Wed Oct 26 14:41:38 2005 From: christopher.saunter at durham.ac.uk (c d saunter) Date: Wed, 26 Oct 2005 18:41:38 +0000 (UTC) Subject: Jpg References: <1130349223.948333.83230@g49g2000cwa.googlegroups.com> Message-ID: Tuvas (tuvas21 at gmail.com) wrote: : I am building a GUI interface at the moment, and would like to have : support for displaying a jpg file, and a FITS file if possible. Is : there any way to do this? My interface has been written in Tkinter at : the moment, especially because of it's great portability, I wouldn't : have to install the other interface software on every computer that I : use (At the moment it is 3, and will signifigantly increase). I'd : prefer to only use built-in functions, but if it can't be done, I'm : willing to look for something else. Is there any way I can do this? : Thanks! Plenty of ways to do it, although I'm not familiar with TKInter so I'll leave that part to someone else. You might find pCFITSIO usefull reading the FITS files though. http://panoramix.stsci.edu/~npirzkal/python/pcfitsio/ You would then use some python code or the PIL module to convert the FITS data in a suitable format for TKInter. --- cds From davids at webmaster.com Sat Oct 22 19:17:20 2005 From: davids at webmaster.com (David Schwartz) Date: Sat, 22 Oct 2005 16:17:20 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> Message-ID: "Steven D'Aprano" wrote in message news:pan.2005.10.22.09.12.53.825745 at REMOVETHIScyber.com.au... > On Fri, 21 Oct 2005 21:47:27 -0700, David Schwartz wrote: >>> That's basic economics. Something which can be allowed or ignored or >>> even >>> encouraged when done by small businesses in a competitive market can >>> easily become harmful and bad for the economy when done by a monopolist >>> or >>> duopolist in an uncompetitive market. >> Microsoft goal is and should be their own success, not the success of >> the economy or the market in general. > Neither I, nor you, nor the government of any nation, should care a > monkey's toss specifically for Microsoft's success. Microsoft is one > special interest, out of a potentially unbounded number of possible > players in the economy of a country and the world. No, not at all. It is the gravest act of self-contradiction to maintain that one should be allowed to pursue one's own interest while denying that same right to others. > Unless you or I are specifically shareholders in Microsoft, we should not > care about their specific success; and the government should be entirely > agnostic about who are the winners and losers in an economy. We should certainly care that Microsoft be allowed to pursue their own success. The government should be agnostic about who the winners and losers are, but must respect each entity's right to attempt to be that winner. > The > government's role should be to ensure a level playing field, and minimum > levels of health, safety and environmental standards. There is no place > for government giving special-interests like Microsoft favours. The problem is, people complain when the playing field is in fact level. For example, Microsoft's "exclusionary" Windows agreements didn't ask for more than Windows was worth (or nobody would have agreed to them). Yet they are considered examples of the playing field not being level. > Society regulates where and how we park our cars: for instance, none of us > are allowed to park our car in the middle of busy road. and if we try, our > car is likely to be impounded. This is not because there is anything in > and of itself *wrong* with parking at such-and-such a place, but because > of the effect it has on others. Umm, no. It's because the government owns the roads and operates them for the benefit of all. This analogy applies *only* to government property. > A sensible government cares for smooth > flowing traffic on the roads, with the minimum of delays and the maximum > flow practical. You could replace "government" with "road owner" and the analogy would then be correct. Governments don't give a damn if traffic flows smoothly on private roads. > Perhaps Walmart or Safeway might find it convenient to > park their trucks on public roads for any number of reasons. Too bad for > them: the benefit to them does not outweigh the loss to everyone else, > even if they don't specifically block access to their competitors. And this is what any road owner would do. > Microsoft's behaviour over-all has been just as anti-social, > anti-competitive and harmful to the over-all running of the economy as a > hypothetical Walmart or Safeway that regularly parked their trucks in the > middle of the main road for a few hours while they unloaded. The problem is, the government does not own the economy. So it does not get to manage it the way it gets to manage the roads it in fact owns. > Maybe, just maybe, if Mom & Pop's Corner Store tried it once or twice, we > could afford to turn a blind eye, especially if the disruption caused by > towing their delivery van was greater than the disruption caused by their > double-parking. Thousands of people break the law by double-parking for a > few minutes, and society doesn't collapse. But something that we can > afford to ignore when done by M&P's Corner Store becomes a serious problem > if done by somebody with the economic power of Walmart, with their > thousands of deliveries by 18-wheelers every day across the country. Again, the analogy fails. You are comparing the government's right to manage its own property with the government's "right" to interfere with other people's right to manage their property. >> Microsoft's status of a "monopolist" >> is only meaningful if you define the market as "desktop operating systems >> for 32-bit x86 computers". > That is *precisely* the market we're talking about. Not "any item that > runs off electricity", not "orange juice", not "pork bellies", not "all > computing devices", but desktop PCs. What did you think the Justice > Department's investigation was about? Motor vehicles? I thought it was about operating systems, actually. And I thought that both OSX and Linux competed with it. >> There is no way Microsoft could have expected the >> market to be defined in this way and no way to argue that Microsoft had >> any >> reason to believe their conduct was illegal. > Microsoft have lawyers. Microsoft destroyed emails and at least one senior > manager perjured himself in court. Microsoft created a fake video > demonstration which they then gave as evidence. Do you really believe that > Microsoft's executives are so incompetent that they don't get legal advice > before writing up contracts? Or that nobody in authority at Microsoft > realised that destroying evidence and lying to a judge are crimes? When a criminal willing to use force points a gun at your head, you lie to him. > In any case, even if you are right that Microsoft had no ideas... so what? > Ignorance of the law never has been an excuse for criminal behaviour. It > has always been every individual's responsibility to make sure that they > do not act illegally, and that goes for companies as well. I am not saying Microsoft did not know the law. I am saying that no rational person could have expected the law to be applied to Microsoft that way it was. The law *must* put a person on notice of precisely what conduct it prohibits. However, in this case, the law's applicability was conditioned on an abritrary and irrational choice of what the relevant market was. DS From claudio.grondi at freenet.de Thu Oct 13 20:03:28 2005 From: claudio.grondi at freenet.de (Claudio Grondi) Date: Fri, 14 Oct 2005 00:03:28 -0000 Subject: matching elements of numeric arrays References: <1129239096.340248.222440@g49g2000cwa.googlegroups.com> Message-ID: <3r83udFid3bdU1@individual.net> wrote in news:1129239096.340248.222440 at g49g2000cwa.googlegroups.com... > I have two one-dimensional Numeric arrays, and I need to know the > indices in the second array of elements from the first. > > so if i had: > > a=array([2,4,6]) > b=array([2,3,4,5,6]) > > i want a function match that does this: > > >>> match(a,b) > array([0,2,4]) > > i have something that works, but it involves converting things to lists > and using 'in', and it is rather slow. if someone could point me to a > better solution, i would appreciate it. I have no idea about Numeric array module, so I will use the built-in Python one for it (how about the speed if compared to Numeric arrays?): from array import array a = array('I', [2,4,6]) b = array('I', [2,3,4,5,6]) def match(a,b): retVal = array('I') for item in a: retVal.append(b.index(item)) return retVal print a print b print str(match(a,b)) Outputs: array('I', [2L, 4L, 6L]) array('I', [2L, 3L, 4L, 5L, 6L]) array('I', [0L, 2L, 4L]) Claudio From mwm at mired.org Tue Oct 11 02:58:03 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 11 Oct 2005 02:58:03 -0400 Subject: Batteries Included? References: <1129010199.291968.142720@g47g2000cwa.googlegroups.com> Message-ID: <86achgzgjo.fsf@bhuda.mired.org> "Alex" writes: > One of the first things I wanted to do when I start learning Python was > to produce a simple standalone application that I could distribute to > my users (windows users). Python's moto is "Batteries Included", but > where are the batteries for making exe files and making an installer > file? I had to download, install and use py2exe and Inno Setup in order > to accomplish this. I might be wrong expecting that a language whose > moto is "Batteries Included" would be able to produce exe files. Are > there plans to do this in the future version of Python? Did you try looking through the distutils docs? After you create a setup.py file for you program, doing "python setup.py bdist --formats=wininst" should do the trick. Of course, I don't own a Windows box, so I can't check it, but when I ask a setup file for help on formats, it tells me the wininst format is a windows installer. Personally, I think of building a platform-specific bundle for distribution to end users as more along the lines of shipping than batteries. Python comes with lots of tools to help you get your application working - the batteries. Once it's working, you don't need batteries: you need wrapping paper, and a box, and tape, and so on. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From greymaus at cableone.net Sun Oct 16 13:27:44 2005 From: greymaus at cableone.net (Greymaus) Date: Sun, 16 Oct 2005 12:27:44 -0500 Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <11l369039d6ppe0@corp.supernews.com> Message-ID: <11l53696mb7s073@corp.supernews.com> Tim Hammerquist wrote: > > I loved my little CoCo! I had the original CoCo, upgraded with > the 5 1/4" floppy drive, and later upgraded the whole system to > CoCo 3 with OS9. > I put the piggyback RAM board in, which gave me, I think, 1 Meg of RAM. I also found that the whole system ran faster and better (especially under OS9) with two floppy drives. Programmed that puppy in OS9BASIC and 6809 Assembler...Much preferred the Assembler. A lot less confusing than Microsoft's assembler! But I had to shift over to PCs when I figured out that Tandy wasn't supporting the CoCo system. They took the 40-connector extension boards out of their inventory and that killed the market right there. Another raid from Microsoft? From skip at pobox.com Sun Oct 16 00:19:17 2005 From: skip at pobox.com (skip at pobox.com) Date: Sat, 15 Oct 2005 23:19:17 -0500 Subject: List of strings to list of floats ? In-Reply-To: <4351d29e$0$41148$14726298@news.sunsite.dk> References: <4351d29e$0$41148$14726298@news.sunsite.dk> Message-ID: <17233.54469.296474.998863@montanaro.dyndns.org> Madhusudan> Is it possible to convert a very long list of strings to a Madhusudan> list of floats in a single statement ? Madhusudan> I have tried float(x) and float(x[:]) but neither work. I Madhusudan> guess I would have to write a loop if there isn't a way. Try: >>> los = ["123.0", "2", "1e-6"] >>> map(float, los) [123.0, 2.0, 9.9999999999999995e-07] >>> [float(s) for s in los] [123.0, 2.0, 9.9999999999999995e-07] Skip From deets at web.de Fri Oct 7 10:26:52 2005 From: deets at web.de (Diez B. Roggisch) Date: 7 Oct 2005 07:26:52 -0700 Subject: "no variable or argument declarations are necessary." In-Reply-To: <7x3bndbg7v.fsf@ruckus.brouhaha.com> References: <3qi8erFf252rU1@uni-berlin.de> <3qkdbrFfgga9U1@uni-berlin.de> <3qkn7qFffkl6U1@uni-berlin.de> <3qkr1hFfgj5uU1@uni-berlin.de> <7xr7ax690j.fsf@ruckus.brouhaha.com> <434651f4$0$11145$626a14ce@news.free.fr> <7xwtkp8rwy.fsf@ruckus.brouhaha.com> <1128687719.783871.50090@f14g2000cwb.googlegroups.com> <7x7jcpzeyn.fsf@ruckus.brouhaha.com> <1128689163.357942.107850@g47g2000cwa.googlegroups.com> <7x3bndbg7v.fsf@ruckus.brouhaha.com> Message-ID: <1128695212.510656.310880@o13g2000cwo.googlegroups.com> > How about Lisp? It seems to do some good there, without getting in > the way. I don't know much about lisp. But the thing is that one of the most important data structures in python (and basically the only one in LISP), lists, are a big problem to type-checking if they aren't homogenous. So I guess one can write a compiler that generates specialized code for lists of a certain homogenous kind, like lists of int, float and maybe string - and as long as you ensure that code is called with such a list, you're ok. But I think that is what psyco does, too (no idea how these two compare) Basically, all type-inferencing boils down to collecting constraints on variable values. Like in this expression z = x + y It will be internall represented by this: z:C = x:A + y:B which introduces type-variables A,Band C. That tells us that all operations __plus__ and their respective types could be meant, thus A B C are constrained by these types. Which, in an overloading-allowing language, can get pretty much. The trick is to find a solution for the variables that satisfy all the constraints. And a solution are actual types, not ad-hoc sets of types - otherwise, you can't create any specialized code, and the compiler will puke on you. Saying z += 10 now creates a constraint that binds C to int, and subsequently A and B. Now the problem is someting like this: if x is None: x = 10 else: x = x * 10 Lets assume A as type-var for x. Then we have the two contstraints A -> int and A -> None. Now - is there a type that satisfies both constraints? No. And even worse, A shall be int by x = 10 - but that collides with A->None. So the only thing you can do is resort to A=ANY - and interpret that code above :) Diez From my_email_is_posted_on_my_website at munged.invalid Wed Oct 19 04:47:42 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 19 Oct 2005 08:47:42 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <11l48meji6u4e69@corp.supernews.com> Message-ID: <6u1cl1dvqaac21klrqsoumsoh0ugrbom9e@4ax.com> On Wed, 19 Oct 2005 07:10:55 GMT, Alan Connor wrote or quoted : >To all the shit-for-brains trolls that are polluting these groups >with this crap, which I haven't even bothered to read: A single thread does not pollute a group. It is trivially easy to ignore a thread. If your newsreader does not support that feature, try an different newsreader. See http://mindprod.com/jgloss/newsgroups.html It is a big thread. Obviously people are interested in it even if you are not. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From rrr at ronadam.com Wed Oct 19 19:52:37 2005 From: rrr at ronadam.com (Ron Adam) Date: Wed, 19 Oct 2005 23:52:37 GMT Subject: multi-property groups? In-Reply-To: References: Message-ID: <9%A5f.200365$p_1.19615@tornado.tampabay.rr.com> This is what I like about Python, there's almost always a way to do it. ;-) Here's an updated version that I think works, but it could use some review. Any way to make this better? Should grouped properties share references to objects? Cheers, Ron """ Grouped properties: This need presented it self while programming Tkinter applications where a lot of keywords are used, but I think it would also be good for general interface building. The external view is of a single object, while the internal mechanism keeps the attributes groups so they can be forwarded easily as **kwds. class foo(object): def __init__(self): self.__setprops__(name, item_1, item_2, ... item_n) name.__doc__ = 'this is the name group of properties' def getter(): ... def setter(): ... def remover(): ... name.__getitem__ = getter name.__setitem__ = setter name.__delitem__ = remover The following is as close to getting to as I am able I think. Only somewhat tested... but it seems to work. """ class Pdict(dict): # we need this so we can override the methods. __doc__ = "a property dictionary" class Pobject(object): """ an object with grouped properties """ __properties__ = {} def __setprops__(self, *args): """ Create a group property __setprops__(name, p1, p2, p3, ... pn) * all arguments are strings to be made into names. """ dct = Pdict() for i in args[1:]: dct.setdefault(i,None) self.__properties__[args[0]] = dct self.__dict__[args[0]] = dct def __getattr__(self, name): for dct in self.__properties__: if name in self.__properties__[dct]: return self.__properties__[dct].__getitem__(name) return self.__dict__[name] def __setattr__(self, name, value): for dct in self.__properties__: if name in self.__properties__[dct]: self.__properties__[dct].__setitem__(name,value) return self.__dict__[name] = value ## A simple example to test it. ## class shapes(Pobject): def __init__(self): # init the A properties self.__setprops__('A', 'square', 'triangle', 'cube', 'circle') self.A.__doc__ = 'These are the "A" properties' def A_getter(name): return -self.A[name] # just to show it will self.A.__getitem__ = A_getter # init the B properties self.__setprops__('B', 'red', 'blue', 'green', 'orange') self.B.__doc__ = 'These are the "B" properties' def show(self, it): if it == 'shapes': self.pprint(self.A) # pass properties as groups! elif it == 'colors': self.pprint(self.B) # have several property groups! else: print "I have no %s.\n" % it def pprint(self, obj): print obj.__doc__ for item in obj.keys(): print ' %s = %r' % (item,obj[item]) print box = shapes() # Set items; no need to now what group # they are in. box.cube = 6 box.square = 4 box.triangle = 3 box.circle = 0 # Update a whole group at once with the group name. box.B.update(blue='blue', green='green', red='rose', orange='orange') box.red = 'red' # Get items print box.square print box.blue print box.green # Show the groups. box.show('shapes') box.show('colors') box.show('flowers') ## outputs ## -4 blue green These are the "A" properties cube = 6 square = 4 triangle = 3 circle = 0 These are the "B" properties blue = 'blue' green = 'green' orange = 'orange' red = 'red' I have no flowers. ## end ## From fredrik at pythonware.com Thu Oct 6 15:31:19 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 6 Oct 2005 21:31:19 +0200 Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net><1128306351.13c600edac4bfa99f9f10238681bf68f@teranews><6xO0f.166857$p_1.72982@tornado.tampabay.rr.com><4344c53e.3325034196@news.oz.net> Message-ID: Ron Adam wrote: > Is there a way to conditionally decorate? For example if __debug__ is > True, but not if it's False? I think I've asked this question before. (?) the decorator is a callable, so you can simply do, say from somewhere import debugdecorator if not __debug__: debugdecorator = lambda x: x or def debugdecorator(func): if __debug__: ... else: return func etc. From nephish at xit.net Thu Oct 27 22:06:57 2005 From: nephish at xit.net (nephish at xit.net) Date: 27 Oct 2005 19:06:57 -0700 Subject: how do i run another script from my python script In-Reply-To: <86fyqmix52.fsf@bhuda.mired.org> References: <1130431172.443751.230730@o13g2000cwo.googlegroups.com> <86fyqmix52.fsf@bhuda.mired.org> Message-ID: <1130465217.891307.177370@g49g2000cwa.googlegroups.com> well i know i dont want to do another thread, my program has six running all the time. whew. that can get nuts. i mean, this will come to me easier later i am sure. But right now..... simple is best. thanks for all the suggestions, gents. right now i am just doing a varient of Steves suggestion, and so far, its working. thanks again, sk From anil.pundoor at gmail.com Mon Oct 3 03:24:59 2005 From: anil.pundoor at gmail.com (anil.pundoor at gmail.com) Date: 3 Oct 2005 00:24:59 -0700 Subject: Bwidget for tkinter In-Reply-To: References: <1128318804.997697.127310@g47g2000cwa.googlegroups.com> Message-ID: <1128324299.671382.146480@f14g2000cwb.googlegroups.com> thanks u man. i am new to tk inter. i tried installing the lib. but while running the demo script am getting following error. python sam.py Traceback (most recent call last): File "sam.py", line 1, in ? import bwidget, Tkinter, sys, os File "/usr/local/lib/python2.2/site-packages/bwidget/__init__.py", line 149, in ? class _Frame: File "/usr/local/lib/python2.2/site-packages/bwidget/__init__.py", line 152, in _Frame getframe = makeswidget(getframe, Tkinter.Frame) File "/usr/local/lib/python2.2/site-packages/bwidget/__init__.py", line 74, in makeswidget return _wrap(w, f) File "/usr/local/lib/python2.2/site-packages/bwidget/__init__.py", line 59, in _wrap oldfunc.func_name, wrapper.func_defaults, wrapper.func_closure) TypeError: function() takes at most 4 arguments (5 given) can u plz help me From simonroses at granisla.com Mon Oct 31 13:46:25 2005 From: simonroses at granisla.com (Simon Roses Femerling) Date: Mon, 31 Oct 2005 19:46:25 +0100 Subject: Python Linked list? Message-ID: <001f01c5de4b$65e18880$0201a8c0@LOKI> Hi there! I'm looking for a linked list class or lib ? Any suggestions ? Is for a project I'm working on. Sincerely, Simon Roses Femerling -------------- next part -------------- An HTML attachment was scrubbed... URL: From bearophileHUGS at lycos.com Sun Oct 2 08:37:13 2005 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 2 Oct 2005 05:37:13 -0700 Subject: Nufox : Xul + Python In-Reply-To: <1128255017.708134.49380@g14g2000cwa.googlegroups.com> References: <1128163366.631178.74800@o13g2000cwo.googlegroups.com> <1128182754.232912.9980@z14g2000cwz.googlegroups.com> <433f051f$0$49786$ed2e19e4@ptn-nntp-reader04.plus.net> <1128249650.166566.81790@g44g2000cwa.googlegroups.com> <1128255017.708134.49380@g14g2000cwa.googlegroups.com> Message-ID: <1128256633.686293.181220@g43g2000cwa.googlegroups.com> It doesn't work yet, to me... bearophile From johnnyandfiona at hotmail.com Tue Oct 11 23:51:18 2005 From: johnnyandfiona at hotmail.com (Johnny Lee) Date: 11 Oct 2005 20:51:18 -0700 Subject: A problem while using urllib In-Reply-To: <1h49slu.1gaj0nnmdk5ghN%aleax@mail.comcast.net> References: <1129024641.113182.74420@g49g2000cwa.googlegroups.com> <1h49slu.1gaj0nnmdk5ghN%aleax@mail.comcast.net> Message-ID: <1129089078.852454.153800@f14g2000cwb.googlegroups.com> Alex Martelli wrote: > Johnny Lee wrote: > ... > > try: > > webPage = urllib2.urlopen(url) > > except urllib2.URLError: > ... > > webPage.close() > > return True > > ---------------------------------------------------- > > > > But every time when I ran to the 70 to 75 urls (that means 70-75 > > urls have been tested via this way), the program will crash and all the > > urls left will raise urllib2.URLError until the program exits. I tried > > many ways to work it out, using urllib, set a sleep(1) in the filter (I > > thought it was the massive urls crashed the program). But none works. > > BTW, if I set the url from which the program crashed to base url, the > > program will still crashed at the 70-75 url. How can I solve this > > problem? thanks for your help > > Sure looks like a resource leak somewhere (probably leaving a file open > until your program hits some wall of maximum simultaneously open files), > but I can't reproduce it here (MacOSX, tried both Python 2.3.5 and > 2.4.1). What version of Python are you using, and on what platform? > Maybe a simple Python upgrade might fix your problem... > > > Alex Thanks for the info you provided. I'm using 2.4.1 on cygwin of WinXP. If you want to reproduce the problem, I can send the source to you. This morning I found that this is caused by urllib2. When I use urllib instead of urllib2, it won't crash any more. But the matters is that I want to catch the HTTP 404 Error which is handled by FancyURLopener in urllib.open(). So I can't catch it. Regards, Johnny From mwm at mired.org Tue Oct 25 18:13:14 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 25 Oct 2005 18:13:14 -0400 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> <86zmox2vj1.fsf@bhuda.mired.org> Message-ID: <86d5lt2qkl.fsf@bhuda.mired.org> Not Bill Gates writes: > mwm at mired.org wrote... >> Not Bill Gates writes: >> > steve at REMOVETHIScyber.com.au wrote... >> >> On Tue, 25 Oct 2005 15:35:47 +0000, Not Bill Gates wrote: >> >> > Heck, I dunno. Like you, I don't even really care all that much. >> >> You don't care that innovation in desktop software has been crippled by >> >> the actions of the monopoly player Microsoft? >> > You need to first prove innovation in desktop software has been >> > crippled, don't you? >> >> MS took desktop software through pretty much the same sequence of >> offerings that the mainframe and minicomputer software industry had >> been throgh: flat file systems and single-tasking OS's in a command >> line environment, adding nested file systems, adding TSRs, adding a >> windowing environment, adding true multitasking and finally >> multiprocessor systems. This took them what - 20+ years? > > Being pissed off about how things could have been done > better is a losing proposition. I'm not pissed off about it - I've got better things to do. You asked for prove that desktop software development was crippled by MS. I provided it. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From tim.golden at viacom-outdoor.co.uk Wed Oct 12 12:12:41 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Wed, 12 Oct 2005 17:12:41 +0100 Subject: Listen for directory events Message-ID: <9A28C052FF32734DACB0A288A3533991044D2265@vogbs009.gb.vo.local> [Bell, Kevin] | Anyone have any advice on listening for directory events? Would this be of any use? http://tgolden.sc.sabren.com/python/win32_how_do_i/watch_directory_for_changes.html 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 nephish at xit.net Fri Oct 21 12:34:45 2005 From: nephish at xit.net (nephish at xit.net) Date: 21 Oct 2005 09:34:45 -0700 Subject: need some advice on x y plot In-Reply-To: <1129831950.926154.196420@g47g2000cwa.googlegroups.com> References: <1129823043.104864.73750@f14g2000cwb.googlegroups.com> <11lfgebn85liq1b@corp.supernews.com> <1129825379.218308.242010@g47g2000cwa.googlegroups.com> <4357d998$1_2@newspeer2.tds.net> <1129831950.926154.196420@g47g2000cwa.googlegroups.com> Message-ID: <1129912485.866312.298390@g47g2000cwa.googlegroups.com> ok, i tried something similar to what you posted. a little simpler though. i am running a query on a database and making a list of time, value pairs kinda like this plot_points = ([time, value], [time, value], [time, value]) gnuplot complains that it needs a float for one of the values. i can plot just the value, and it shows up ( no x value found) how should i proceed? From robert.kern at gmail.com Fri Oct 7 01:30:00 2005 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 06 Oct 2005 22:30:00 -0700 Subject: Continuous system simulation in Python In-Reply-To: References: <20051007011222.1aeab426@linuxcestcomplique.fr> Message-ID: Dennis Lee Bieber wrote: > On Fri, 7 Oct 2005 01:12:22 +0200, Nicolas Pernetty > declaimed the following in comp.lang.python: > >>I'm aware of SimPy for discrete event simulation, but I haven't found >>any work about continuous system. >>I would like to develop a generic continous system simulator, and so >>would be eager to join any open source effort on the subject. >> >>For instance, it would be useful for modelling an airplane with all the >>dynamics (flight simulator). > > Unless that flight simulator is running on some big ugly ANALOG > computer (the ones that used rheostats, transformers, and amplifiers), > they all are really using discrete time intervals and computing values > at those time points. Such computation may require integration of > continuous functions from previous time step to current time step. I think Nicolas means "(discrete event) simulation" as opposed to "discrete (event simulation)" and "(continuous system) simulation" as opposed to "continuous (system simulation)". The methods used in SimPy to model (discrete events) don't apply terribly well to simulating many (continuous systems) like airplane dynamics. For example, an ODE integrator would probably want to adaptively select its timesteps as opposed to laying out a uniform discretization upfront. -- 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 mline at abilitec.com Fri Oct 21 04:09:42 2005 From: mline at abilitec.com (Mark Line) Date: Fri, 21 Oct 2005 08:09:42 +0000 (UTC) Subject: Searching for txt file and importing to ms access References: <86br1kunnd.fsf@bhuda.mired.org> Message-ID: Once i have this working i was planing to kept all the txt files as logs, i'd have to give them a real name and stuff. But thanks for you help so far Mark "Mike Meyer" wrote in message news:86br1kunnd.fsf at bhuda.mired.org... > "Mark Line" writes: >> I'm managed to get some code to download a message from the email account >> and save it to a text file, does any one have a link to some sample code >> to >> search though a file until a string of characters is matched? Or could >> point me to some functions that may help me with this? > > datafile = open("c:\\myfile.txt", "r") > data = datafile.read() > datafile.close() > start = data.index(myindicator) > > will leave start as the index in data where the the string in > myindicator first appears. If you want the end of myendicator, use > start = data.find(myindicator) + len(myindicator). > > Have you considered not saving the message to disk? You can manipulate > it all in memory. > >> I've also managed to connect to my access database, and just print out a >> field in a table, but I cant find anywhere on the web that will help me >> to >> import data? Any help would be great?! > > Can't help with that. The phrase "win32com" comes to mind, but I'm not > a windows person. > > -- > Mike Meyer http://www.mired.org/home/mwm/ > Independent WWW/Perforce/FreeBSD/Unix consultant, email for more > information. From kylotan at gmail.com Wed Oct 5 05:15:01 2005 From: kylotan at gmail.com (Ben Sizer) Date: 5 Oct 2005 02:15:01 -0700 Subject: Pygame: Filling the screen with tile images In-Reply-To: <1128464827.774164.164720@g14g2000cwa.googlegroups.com> References: <1128464827.774164.164720@g14g2000cwa.googlegroups.com> Message-ID: <1128503701.255999.149180@z14g2000cwz.googlegroups.com> I don't think PyGame will handle tiling for you, or any concept of a 'background image'. If you want something to appear multiple times on the screen, you need to draw it multiple times. If you do that onto a surface that is the same size as your screen, you can then consider that the background image and blit that to the screen at the start of every frame you draw. -- Ben Sizer From thomasbartkus at comcast.net Thu Oct 6 09:13:05 2005 From: thomasbartkus at comcast.net (Thomas Bartkus) Date: Thu, 6 Oct 2005 08:13:05 -0500 Subject: Python, Mysql, insert NULL References: <1128509544.189126.51090@g44g2000cwa.googlegroups.com> <4343B4E0.1040902@designaproduct.biz> <1128511466.880413.158140@g49g2000cwa.googlegroups.com> Message-ID: "Steve Holden" wrote in message news:mailman.1588.1128583570.509.python-list at python.org... > > > If you don't understand parameterized SQL queries you would do well to > refrain from offering database advice :-) Did the poster ask a question about parameterized queries or server security? > Presumably you always check whether StrToConcatenateIntoSqlStatement > contains no apostrophes before you actually construct the SQL? > > Can we say "SQL injection exploit"? Not every query passes along public internet wires and all the guy asked for was how to insert a Null. But - I really do appreciate your concern :-) Thomas Bartkus From steve at holdenweb.com Thu Oct 27 22:35:42 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 28 Oct 2005 03:35:42 +0100 Subject: Distutils patch for MS toolkit use Message-ID: I've just realised that my 2.4.1 upgrade removed the patch I made to distutils to use the Microsoft free toolchain. unfortunately www.vrplumber.com appears to be down. Does anyone reading this have the details? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From robbyd at u20.org Fri Oct 21 16:13:09 2005 From: robbyd at u20.org (Robby Dermody) Date: Fri, 21 Oct 2005 16:13:09 -0400 Subject: python gc performance in large apps Message-ID: <43594BD5.7050104@u20.org> Hey guys (thus begins a book of a post :), I'm in the process of writing a commercial VoIP call monitoring and recording application suite in python and pyrex. Basically, this software sits in a VoIP callcenter-type environment (complete with agent phones and VoIP servers), sniffs voice data off of the network, and allows users to listen into calls. It can record calls as well. The project is about a year and 3 months in the making and lately the codebase has stabilized enough to where it can be used by some of our clients. The entire project has about 37,000 lines of python and pyrex code (along with 1-2K lines of unrelated java code). Now, some disjointed rambling about the architecture of this software. This software has two long-running server-type components. One component, the "director" application, is written in pure python and makes use of the twisted, nevow, and kinterbasdb libraries (which I realize link to some C extensions). The other component, the "harvester", is a mixture of python and pyrex, and makes use of the twisted library, along with using the C libs libpcap and glib on the pyrex end. Basically, the director is the "master" component. A single director process interacts with users of the system through a web and/or pygtk client application interface and can coordinate 1 to n harvesters spread about the world. The harvester is the "heavy lifter" component that sniffs the network traffic and sifts out the voice and signalling data. It then updates the director of call status changes, and can provide users of the system access to the data. It records the data to disk as well. The scalibility of this thing is really cool: given a single director sitting somewhere coordinating the list of agents, multiple harvester can be placed anywhere there is voice traffic. A user that logs into the director can end up seeing the activity of all of these seperate voice networks presented like a single giant mesh. Overall, I have been very pleased with python and the 3rd party libraries that I use (twisted, nevow, kinterbasdb and pygtk). It is a joy to program with, and I think the python community has done a fine job. However, as I have been running the software lately and profiling its memory usage, the one and only Big Problem I have seen is that of the memory usage. Ideally, the server application(s) should be able to run indefinitely, but from the results I'm seeing I will end up exhausting the memory on a 2 GB machine in 2 to 3 days of heavy load. Now normally I would not raise up an issue like this on this list, but based on the conversations held on this list lately, and the work done by Evan Jones (http://evanjones.ca/python-memory.html), I am led to believe that this memory usage -- while partially due to some probably leaks in my program -- is largely due to the current python gc. I have some graphs I made to show the extent of this memory usage growth: http://public.robbyd.fastmail.fm/iq-graph1.gif http://public.robbyd.fastmail.fm/iq-graph-director-rss.gif http://public.robbyd.fastmail.fm/iq-graph-harv-rss.gif The preceding three diagrams are the result of running the 1 director process and 1 harvester process on the same machine for about 48 hours. This is the most basic configuration of this software. I was running this application through /usr/bin/python (CPython) on a Debian 'testing' box running Linux 2.4 with 2GB of memory and Python version 2.3.5. During that time, I gathered the resident and virtual memory size of each component at 120 second intervals. I then imported this data into MINITAB and did some plots. The first one is a graph of the resident (RSS) and virtual memory usage of the two applications. The second one is a zoomed in graph of the director's resident memory usage (complete with a best fit quadratic), and the 3rd one is a zoomed in graph of the harvester's resident memory usage. To give you an idea of the network load these apps were undergoing during this sampling time, by the time 48 hours had passed, the harvester had gathered and parsed about 900 million packets. During the day there will be 50-70 agents talking. This number goes to 10-30 at night. In the diagrams above, one can see the night-day separation clearly. At night, the memory usage growth seemed to all but stop, but with the increased call volume of the day, it started shooting off again. When I first started gathering this data, I was hoping for a logarithmic curve, but at least after 48 hours, it looks like the usage increase is almost linear. (Although logarithmic may still be the case after it exceeds a gig or two of used memory. :) I'm not sure if this is something that I should expect from the current gc, and when it would stop. Now, as I stated above, I am certain that at least some of this increased memory usage is due to either un-collectable objects in the python code, or memory leaks in the pyrex code (where I make some use of malloc/free). I am working on finding and removing these issues, but from what I've seen with the help of gc UNCOLLECTABLE traces, there are not many un-collectable reference issues at least. Yes, there are some but definitely not enough to justify growth like I am seeing. The pyrex side should not be leaking too much, I'm very good about freeing what I allocate in pyrex/C land. I will be running that linked to a memory leak finding library in the next few days. Past the code reviews I've done, what makes me think that I don't have any *wild* leaks going on at least with the pyrex code is that I am seeing the same type of growth patterns in both apps, and I don't use any pyrex with the director. Yes, the harvester is consuming much more memory, but it also does the majority of the heavy lifting. I am alright with the app not freeing all the memory it can between high and low activity times, but what puzzles me is how the memory usage just keeps on growing and growing. Will it ever stop? What I would like to know if others on this list have had similar problems with python's gc in long running, larger python applications. Am I crazy or is this a real problem with python's gc itself? If it's a python gc issue, then it's my opinion that we will need to enhance the gc before python can really gain leverage as a language suitable for "enterprise-class" applications. I have surprised many other programmers that I'm writing an application like this in python/pyrex that works just as well and even more efficiently than the C/C++/Java competitors. The only thing I have left to show is that the app lasts as long between restarts. ;) Robby From my_email_is_posted_on_my_website at munged.invalid Sat Oct 22 02:28:39 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sat, 22 Oct 2005 06:28:39 GMT Subject: Microsoft Hatred FAQ References: <86ll0vs1sw.fsf@bhuda.mired.org> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> Message-ID: <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> On Fri, 21 Oct 2005 21:47:27 -0700, "David Schwartz" wrote or quoted : > There is no way Microsoft could have expected the >market to be defined in this way and no way to argue that Microsoft had any >reason to believe their conduct was illegal. If what they did to me in the 90s was not illegal it damn well should have been. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From maksim.kasimov at gmail.com Wed Oct 12 03:18:22 2005 From: maksim.kasimov at gmail.com (Maksim Kasimov) Date: Wed, 12 Oct 2005 10:18:22 +0300 Subject: can we save print msg into a file when script running ? In-Reply-To: <1129079641.137785.320000@g44g2000cwa.googlegroups.com> References: <1129079641.137785.320000@g44g2000cwa.googlegroups.com> Message-ID: black wrote: > hi all~ > > in my .py file there are a few print to trace out some message and i > wonder if we can save it into a specified file when that script get > running. if so, i may just check that file to c how the script is > running. can anyone show me a right direction ? > > one million tks~ > script.py >> script.log 2>&1 -- Best regards, Maksim Kasimov mailto: maksim.kasimov at gmail.com From xah at xahlee.org Thu Oct 20 16:25:34 2005 From: xah at xahlee.org (Xah Lee) Date: 20 Oct 2005 13:25:34 -0700 Subject: Python Doc Error: os.makedirs In-Reply-To: References: <1129685449.372717.56900@z14g2000cwz.googlegroups.com> Message-ID: <1129839934.602876.141270@g14g2000cwa.googlegroups.com> Thomas Bellman wrote: > try: > os.makedirs("/tmp/trh/spam/norwegian/blue/parrot/cheese") > except os.error, e: > if e.errno != errno.EEXIST: > raise This is what i want. Thanks. (the doc needs quite some improvement...) Xah xah at xahlee.org ? http://xahlee.org/ From erniedude at gmail.com Thu Oct 20 17:45:37 2005 From: erniedude at gmail.com (Ernesto) Date: 20 Oct 2005 14:45:37 -0700 Subject: Execute C code through Python Message-ID: <1129844737.586396.61080@g47g2000cwa.googlegroups.com> What's the easiest and quickest way to execute a compiled C "command line interface" program THROUGH Python? From jjl at pobox.com Sat Oct 1 06:24:35 2005 From: jjl at pobox.com (John J. Lee) Date: 01 Oct 2005 10:24:35 +0000 Subject: PEP 308 accepted - new conditional expressions References: <3q4ro9Fd770nU3@individual.net> <0qh%e.20023$Ix4.15230@okepread03> <1128146343.001242.66990@z14g2000cwz.googlegroups.com> Message-ID: <8764shzg9o.fsf@pobox.com> "Michele Simionato" writes: [...] > Guido could have decided two years ago, sparing us the PEP 308 ordalia. > So, I am happy that at the end we will have a conditional operator, but > I am not happy of how the process worked out. It was just an enormous > waste of resources that could have been employed much better :-( Seems that's what Guido thinks too: http://mail.python.org/pipermail/python-dev/2005-September/056561.html | If there's one thing I've learned from the PEP 308 vote, it is that | votes for language don't work. I prefer some discussion on Python-dev | after which I pick one. I think he said at the time that it was an experiment. John From mwm at mired.org Tue Oct 18 12:18:23 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 18 Oct 2005 12:18:23 -0400 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <11kj8ghonmialfc@corp.supernews.com> Message-ID: <86irvuyf1s.fsf@bhuda.mired.org> Tim Tyler writes: > In comp.lang.java.programmer Ross Bamford wrote or quoted: > About all email has going for it these days is an open format and a > large existing user base. Yeah, and all that Windows has going for it is being on 9X% of the desktops. Nothing really important at all. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From c.peres2 at wanadoo.fr Mon Oct 17 03:56:09 2005 From: c.peres2 at wanadoo.fr (Peres) Date: Mon, 17 Oct 2005 09:56:09 +0200 Subject: graphic memory & animation Message-ID: <009d01c5d2f0$3c634590$0a01a8c0@NEWLAT> Thanks a lot for your answer, Fredrik, Slow means more than 20ms to erase the screen. After double buffering it improved a lot , of course (16 ms) but I'll need a faster speed. I program 2D animated sequences on a PC. Do you think OpenGL is the correct direction to take? If so is it easy to interface with Python (it seems PyOpenGL is not freeware...) Thanks again for your kind help Valerie Peres -------------- next part -------------- An HTML attachment was scrubbed... URL: From jhu at metrigenix.com Thu Oct 20 16:26:35 2005 From: jhu at metrigenix.com (James Hu) Date: Thu, 20 Oct 2005 16:26:35 -0400 Subject: create user message for wxPython Message-ID: <90DEA7ED93F71A4580CEDF76A02682EA03ACC4@torexch.metrigenix.com> Hi, There are 2 wxPython application, A and B and need to exchange msg. Sending WM_CLOSE, wxEVT_MOUSEWHEEL to B is OK, and sending user message like 1225 from A to B is also OK. But B didn't catch this message, note, B is running before A sends msg and can receive "WM_CLOSE". Do I have to make my own msg loop by using win32api, win32gui? I used win32gui to post Message to other windows. Using wx.Frame: wx.EVT_START_MSG= 1225 EVT_START_MSG_EVENT= wx.PyEventBinder(wx.EVT_START_MSG, 0) EVT_START_MSG_EVENT(self, self.OnStart) Or Self.Bind(EVT_START_MSG_EVENT,self.OnStart) def OnStart(self, event): print 'got start message' Thanks a lot in advance! James From david.murmann at rwth-aachen.de Sun Oct 2 15:34:51 2005 From: david.murmann at rwth-aachen.de (David Murmann) Date: Sun, 02 Oct 2005 21:34:51 +0200 Subject: Statement orders In-Reply-To: References: <1128236799.839645.101270@g14g2000cwa.googlegroups.com> <3qanooFdu6okU1@news.dfncis.de> Message-ID: <3qaqvpFe1bjcU1@news.dfncis.de> jepler at unpythonic.net wrote: > Here's one case where it's bad to call update. > > def perform_longrunning_calculation(): > time.sleep(1) > app.update() > time.sleep(1) > would it be advisable to guard against this with something like this? def perform_longrunning_calculation(): if not app.busy: app.busy = 1 time.sleep(1) app.update() time.sleep(1) app.busy = 0 or does this have flaws i'm not seeing? David. From aleaxit at yahoo.com Tue Oct 25 10:54:56 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 25 Oct 2005 07:54:56 -0700 Subject: Tricky Areas in Python References: <1130097286.772836.94930@g44g2000cwa.googlegroups.com> Message-ID: <1h4z9gc.1orudh21d9y4lsN%aleaxit@yahoo.com> Tim Roberts wrote: > "PyPK" wrote: > > > >What possible tricky areas/questions could be asked in Python based > >Technical Interviews? > > What's the point of asking "tricky" questions? Aren't you really more > interested in what applications they have worked on and whether they were > successful? Understanding exactly what contribution they did, to the applications they worked on, may be even more important. After all, we've all seen people who worked on app "X" and made a NEGATIVE net contribution to "X"'s success, compensated by the far better efforts of others on the team. But it's unlikely that the candidate will actually say "I worked on X, but my grasp of the language was so feeble that in fact I made it _worse_ than it would have been without me in the team";-). > I don't know. I'm not sure I need a job with a company that insists on > playing "Programming Jeopardy" during the interview. I understand how some "quiz-like" questions may rub you the wrong way. For questions such that knowing the answers is of little or no use on the job I might even concur -- e.g., "On what exact date was Python 1.0 released" (even if the candidate claims to have been actively part of that release, he might perfectly well misremember the date!-). Others are iffier, e.g., "what are all the optional arguments to built-in function 'open'" -- some people easily memorize those even if they use them once in a blue moon, others look them up in 2 seconds every time they need to with a "help(open)" on the interactive interpreter prompt, so while the knowledge sure doesn't hurt it's not very important. That's even truer for other functions and classes with many more, and more obscure, optional arguments. If I asked such a question in the course of a programming task, I would consider "hmmm, there's an optional argument for that, I don't remember it but in real life I'd look it up in a jiffy" perfectly acceptable (if the candidate appears to have no idea that there IS an optional argument for a cerrtain purpose, that's slightly less good, but no disaster). But -- being presented with a flawed solution and asked to help debug it (by identifying the "tricky issue" on which it fails) appears to me to be perfectly acceptable. It IS the kind of task you face all the time IRL, and checks how well you know the language and libraries... Alex From rschroev_nospam_ml at fastmail.fm Sun Oct 16 17:06:24 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Sun, 16 Oct 2005 21:06:24 GMT Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: John Bokma wrote: > Roel Schroeven wrote: > > >>John Bokma wrote: > > >>>web based applications that work with any browser make OS irrelevant >>>-> not true, since for OpenOffice it doesn't matter which Linux >>>distribution one runs (or even if it's Linux), yet people seem to >>>make a point of which distribution they use. >> >>You make the point yourself now: if web based applications work with >>any browser, people can freely choose their distribution based on >>their own preferences. > > > Yup, and what will they pick? The one of their choice. Nobody knows which one that will be. Maybe MS. But that's not the point; the point is that they have the choice. If MS had it its way, they wouldn't have that choice. > >>- An application works in IE, Firefox, Konqueror, Safari, Lynx, Links, >>Opera, ... -> users can use it with any browser on any OS > > > I think that we both understand that one browser will be more compatible > then an other. It will only happen if all use exactly the same render > engine, or all web recommendations are frozen. Thousands and thousands of website work perfectly in all of the aforementioned websites right now. > And if that happens, people selling stuff will find ways to make > their version just a little better. It's very well possible to compete without breaking compatibility. That's what Firefox, Opera, Konqueror etc. are already doing. > Look at processors: which one would you buy at the moment? AMD? Intel? > and if you pick a brand, which type? Depends on my needs, budget and the specs and price of the available offers. Plus I always have a small, admittedly perhaps unjustified, preference for the underdog; in the past that was AMD, in the future that may very well be Intel. But I don't see the point of that question. > As soon as products can't evolve much more, the producers will find > ways to make them even better compared to last week. As products can't evolve much more, the producers will find ways to make them evolve?? Sorry, I don't understand what you're trying to say here. >>- An application only works in IE -> users are forced to use Windows >>(or one of the other few OS's that IE exists on) > > > Or wait until there comes a solution from a 3rd party. Force doesn't > exists with software unless you can manipulate the law to enforce it. > And I don't believe that everybody at Microsoft was/is that stupid to > think they can make that something they don't controll only works with > their software. Sure they can make it harder, like I said, you can > always add things, especially if you are the major player, but Firefox > is a nice proof that there is no such force, and I doubt that there are > people working at Microsoft in major positions who didn't see this > coming. Maybe they can force it, maybe not, but that's not the point (again). The point is what their intentions are, and that is trying to lock people into using their software. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From email at christoph-haas.de Sat Oct 1 14:28:53 2005 From: email at christoph-haas.de (Christoph Haas) Date: Sat, 1 Oct 2005 20:28:53 +0200 Subject: Printing and prompting adds a mysterious extra space Message-ID: <20051001182853.GA11802@torf.workaround.org> Evening... I'm writing a simple interactive program to maintain a database. The goal was to print "> " at the beginning of the line, wait for user input and then deal with it. Minimal test program: import sys; print ">", ; print sys.stdin.readline() However when I run the program and enter "foobar" it looks like this: ./test.py >foobar foobar ^----------- where does this space come from? I wonder where the space comes from in the line where I print what the user typed. Does it have to do with the "," after the print which I use to suppress the newline? Any ideas? Regards Christoph -- I'm still confused - just on a higher level now. ~ ~ ".signature" [Modified] 1 line --100%-- 1,48 All From rbt at athop1.ath.vt.edu Mon Oct 10 10:19:55 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Mon, 10 Oct 2005 10:19:55 -0400 Subject: socketServer questions In-Reply-To: <7x4q7po7l2.fsf@ruckus.brouhaha.com> References: <1128699247.9040.15.camel@athop1.ath.vt.edu> <7xll15paha.fsf@ruckus.brouhaha.com> <1128718708.7800.2.camel@athop1.ath.vt.edu> <7xoe61yoa2.fsf@ruckus.brouhaha.com> <1128774994.14078.2.camel@athop1.ath.vt.edu> <7xu0frogwj.fsf@ruckus.brouhaha.com> <1128948284.15030.7.camel@athop1.ath.vt.edu> <7x4q7po7l2.fsf@ruckus.brouhaha.com> Message-ID: <1128953995.15590.19.camel@athop1.ath.vt.edu> On Mon, 2005-10-10 at 05:54 -0700, Paul Rubinhttp: wrote: > rbt writes: > > > I don't understand the question. HMAC requires that both ends share a > > > secret key; does that help? > > > > That's what I don't get. If both sides have the key... how can it be > > 'secret'? All one would have to do is look at the code on any of the > > clients and they'd then know everything, right? > > Yes, clients have to keep the key secure. > > > > What do you mean by verification? > > > > I'm trying to keep script kiddies from tampering with a socket server. I > > want the server to only load a valid or verified string into its log > > database and to discard everything else. > > If the clients can keep a secret key secure, then use hmac. Note that > if there's lots of clients, they shouldn't all use the same secret key. > Instead, for client #i, let that client's key be something like > hmac(your_big_secret, str(i)).digest() > and the client would send #i as part of the string. How is this different from sending a pre-defined string from the client that the server knows the md5 hash of? The clients know the string, the server knows the hash of that string. Also, could this not be done both ways? So that, if an attacker figures out the string he's supposed to send from a client to the server (which he could easily do). He could not easily figure out the string the server should send back as all he would have is the hash of that string. So, before the actual data is sent from the client to the server. The client would send it's secret string that the server would verify and then if that worked, the server would send its own secret string that the client must verify. We'd have two secret strings instead of one. > You'd use > #i to recompute the client's key and then use that derived key to > verify the string. This is called "key derivation" or "key > diversification". If an attacker gets hold of that client's key and > starts hosing you, you can disable that key without affecting the > other ones. (The client is issued only the derived key and never sees > the big secret). This is interesting. I didn't know that was possible. > > > Strings could come to the socket server from anywhere on the Net from > > any machine. This is outside my control. What is there to prevent a > > knowledgeable person from finding the py code on a client computer, > > understanding it and then being able to forge a string that the server > > will accept? > > Yes, if you're concerned about insecure clients, you have a much more > complex problem. But your x..z..y scheme is far worse than hmac. > Once the attacker figures that out, there's no security at all. I dropped the x,y,z scheme after your first response ;) > > What is the actual application, if you can say? Depending on the > environment and constraints, various approaches are possible. Nothing important. It just logs network data. It's an anti-theft program for laptops that phones home data like this: public and private IP(s), MAC addy, date, time, etc. Maybe I'm putting too much thought into it. Python encourages good design and I try to follow that encouragement when coding... even for trivial things such as this. From smitty_one_each at bigfoot.com Tue Oct 18 17:36:09 2005 From: smitty_one_each at bigfoot.com (Chris Smith) Date: Tue, 18 Oct 2005 17:36:09 -0400 Subject: Dealing with Excel References: <1129670191.061006.146320@g47g2000cwa.googlegroups.com> Message-ID: <87ll0qpkxi.fsf@bigfoot.com> >>>>> "Robert" == Robert Hicks writes: Robert> I need to pull data out of Oracle and stuff it into an Robert> Excel spreadsheet. What modules have you used to interface Robert> with Excel and would you recommend it? Robert> Robert For simple enough tasks, I think you can make SQL*plus output HTML, which Excel could suck up directly. For a sripted approach, I would recommend getting an ADODB.Connection object to your Oracle database , opening an ADODB.Recordset against the connection , setting an Excel.Range object to Cell A1 , enumerating your recodset field names into the cells of row 1 , setting the Exel.Range to Cell A2 , using the ridiculously fast CopyFromRecordset method of the Excel.Range to dump the recordset to the sheet. HTH, Chris From thakadu at gmail.com Thu Oct 6 12:40:03 2005 From: thakadu at gmail.com (thakadu) Date: 6 Oct 2005 09:40:03 -0700 Subject: Simple prototype text editor in python In-Reply-To: References: <1128530997.895468.164240@g49g2000cwa.googlegroups.com> <1128609090.858119.28110@g43g2000cwa.googlegroups.com> Message-ID: <1128616803.591030.83360@o13g2000cwo.googlegroups.com> Thanks Robert I have packaged it up with distutils and included the license in the README.txt file. I think I am missing something as I have only seen a place (under submissions) on http://python.org/pypi?%3Aaction=submit_form to submit the PKG_INFO file, or to submit a url manually but nowhere to actually upload the distribution file. (the tar.gz file) Am I looking in the wrong place? Or is it acceptable to post a .tar.gz file in place of the PKG_INFO file? From steve at holdenweb.com Thu Oct 20 06:53:52 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 20 Oct 2005 11:53:52 +0100 Subject: Would there be support for a more general cmp/__cmp__ In-Reply-To: References: Message-ID: Antoon Pardon wrote: > I was wondering how people would feel if the cmp function and > the __cmp__ method would be a bit more generalised. > > The problem now is that the cmp protocol has no way to > indicate two objects are incomparable, they are not > equal but neither is one less or greater than the other. > > So I thought that either cmp could return None in this > case or throw a specific exception. People writing a > __cmp__ method could do the same. > The current behaviour is, of course, by design: """The operators <, >, ==, >=, <=, and != compare the values of two objects. The objects need not have the same type. If both are numbers, they are converted to a common type. Otherwise, objects of different types always compare unequal, and are ordered consistently but arbitrarily.""" Personally I'm still not convinced that your requirement reflects a substantial use case (but then I'm getting used to that ;-). Just because an ordering is partial that doesn't mean that two instances of a class shouldn't be compared. What would you have Python do when the programmer tries to perform an invalid comparison (i.e. what are the exact semantics imposed when __cmp__() returns None/raises an exception)? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From vinay_sajip at yahoo.co.uk Tue Oct 25 10:33:08 2005 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: 25 Oct 2005 07:33:08 -0700 Subject: How to prevent logging warning? References: <1128551304.960549.235420@f14g2000cwb.googlegroups.com> Message-ID: <1130250788.241127.93600@g47g2000cwa.googlegroups.com> I have now checked a change into CVS whereby the one-off error message is not printed unless raiseExceptions is 1. The default behaviour is thus unchanged, but if you set raiseExceptions to 0 for production use and then don't configure any handlers, then the message is not printed. Regards, Vinay Sajip From dcrespo at gmail.com Tue Oct 25 08:29:38 2005 From: dcrespo at gmail.com (dcrespo) Date: 25 Oct 2005 05:29:38 -0700 Subject: Security on XML-RPC Message-ID: <1130243378.736452.270130@g43g2000cwa.googlegroups.com> Hi all, Anyone knows a simpler but stronger control access to XML-RPC functions than the one I comment here? My actual system works like this: I have a TCP Server and an XML-RPC Server. Both of them verify if the IP address is allowed. The TCP Server works for validate and register an IP address if it wasn't validated previously, while the XML-RPC Server works only if the requester IP address was allowed through the mentioned TCP Server. This means, anyone who wants to connect to the XML-RPC Server has to pass the TCP Server. How a client connects to the TCP Server and authenticate his IP? Well, there is an interchange of encrypted data between the Client and the TCP Server, where, in few words, the client sends a UserName and a Password, all this through the send() function of the Socket connection. If the TCP Server authenticate an IP address, then that Client will be able to connect to the XML-RPC Server and use its defined functions. The problem I see here is that if I want someone to taking advantage of my XML-RPC functions, I have to tell him all these. I would like to get a strong but simpler way of doing all these. Thank you for reading and thinking. Daniel From davegu1 at hotmail.com Wed Oct 19 10:13:30 2005 From: davegu1 at hotmail.com (David Gutierrez) Date: Wed, 19 Oct 2005 09:13:30 -0500 Subject: No subject In-Reply-To: Message-ID: Hugo, Cual documento es el que leiste. David. From: hugo hernandez diaz To: python-list at python.org Date: Tue, 18 Oct 2005 23:03:39 -0600 MIME-Version: 1.0 Received: from smtp-vbr3.xs4all.nl ([194.109.24.23]) by MC8-F32.hotmail.com with Microsoft SMTPSVC(6.0.3790.211); Tue, 18 Oct 2005 22:04:25 -0700 Received: from bag.python.org (bag.python.org [194.109.207.14])by smtp-vbr3.xs4all.nl (8.13.3/8.13.3) with ESMTP id j9J54MXa061233for ; Wed, 19 Oct 2005 07:04:22 +0200 (CEST)(envelope-from python-list-bounces+davegu1=hotmail.com at python.org) Received: from bag.python.org (bag [127.0.0.1])by bag.python.org (Postfix) with ESMTP id 95D231E4032for ; Wed, 19 Oct 2005 07:04:15 +0200 (CEST) Received: from bag.python.org (bag [127.0.0.1])by bag.python.org (Postfix) with ESMTP id 5BCAF1E4002for ; Wed, 19 Oct 2005 07:03:40 +0200 (CEST) Received: from bag (HELO bag.python.org) (127.0.0.1)by bag.python.org with SMTP; 19 Oct 2005 07:03:40 +0200 Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.207])by bag.python.org (Postfix) with ESMTPfor ; Wed, 19 Oct 2005 07:03:40 +0200 (CEST) Received: by xproxy.gmail.com with SMTP id t13so5516wxcfor ; Tue, 18 Oct 2005 22:03:39 -0700 (PDT) Received: by 10.70.96.6 with SMTP id t6mr122000wxb;Tue, 18 Oct 2005 22:03:39 -0700 (PDT) Received: by 10.70.109.10 with HTTP; Tue, 18 Oct 2005 22:03:39 -0700 (PDT) X-Message-Info: JGTYoYF78jFNYkjVuLjbNX85tc7/i/AXgguzCWP7ndw= X-Original-To: python-list at python.org Delivered-To: python-list at bag.python.org X-Spam-Status: OK 0.270 X-Spam-Level: ** DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com;h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition;b=FLIvjmWGtDhqri9Sr8YsEbgpdJLtM4URogb830Eda/pS+LRylIhvEgXwUstU1Mx/ZUvgk377zjFPDO6aNv9/SZqJlxHkS9RZJEYhx4GjZ4w2mRKYVmirFA1TxXutondJEVbSU9a9l9UfqpW0meVJKGG5Y6nSbIKttyTxRgiWQQQ= X-BeenThere: python-list at python.org X-Mailman-Version: 2.1.6 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: python-list-bounces+davegu1=hotmail.com at python.org X-Virus-Scanned: by XS4ALL Virus Scanner Return-Path: python-list-bounces+davegu1=hotmail.com at python.org X-OriginalArrivalTime: 19 Oct 2005 05:04:26.0637 (UTC) FILETIME=[941B5BD0:01C5D46A] hola la vdd lei su documento pero no le entoendo bien mas que nada puedo crear algo con este programa si la respuesta es si mas o menos que si la respuesta en no entoncs pa que sirve a ademas no me pueden pasar oyta guia mas facil mmm soy medio lento de aprendizaje gracias -- http://mail.python.org/mailman/listinfo/python-list From jmdeschamps at cvm.qc.ca Wed Oct 26 15:58:29 2005 From: jmdeschamps at cvm.qc.ca (jean-marc) Date: 26 Oct 2005 12:58:29 -0700 Subject: textwidget.tag_bind("name", "", self.donothing) not working In-Reply-To: <1130356366.749611.148240@g14g2000cwa.googlegroups.com> References: <1130266889.246361.268610@g47g2000cwa.googlegroups.com> <1130356366.749611.148240@g14g2000cwa.googlegroups.com> Message-ID: <1130356709.694069.295350@f14g2000cwb.googlegroups.com> Sorry, kinda wrote over your intentions... From rschroev_nospam_ml at fastmail.fm Mon Oct 3 11:50:27 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Mon, 03 Oct 2005 15:50:27 GMT Subject: Reply-To header In-Reply-To: References: <2ECA6FE9-3C8F-4C60-9E89-70CC078B14EF@gmail.com> Message-ID: <7rc0f.11261$Un.585792@phobos.telenet-ops.be> Peter Decker wrote: > On 10/3/05, Roel Schroeven wrote: > > >>Indeed, and that's by design: http://www.unicom.com/pw/reply-to-harmful.html > > > Of course, that's only one side of the argument: > > http://www.blackgate.net/consulting/reply-to_munging_useful.html > > On lists like this, where everyone benefits by sharing information, it > seems pretty lame to hide behind purist arguments about Reply-To: > headers. The default behavior should be the one most useful to the > list. Think for a moment how many useful bits of information you've > missed because the default for this list it to make conversations > private. The default of this list is not to make conversations private; in fact the list doesn't have any default. It's you who chooses to send replies to the original author, to the list, or both, by choosing which button to press in your mail client. Unfortunately AFAIK most of the popular mail clients don't offer a 'Reply to list' button. Even mutt only offers that functionality of you manually define all your mailing lists. But that's a design problem in these clients, not in the mailing list software. Not that it matters that much to me, since I read practically all mailing lists via gmane.org. That turns the lists into newsgroups, where the reply button (follow-up, more accurately) does send the reply to the newsgroup. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From jstroud at mbi.ucla.edu Mon Oct 24 14:59:53 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Mon, 24 Oct 2005 11:59:53 -0700 Subject: Would there be support for a more general cmp/__cmp__ In-Reply-To: References: Message-ID: <200510241159.53032.jstroud@mbi.ucla.edu> On Monday 24 October 2005 04:33, Steve Holden wrote: > Well in that case it's time to declare Principia Mathematica obsolete. > The real numbers are a two-dimensional field, and you are proposing to > define an ordering for it. I wasn't a math major, but don't you mean "the complex numbers are a two dimensional field"? If you mean real numbers, please do explain. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From http Wed Oct 26 20:16:22 2005 From: http (Paul Rubin) Date: 26 Oct 2005 17:16:22 -0700 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <3s6l8mFmj3fjU1@individual.net> <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> Message-ID: <7xwtjz3jc9.fsf@ruckus.brouhaha.com> "David Schwartz" writes: > If you want to sell meals with Whoppers in them, you have to get > permission to do so from Burger King corporate. And they will not let you > also sell Big Macs in the same store, even if McDonald's had no objection. Why do you keep comparing Microsoft with Burger King? They are not the same. Burger King is operating in a competitive environment. Microsoft is a convicted illegal monopolist. Monopolists are not allowed to do the same things that competitors are allowed to do. So, your observations about Burger King are irrelevant to Microsoft. From grante at visi.com Fri Oct 21 12:07:05 2005 From: grante at visi.com (Grant Edwards) Date: Fri, 21 Oct 2005 16:07:05 -0000 Subject: Execute C code through Python References: <1129844737.586396.61080@g47g2000cwa.googlegroups.com> <1129861083.010702.6770@g49g2000cwa.googlegroups.com> <1129906892.696582.288010@g43g2000cwa.googlegroups.com> <11li3b2hsa3lhb5@corp.supernews.com> Message-ID: <11li4h95pnci35b@corp.supernews.com> On 2005-10-21, Micah Elliott wrote: > On Oct 21, Grant Edwards wrote: >> I'm guessing you're using Windows based on the question. > > +1 QOTW. Yow! That's two in one day, what do I win? -- Grant Edwards grante Yow! I'll take ROAST BEEF at if you're out of LAMB!! visi.com From larry.bates at websafe.com Tue Oct 25 13:16:22 2005 From: larry.bates at websafe.com (Larry Bates) Date: Tue, 25 Oct 2005 12:16:22 -0500 Subject: Log rolling question In-Reply-To: <1130259387.787107.120740@g14g2000cwa.googlegroups.com> References: <1130259387.787107.120740@g14g2000cwa.googlegroups.com> Message-ID: import time # # 120 days, 24 hours, 60 monutes, 60 seconds # fourmonthsago=time.time()-(120*24*60*60) Compare fourmonthsago value to modified date of files. Delete those that are less. Larry Bates elake wrote: > I have an application that creates a lot of large log files. I only > want to keep logs for the previous 4 months. I am looking for a way to > list the contents of the log dir and if the create date on the log is > older than 4 months delete it. I have looked at the os.stat() function > to get the created date but I can't figure out how to get the date to > go back to a previos time. > > Any help would be appreciated. > From egbert.bouwman at hccnet.nl Fri Oct 28 06:38:46 2005 From: egbert.bouwman at hccnet.nl (egbert) Date: Fri, 28 Oct 2005 12:38:46 +0200 Subject: Opaque documentation Message-ID: <20051028103846.GA6382@hccnet.nl> Once in a while you come acros aline of documentation that you have to, or that invites you to, read it again. This is what I found in PyGTK: The set_screen method sets the 'screen" property to the gtk.gdk.Screen specified by screen. The "screen" property contains the screen that the window is displayed on. The screen on the second line, before the period, is in italics, if that helps. I like these texts. Prose should not disclose its secrets at once. If you have other examples, please let us know. -- Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991 ======================================================================== From phil_nospam_schmidt at yahoo.com Tue Oct 11 22:14:51 2005 From: phil_nospam_schmidt at yahoo.com (phil_nospam_schmidt at yahoo.com) Date: 11 Oct 2005 19:14:51 -0700 Subject: HELP: Searching File Manager written in Python References: <1129037968.366932.144250@g44g2000cwa.googlegroups.com> Message-ID: <1129083291.906896.290480@f14g2000cwb.googlegroups.com> I don't know about Norton Commander either. But, have you looked at twander? http://www.tundraware.com/Software/twander/ From gagenellina at softlab.com.ar Wed Oct 26 18:29:18 2005 From: gagenellina at softlab.com.ar (Gabriel Genellina) Date: 26 Oct 2005 15:29:18 -0700 Subject: Pickle to source code In-Reply-To: References: <1130332534.999358.152530@g49g2000cwa.googlegroups.com> Message-ID: <1130365758.724259.165790@g47g2000cwa.googlegroups.com> Jean-Paul Calderone ha escrito: > >In other words, I need a *string* which, being sent to eval(), would > >return the original object state saved in the pickle. > > You may find twisted.persisted.aot of some use. Here is an example: > > AOT is unmaintained in Twisted, and may not support some newer features of Python (eg, datetime or deque instances). If this seems useful, you may want to contribute patches to bring it up to the full level of functionality you need. Oh, thanks. I have some problems installing the package but I hope it will be useful. If any changes are needed I'll report them. Gabriel Genellina Softlab SRL From programmer.py at gmail.com Sat Oct 1 21:56:45 2005 From: programmer.py at gmail.com (Jaime Wyant) Date: Sat, 1 Oct 2005 20:56:45 -0500 Subject: How is wxWindows related to Python? In-Reply-To: <1128216966.664758.179160@f14g2000cwb.googlegroups.com> References: <1128216966.664758.179160@f14g2000cwb.googlegroups.com> Message-ID: That is a reference to wxPython. wxPython is a thin wrapper around the wxWidgets c++ library. But really, it has grown quite a bit lately and has a bunch of neato widgets that aren't included with wxWidgets c++. Visit www.wxpython.org. jw On 1 Oct 2005 18:36:06 -0700, Sathyaish wrote: > My question will sound daft to the good old craftsmen, but they will > excuse my nescience on the subject. I come new to the Pythonic world > from the land of .NET languages, VB6 and some familiarity in C and C++. > > I just read about wxWindows last night. From my understanding, it is a > GUI framework like MFC that lets you create UI apps with ease calling a > standard set of API accross multiple platforms (unlike MFC) and if the > Windows port is complementary to MFC in that it shields you from > calling the Win32 API directly. > > However, I do not understand its correlation with Python. The > documentation page says, "wxWindows 2.4.2: A portable C++ and Python > GUI toolkit." So, my question is, "How is wxWindows related to Python?" > > -- > http://mail.python.org/mailman/listinfo/python-list > From lasse at vkarlsen.no Fri Oct 7 18:17:56 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Sat, 08 Oct 2005 00:17:56 +0200 Subject: Contest snub? In-Reply-To: References: Message-ID: maxx at easynews.com wrote: > Notice anything strange here? The Python entry seems to have edged the PHP > entries, but is not declared the victor. Source is missing as well (the archive > is empty.) > > http://www.apress.com/promo/fractal/seesource.html > > Hmmmm... an irrational fear of snakes perhaps? > Clearly Python is superior because it doesn't need any code at all to do fractals. Surely you can see that? :) I question the timings though, 2+ minutes to execute nothing doesn't seem very pythonesque. -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From peter at engcorp.com Fri Oct 21 09:50:36 2005 From: peter at engcorp.com (Peter Hansen) Date: Fri, 21 Oct 2005 09:50:36 -0400 Subject: Converting 2bit hex representation to integer ? In-Reply-To: <43567508$0$41148$14726298@news.sunsite.dk> References: <43567027$0$41144$14726298@news.sunsite.dk> <-_2dndLn4eEm78veRVn-qg@comcast.com> <4356740c$0$41148$14726298@news.sunsite.dk> <43567508$0$41148$14726298@news.sunsite.dk> Message-ID: <44GdnTlgTrKJb8XeRVn-sg@powergate.ca> Madhusudan Singh wrote: > I just tried > > n=str(x) > print struct.unpack("b",n) > > I get (51,) > > What is the deal with the parenthesis > and the comma ? If you really don't know what the parentheses and comma mean in the above output, I would suggest that you need to go back a step and walk through the Python tutorial before you try to continue on with what you are attempting to do. (Section 5.3 specifically covers your question.) Either that, or read the documentation on struct.unpack() since that describes what it returns fairly clearly. Assuming your input represents a C-style integer (i.e. fixed size) rather than a Python long integer (of arbitrary length), you should be able to use just struct.unpack('i', mybinarydata)[0] to get the result you need... -Peter From robert.kern at gmail.com Wed Oct 12 11:44:15 2005 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 12 Oct 2005 08:44:15 -0700 Subject: calling matlab In-Reply-To: References: Message-ID: Mohammed Smadi wrote: > Hi; > > Does anyone know if we can call matlab for a python or bash script while > feeding the matlab script some command line arguments? I have an > interactive matlab script which i want to automate by feeding the args > from a script. Depending on how interactive it is, you should look at the subprocess module in the stdlib or pexpect. http://docs.python.org/lib/module-subprocess.html http://pexpect.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 sszmidt at netwvcom.com Mon Oct 3 19:10:32 2005 From: sszmidt at netwvcom.com (sszmidt at netwvcom.com) Date: Mon, 3 Oct 2005 19:10:32 -0400 Subject: Reply-To header In-Reply-To: <7rc0f.11261$Un.585792@phobos.telenet-ops.be> References: <2ECA6FE9-3C8F-4C60-9E89-70CC078B14EF@gmail.com> <7rc0f.11261$Un.585792@phobos.telenet-ops.be> Message-ID: <200510031910.32684.sszmidt@netwvcom.com> On Monday 03 October 2005 11:50, Roel Schroeven wrote: > Peter Decker wrote: > Unfortunately AFAIK most of the popular mail clients don't offer a > 'Reply to list' button. Even mutt only offers that functionality of you Of course if you have kmail it has full list support and allows you to do that. This is my all time favorite email client. -- Steve From UrsusMaximus at gmail.com Thu Oct 6 10:43:43 2005 From: UrsusMaximus at gmail.com (UrsusMaximus at gmail.com) Date: 6 Oct 2005 07:43:43 -0700 Subject: So far In-Reply-To: References: Message-ID: <1128609823.151531.24940@z14g2000cwz.googlegroups.com> Try PythonCard Ron Stephens Python Learning Center a prententious name for a nice hobbyist resource www.awaretek.com/plf.html From andreas.zwinkau at googlemail.com Wed Oct 5 06:39:30 2005 From: andreas.zwinkau at googlemail.com (beza1e1) Date: 5 Oct 2005 03:39:30 -0700 Subject: bug or feature? Message-ID: <1128508770.727391.313300@f14g2000cwb.googlegroups.com> Coming back from a bug hunt, i am not sure what to think of this python behaviour. Here is a demo program: class A: def __init__(self, lst=[]): self.lst = lst a = A() b = A() b.lst.append("hallo") print a.lst # output: ["hallo"] The point seems to be, that lst=[] creates a class attribute (correct name?), which is shared by all instances of A. So a.lst ist the same object as b.lst, despite the fact, that object a is different to object b. From sjdevnull at yahoo.com Wed Oct 19 18:31:46 2005 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: 19 Oct 2005 15:31:46 -0700 Subject: Python variables are bound to types when used? In-Reply-To: References: <1129751462.061785.124830@g49g2000cwa.googlegroups.com> Message-ID: <1129761106.725465.42290@g49g2000cwa.googlegroups.com> Fredrik Lundh wrote: > reset your brain: > > http://effbot.org/zone/python-objects.htm Neat link. Can you expand on this: > a type (returned by type(x)) ... > You cannot change the type. Especially what's going on here: >>> class a(object): ... pass ... >>> class b(a): ... pass ... >>> x=b() >>> x.attr=1 >>> type(x) >>> type(y) >>> x.__class__=a >>> type(x) >>> x.attr 1 It looks to me like x is still referencing the same object (and still has the "attr" attribute) but its type has changed. Is that not right? From lasse at vkarlsen.no Sat Oct 8 18:03:05 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Sun, 09 Oct 2005 00:03:05 +0200 Subject: Jargons of Info Tech industry In-Reply-To: <863bnbofe5.fsf@bhuda.mired.org> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > If you've got a browser with a better solution, what's the browser, > and what's the solution? There is no single solution. On one side you got control freaks who condemn everyone who dares send an email with something other than what you've got your own email set up to use. "You dare specify the font sized when I finally figured out that 10 is just right? Infidel!" On the other side you got people who would like to have slightly more control over their email formatting than the ability to hit enter to denote a line break. "Whaddya mean I can't specify bold text to emphasize a point?" As long as you got something called a feature, there will always be people who will be able to abuse it. Now, if you want to get into a big huff because someone you knows use a font that is "slightly oversized" because of Windows, then I think you missed the point of the email altogether, which was probably to convey a message. Just the same as people that sends bright red text on green background seems to miss the whole issue of "appropriate". It doesn't matter what is used, decided, controlled, allowed, removed, whatever. Some people will always like it, some will hate it, some will abuse it, but most of all there will always be people that will discuss it. Hopefully most people will use it for what it is. In any case, html email is here to stay. Or perhaps I should remove html and say "richly formatted", whatever that might mean in the future. But trying to keep your email world into a pure text-based no-formatting-whatsoever world, that's a fantasy bubble that is bound to burst, sooner rather than later. Deal with it. -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From strombrg at dcs.nac.uci.edu Sat Oct 15 23:57:07 2005 From: strombrg at dcs.nac.uci.edu (Dan Stromberg) Date: Sun, 16 Oct 2005 03:57:07 GMT Subject: Two python database questions Message-ID: Hi folks. I'm working on some file indexing software, in python of course. Over the course of working on it, I've come upon two python+database related questions: 1) Is there a reason for the gdbm module in python 2.4.1 not to have a get method? This makes it a touch less dictionary-like. 2) Has anyone already written some sort of in-memory cache wrapper for gdbm or anydbm or whatever? As I'm writing this program, I'm finding that there's an awful lot of disk I/O going on - it'd be great if there were some way of keeping the n most recently used items in memory, and only write them to disk when room needs to be made in the cache or when the program exits? Thanks! From aleaxit at yahoo.com Fri Oct 28 22:56:36 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 28 Oct 2005 19:56:36 -0700 Subject: How do I sort these? References: <1130524906.918612.38540@g49g2000cwa.googlegroups.com> <1130531874.710810.39050@g43g2000cwa.googlegroups.com> <7x8xwdid3e.fsf@ruckus.brouhaha.com> Message-ID: <1h55r8f.1ut74echynglzN%aleaxit@yahoo.com> Paul Rubin wrote: > "KraftDiner" writes: > > In C++ you can specify a comparision method, how can I do this with > > python... > > Yes, see the docs. Just pass a comparison func to the sort method. Or, better, pass a key-extraction function, that's much handier and faster (it automates the "decorate-sort-undecorate", DSU, idiom). Alex From money at paiddriver.net Sat Oct 29 23:25:32 2005 From: money at paiddriver.net (Poker Paid Us) Date: Sun, 30 Oct 2005 03:25:32 GMT Subject: Online Poker Pays! Learn All The Secrets Now!NBP Unregistered. Message-ID:

Did you know that online Poker pays huge money? In the last three days my wife and I have made over 343.00 USD with online poker while we slept

Want to know our secret? Click HERE and visit a link of your choice.

-------------- next part -------------- An HTML attachment was scrubbed... URL: From smadim2 at grads.ece.mcmaster.ca Tue Oct 4 13:21:56 2005 From: smadim2 at grads.ece.mcmaster.ca (Mohammed Smadi) Date: Tue, 4 Oct 2005 13:21:56 -0400 (EDT) Subject: tcp socket programming Message-ID: hi; If i have a tcp connection with a remote server, what is a good way to read all the data into a buffer before starting to process the data? I know that the data recieved will be 3 lines with CRLF between them. However if I can sock.recv(1024) the output is not consistent all the time, sometime i get one line and sometimes i get two. So I figures I should read all the data first then work on it and I used the following code: result = [] while True: got=s.recv(1024) print got if not got: break result.append(got) got = [] # i tried also taking this out s.close() but this code just hangs in the loop and never quits any ideas will be much appreciated moe smadi From fergdeff at gmail.com Tue Oct 25 11:08:33 2005 From: fergdeff at gmail.com (ferg) Date: 25 Oct 2005 08:08:33 -0700 Subject: MoinMoin - Can't create new pages In-Reply-To: <1130252427.220729.312180@o13g2000cwo.googlegroups.com> References: <1130252059.474472.102670@g14g2000cwa.googlegroups.com> <1130252427.220729.312180@o13g2000cwo.googlegroups.com> Message-ID: <1130252913.385217.64250@g49g2000cwa.googlegroups.com> Newsflash: I've tried the [[NewPage]] macro and that works, but still no joy with the WikiName links. Well that's a work around for now, but it'd still be great to know why the other methods don't work... From shannonlayland at gmail.com Tue Oct 25 15:01:29 2005 From: shannonlayland at gmail.com (shannonl) Date: 25 Oct 2005 12:01:29 -0700 Subject: textwidget.tag_bind("name", "", self.donothing) not working Message-ID: <1130266889.246361.268610@g47g2000cwa.googlegroups.com> Hi all, For some reason this bind is calling the donothing function, like it should, but is then allowing the text to be inserted into the Text widget. Here is the code: self.framebody.tag_config("name", underline=1) self.framebody.tag_bind("name", "", self.donothing) line = '\t%s' % ('sometext') self.framebody.insert(END, line, "name") def donothing(self): return 'break' This donothing function should keep the tcl bind from inserting the text...at least so I thought. This bind does work on the text widget as a whole, but on a individual tag, it does not. Can anyone help me out with this? Thanks in advance, Shannon From steve at REMOVETHIScyber.com.au Sun Oct 9 11:58:39 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 10 Oct 2005 01:58:39 +1000 Subject: Function decorator that caches function results References: <7x4q7rt3yl.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 09 Oct 2005 13:43:38 +0200, Fredrik Lundh wrote: >> If I wanted to inspect the value of cache, where would I find it? > > nowhere. at least no officially; see "Rebinding names in enclosing > scopes" in the design document for a discussion: > > http://www.python.org/peps/pep-0227.html That's interesting to read, and does clarify a few things that weren't straight in my head, but I notice that the author, Jeremy Hylton, distinguishes between Python creating function definitions that are closures from those that aren't: "Each def or lambda expression that is executed will create a closure if the body of the function or any contained function has free variables." Presumably that means that if there are no free variables, no closure is created. >> That assumes that cache can be seen in this way. If it can't, is this a >> way to create "really private" variables in Python? > > no, because Python doesn't prevent you from digging into the > internals: > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440515 That's blackest voodoo, and as the warning says, could cause Python to sigfault if you get the opcodes wrong. I think that this is close enough to "really private" to satisfy most people. Maybe even Paul Rubin *wink* -- Steven. From steve at REMOVETHIScyber.com.au Wed Oct 5 09:39:31 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Wed, 05 Oct 2005 23:39:31 +1000 Subject: While and If messing up my program? References: Message-ID: On Wed, 05 Oct 2005 06:48:59 +0000, CJ wrote: > > Hey, I'm new to the Python world, but I do have experience in several > other languages. I've been running through a tutorial, and I decided that > I'd make a program that runs through a list, finds if there are any > duplicates. The program, doesn't work, but since its a first build I > wasn't too worried about it. I'd be highly impressed if I got the program > to run correctly in the first build, I want to debug it myself later. > > What does worry me, is that I can't seem to get the program by a > certain spot. It keeps giving me the same error, and I don't know why. Here are some techniques for tracking down this sort of bug. The best thing is, these techniques will help you write better code in the first place, as well as easier to debug. Firstly, encapsulate your code. Instead of writing one big lump of code, break it into small digestible functions. def run_test(): choice=raw_input("Begin? ") return choice == "yes" or choice == "y" # or better still: # choice.lower() in ("yes", "y", "begin"): def do_test(ttllst): # initialise variables cnto=0 cntt=1 rept=-1 # loop through the list, counting duplicates while cnto<>len(ttllst)+1: print "debugging...", cnto, cntt if ttllst[cnto]==ttllst[cntt]: rept=rept+1 if cntt==len(ttllst): print ttllst[cnto],"appears in the list",rept,"times." cntt=-1 cnto=cnto+1 rept=-1 cntt=cntt+1 print "done." def main(): if run_test(): ttllst=[4,3,45,3] do_test(ttllst) if __name__ == "__main__": # only happens when *running* the file, # not when *importing* it main() Now you have separated your user interface from the business end of your code, and you can isolate more simply where the error lies. Continue to encapsulate your code: the while loop is a good candidate. It runs through the list comparing each character to one known character. So I would change do_test to look like this: def do_test(L): """Run our item-counting test on list L.""" # loop through the list, counting duplicates for index in range(len(L)): current_item = L[index] item_count = item_counter(L, current_item) print current_item, "appears in the list", item_count, "times." # or better still # print "%s appears in the list %d times." % (current_item,item_count) print "done" def item_counter(L, obj): """Return the number of times obj is in list L.""" counter = 0 for item in L: if item == obj: counter = counter + 1 return counter Now that you (hopefully) have bug-free code, you can continue to improve and optimize your program. For example, instead of creating your own item_counter function, you will soon learn that Python lists have their own much quicker version. In general, you want to make your code as general as practical, without being too specific. You started with the problem "How can I count the number of times each item in list ttllst exists in ttllst?" A more general question is "How do I count the number of items *any* object exists in *any* list?", and then use that code to answer your first question. Hope this helps, -- Steven. From mtobis at gmail.com Wed Oct 26 17:56:56 2005 From: mtobis at gmail.com (Michael Tobis) Date: 26 Oct 2005 14:56:56 -0700 Subject: assignment to reference In-Reply-To: References: Message-ID: <1130363816.457178.320790@f14g2000cwb.googlegroups.com> I apparently don't understand this question in the same way the way others do. I think the question is about the mutability of strings. To my understanding of your question, it is impossible, at least if the referenced objects are strings or other objects of immutable type. 'cabbage' cannot be changed into 'coconut', though list('cabbage') can be changed to list('coconut') in place. >>> x = list('cabbage') >>> id(x) 458640 >>> y = list('coconut') >>> id(y) 458736 >>> x[:] = y[:] >>> x ['c', 'o', 'c', 'o', 'n', 'u', 't'] >>> id (x) 458640 >>> "".join(x) 'coconut' You would need to be doing a LOT of these for any of this to be worth the bother, or else have some rather exotic application you aren't telling us about. If I am reading you right the eval() is a red herring. I agree with the others that you don't want an eval() here and you're better off with a dict, but I am not sure that answers your question. mt From gsakkis at rutgers.edu Tue Oct 11 08:52:36 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: 11 Oct 2005 05:52:36 -0700 Subject: How to do *args, **kwargs properly References: <434ba819$0$38698$edfadb0f@dread12.news.tele.dk> Message-ID: <1129035156.328142.216850@g44g2000cwa.googlegroups.com> "Lasse V?gs?ther Karlsen" wrote: > So what you're saying is that instead of: > > def fn(*values, **options): > > I should use: > > def fn(values, cmp=cmp): > > in this specific case? > > and then instead of: > > fn(1, 2, 3, cmp=...) > > this: > > fn([1, 2, 3], cmp=...) > > > > I think I'll re-write to use a list instead Actually in most cases you don't need to assume it's a list; any iterable is usually good enough. You can always turn it into a list (or a tuple or a set or..) in the function if you really have to. So when you do have to and when you don't ? You don't have to if all you do is iterate over the elements. This is true even if you want to iterate more than once; just use the itertools.tee() function to create N independent iterators. To sum up, a better signature for your function is likely to be "def fn(iterable, cmp=cmp)". George From email at christoph-haas.de Fri Oct 14 16:37:48 2005 From: email at christoph-haas.de (Christoph Haas) Date: Fri, 14 Oct 2005 22:37:48 +0200 Subject: Best way to handle cgi sessions In-Reply-To: <17fc20160510141222g65b11873y28ca495874a64156@mail.gmail.com> References: <17fc20160510141222g65b11873y28ca495874a64156@mail.gmail.com> Message-ID: <200510142237.48682.email@christoph-haas.de> On Friday 14 October 2005 21:22, Derek Perriero wrote: > What would be the best way to create a cgi session that contains the > basic elements of a cookie and can also hold secure data, such as a > username/password. I've explored the possibilities of using SmartCookie, > but that doesn't encrypt my parameters. Encrypting the parameters is probably not the best way. Usually you store the information you need in your own database and just pass the client (web browser/user) a handle (session ID). That way you temporarily identify the user through the session ID but can store data in your database that the user cannot even see. There are a few things you need to take care of like: - only pass a new session cookie if necessary (otherwise the user may be prompted to accept the same cookie time and again) - expire the session if the user hasn't been using it - check if the session ID fits the IP address you recorded - create unique session IDs A link from my list of bookmarks about session handling: http://starship.python.net/~davem/cgifaq/faqw.cgi?req=show&file=faq02.011.htp We have recently developed such a session handler for a Debian-related web site which uses a MySQL table to store session information. If there is interest I'll tidy it up a bit and make it publicly available. Cheers Christoph -- ~ ~ ".signature" [Modified] 1 line --100%-- 1,48 All From sjmaster at gmail.com Sat Oct 15 19:31:32 2005 From: sjmaster at gmail.com (Steve M) Date: 15 Oct 2005 16:31:32 -0700 Subject: Queue question In-Reply-To: <1129413036.271162.279880@g43g2000cwa.googlegroups.com> References: <1129413036.271162.279880@g43g2000cwa.googlegroups.com> Message-ID: <1129419092.954592.59630@z14g2000cwz.googlegroups.com> According to my "Python in a Nutshell": q.get(block=True) is the signature, so, as you use it above, the call will hang until something is on the queue. If block is false and the queue is empty, q.get() will raise the exception Empty. q.get_nowait is apparently synonymous with q.get(block=False) q.not_empty, if it existed, I expect would be true just in case there was at least one item in the queue. But according to my book there is q.empty and q.full, which is true when the queue has the maximum allowed number of items (a value specified when the queue is created). Also, I don't think you can rely on q.empty in the way you may expect. For example, another thread can empty the queue between the time you test whether q.empty is false and the time you call q.get. From deets at nospam.web.de Thu Oct 6 09:30:33 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 06 Oct 2005 15:30:33 +0200 Subject: "no variable or argument declarations are necessary." In-Reply-To: References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <3qi8erFf252rU1@uni-berlin.de> <3qkdbrFfgga9U1@uni-berlin.de> Message-ID: <3qkn7qFffkl6U1@uni-berlin.de> > > I can't help but feel that a lot of people have specific typechecking > systems in mind and then conclude that the limits of such a symtem > are inherent in typechecking itself. I've been writing a type-checker for my diploma thesis for a functionnal programmming language. And it _is_ limited. The very subject of my work was to explore extended type-checking methods (so called multi-level-specifications),, which can be shwon to be NP-hard problems. Which naturally limits the domains they can be used to. > IMO a good type system doesn't need to limit python in any way. It has to. certainly. Take alone the list implementation - while typesystems as ML allow for generics (with much less typing overhead than JAVA), the list is always homogenous. Which python's aren't - and that a great thing(tm), even though ususally the contents of a list share some common behaviour. And that exactly is the key point here: in a statically typed world, that common behaviour must have been extracted and made explicit. Which is the cause for that notorious java io API. And, to extend the argument to ML-type type-checking, there you need a disjoint union of the possible types - _beforehand_, and the code dealing with it has to be aware of it. In python OTH, I just pass objects I like into the list - if they behave, fine. DIez From erchamion.beren at gmail.com Mon Oct 31 07:21:07 2005 From: erchamion.beren at gmail.com (Sinan Nalkaya) Date: Mon, 31 Oct 2005 14:21:07 +0200 Subject: taking x-window screen shot Message-ID: <43660C33.5080603@gmail.com> hi i have some python practice and want to develop tiny prgramme that takes screen shots from command line, im using gnome now but my programme should support the others especially pure X - window. also i want to learn some more about inside when taking screen shots. thanks. From xushanjun1212 at yahoo.com-dot-cn.no-spam.invalid Mon Oct 3 08:46:18 2005 From: xushanjun1212 at yahoo.com-dot-cn.no-spam.invalid (shanjunxu) Date: 03 Oct 2005 12:46:18 GMT Subject: about pyopengl Message-ID: <4341281a$0$98071$892e7fe2@authen.white.readfreenews.net> I am a chinese boy,my english is not good,so i don not know how to tell you about my question,i hope you can understand what i say. I like python, and now i using pyopengl to draw three-dimensional. but how can i use mouse to control objects?such as selecting object.I know a function( glSelectBuffer() ) can be used,In C language the format is glSelectBuffer(size, buffer), but in python the format is glSelectBuffer(size), how can i get the "buffer" pointer? The following is one section function of my codes: def ProcessSelection(x,y): viewport=range(4) glSelectBuffer(64) viewport=glGetIntegerv(GL_VIEWPORT) glMatrixMode(GL_PROJECTION) glPushMatrix() glRenderMode(GL_SELECT) glLoadIdentity() gluPickMatrix(x, viewport[3]-y, 2, 2, viewport) gluPerspective(45.0, aspect, 0.1, 200.0) DrawButton() hits=glRenderMode(GL_RENDER) glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) If you know how to do ,can you mail to me?thank you! my e-mail is xushanjun1212 at yahoo.com.cn From ptb at oboe.it.uc3m.es Wed Oct 26 18:01:08 2005 From: ptb at oboe.it.uc3m.es (Peter T. Breuer) Date: Thu, 27 Oct 2005 00:01:08 +0200 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <3s6l8mFmj3fjU1@individual.net> <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> Message-ID: <4ua533-60t.ln1@news.it.uc3m.es> In comp.os.linux.misc David Schwartz wrote: > "Peter T. Breuer" wrote in message news:b94533-nu5.ln1 at news.it.uc3m.es... >> In comp.os.linux.misc David Schwartz wrote: > That doesn't at all address my point. The point is, there are large > numbers of people looking for computers with Windows installed on them. If > you sell this type of computer, this type of person will come to you. That is an item of data which is largely true - it's not totally true, because most people could not care less what operating system is on their computer so long as it is one which causes them no trouble and which doesn't get in the way (uh, fail to MS win there, twice) and which in general is a plus for them rather than a minus (porbably true for MS windows and most of the hoi poloi, not me). But it's not a POINT, at least not the intended conclusion of an argument or subargument, which is what I understand a point to be. The type you score, that is. >> No it isn't. Quite the opposite - look at a computer shop or a >> computer advert, and you will see "Pentium 4 3.4GHz 1MB cache, 1GB DDR >> RAM", etc. etc. > And you will also see "Designed for Windows XP" or a Microsoft logo in > the ad. If they said that, that would be an actionable statement, because it isn't, if it is a PC clone - PC's have defined standard interfaces, that's the idea and design of a PC. Therefore a PC cannot be designed for an operating system, just as a wall switch cannot be designed for a lampshade. A PC is designed without reference to an operating system, just as a lightswitch is designed withut reference to a particular lampshade. Will you PLEASE stop these nonsense detours! You know perfectly well that there is no "windows franchise" in the sense that there is a MacDonalds franchise. Shops which sell computers do not have (metaphorical) MS arches over the door. They say "get your compyutas 'ere", not "welcome to the Microsoftiland total experience. Enjoy". And MS in particular has no hardware side (modulo the mouse and matching mat). They tried to rig the market in operating systems for the IBM PC, not get a monopoloy on PC manufacture. > No, my point is that this specific Microsoft tactic was a *lesser* > tactic than offering only exclusive wholesale deals and there's nothing > wrong with a company that only offers exclusive wholesale deals. That is not a point, it is an incomplete claim of fact plus a judgment (first half-sentence), and a hypohetical case plus judgment (second half-sentence). claim 1a) Microsoft's tactic is X (fill in, please) judgment 1b) tactic X is somehow not as bad as (sense?) offering "exclusive wholesale deals" (please define) hypothesis 2a) Company Z (arbitrary) offers exclusive wholesale deal. judgment 2b) Company Z does no wrong in doing so. I presume your argument then goes via 1b and 2b to conclude that there is nothing wrong with Microsofts tactic X. The logic is fine - it remains to dispute your claims and judgments. > What Microsoft didn't want was someone going to a store to buy a PC with > Windows and being told that another OS is better and cheaper. Tough - that's what salespeople are for (notionally, in a shop you trust). Peter From kevin.bell at slcgov.com Wed Oct 5 12:49:48 2005 From: kevin.bell at slcgov.com (Bell, Kevin) Date: Wed, 5 Oct 2005 10:49:48 -0600 Subject: change a value to NULL? Message-ID: <2387F0EED10A4545A840B231BBAAC722607F10@slcimail1.slcgov.com> Just tested it. Access does recognize None as null/blank/etc when None is passed in from python. Kevin Bell -----Original Message----- From: python-list-bounces+kevin.bell=slcgov.com at python.org [mailto:python-list-bounces+kevin.bell=slcgov.com at python.org] On Behalf Of Bell, Kevin Sent: Wednesday, October 05, 2005 10:33 AM To: python-list at python.org Subject: RE: change a value to NULL? Thanks, being new to this, I wasn't sure if I should use None, Null, Nope, Nada, or Nil! I'm going to be loading a list into an MS Access db. Do you know if I load None into an Access field if Access will recognize that as blank/null? I suppose I'll just go test it out. Thanks again... Kevin Bell -----Original Message----- From: Laszlo Zsolt Nagy [mailto:gandalf at designaproduct.biz] Sent: Wednesday, October 05, 2005 10:18 AM To: Bell, Kevin; python-list at python.org Subject: Re: change a value to NULL? Bell, Kevin wrote: >I'm pulling a list of numbers from MS Excel, but occasionally if there >is no data from excel, the value is an asterisk, but I need to make it >null. > >What is the best way to do that? Thus far, I'm using: > > >for value in myRange: > try: > intV = int(value) > print intV > except: > print "its an asterisk" > > I'm affraid I did not understand what is your real problem. Here is an answer, anyway. When converting a string intoto an int, you should use TypeError to trap type errors only: try: intV = int(value) except TypeError: intV = None print intV # It will be None if 'value' is not an int Best, Les -- http://mail.python.org/mailman/listinfo/python-list From jgrahn-nntq at algonet.se Sat Oct 15 04:36:47 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 15 Oct 2005 08:36:47 GMT Subject: Let My Terminal Go References: <1129010288.251817.147690@z14g2000cwz.googlegroups.com> <1129012665.29863.2.camel@blackwidow> <1129026623.319531.97420@g43g2000cwa.googlegroups.com> <7x4q7lmk6j.fsf@ruckus.brouhaha.com> Message-ID: On 13 Oct 2005 09:54:44 -0700, Paul Rubin wrote: > Jorgen Grahn writes: >> It depends on what you mean by expensive -- web servers can fork for each >> HTTP request they get, in real-world scenarios, and get away with it. > > This is OS dependent. Forking on Windows is much more expensive than > forking on Linux. Forking, to me, means doing what the Unix fork(2) system call does. Since AFAIK there is no corresponding Win32 call, I assumed the original poster was on Unix. But now I see that he didn't use the word "fork"; someone else in the thread did ... You are correct, of course; the cost of spawning processes varies a lot between OSes, and it's distinctly higher on Windows compared to Unixes in general and Linux in particular. (BTW, Eric Raymond argues that low-cost spawning is an important characteristic of an OS: see http://www.faqs.org/docs/artu/ch03s01.html#id2892171 ) /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From jjl at pobox.com Fri Oct 7 17:00:47 2005 From: jjl at pobox.com (John J. Lee) Date: 07 Oct 2005 21:00:47 +0000 Subject: Where to find python c-sources References: <878xxegrtx.fsf@pobox.com> <200510070015.56786.hancock@anansispaceworks.com> Message-ID: <877jcpavpc.fsf@pobox.com> Terry Hancock writes: > On Friday 30 September 2005 04:37 pm, John J. Lee wrote: > > "Tor Erik S?nvisen" writes: > > > Thanks for the answers... And yes, I have searched google! > > > > How odd -- the most useful link (the viewcvs page for this source > > file) is the very first link for me when I search for socketmodule.c > > > > Does google vary in its results across the globe? > > Of course you meant to be snippy and sarcastic, I really was wondering if such results varied, because it seemed hard to believe somebody wouldn't do a similar search. And the idea that he might have been too lazy didn't enter my head > but you've actually > exemplified the reason why so many people don't find such a thing > with Google. Like all search engines, you have to know the right > keyword -- to a fair degree of precision -- in order to find what > you're looking for. Oh, come off it. It seems hard to imagine that trying socketmodule.c when looking for socketmodule.c requires some expert search-fu that I'm supposed to posess. > This is very unlike asking a question of a human being. *People* > respond much better to general subject headings such as "socket > module" or "python sources" rather than looking for something > ultra-specific like a particular file name. He wasn't looking for general information. He told us he was looking for socketmodule.c, for Pete's sake! And "python sources" *does* takes you to the Python sources. > Researchers take this > training with them when they approach Google and treat it like > a magic librarian -- they give it the same thing they would come > to a human librarian with. You conjure up in my mind a nice picture of an be-cardiganed gentleman in an oak-panelled corner of the British Library, in his early seventies complete with pipe, dust, and technophobia. Seems an unlikely image for somebody with an email address containing the string "@stud.cs." and stating their interest in reading networking code written in C Still, going back to researchers-with-pipes ("researcher" meaning "collator of information" rather than "creator/discoverer of original ideas"), I perhaps naively assume that such Google-phobic researchers must nowadays do other work for a living. Who'd want to employ a researcher who can't efficiently use search engines and other databases these days? But as I say, I could well be naive here... I recall my not-astonishment at trying to find a book in a local (but not small) public library, and finding that the librarian was unable to do so, despite their apparent enthusiasm at my request, and initial proud promises that the databases they pay for would find it even if none of the regional libraries had a copy (due in this case I suspect, and hasten to add, to the databases simply lacking the relevant records, rather than incompetence on the part of the librarian). I walked round the corner and found it on both Amazon and Google in around a few seconds each time. I had been led to believe books were something of a library speciality... In fact, rambling a little further, I can honestly say (in the certainty and enjoyment of offending any librarians reading <0.75 wink>) that I've never knowingly extracted any useful information from a librarian, who in legend are supposed to have such old-style researcher-fu as you refer to. This applies even to pre-Google days, despite having spent a fair amount of time in libraries, and asking a fair range of questions over a period of years: some very specific, some quite general and wooly; some particular, some about general search strategies and techniques. Perhaps that just reflects my interests or level of competence in one way or another. [...] > Seriously, though, for anybody new to using search engines, it > is a very useful rule of thumb -- search for a specific word > likely to appear on the page you are looking for, and not > elsewhere. [...] It's quite true that has to be learned. John From nnorwitz at gmail.com Sun Oct 9 22:01:25 2005 From: nnorwitz at gmail.com (Neal Norwitz) Date: 9 Oct 2005 19:01:25 -0700 Subject: Idle bytecode query on apparently unreachable returns In-Reply-To: References: Message-ID: <1128909685.049438.110370@f14g2000cwb.googlegroups.com> Tom Anderson wrote: > Evening all, > > Here's a brief chat with the interpretator: [snip] > What puzzles me, though, are bytecodes 17, 39 and 42 - surely these aren't > reachable? Does the compiler just throw in a default 'return None' > epilogue, with routes there from every code path, even when it's not > needed? If so, why? I think the last RETURN_VALUE (None) isn't thrown in unless there is some sort of conditional the precedes it as in this example. As to why: it's easier and no one has done anything about fixing it. If you (or anyone else) are interested, the code is in Python/compile.c. Search for the optimize_code() function. n From my_email_is_posted_on_my_website at munged.invalid Wed Oct 12 20:08:24 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Thu, 13 Oct 2005 00:08:24 GMT Subject: Jargons of Info Tech industry References: <1124804082_1011@spool6-east.superfeed.net> <5hrik11q3p5ugcjm4hmmgqgq20o8fdrhr9@4ax.com> <7x4q7q2yer.fsf@ruckus.brouhaha.com> <8q0rk1tiktr86ksdu55mgsqffpkf2uus1c@4ax.com> <11kr5p3hstor935@corp.supernews.com> Message-ID: On Wed, 12 Oct 2005 23:07:15 -0000, gordonb.e2yfo at burditt.org (Gordon Burditt) wrote or quoted : > Links > Javascript > Forms > References to other files the only piece of that particularly dangerous is JavaScript. So long as you have a scheme to unmask where links are really going links are no more dangerous than they are in browser. Even a form is not dangerous. You have to fill it in and hit submit. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From christian at spam.not Fri Oct 21 08:36:12 2005 From: christian at spam.not (Christian) Date: Fri, 21 Oct 2005 14:36:12 +0200 Subject: Set an environment variable In-Reply-To: References: <43573022$0$155$edfadb0f@dread16.news.tele.dk> <1129798724.366618.194650@g44g2000cwa.googlegroups.com> <43589205$0$125$edfadb0f@dread16.news.tele.dk> <4358d112$0$187$edfadb0f@dread16.news.tele.dk> Message-ID: <4358e0bd$0$125$edfadb0f@dread16.news.tele.dk> Steve Holden wrote: > Time you answered your own questions by trying things at the interactive > interpreter prompt! > > regards > Steve Right again, Steve. Thanks From duncan.booth at invalid.invalid Wed Oct 26 03:53:31 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 26 Oct 2005 07:53:31 GMT Subject: Top-quoting defined [was: namespace dictionaries ok?] References: Message-ID: James Stroud wrote: > On Tuesday 25 October 2005 00:31, Duncan Booth wrote: >> P.S. James, *please* could you avoid top-quoting > > Were it not for Steve Holden's providing me with a link off the list, > I would have never known to what it is you are referring. I have read > some relevant literature to find that this is more widely known as > "top-posting". I'll go with majority rules here, but I would like to > say that my lack of "netiquette" in this matter comes from > practicality and not malice. No, I didn't think it was malice which is why I just added what I considered to be a polite request at the end of my message. I assumed that most people either knew the phrase or could find out in a few seconds using Google so there wasn't much point in rehashing the arguments. Probably I should have equally lambasted Ron for the heinous crime of bottom-quoting. In general, there are three ways to quote a message: top-quoting, which forces people to read the message out of order; bottom-quoting which is nearly as bad because it hides the new comments; and proper quoting in context where you trim the message and put specific points under brief bits of context. The thread in question had a horrific mix of top and bottom quoting, so that when I tried to reply at what I thought was an appropriate point in the thread () I think the order it went was something like: > quote from James (4) comment from Ron (5) >>> quote from James (2) >> comment from Ron (3) >>> quote from James (2) >>>> quote from Ron (1) I spent a while trying to trim that down to relevant context, and in particular trying to work out in what order the original statements had been made. In the end I gave up and replied to an earlier message which was more easily trimmable. > Also, here is a well written synopsis of the arguments in > favor of top-posting and they may even be strong enough to legitimize the > practice: The arguments are mostly sound, but I would draw slightly different conclusions: Follow the conventions of the particular newsgroup or mailing list, but with that in mind, for all replies, Middle Post. Respond to each point in turn with lots of snipping. He's right though, its not a religious issue. From skip at pobox.com Mon Oct 24 11:20:48 2005 From: skip at pobox.com (skip at pobox.com) Date: Mon, 24 Oct 2005 10:20:48 -0500 Subject: more than 100 capturing groups in a regex In-Reply-To: <1130160675.270886.208420@z14g2000cwz.googlegroups.com> References: <1130160675.270886.208420@z14g2000cwz.googlegroups.com> Message-ID: <17244.64464.996726.7126@montanaro.dyndns.org> Joerg> Or is there a way to circumvent [capturing groups limitation]? Sure, submit a patch to SourceForge that removes the restriction. I've never come anywhere close to creating regular expressions that need to capture 100 groups even though I generate regular expressions from a higher-level representation. I suspect few will have hit that limit. Perhaps explain what motivates you to want to capture that many groups. Other people may be able to suggest alternatives. And remember: Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. --Jamie Zawinski Skip From davids at webmaster.com Mon Oct 17 22:44:55 2005 From: davids at webmaster.com (David Schwartz) Date: Mon, 17 Oct 2005 19:44:55 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: "Roedy Green" wrote in message news:adh8l1thpq22n9ub1ic2suhkjn81m0ik6i at 4ax.com... > On Sun, 16 Oct 2005 22:36:53 -0700, "David Schwartz" > wrote or quoted : >> As for it being illegal, it was illegal only because if was Microsoft >>doing it. There's nothing illegal about a car dealer not selling a car >>without an engine. > But that is not what was happening. It was not Microsoft selling > computers with MS OSs. MS was arm-twisting retailers like me to > bundle a copy of Windows with every sale whether the customer wanted > it or not. I think some imagine a computer is worthless without > Windows. It is Microsoft's view that a computer is worthless without Windows. They are fully entitled to have that view. > That gave their OS a grossly unfair price advantage. It is not Microsoft's obligation to be "fair". It is Microsoft's obligation to push their vision of the future of computing, one with Microsoft's products at the center, using anything short of force or fraud. DS From steve at holdenweb.com Mon Oct 24 14:55:41 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 24 Oct 2005 19:55:41 +0100 Subject: Tricky Areas in Python In-Reply-To: <1130175703.541446.153670@g47g2000cwa.googlegroups.com> References: <1130097286.772836.94930@g44g2000cwa.googlegroups.com> <1h4wbvb.1dblc4317zeuw2N%aleaxit@yahoo.com> <1130175703.541446.153670@g47g2000cwa.googlegroups.com> Message-ID: beza1e1 wrote: > let me try. > > 1) ''.join(lots_of_pieces) > > 2) This doesn't even work, if something is removed, the list is too > short. So: > [x for x in somelist if not isbad(x)] > well, list comprehension is Python 2.4 and 2.3 is the standard in many > OSes, so it is possibly not the most portable solution > I had to look up the syntax, because i never use it in my code, yet. Python 2.2.1 (#1, Aug 25 2004, 16:56:05) [GCC 2.95.4 20011002 (Debian prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> [a.upper() for a in ['two', 'point', 'two']] ['TWO', 'POINT', 'TWO'] >>> > > 3+4) I never used property - had to look it up. So i learned something > :) > regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From lycka at carmen.se Fri Oct 14 10:29:58 2005 From: lycka at carmen.se (Magnus Lycka) Date: Fri, 14 Oct 2005 16:29:58 +0200 Subject: File compare In-Reply-To: <1129150273.991158.203660@g49g2000cwa.googlegroups.com> References: <1129150273.991158.203660@g49g2000cwa.googlegroups.com> Message-ID: PyPK wrote: > I have two files > file1 in format > > 'AA' 1 T T > 'AB' 1 T F > > file2 same as file1 > > 'AA' 1 T T > 'AB' 1 T T > > Also the compare should be based on id. So it should look for line > starting with id 'AA' (for example) and then match the line so if in > second case. See the recent thread with subject line "List performance and CSV". From steve at REMOVETHIScyber.com.au Wed Oct 19 10:02:17 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Thu, 20 Oct 2005 00:02:17 +1000 Subject: [newbie]Is there a module for print object in a readable format? References: Message-ID: On Wed, 19 Oct 2005 09:39:48 +0800, James Gan wrote: > Hi, Steven > > :) width parameter do the magic : > > >>> pprint.pprint([1,2,3,4,[0,1,2,[3,4]],5], width=1,indent=4) > [ 1, > 2, > 3, > 4, > [ 0, > 1, > 2, > [ 3, > 4]], > 5] > >>> That's not what I get. What are you using? py> pprint.pprint([1,2,3,4,[0,1,2], 5], width=1, indent=4) Traceback (most recent call last): File "", line 1, in ? TypeError: pprint() got an unexpected keyword argument 'width' -- Steven. From http Fri Oct 28 16:21:01 2005 From: http (Paul Rubin) Date: 28 Oct 2005 13:21:01 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <66u633-etj.ln1@news.it.uc3m.es> <7xbr1aewtq.fsf@ruckus.brouhaha.com> <86acgulv5z.fsf@localhost.localdomain> <7xvezi8ypy.fsf@ruckus.brouhaha.com> Message-ID: <7xr7a52y1e.fsf@ruckus.brouhaha.com> "David Schwartz" writes: > Is it your position that Micorosoft's monopoly was illegal when they > first acquired it? It's utterly irrelevant whether it was illegal when they acquired it. The law is against acquiring OR MAINTAINING a monopoly by anticompetitive means. That's what MS was convicted of. > No. I have never received a dime from Microsoft, either directly or > indirectly. I am one of those people who believes that conduct that's > perfectly legal, moral and ethical before you can be said to have a monopoly > does not suddenly become immoral or unethical the day you acquire 51% of > what someone calls a market. The Sherman Act has nothing to do with acquiring 51% of a market. > I am not the only person with this view. > http://www.capitalism.org/faq/antitrust.htm > http://www.amazon.com/exec/obidos/tg/detail/-/0945999623?v=glance > http://www.cato.org/pubs/pas/pa-169.html > http://www.independent.org/publications/books/book_summary.asp?bookID=31 > http://www.ntu.org/main/press.php?PressID=344&org_name=NTUF I could care less what the self-serving libertarian lunatic fringe thinks. From Ido.Yehieli at gmail.com Thu Oct 6 14:07:20 2005 From: Ido.Yehieli at gmail.com (Ido.Yehieli at gmail.com) Date: 6 Oct 2005 11:07:20 -0700 Subject: replacments for stdio? In-Reply-To: <1128615824.381261.47200@g14g2000cwa.googlegroups.com> References: <1127477278.036977.189230@g44g2000cwa.googlegroups.com> <1127670588.872596.117560@o13g2000cwo.googlegroups.com> <1128079278.563621.8310@g47g2000cwa.googlegroups.com> <1128548582.759883.326290@g47g2000cwa.googlegroups.com> <1128597932.529665.51810@g14g2000cwa.googlegroups.com> <1128615824.381261.47200@g14g2000cwa.googlegroups.com> Message-ID: <1128622040.860350.24710@f14g2000cwb.googlegroups.com> Yes, i thought so myself. Thanks, Ido. From lasse at vkarlsen.no Sat Oct 8 11:39:30 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Sat, 08 Oct 2005 17:39:30 +0200 Subject: Function decorator that caches function results In-Reply-To: References: Message-ID: <1_WdnUc73sXUddre4p2dnA@telenor.com> Fredrik Lundh wrote: >>k1 = fibonacci(100) >>k2 = fibonacci(idx = 100) > whoever writes code like that deserves to be punished. > > I'd say this thread points to a misunderstanding of what keyword arguments > are, and how they should be used. the basic rule is that you shouldn't mix and > match; use positional arguments for things that are documented to be positional I agree completely. However, it turns out I have to communicate code with and from people that have a coding standard that dictates using keyword arguments for all interfaces. Those functions will also benefit from the cache system as many of them involves database lookups. In any case, your response gave me another thing that my solution won't handle so I'm going to just leave it as it is and look at it if I ever need it for positional arguments, which I honestly don't believe I will. -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From bokr at oz.net Tue Oct 4 13:40:23 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 04 Oct 2005 17:40:23 GMT Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> <434245F5.6060500@REMOVEMEcyber.com.au> <7xr7b14lk0.fsf@ruckus.brouhaha.com> Message-ID: <4342bd9a.3192006743@news.oz.net> On Tue, 04 Oct 2005 10:18:24 -0700, Donn Cave wrote: [...] >In the functional language approach I'm familiar with, you >introduce a variable into a scope with a bind - > > let a = expr in > ... do something with a > >and initialization is part of the package. Type is usually >inferred. The kicker though is that the variable is never >reassigned. In the ideal case it's essentially an alias for >the initializing expression. That's one possibility we can >probably not find in Python's universe. > how would you compare that with lambda a=expr: ... do something (limited to expression) with a ? Regards, Bengt Richter From christian.siegl at gmail.com Fri Oct 14 10:25:04 2005 From: christian.siegl at gmail.com (christian.siegl at gmail.com) Date: 14 Oct 2005 07:25:04 -0700 Subject: How to delete yourself???? Message-ID: <1129299904.130287.287680@g44g2000cwa.googlegroups.com> Hello, I got a problem deleting objects, which are placed in a hirarchy.... Asume we have the following code: ######################################################## class parent: MyChilds = [] # this list is filled with childs.... def AddChild(self, child): # add childs here, however this is done, it's not the point... child.MyParent = self def RemoveChild(self, child): # delete child from the list.... the way this is done is not our # problem here class child: MyParent = 0 def deleteMe(self): MyParent.RemoveChild(self) ############################################################## So my code looks something like that.... and it works. I works because you do not touch any member variables in class child after deleting it... But is this nice code??? Is there another way to delete yourself??? Thanks for any comments... Chris From duncan.booth at invalid.invalid Wed Oct 5 12:52:47 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Oct 2005 16:52:47 GMT Subject: updating local() References: <1128530014.323801.290360@g47g2000cwa.googlegroups.com> Message-ID: Flavio wrote: > Can anyone tell me why, if the following code works, I should not do > this? > > # > # Extending Local namespace > # > > def fun(a=1,b=2,**args): > > print 'locals:',locals() > locals().update(args) > print locals() > > e = {'s':3,'e':4} > fun(k=10,v=32,**e) > Because if all you want is to update a dictionary you might as well use another dictionary which isn't locals(). If what you want is to update the local variables, that won't work: >>> def fun(a=1,b=2,**args): s = 1 print 'locals:',locals() locals().update(args) print locals() print s, e >>> e = {'s':3,'e':4} >>> fun(k=10,v=32,**e) locals: {'a': 1, 's': 1, 'args': {'s': 3, 'e': 4, 'k': 10, 'v': 32}, 'b': 2} {'a': 1, 'b': 2, 'e': 4, 'k': 10, 'args': {'s': 3, 'e': 4, 'k': 10, 'v': 32}, 's': 1, 'v': 32} 1 {'s': 3, 'e': 4} >>> Note that k, v, and e are added to the locals dictionary, but real local variables such as 's' are not updated. Also you cannot access k, v, and e as local variables within the function, if you try you get the global variables (if they exist). Also, this behaviour is undefined. Different versions of Python will behave differently, and even minor code changes can change the behaviour. With this version, 's' still doesn't update, but we can now access the 'e' value as a variable: >>> def fun(a=1,b=2,**args): s = 1 print 'locals:',locals() locals().update(args) print locals() exec "print 'hi'" print s,e >>> fun(k=10,v=32,**e) locals: {'a': 1, 's': 1, 'args': {'s': 3, 'e': 4, 'k': 10, 'v': 32}, 'b': 2} {'a': 1, 'b': 2, 'e': 4, 'k': 10, 'args': {'s': 3, 'e': 4, 'k': 10, 'v': 32}, 's': 1, 'v': 32} hi 1 4 >>> Short answer: don't even think of trying to update locals(). From barnesc at engr.orst.edu Fri Oct 7 09:11:35 2005 From: barnesc at engr.orst.edu (barnesc at engr.orst.edu) Date: Fri, 7 Oct 2005 06:11:35 -0700 Subject: Python recipes: list mixin, improved timeit, etc Message-ID: <1128690695.43467407e8746@webmail.oregonstate.edu> >So mixins are just a sub-class [pun intended] of sub-classing? > >I've just found this: > >[quote] >A mixin class is a parent class that is inherited from - but not as >a means of specialization. Typically, the mixin will export services to a >child class, but no semantics will be implied about the child "being a >kind of" the parent. >[end quote] > >from http://c2.com/cgi/wiki?MixIn > >Is that all they are? > >It is amazing how you can take the simplest concept, and by using >appropriate terminology, make it as confusing and opaque as you want... > >*wink* > "A mixin is an atomic unit in an object-oriented language that adds functionality to another class." - http://www.macromedia.com/support/documentation/en/flex/1/mixin/ mixin2.html#118542 The only experience I've had with mixins is in Python, where UserDict has a class DictMixin that defines the full dictionary interface from a minimal subset of dictionary methods. The Python docs don't define mixin. I just assumed this was a case where a programmer needed a name more descriptive than foo, so he called it mixin, and that stuck. :) - Connelly Barnes From paul at boddie.org.uk Mon Oct 10 19:47:35 2005 From: paul at boddie.org.uk (Paul Boddie) Date: 10 Oct 2005 16:47:35 -0700 Subject: Python's Performance References: <20051008040614.47429.qmail@web30607.mail.mud.yahoo.com> <178B879D-FDB6-458C-BE00-A03820D98703@advfn.com> <1128888628.643764@yasure> Message-ID: <1128988055.798016.147970@g49g2000cwa.googlegroups.com> Dennis Lee Bieber wrote: > I'd consider that BASIC to be a fully interpreted language, as the > tokens are still a one-for-one equivalence of the source code. Python, > UCSD, and Java are not one-for-one, so on that basis, they fit the > definition of a compiled language... That's an interesting definition which at least attempts to consider the issue from a perspective other than that which is concerned with whether hardware is in use, what kind of hardware, and so on. > The difficulty is that the target architecture in not realized in hardware. Or isn't perhaps feasible/viable for hardware realisation: one of the EuroPython speakers dangled the promise of hardware support for high-level languages (the classic "Python on a chip" concept), but there are probably plenty of areas where hardware support can assist software virtual machines without going to all the trouble of implementing such virtual machines in hardware completely. > And then... I believe the PowerPC chipset emulated the 680xx instruction set, didn't it? There may have been some architectural overlap between PowerPC and M68K, but the PowerMacintosh computers used dynamic recompilation/translation software to execute legacy applications. In the case of CPython, the principal technological factor in determining how "interpreted" it is seems to be the complexity of the bytecode instructions, and I believe some work was done to investigate other instructions that might improve performance [2]. Were the most complex instructions replaced with simpler ones, a more performant implementation might be possible, although the work required to translate programs to such a simplified instruction set is very difficult indeed. On the subject of other virtual machine implementations, I wonder what happened to this one: http://effbot.org/zone/pytte.htm Fredrik? ;-) Paul [1] Theo F. de Ridder, "Enabling bare Python as universal connector for ad-hoc networks": http://www.python-in-business.org/ep2005/download.cpy?document=8912 (warning: huge presentation!) [2] Brett Cannon, "Localized Type Inference of Atomic Types in Python": http://www.ocf.berkeley.edu/~bac/thesis.pdf From ben at wintersun.org Fri Oct 14 23:59:41 2005 From: ben at wintersun.org (Ben Caradoc-Davies) Date: Sat, 15 Oct 2005 11:59:41 +0800 Subject: Reading IEEE 754 format strings directly into a floating point array In-Reply-To: <435075e5$0$54633$14726298@news.sunsite.dk> References: <435075e5$0$54633$14726298@news.sunsite.dk> Message-ID: <43507eae$0$13914$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Madhusudan Singh wrote: > The values are returned as IEEE format binary floating point numbers. There > are 4 bytes per point. Multiple points are not separated by any delimiter. > Is it possible to read these directly into a floating point array of the > size of the string ? Consider using the struct module from the standard library, with format "f". It also allows you to specify endianness in a platform-independent manner, and for mixed formats, supports standard and native alignment. http://docs.python.org/lib/module-struct.html You have a string of length 4*n, so make a format with (for example) ">"+"f"*n, and struct.unpack will return a tuple of length n. For large volumes of data, the array module may be more useful (as someone else has already noted). -- Ben Caradoc-Davies http://wintersun.org/ "Those who deny freedom to others deserve it not for themselves." - Abraham Lincoln From jim.eggleston at gmail.com Fri Oct 28 21:27:16 2005 From: jim.eggleston at gmail.com (jim.eggleston at gmail.com) Date: 28 Oct 2005 18:27:16 -0700 Subject: Automatically creating a HOME environ variable on Windows? Message-ID: <1130549236.679806.297670@g43g2000cwa.googlegroups.com> Windows doesn't have a HOME environment variable, but it does have HOMEDRIVE and HOMEPATH. Could Windows versions of Python automatically populate os.environ with HOME, where HOME = os.path.join(os.environ['HOMEDRIVE'], os.environ['HOMEPATH'])? If this was done, then modules such as pdb, which load resource files from HOME, would work under Windows. Alternatively, here is a patch to make pdb.py read .pdbrc under Windows. *** pdb_orig.py Mon Jun 16 01:26:30 2003 --- pdb.py Sat Oct 29 11:11:07 2005 *************** *** 65,72 **** --- 65,76 ---- # Read $HOME/.pdbrc and ./.pdbrc self.rcLines = [] + envHome = '' if 'HOME' in os.environ: envHome = os.environ['HOME'] + elif 'HOMEDRIVE' in os.environ and 'HOMEPATH' in os.environ: + envHome = os.path.join(os.environ['HOMEDRIVE'], os.environ['HOMEPATH']) + if envHome: try: rcFile = open(os.path.join(envHome, ".pdbrc")) except IOError: From UrsusMaximus at gmail.com Thu Oct 20 18:15:26 2005 From: UrsusMaximus at gmail.com (UrsusMaximus at gmail.com) Date: 20 Oct 2005 15:15:26 -0700 Subject: ANN: Beginning Python (Practical Python 2.0) In-Reply-To: References: Message-ID: <1129846526.743586.250430@f14g2000cwb.googlegroups.com> I found this book at my local Border's this week. It appears to be a most excellent book. I own and have read Magnus' earlier book "Pactical Python" (which was excellent) but this one is even better. The first half of the book covers the language, and then the second half goes into depth developing several practical applications. And of course now the book is very up to date. While I obviously have not had time to really study this book, I believe that anyone looking for an introduction to Python would be very hard pressed to find a better choice than this book. Ron Stephens Python411 podcast sereis http://www.awaretek.com/python/index.html From lard at tardis.ed.ac.molar.uk Mon Oct 31 06:39:37 2005 From: lard at tardis.ed.ac.molar.uk (Alex Hunsley) Date: Mon, 31 Oct 2005 11:39:37 GMT Subject: data hiding/namespace pollution In-Reply-To: <87zmopnco7.fsf@linux.site> References: <4365f743$0$9485$636a15ce@news.free.fr> <87zmopnco7.fsf@linux.site> Message-ID: Jorge Godoy wrote: > Alex Hunsley writes: > > >>Sorry, I wasn't being clear. What I should have said is that I don't like the >>idea of a typo in an assignment causing the assigning of the wrong thing. >>e.g. imagine a simple value-holding class: >> >>class Values: >> pass >> >>v = Values() >> >>v.conductoin = 10 >> >> >>... I meant to type 'conduction' in the source but spelt it wrong. >>My value won't be there when elsewhere I refer to the correct attribute: >>"conduction". > > > Recently there was a big thread where that was raised again (yep, you're not > the first, nor the second, nor the third...). You should write unittests, use > tools like pychecker, pylint, etc. Yup, I'm plannig on using pyunit. Didn't know about pychecker though, thanks for that! From mhardas at kent.edu Thu Oct 13 00:04:19 2005 From: mhardas at kent.edu (mhardas at kent.edu) Date: Wed, 12 Oct 2005 21:04:19 -0700 Subject: ImportError: No module named dbm Message-ID: Hi all, Iam trying to get 'cvs2svn' to get to work on a Trustix Linux machine. However is suspect that no dbm is installed because running cvs2svn gives the following error: ERROR: your installation of Python does not contain a suitable DBM module -- cvs2svn cannot continue. See http://python.org/doc/current/lib/module-anydbm.html to solve. So I ran test for the dbm installation and got the following, root at drbn /usr/local/lib/python2.3/test# python test_dbm.py Traceback (most recent call last): File "test_dbm.py", line 7, in ? import dbm ImportError: No module named dbm Can you tell me how do I go about getting the dbm module and install it.?? Thanks again. Manas. From tim at tt1lock.org Sun Oct 9 09:58:41 2005 From: tim at tt1lock.org (Tim Tyler) Date: Sun, 9 Oct 2005 13:58:41 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> <86psqfmukd.fsf@bhuda.mired.org> <864q7rm1cb.fsf@bhuda.mired.org> Message-ID: In comp.lang.java.programmer Mike Meyer wrote or quoted: > Roedy Green writes: > > On Sat, 08 Oct 2005 19:56:50 -0400, Mike Meyer wrote > >>Show us *examples*! Do you create a style sheet for every site you > >>visit that overrides there classes? What? > > > > Why don't you download a copy of Opera, see > > http://mindprod.com/jgloss/opera.html > > What makes you think I don't have a copy of Opera? Just so happens > I've got a registred copy on my newest computer. > > > Then try out the feature. Click View | style | user > > My copy of Opera doesn't have that menu entry. I suspect you're making > platform-specific suggestions. > > Trying it on a different platform, it looks like it does what I said > earlier: user mode simply disables the authors style sheets. None of > the "merging" you suggested was going on is actually happening. The "user mode" uses style sheets you specify. There's a whole bunch of built-in ones - and you can cascade them: ``User style sheets ``There is also the inclusion of 12 packaged user style sheets and an easy menu application interface (View > Style). These sheets can be cascaded together, with or without the page's styles. They are mostly for accessibility, accessible web design and plain coolness: Emulate text browser, Nostalgia, Accessibility Layout, Show images and links only, High contrast, Hide non-linking images, Disable tables and Use default forms design. There are also three style sheets that are worth mentioning specially: Hide certain-sized elements, Debug with outline, and Show structural elements. Hide certain-sized elements is basically that CSS-powered inline ad-killer that Eric A. Meyer came up with a few years ago. Debug with outline uses the newly added support for the "outline" property to display key elements. Finally, Show structural elements, which with the acrobatic use of generated content, attribute selectors and counters, shows the HTML tags inline, as well as the meta and link data, and a report on the number of font tags and nested tables. Now this is cool!'' - http://www.evolt.org/article/Opera_7_Released/1/54851/ -- __________ |im |yler http://timtyler.org/ tim at tt1lock.org Remove lock to reply. From stijndesaeger at gmail.com Tue Oct 4 06:38:25 2005 From: stijndesaeger at gmail.com (vdrab) Date: 4 Oct 2005 03:38:25 -0700 Subject: pywordnet install problems In-Reply-To: References: <1128057470.285356.211160@g49g2000cwa.googlegroups.com> <1128163605.623632.96660@o13g2000cwo.googlegroups.com> Message-ID: <1128422305.423501.305420@g47g2000cwa.googlegroups.com> Thanks, I already figured it out a few days ago. In the wordnet.py file, just override the path (WNHOME and/or WNSEARCH) to the wordnet 2.0directory that has the lexnames files etc... (on my ubuntu box: '/usr/share/wordnet') That seems to fix it, although python gives a few warnings at startup. checking the web it seems this is a known issue. Thanks for the help though... I didn't bother posting the solution as I thought noone was interested anymore. cheers, vdrab. From davids at webmaster.com Thu Oct 27 08:46:25 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 05:46:25 -0700 Subject: Microsoft Hatred FAQ References: <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> <20i1m19cup3s8hb4ikqti1monvtf9nb3dv@4ax.com> Message-ID: Roedy Green wrote: > On Thu, 27 Oct 2005 04:06:16 -0700, "David Schwartz" > wrote, quoted or indirectly quoted someone who > said : >> Well shit, how surprising that they wouldn't want to do business >> with you if you broke your agreements with them. > I am going to summarise this then drop out. My blood pressure is at a > boil. > I was a computer retailer. We built custom computers. I had 8 people > working for me. This was in the time prior to Win95 when IBM had a > clearly technically superior solution with OS/2 to MS's Windows 3.1 > I had no contract of any kind with MS. I never bought anything from > them directly. I was far too small a fish. I bought the components > including software through dozens of wholesale suppliers. > MS threatened to put any retailer out of business who would not > co-operate with them in extorting money from people who had no use for > MS Windows who explicitly for various reasons did not want to buy MS > windows. No, MS decided only to sell Windows to essentially Windows-only shops. > To me that is no different from a popsicle manufacturer demanding I > sell $200 popsicles with every machine I sold. The machines needed MS > Windows no more than they needed a popsicle. You could have complied with their requests by selling computers only with Windows installed. That is, by only selling Windows PCs. All Microsoft was saying was "sell only our products or don't sell our products". This is a perfectly, normal typical franchise arrangement. You can't sell Whoppers and also sell any competing burgers that aren't Burger King branded. > The particular way MS threatened to put me out of business was by > threatening to arm twist all wholesalers to refuse to sell MS product > to me, which any retailer needed to survive in those days. Right, I get that. You owed your entire business to Microsoft. Without their products, you would have had nothing, by your own admission. The way you repay them is by trying to screw them -- attract people who come in only because you offer Windows and then say "here's an OS that's better and cheaper". > It was obviously quasi legal or the threats would have had paper to > back them up so I could go to court now to sue the fuckers. It's perfectly legal and normal (for non-monopoly products). What do you have to agree to in order to purchase OSX wholesale? What do you have to agree to in order to purchase Solaris wholesale? Honestly, I don't understand why you're so worked up and ballistic about a perfectly typical franchisee/authorized reseller agreement. Microsoft could have refused to sell you Windows wholesale completely. That would have meant no business for you at all. In exchange for making your business possible, all they ask is you don't steer the customers you have only because of them to their competitors. DS From martin at v.loewis.de Tue Oct 11 20:21:39 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 12 Oct 2005 02:21:39 +0200 Subject: Looking for info on Python's memory allocation In-Reply-To: References: <434B1A99.8040107@REMOVEMEcyber.com.au> <1h4a55d.cdmdgr1udkvayN%aleax@mail.comcast.net> Message-ID: <434C5713.2060104@v.loewis.de> Fredrik Lundh wrote: >>>>I = iter(L) >>>>I > > > >>>>len(I) > > 3 [...] > (it's probably not a good idea to rely on this behaviour...) I believe this has been classified as a bug in Python 2.4, which will be undone in Python 2.5. Regards, Martin From john at castleamber.com Mon Oct 17 22:08:44 2005 From: john at castleamber.com (John Bokma) Date: 18 Oct 2005 02:08:44 GMT Subject: Microsoft Hatred FAQ References: <11l16dst501kjdd@corp.supernews.com> <1129491006.021102.43920@g14g2000cwa.googlegroups.com> Message-ID: Roedy Green wrote: > On 17 Oct 2005 03:17:16 GMT, John Bokma wrote > or quoted : > >>Which standards? Again: w3c is not an official standards organization. > > What does it take in your book for a standards organisation to be > "official" -- a Swiss head office, a room at the UN, a branch on the > US government tree? Being recognized as one by other standards organizations? Otherwise I can start my own tomorrow. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From mynewsa at gmail.com Wed Oct 19 22:35:37 2005 From: mynewsa at gmail.com (Amol Vaidya) Date: Thu, 20 Oct 2005 02:35:37 GMT Subject: Python vs Ruby Message-ID: Hi. I am interested in learning a new programming language, and have been debating whether to learn Ruby or Python. How do these compare and contrast with one another, and what advantages does one language provide over the other? I would like to consider as many opinions as I can on this matter before I start studying either language in depth. Any help/comments are greatly appreciated. Thanks in advance for your help. From trentm at ActiveState.com Thu Oct 13 20:04:15 2005 From: trentm at ActiveState.com (Trent Mick) Date: Thu, 13 Oct 2005 17:04:15 -0700 Subject: Yes, this is a python question, and a serious one at that (moving to Win XP) In-Reply-To: <87mzldkmip.fsf@pobox.com> References: <87mzldkmip.fsf@pobox.com> Message-ID: <20051014000415.GA22421@ActiveState.com> [John J. Lee wrote] > 4. There's a registry key for tab completion somewhere... Search for "CompletionChar" and change it to 9. http://www.microsoft.com/resources/documentation/Windows/2000/server/reskit/en-us/Default.asp?url=/resources/documentation/Windows/2000/server/reskit/en-us/regentry/34995.asp Cheers, Trent -- Trent Mick TrentM at ActiveState.com From cs at totallybogus.com.invalid Fri Oct 14 14:08:51 2005 From: cs at totallybogus.com.invalid (Cousin Stanley) Date: Fri, 14 Oct 2005 13:08:51 -0500 Subject: [ANN] XPN 0.5.5 released References: <20051013194207.1700.5269.XPN@orion.homeinvalid> <1129300207_2667@spool6-east.superfeed.net> <20051014170644.1803.75237.XPN@orion.homeinvalid> Message-ID: <1129313331_3115@spool6-east.superfeed.net> > I'm not 100% sure but I think that they could work. > > The only thing is changed is the outgoing articles format, > so if you have article in the oubox delete them > >> Can I install the newer xpn version >> and move the older data files into it >> without reconfiguring & reloading data files ? >> >> o config.txt >> o server_logs.dat >> o dats >> o groups_info >> o groups_list > > It should work, anyway just make a copy of these files > to be sure not to lose them. > I'll give it a try later today & let you know how it turns out .... Thanks .... -- Stanley C. Kitching Human Being Phoenix, Arizona ----== 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 darkpaladin79 at gmail.com Sat Oct 15 11:13:04 2005 From: darkpaladin79 at gmail.com (Ivan Shevanski) Date: Sat, 15 Oct 2005 11:13:04 -0400 Subject: Yes, this is a python question, and a serious one at that (moving to Win XP) In-Reply-To: <7qCdnSkPd-wwFtLeRVn-ig@powergate.ca> References: <7qCdnSkPd-wwFtLeRVn-ig@powergate.ca> Message-ID: <17d4ae400510150813p428f0a69kf710ec48552eb84@mail.gmail.com> On 10/14/05, Peter Hansen wrote: > > Christian Stapfer wrote: > > 0.0. ... and add an item to your SendTo folder that allows > > you to have Windows Explorer open a terminal window with its > > current directory set to the currently displayed folder > > (= "Open terminal here"). > > Or install the "Command Prompt Here" gadget that MS produces, which has > a massive installer and a click-through license thing and everything, > just to open a freakin' prompt at a given directory > > -Peter > > > There's an excellent windows registry edit to open a command prompt at the given directory that I've been using. . .Here's a link. http://www.winguides.com/registry/display.php/260/ Hope that helps, -Ivan -------------- next part -------------- An HTML attachment was scrubbed... URL: From grig.gheorghiu at gmail.com Fri Oct 7 20:09:19 2005 From: grig.gheorghiu at gmail.com (Grig Gheorghiu) Date: 7 Oct 2005 17:09:19 -0700 Subject: Simulating low bandwidth network on localhost In-Reply-To: <1128728893.814798.44050@g49g2000cwa.googlegroups.com> References: <1128728893.814798.44050@g49g2000cwa.googlegroups.com> Message-ID: <1128730159.465804.275010@f14g2000cwb.googlegroups.com> Try dummynet ( and/or Google for it) Grig From mwm at mired.org Tue Oct 25 16:26:10 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 25 Oct 2005 16:26:10 -0400 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: <86zmox2vj1.fsf@bhuda.mired.org> Not Bill Gates writes: > steve at REMOVETHIScyber.com.au wrote... >> On Tue, 25 Oct 2005 15:35:47 +0000, Not Bill Gates wrote: >> > Heck, I dunno. Like you, I don't even really care all that much. >> You don't care that innovation in desktop software has been crippled by >> the actions of the monopoly player Microsoft? > You need to first prove innovation in desktop software has been > crippled, don't you? MS took desktop software through pretty much the same sequence of offerings that the mainframe and minicomputer software industry had been throgh: flat file systems and single-tasking OS's in a command line environment, adding nested file systems, adding TSRs, adding a windowing environment, adding true multitasking and finally multiprocessor systems. This took them what - 20+ years? While MS was "innovating" by giving us directories, others who had learned the lessons from mainframe and minicomputer systems were offering us desktop systems with all those features - and an office suite that ran in the windowing systems - for a fraction of the price of anything that was capable of running MS-DOS. MS managed to kill off or drive into niche markets the companies who were actually doing innovative work on desktop systems, and it's taken the desktop software industry two decades to recover from that. I'll accept that as crippling until a better definition comes along. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From smadim2 at grads.ece.mcmaster.ca Mon Oct 3 14:28:59 2005 From: smadim2 at grads.ece.mcmaster.ca (M.N.A.Smadi) Date: Mon, 03 Oct 2005 14:28:59 -0400 Subject: python getopt functionality Message-ID: <4341786B.1030901@grads.ece.mcmaster.ca> hi; I have a perl script that I need to port to python. The script takes input from the command line. Is there a standard way of processing command line arguments based on the -flag preceeding the argument? thanks moe smadi From deets at nospam.web.de Wed Oct 12 18:49:34 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 13 Oct 2005 00:49:34 +0200 Subject: python server? In-Reply-To: References: Message-ID: <3r5i7vFi1drtU1@uni-berlin.de> > I was wondering if something similar already existed, to use as-is or > to adapt to my needs. > I did a little googling, which pointed me to interesting, but rather > different projects. Has anybody ever seen or heard something of this > kind? Or maybe there is something almost-ready in the amazing python > library (as you understand, I am rather new to python), and I missed > it? Mabybe pyro helps you - it'S pure python, and makes working with remote objects pretty transparent. Diez From darkbard at gmail.com Thu Oct 13 09:06:20 2005 From: darkbard at gmail.com (Gabriele *darkbard* Farina) Date: 13 Oct 2005 06:06:20 -0700 Subject: Adding methods to an object Message-ID: <1129208780.605763.218110@g43g2000cwa.googlegroups.com> Hi, there is a way to add methods to an object dynamically? I need to do something like this. I remember python allowed this ... class A(object): def do(s, m): print m @staticmethod def init(obj): obj.do = A.do class Test(object): pass o = Test() A.init(o) o.do(10) Now it gives me an error ... unbound method ... tnx, gabriele From fredrik at pythonware.com Wed Oct 26 14:42:43 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 26 Oct 2005 20:42:43 +0200 Subject: Raw string fu References: <1130350167.20384.7.camel@localhost.localdomain> Message-ID: Joshua Ginsberg wrote: > >>> r'\' > File "", line 1 > r'\' > ^ > SyntaxError: EOL while scanning single-quoted string > >>> r'\\' > '\\\\' > > Does that seem wrong to anybody else? Shouldn't the first one be > syntactically correct? the "r" prefix doesn't change how string literals are parsed; it only affects how they are converted to string objects. From listspam at flowtheory.net Wed Oct 26 14:09:27 2005 From: listspam at flowtheory.net (Joshua Ginsberg) Date: Wed, 26 Oct 2005 14:09:27 -0400 Subject: Raw string fu Message-ID: <1130350167.20384.7.camel@localhost.localdomain> >>> r'\' File "", line 1 r'\' ^ SyntaxError: EOL while scanning single-quoted string >>> r'\\' '\\\\' Does that seem wrong to anybody else? Shouldn't the first one be syntactically correct? -jag From davids at webmaster.com Tue Oct 25 03:22:36 2005 From: davids at webmaster.com (David Schwartz) Date: Tue, 25 Oct 2005 00:22:36 -0700 Subject: Microsoft Hatred FAQ References: <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> Message-ID: "Antoon Pardon" wrote in message news:slrndlrlt2.hdl.apardon at rcpc42.vub.ac.be... >> I think you need to look up "extortion" in a dictionary. I can walk >> up >> to you and say "if you want me to mow your lawn, you must pay me $1 every >> time you smoke a cigarette". So long as you can say "no" and all that >> happens is that I don't mow your lawn (which I have no obligation to do >> anyway), it isn't extortion. > If you would happen to have a monopoly on the mowing business, which > would make it very hard for me to have my lawn mowed unless I took > your offer, it would be. Yes, but that's the "if". I have a monopoly on *me* mowing your lawn. You can, of course, go to someone else to have your lawn mowed. Microsoft only had a monopoly on *Microsoft* operating systems. Microsoft had no control over OSX, Linux, FreeBSD, and so on. Essentially, Microsoft asked for exclusive arrangements. That is, arrangements wherein you could not sell competing products if you wished to sell Microsoft products. That's not even remotely unusual. DS From AddisonN at iti-ab.com Wed Oct 12 12:33:00 2005 From: AddisonN at iti-ab.com (AddisonN at iti-ab.com) Date: Wed, 12 Oct 2005 17:33:00 +0100 Subject: Scope problem with nested functions. Message-ID: <9355218C54DDFF4CA43FC31AEB6FB0EC5B102C@iti00-exc01.iti.arabbank.plc> I'm having trouble resolving a scope problem. I have a module, called from another script, with this structure: def parseFile(file, myLocation, defaults): # initialisation. ccyMappings = {} def getCcyMappings() global ccyMappings # read values into ccyMappings. ccyMappings['CAN'] = ['CAD'] # for example. def mapCcy(myCcy): if ccyMappings.has_key(myCcy): return ccyMapping['myCcy'] else: return myCcy My problem is that, although the ccyMappings dictionary is populated within the def getCcyMappings() function, the value goes to 'None' when I leave it and so is not available when the mapCcy function is called. I've used the global scope declaration successfully before, but not with nested functions like this, admittedly. Any assistance gratefully received. Nick. ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. Information Technology International (ITI) +44 (0)20 7315 8500 ********************************************************************** -------------- next part -------------- An HTML attachment was scrubbed... URL: From usgog at yahoo.com Fri Oct 28 13:37:06 2005 From: usgog at yahoo.com (usgog at yahoo.com) Date: 28 Oct 2005 10:37:06 -0700 Subject: Newbie question: string replace In-Reply-To: <3s7620FlqdmnU1@uni-berlin.de> References: <1130258229.662596.228630@g49g2000cwa.googlegroups.com> <3s7620FlqdmnU1@uni-berlin.de> Message-ID: <1130521026.584455.288370@g44g2000cwa.googlegroups.com> Now it works: rex = re.compile(r'(^.*username *=[^"]*")([^"]*)(".*$)') for line in fileinput.input(FILE, inplace=1): m = rex.match(line) if m is not None: line = "%s%s%s\n" % (m.group(1), new_name, m.group(3)) print line But there is an extra line break after each line in FILE. Why is that? I tried to line = "%s%s%s" % (m.group(1), new_name, m.group(3)) but it turns out there are two extra line breaks after each line... From onurb at xiludom.gro Mon Oct 31 05:51:44 2005 From: onurb at xiludom.gro (bruno at modulix) Date: Mon, 31 Oct 2005 11:51:44 +0100 Subject: data hiding/namespace pollution In-Reply-To: References: Message-ID: <4365f743$0$9485$636a15ce@news.free.fr> Alex Hunsley wrote: > There's no really specific questions in this post, but I'm looking for > people's thought on the issues within... > > > The two main versions I've encountered for data pseudo-hiding > (encapsulation) Hmmm... Are data-hiding and encapsulation really the same things ? > in python are: > > method 1: > > _X - (single underscore) - just cosmetic, a convention to let someone > know that this data should be private. > > > method 2: > > __X - (double underscore) - mangles the name (in a predictable way). > Avoids name pollution. > > > How often does either tend to get used? Personally, I'd be a little > worried about using method 1, because namespace clashes could happen. Is > this overly paranoid? Probably. Note that prefixing names with a single underscore have a 'protected' semantic - which means that such names (well, the objects that are bound to...) can be overriden/extends by child classes. I personnally only use the double-underscore notation only for things that are *really* implementation-specific *and* should *really not* be overriden. > > Also, I presume that rather than people writing their own manual getter > and setter methods, they tend to use either overloading on __getattr__ > and __setattr__, or the Property class (which itself uses aforementioned > methods). Yeps... This is the pythonic way. > Overloading __getattr__ etc. seems more attractive to me, as > then I can capture access to unknown names, and raise an exception! > (I really don't like the idea of random attribute name typos going > unnoticed when accessing attributes in a class!) Err... Have you *really* tried to access an inexistant attribute ? This is usually not 'unnoticed' (unless you consider the raising of an AttributeError as being the same as 'unnoticed' !-) I personnaly use 'magic' accessors only for delegation or like, and properties (or custom descriptors) for anything else (that requires it...). This avoid the Big-Switch-Syndrom in __getattr__ and setattr__, and is much more explicit (API, documentation, introspection etc...). > Note: I do know that the use of the above things is quite dependent on > what exactly you're coding, the size of the project etc., but what I'm > trying to find out about is the python communities' recognised good > practices. Then launch your python interactive shell and type "import this" HTH -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From john at castleamber.com Sat Oct 15 14:01:23 2005 From: john at castleamber.com (John Bokma) Date: 15 Oct 2005 18:01:23 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: Michael Heiming wrote: > The only thing positive about M$ entering the market, probably > due to their ineffective programming style they pushed Intel into > producing pretty fast while cheapo CPUs. Amazing, I thought Xah Lee was the only one able to fit so much BS in one sentence. > Ironically exactly this > is the key to Linux/*BSD success in the unix server market. ;) Yeah, right. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From lard at tardis.ed.ac.molar.uk Mon Oct 31 05:39:40 2005 From: lard at tardis.ed.ac.molar.uk (Alex Hunsley) Date: Mon, 31 Oct 2005 10:39:40 GMT Subject: mixin helper class for unknown attribute access? Message-ID: I know that I can catch access to unknown attributes with code something like the following: class example: def __getattr__(self, name): if name == 'age': return __age else: raise AttributeError but is there an existing mixin helper class in Python (or one someone has written) already that will assist with this? (Just not wanting to reinvent the wheel....) From jramirez08063 at yahoo.com Mon Oct 3 06:35:01 2005 From: jramirez08063 at yahoo.com (Pepe Pena) Date: Mon, 3 Oct 2005 03:35:01 -0700 (PDT) Subject: Load PDF Message-ID: <20051003103501.50007.qmail@web35011.mail.mud.yahoo.com> Hello, I am attempting to load a pdf file programatically within Adobe Reader using the Adobe Acrobat 7.0 Browser Control Type Library. If I run this code PythonWin terminates abruptly, can anyone suggest any changes I should make to the following lines of code, thanks. import win32com.client test = win32com.client.Dispatch("AcroPDF.PDF.1") test.LoadFile("D:\\sql.pdf") --------------------------------- Yahoo! for Good Click here to donate to the Hurricane Katrina relief effort. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jack at performancedrivers.com Fri Oct 7 17:51:14 2005 From: jack at performancedrivers.com (Jack Diederich) Date: Fri, 7 Oct 2005 17:51:14 -0400 Subject: When someone from Britain speaks, Americans hear a "British accent"... In-Reply-To: <11kdpab4l7i7ecb@corp.supernews.com> References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kdpab4l7i7ecb@corp.supernews.com> Message-ID: <20051007215114.GM6255@performancedrivers.com> On Fri, Oct 07, 2005 at 09:14:51PM -0000, Grant Edwards wrote: > On 2005-10-07, Terry Hancock wrote: > > > Of course, just to keep y'all on your toes, we Texans have not only > > construed "their" to singular, but also "you", and added a new > > plural "y'all". > > AFAICT, in many parts of "The South", y'all is now used in the > singular (e.g. "y'all" is used when addressing a single > person), and "all y'all" is the plural form used when > addressing a group of people collectively. > "What word(s) do you use to address a group of two or more people?" http://cfprod01.imt.uwm.edu/Dept/FLL/linguistics/dialect/staticmaps/q_50.html A map from a US dialect survey. Click around for many more questions. The question was a bit broken, it did not list "all y'all" and its most glaring omission was "yous guys" The Philly responders selected the next best option of "yous" It is a bit odd that You'uns, yins, and yous are confined to Pennsylvania and very distinct east-west regions inside PA at that (Pittsburgh vs Philly orbits). -jack From steve at holdenweb.com Mon Oct 10 03:17:36 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 10 Oct 2005 08:17:36 +0100 Subject: Python on the Power PC In-Reply-To: References: Message-ID: Peter Milliken wrote: > Hi, > > I (think I have :-)) installed Python on my Pocket PC (obtained from > http://fore.validus.com/~kashtan/). > > There were Tkinter binaries with it so I installed those as well. When I > attempt to run the most simplistic of python programs using Tkinter, I get > an error message stating that Python can't find any tkinter module. > > Any ideas what I have done wrong anybody? > > Thanks > Peter > > import Tkinter > > if __name__ == '__main__': > root = Tkinter.Tk() > > root.title('Hello World?') > > root.mainloop() > > Are you sure it didn't say "_tkinter" was what it couldn't find? On my Windows system the Tkinter.py file tries to import an extension (compiled C) module called _tkinter (provided as _tkinter.dll) that provides the low-level Tkinter functionality. It's likely that that's missing. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From paul at boddie.org.uk Thu Oct 27 11:00:57 2005 From: paul at boddie.org.uk (Paul Boddie) Date: 27 Oct 2005 08:00:57 -0700 Subject: handling ExpatError exception raised from ElementTree.XML() method References: <1130386520.772048.117530@o13g2000cwo.googlegroups.com> Message-ID: <1130425257.683957.130440@g43g2000cwa.googlegroups.com> mirandacasc... at yahoo.com wrote: > > NameError: name 'ExpatError' is not defined > > I'm guessing that I need to define/describe the ExpatError exception > class and then refer to that defined exception class after the keyword > 'except' and before the ':', but I cannot figure out how to do that. You just need to know how to reference ExpatError yourself. Doing a grep on the site-packages directory revealed that the most likely location of the ExpatError class is xml.parsers.expat. So, first you need to import that package: import xml.parsers.expat Then, you can refer to the class as an attribute of that package. Alternatively... from xml.parsers.expat import ExpatError ...lets you use the name directly. I think that it can be useful when making a library to make common exception classes attributes of certain principal classes/objects, in order to simplify this kind of situation and to avoid the need to find the originating module of some exception or other. Paul From *firstname*nlsnews at georgea*lastname*.com Mon Oct 17 23:11:20 2005 From: *firstname*nlsnews at georgea*lastname*.com (Tony Nelson) Date: Tue, 18 Oct 2005 03:11:20 GMT Subject: Mutual module imports Message-ID: <*firstname*nlsnews-B5E898.23113017102005@news.verizon.net> How does one normally make a Python extension module that has some parts in Python and some functions in C share globals between the Python and C functions? Will that approach work with Pyrex? I have written a Python module that uses some C functions. I wrote the module in two parts, one Python, one Pyrex (C). They need to share some globals. (I use pyrex to handle ref counting. I think I'm glad I did.) At first they just sort of mutually imported each other, and it worked until I put tests in the Python one and set it up to run them when it is named "__main__". What happened reminded me that there are also other ways modules can be imported under different names, so I tried a different approach. Now the Python module imports the Pyrex module and just shoves references to its globals into the Pyrex module (the Pyrex module defines them as None). The Pyrex module doesn't import the Python module anymore. This also works, even when the Python module has a different name (e.g. "__main__"). I just feel dirty about it. ________________________________________________________________________ TonyN.:' *firstname*nlsnews at georgea*lastname*.com ' From rrr at ronadam.com Sun Oct 16 06:24:08 2005 From: rrr at ronadam.com (Ron Adam) Date: Sun, 16 Oct 2005 10:24:08 GMT Subject: Comparing lists In-Reply-To: References: <1128930699.799657.146210@g47g2000cwa.googlegroups.com> <1128952417.0544cc73190bbbd4e683448c137969c8@teranews> <434ba977@nntp0.pdx.net> <1129216693.445956.155490@g47g2000cwa.googlegroups.com> Message-ID: Christian Stapfer wrote: > This discussion begins to sound like the recurring > arguments one hears between theoretical and > experimental physicists. Experimentalists tend > to overrate the importance of experimental data > (setting up a useful experiment, how to interpret > the experimental data one then gathers, and whether > one stands any chance of detecting systematic errors > of measurement, all depend on having a good *theory* > in the first place). Theoreticians, on the other hand, > tend to overrate the importance of the coherence of > theories. In truth, *both* are needed: good theories > *and* carefully collected experimental data. > > Regards, > Christian An interesting parallel can be made concerning management of production vs management of creativity. In general, production needs checks and feedback to insure quality, but will often come to a stand still if incomplete resources are available. Where as creativity needs checks to insure production, but in many cases can still be productive even with incomplete or questionable resources. The quality may very quite a bit in both directions, but in creative tasks, that is to be expected. In many ways programmers are a mixture of these two. I think I and Steven use a style that is closer to the creative approach. I get the feeling your background may be closer to the production style. Both are good and needed for different types of tasks. And I think most programmers can switch styles to some degree if they need to. Cheers, Ron From vasilijepetkovic at yahoo.com Wed Oct 26 04:49:04 2005 From: vasilijepetkovic at yahoo.com (vasilijepetkovic at yahoo.com) Date: 26 Oct 2005 01:49:04 -0700 Subject: Looping Problem (Generating files - only the last record generates a file) Message-ID: <1130316544.381673.209190@g44g2000cwa.googlegroups.com> Hello All, I have a problem with the program that should generate x number of txt files (x is the number of records in the file datafile.txt). Once I execute the program (see below) only one file (instead of x files) is created. The file created is based on the last record in datafile.txt. The program is as follows: ==================================== #! python HEADER = "This page displays longitude-latitude information" SUBHEADER = "City" for line in open("datafile.txt"): town, latlong = line.split('\t') f = open(town + ".txt", "w+") f.write(HEADER + "\n") f.write(SUBHEADER + ": " + town + "\n") f.write("LAT/LONG" + ": " + latlong + "\n") f.close() # end ==================================== The datafile.txt is as follows (tab separated columns): ==================================== NYC 1111-2222 Lima 3333-4444 Rome 5555-6666 ==================================== Once executed, the program will create a single file (named Rome.txt) and it would not create files NYC.txt and Lima.txt as I would expect it to do. I'd appreciate if you can pinpoint my error. Best, Vasa From aleax at mail.comcast.net Sat Oct 15 04:51:41 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Sat, 15 Oct 2005 10:51:41 +0200 Subject: Problem splitting a string References: Message-ID: <1h4gzgc.er0q43111v2w5N%aleax@mail.comcast.net> Steven D'Aprano wrote: ... > You can *almost* do that as a one-liner: No 'almost' about it... > L2 = [item.split('_') for item in mystr.split()] > > except that gives a list like this: > > [['this', 'NP'], ['is', 'VL'], ['funny', 'JJ']] > > which needs flattening. ....because the flattening is easy: [ x for x in y.split('_') for y in z.split(' ') ] Alex From rrr at ronadam.com Thu Oct 6 16:44:42 2005 From: rrr at ronadam.com (Ron Adam) Date: Thu, 06 Oct 2005 20:44:42 GMT Subject: "no variable or argument declarations are necessary." In-Reply-To: References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net><1128306351.13c600edac4bfa99f9f10238681bf68f@teranews><6xO0f.166857$p_1.72982@tornado.tampabay.rr.com><4344c53e.3325034196@news.oz.net> Message-ID: <_0g1f.135529$xl6.20871@tornado.tampabay.rr.com> Fredrik Lundh wrote: > Ron Adam wrote: > > >>Is there a way to conditionally decorate? For example if __debug__ is >>True, but not if it's False? I think I've asked this question before. (?) > > > the decorator is a callable, so you can simply do, say > > from somewhere import debugdecorator > > if not __debug__: > debugdecorator = lambda x: x Ah... thanks. I suppose after(if) lambda is removed it would need to be. def nulldecorator(f): return f if not __debug__: debugdecorator = nulldecorator > or > > def debugdecorator(func): > if __debug__: > ... > else: > return func > > etc. This one came to mind right after I posted. :-) > From skip at pobox.com Fri Oct 21 10:39:37 2005 From: skip at pobox.com (skip at pobox.com) Date: Fri, 21 Oct 2005 09:39:37 -0500 Subject: python and outlook In-Reply-To: References: Message-ID: <17240.64937.550731.289790@montanaro.dyndns.org> dt> Are there any links or sites on how to read outlook mail boxes or dt> address book? Check the Outlook plugin code in SpamBayes . Skip From jason.lai at gmail.com Sat Oct 22 09:17:02 2005 From: jason.lai at gmail.com (Jason Lai) Date: 22 Oct 2005 06:17:02 -0700 Subject: C replacement for Queue module In-Reply-To: References: <1129934643.874242.37150@g47g2000cwa.googlegroups.com> Message-ID: <1129987022.064904.84510@g44g2000cwa.googlegroups.com> As far as Queues go, the adding/popping is apparently done with deque which are implemented in C. The Queue class pretty much just provides blocking operations and is otherwise a very thin layer around deque. As far as primitives go, only threading.Lock is written in C and the others are pure Python, so they're not that fast, which might be a reason for Queue's slowness. As far as writing a custom C module, you could probably leave most of the work to deque and just implement blocking. If you stick to a simple lock primative, you can keep it portable and use Python's abstracted thread interface with an amazing choice of two whole functions: acquire and release. From martin at v.loewis.de Fri Oct 7 03:57:28 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 07 Oct 2005 09:57:28 +0200 Subject: PyObject_New In-Reply-To: References: Message-ID: <43462a69$0$6776$9b622d9e@news.freenet.de> Jeremy Moles wrote: > PyObject* obj = _PyObject_New(&PyType_MyType); > obj = PyObject_Init(obj, &PyType_MyType); > > ... > > return obj; The call to PyObject_Init is redundant: _PyObject_New is malloc+init. However, this shouldn't cause any crashes (except in the debug build). PyObject_Init is documented as Initialize a newly-allocated object op with its type and initial reference. Returns the initialized object. If type indicates that the object participates in the cyclic garbage detector, it is added to the detector's set of observed objects. Other fields of the object are not affected. [I don't know where the mentioning of GC comes from - it appears to be incorrect] > When "obj" gets back to the interpreter, Python sees it (or rather, it's > __repr__) in accordance with what it "should" be. However, any attempt > to USE the object results in a segfault. I feel my problem is simply > that I'm not allocating "obj" correctly in the C++ function. It doesn't crash because of the allocation - this code is correct. However, it is also incomplete: none of the state of the new object gets initialized in the fragment you are showing. So it likely crashes because the members of the object are stray pointers or some such, and accessing them causes a crash. Regards, Martin From tziade at nuxeo.com Fri Oct 14 20:32:51 2005 From: tziade at nuxeo.com (=?ISO-8859-1?Q?Tarek_Ziad=E9?=) Date: Sat, 15 Oct 2005 02:32:51 +0200 Subject: machine-independant bench Message-ID: <43504E33.6030209@nuxeo.com> Hi list, I am trying to code some utilities to bench code performances, machine-independant, to be able to measure the absolute cost of a piece of code. So i came up with the pystone idea (i've been told too in fact ;)). so I just run pystones on the test machines and use it as a ratio over code performance measurement. This is pretty good, but the major caveat is that if the CPU is busy , it can be slower than expected. So i've introduced a tolerance flag, (another approach than the three times run like hotshot does). Any comment ? Any alternatives to pystone in mind ? Tarek -- Tarek Ziad? | Nuxeo R&D (Paris, France) CPS Plateform : http://www.cps-project.org mail: tziade at nuxeo.com | tel: +33 (0) 6 30 37 02 63 You need Zope 3 - http://www.z3lab.org/ From onurb at xiludom.gro Mon Oct 17 05:35:29 2005 From: onurb at xiludom.gro (bruno modulix) Date: Mon, 17 Oct 2005 11:35:29 +0200 Subject: Question on class member in python In-Reply-To: <1129537638.714752.120290@g49g2000cwa.googlegroups.com> References: <1129537638.714752.120290@g49g2000cwa.googlegroups.com> Message-ID: <43537063$0$4340$626a54ce@news.free.fr> Johnny Lee wrote: > Class A: s/C/c/ > def __init__(self): > self.member = 1 > > def getMember(self): > return self.member > > a = A() > > So, is there any difference between a.member and a.getMember? yes : a.member is an integer, a.getMember is a bound method. You could have found this by yourself... Note that the getter/setter plague is useless and unpythonic. Use properties instead if you need to control attributes access. There are decorator idioms to make clean and easy properties, look here: http://wiki.python.org/moin/PythonDecoratorLibrary -- 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 Sun Oct 30 21:36:49 2005 From: mwm at mired.org (Mike Meyer) Date: Sun, 30 Oct 2005 21:36:49 -0500 Subject: need start point for getting html info from web References: <1130724071.688187.59230@g47g2000cwa.googlegroups.com> Message-ID: <86br16bef2.fsf@bhuda.mired.org> nephish at xit.net writes: > i have a small app that i am going to need to get information from a > few tables on different websites. i have looked at urllib and httplib. > the sites i need to get data from mostly have this data in tables. So > that, i think would make it easier. Anyone suggest a good starting > point for me to find out how to do this, or know of a link to a good > how-to? Don't have a link to a howto. But you're halfway there. urllib (and urllib2) will get HTML text from the websites. Pulling data from it sort of depends on the nature of the HTML. If it's well-structured XHTML, you can use your favorite xml library. if it's well structured HTML, you can try htmllib, but it's pretty primitive. If it's not well-structured, you can use BeautifulSoup. I've used it to pull data from tables. The problem with any of this is that your code really depends on the structure - or lack thereof - of the HTML you're scraping. If they change it, your code breaks. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From kylotan at gmail.com Thu Oct 20 06:28:04 2005 From: kylotan at gmail.com (Ben Sizer) Date: 20 Oct 2005 03:28:04 -0700 Subject: Minimizing Connection reset by peer exceptions In-Reply-To: <1129777447.614500.232050@z14g2000cwz.googlegroups.com> References: <1129777447.614500.232050@z14g2000cwz.googlegroups.com> Message-ID: <1129804084.245716.242040@g47g2000cwa.googlegroups.com> mirandacascade at yahoo.com wrote: > Occasionally (perhaps 5% of the time) the following exception gets > raised: > > (10054, 'Connection reset by peer') Generally this just means the connection has closed through some unusual means, perhaps by being turned off, or a network cable being unplugged, or a timeout along the way, etc. 5% is a high figure, but perhaps you connect to hosts that are unreliable for some reason. You don't have control over this really; just make sure you handle the exception. Such is life, when dealing with networking. -- Ben Sizer From kent37 at tds.net Thu Oct 13 08:02:13 2005 From: kent37 at tds.net (Kent Johnson) Date: Thu, 13 Oct 2005 08:02:13 -0400 Subject: Looking for a Python mentor In-Reply-To: <1129167866.253155.157850@g43g2000cwa.googlegroups.com> References: <1129167866.253155.157850@g43g2000cwa.googlegroups.com> Message-ID: <434e4ae7$1_1@newspeer2.tds.net> LenS wrote: > Hello > > Was wandering if there is any place where some one could go to get > mentoring on python coding. I have started coding in python but I am > the only one in the shop using it. So there is no one around to look > over my code give suggestions on improvement, in style, logic, easier > ways of doing things etc. I second gene's recommendation of the python-tutor mailing list - we do all of the above as well as cheerfully answer all questions, give suggestions on how to do things, etc. Kent From kent37 at tds.net Mon Oct 31 14:39:31 2005 From: kent37 at tds.net (Kent Johnson) Date: Mon, 31 Oct 2005 14:39:31 -0500 Subject: Function returns none In-Reply-To: <1130785944.632805.156810@o13g2000cwo.googlegroups.com> References: <1130785944.632805.156810@o13g2000cwo.googlegroups.com> Message-ID: <436670bb$1_3@newspeer2.tds.net> noahlt at gmail.com wrote: > I'm trying to write a website updating script, but when I run the > script, my function to search the DOM tree returns None instead of what > it should. When you call findelement() recursively you have to return the value from the recursive call to the next caller up. See example below. Kent > > I have this program: > -------- > import sys > from xml.dom.minidom import parse > > > # search the tree for an element with a particular class > > def findelement(current, classtofind, topnode = None): > if topnode == None: topnode = current > > > > # if it's an xml element... > if current.nodeType == 1: > print current.nodeName, ':', current.getAttribute('class') > if current.getAttribute('class') == classtofind: > print 'Returning node:', current > return current > elif current.hasChildNodes(): > findelement(current.firstChild, classtofind, topnode) Should be return findelement(current.firstChild, classtofind, topnode) and similarly wherever you call findelement(). > elif current.nextSibling: > findelement(current.nextSibling, classtofind, topnode) > > elif (current.parentNode != topnode) \ > > and (current.parentNode.nextSibling != None): > > findelement(current.parentNode.nextSibling, classtofind, > topnode) > else: > > print 'Returning None...' > > return None > > # others (text, comment, etc) > > else: > > if current.nextSibling: > > findelement(current.nextSibling, classtofind, topnode) > > elif (current.parentNode != topnode) \ > > and (current.parentNode.nextSibling != None): > > findelement(current.parentNode.nextSibling, classtofind, > topnode) > else: > > print 'Returning None...' > > return None > > > > # parse the document > > blog = parse('/home/noah/dev/blog/template.html') > > > > # find a post > > postexample = findelement(blog.documentElement, 'post') > > > > print 'Got node: ', postexample > > ----- > > My output is this: > > ----- > html : > head : > title : > body : > h1 : > ul : > li : > h2 : > ol : > li : post > Returning node: > Got node: None > ----- > > The function finds the right element fine, and says it will return Element: li at -0x48599c74>, but the program gets None instead. What's > happening here? Any suggestions? > From phil_nospam_schmidt at yahoo.com Sun Oct 9 00:36:05 2005 From: phil_nospam_schmidt at yahoo.com (phil_nospam_schmidt at yahoo.com) Date: 8 Oct 2005 21:36:05 -0700 Subject: Continuous system simulation in Python References: <20051007011222.1aeab426@linuxcestcomplique.fr> <1128708054.819697.232950@o13g2000cwo.googlegroups.com> <20051007224533.08bde751@linuxcestcomplique.fr> Message-ID: <1128832565.028584.10590@z14g2000cwz.googlegroups.com> Nicholas, I have a particular interest in this subject as well. I've also used the Python/Scipy combination, and it is a tantalizing combination, but I found it to be a bit more clumsy than I'd like. Plus, my need for continuous-time simulation is not as great as it has been in the past. That said, I've been down this path before (see http://custom.lab.unb.br/pub/asme/DYNAMICS/BUFORD1.zip), and I would be interested in helping to develop something. I agree that Python would be a great foundation to build upon. From prasad.c.iyer at capgemini.com Tue Oct 18 03:37:40 2005 From: prasad.c.iyer at capgemini.com (Iyer, Prasad C) Date: Tue, 18 Oct 2005 13:07:40 +0530 Subject: Don't want to serialize a variable of object Message-ID: Thanks a lot. Actually you are right I would be trying same thing now. Writing my own custom serializable for the object. But everyone else who face the same problem would come up with their own Serializable code. Can't we plug something into cpickle So that it discards some variable from being serializable. Similar to __data for private variables. But on second thought that would be too much of change that I am asking. Anyway thanks a lot. regards prasad chandrasekaran --- Cancer cures smoking #-----Original Message----- #From: Tarek Ziad? [mailto:tziade at nuxeo.com] #Sent: Tuesday, October 18, 2005 1:01 PM #To: Iyer, Prasad C #Cc: python-list at python.org #Subject: Re: Don't want to serialize a variable of object # #Iyer, Prasad C wrote: # #>Hi, #>I got a class which I need to serialize, except for couple of variable. #>i.e. #> #>import cPickle as p #>class Color: #> def __init__(self): #> print "hello world" #> self.x=10 #> self.somechar="this are the characters" #>color=Color() #>f=file('poem.txt', 'w') #>p.dump(color, f) #>f.close() #> #>How do I serialize the object color without serializing the x and #>somechar variables? #>Is there any modifier which prevents the variable from being serialized. #> #> #You can create your own serialization process, by providing some kind of #serialize() method # in a base class that would dump part of the object. # #Let's say, the instance __dict__ dictionnary ? #this serialize method can then remove the attributes that starts with '_v_' #(that's what we do in Zope to avoid pickling some attribute) # #> #> #> #>Another question: #> Is there a concept of private variables? #> #> #That's a long discussion, you should look at the archives in the list. # #But anyway, all attributes that starts with '__' are considered private #to the class. #(ie: can't be reached by "instance.__attribute") # #even though you can find it if you dig into instance.__dict__ # # #Regards, # #Tarek This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. From piet at cs.uu.nl Sun Oct 2 12:59:45 2005 From: piet at cs.uu.nl (Piet van Oostrum) Date: Sun, 02 Oct 2005 18:59:45 +0200 Subject: output events on select References: Message-ID: >>>>> "Tor Erik S?nvisen" (TES) wrote: >TES> When using select, what exactly will trigger an output-event? I have >TES> a socket registered in the output-list of the select but an >TES> output-event is never generated for that socket. I know the socket is >TES> ready to send data, so how can I make select return with an >TES> output-event? It is better to talk about status than event. The select should return the socket in the ready set for write when a write on that socket can be done without blocking. So if it doen't return it then something is wrong. This is on Unix systems, by the way. On Windows things might be different. -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4] Private email: piet at vanoostrum.org From dietz at dls.net Sat Oct 1 12:11:34 2005 From: dietz at dls.net (Paul F. Dietz) Date: Sat, 01 Oct 2005 11:11:34 -0500 Subject: OT: Phases of the moon [was Re: A Moronicity of Guido van Rossum] In-Reply-To: References: <1128003857.930444.47650@g14g2000cwa.googlegroups.com> <1128013745.763757.144280@g44g2000cwa.googlegroups.com> <1128015868.201617.153240@g14g2000cwa.googlegroups.com> <0001HW.BF63479501083049F0407550@news.individual.de> Message-ID: Bart Lateur wrote: > As a similar example: I've been told by various women independently, > that "there are more babies born near a full moon." That's also a myth. Paul From peck at spss.com Mon Oct 3 10:42:39 2005 From: peck at spss.com (Peck, Jon) Date: Mon, 3 Oct 2005 09:42:39 -0500 Subject: Finding the Process Path Message-ID: <5CFEFDB5226CB54CBB4328B9563A12EE02C62228@hqemail2.spss.com> Problem solved, but sys.executable seems to be (mostly) what I need. The context here is that my code is embedded in another process, so the Python interpreter is not the process executable, and in fact argv is not set (for various reasons not related to Python.) If I run this code directly through the interpreter, of course Python is what I get from sys.executable. -----Original Message----- From: python-list-bounces+jkpeck=aya.yale.edu at python.org [mailto:python-list-bounces+jkpeck=aya.yale.edu at python.org] On Behalf Of Steve Holden Sent: Monday, October 03, 2005 9:26 AM To: python-list at python.org Subject: Re: Finding the Process Path Peck, Jon wrote: > Thanks, but this doesn't tell me what I am looking for. > > I am looking for the path for the current process (which will not be the Python interpreter). > Actually the core image will be that of the Python interpreter. > I see, though, that this is available as sys.executable > The interpreter? That's correct. What you probably want is import os, sys print os.path.abspath(sys.argv[0]) this will give you the path to the Python script the interpreter is running. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list From allen.cross at gmail.com Mon Oct 3 22:50:43 2005 From: allen.cross at gmail.com (whoopsi) Date: 3 Oct 2005 19:50:43 -0700 Subject: help w/ simple GPIB prog. Message-ID: <1128394242.934045.165100@z14g2000cwz.googlegroups.com> Hi, Could someone give me some simple commands for communicating with GPIB devices. All I want is to aquire values from a multimeter/fiber optic attenuator/and a power meter. Nothing too complex. I was able to do so using Matlab (however, I was using the serail port) and communicating via SCPI language, but now the computer I'm using doesn't have Matlab, so I'm trying to learn with Python. I've downloaded and installed: ActivePython_2.4, pyserial-2.2, and gpib-devices-0.0.4.win32.exe. I have read some beginner's guides to python, but they don't discuss GPIB programming much. I thought I would simply be able to open a port, and send SCPI commands to configure and aquire values. But when I tried to run GPIB .py files from gpib-device-0.0.4 I got an error: "symbol 'ibsta' not found". Doing some searching I found that ibsta was refering to a library for GPIB (I'm assuming some .dll from a driver) and wrapping them???. But these instruments as far as I know don't need drivers. The instruments I'm using are: -PC w/ WIN2k -Keithley 2000 multimeter -HP 8156A optical attenuator -ILXLightwave Fiber Optic Power Meter Essentially what I would like to do is simply run the attenuator through different dB values and measure the voltage using the multimeter. And possibly later integrating the power meter. If you could help me I would appreciate it, and please forgive the above longwindedness. thanks. -Allen From http Sun Oct 2 07:52:13 2005 From: http (Paul Rubin) Date: 02 Oct 2005 04:52:13 -0700 Subject: Will python never intend to support private, protected and public? References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xd5mstqab.fsf@ruckus.brouhaha.com> <7xzmpwuxd0.fsf@ruckus.brouhaha.com> <20050930075313.67b9b676.jk@ospaz.ru> <7xbr2a6dlz.fsf@ruckus.brouhaha.com> <7xk6gyoibc.fsf@ruckus.brouhaha.com> <433f56a3.2969039483@news.oz.net> Message-ID: <7x1x34f85u.fsf@ruckus.brouhaha.com> bokr at oz.net (Bengt Richter) writes: > I decided to read this thread today, and I still don't know exactly > what your requirements are for "private" whatevers. No one seems to > have discussed what you could do with properties and __getattribute__ > and metaclasses and decorators, yet there are many possibilities > that might satisfy some or maybe all your requirements. I probably > missed something... Well, it's a discussion of why a certain feature might be useful, not that it's required. Mike Meyer points out some reasons it might be hard to do smoothly without changing Python semantics in a deep way (i.e. Python 3.0 or later). The basic notion is that if x.private_var is a private instance variable on x, then the only functions that are allowed to touch it are bound methods on x. Also there has to be some way to stop the client (the "client" means code that calls methods on x) from injecting new methods into x's class definition. Alternatively, if x and y are objects, and the app calls x.foo(y), then privacy means x cannot see any of y's private variables no matter what x does (this is sort of the applet model). Python used to have a module called rexec/Bastion that did something like this, but required the client to be wrapped in a special proxy-like object, and it turned out to still have hard-to-fix holes, so it was removed. Maybe if Python objects are organized a bit differently in PyPy, something like Bastion can be done again. > What "privately" seems to mean is that within a method using > private_var, you'd still like the code to read self.private_var, > and not be translated to self.__some_kind_of_extreme_mangling_private_var > even if the mangling had vanishing collision probability, like a name > built from a secure hash GUID algorithm, right? Only if clients were somehow prevented from examining self.__dict__ to find the GUID-like name. > Also, if an outside access to an instance said inst.private_var = 123 > that would be ok, and bind a public attribute of that name as usual > without interfering with the methods using the bona fide self.private_var? > Or should it be an attribute error (which would thus leak the name even > if it didn't make access possible). If the mangled name were really long and random, the chance of such a collision would be negligible. But I think extreme mangling isn't the way to go about this. The right way is with some version of __getattr__ that's harder to circumvent. > I take it that a clever subclassing trick (like a post somewhere in > this thread showed) should not provide access, but how about the > inspect module? Or an expression like instance.__dict__[1] if that > was the sneaky spelling of instance.private_var? (note that integers > are not allowed for instance attributes, even via get/setattr. (BTW > & OTOH, interestingly type.__setattribute__(cls, att) allows integer > att) Where do you want to draw the line? If it's like Java, stuff like inspect should only work through special interfaces in the interpreter and not be available to code in the app unless some flags were set. > I'm not trying to be provocative, just to get the requirements defined ;-) > > What if you could define a class something like > > class C(object): > # privatize factory makes callable to make the changes and clean up after itself > __metaclass__ = privatize(method_foo='private_var1 pv2', method_bar='pv2') > ... > > and have method_foo access self.private_var1 and self.pv2 as > effectively private variables, and method_bar only self.pv2 and > everything else work as usual? Would that meet your requirements? I'm not sure; metaclasses confuse me too much. But I think what I'm imagining just can't be done in the current definition of Python. Otherwise rexec/Bastion would be a special case of it and wouldn't have had to be removed. It would take a language change to fix it. > I'm not sure I could do this with just a tricky metaclass, but I am > pretty sure if you allowed byte-code-munging decoration calls from > the metaclass to mess with method_foo and method_bar (as specified > in the privatize factory call args), I could. Yeah, in the extreme, you could just implement OOP as closures instead of class instances, like Scheme does. > This would still leave the access door open via something like > type(instance).__dict__['method_foo'].func_code.co_consts[1][id(instance), > 'priv_var'] so, again, where do you want to draw the line. Starting > and communicating with a slave debugger in another (privilaged) > process? Ugh, yes, I guess that would allow reaching inside closures and getting the variables out. But it looks CPython-specific. Maybe with PyPy, there could be a way to prevent that. > But the bottom line question is, would you actually use this privacy feature? I have a crypto library right now that implements private vars by putting the sensitive objects in a completely separate Python interpreter from the client app, and communicating with proxy objects in the client by RPC through sockets. I couldn't think of a more secure way to do it. But of course the RPC overhead is pretty severe compared with a normal method call. > Or maybe, what are your real requirements? ;-) Well, there are several levels being discussed: 1) Something that fixes the broken name mangling in the current system, but still doesn't try to defeat intentional unmangling. Currently, if you have a class with the same name as one of its superclasses, the name mangling can fail even its existing purpose of preventing accidental collisions. 2) Something that makes code audits more reliable, by guaranteeing that private variables are inaccessible outside the class definition, maybe excepting if the client code does something very bizarre like using bytecode munging. Using a documented name mangling feature would not count as bizarre--it's there to be used, so you have to assume that it's being used. 3) Something that makes serious effort to enforce privacy against determined attackers, like Java does. This can be used to implement either privilege separation inside an app (like my crypto library now uses a separate process and RPC for that purpose) or as a container for potentially hostile foreign code (applet sandbox). I'm not really calling for anything to be added to Python (especially at levels 2 or 3), since the difficulties are pretty substantial. I'm mainly trying to answer the people who say such a feature is useless. From winexpert at hotmail.com Wed Oct 12 10:48:50 2005 From: winexpert at hotmail.com (David Stockwell) Date: Wed, 12 Oct 2005 14:48:50 +0000 Subject: Very dumb question In-Reply-To: <434D1211.6010903@designaproduct.biz> Message-ID: Indeed, Are you writing a new book? http://www.amazon.com/exec/obidos/ASIN/1563052857/wildwierdmathpro David ------- Surf a wave to the future with a free tracfone http://cellphone.duneram.com/index.html >From: Laszlo Zsolt Nagy >To: python-list at python.org >Subject: Very dumb question >Date: Wed, 12 Oct 2005 15:39:29 +0200 >I have a program with this code fragment: > > print len(data) > print data[:50] > raise SystemExit > >This prints: > >20381 > >But if I change 50 to 51 > > print len(data) > print data[:51] > raise SystemExit > >then it prints > >20381 > !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" > >After all, only the last 50 bytes are printed. The string is the same >(length 20381) in both cases. >Surprisingly, I can print more than 50 characters, this works: > >print "012345678901234567890123456789012345678901234567890123456789A" > >I'm sure it is my mistake, but I don't know what am I doing wrong. Do >you have an idea? >Thanks, > > Les > >-- >http://mail.python.org/mailman/listinfo/python-list From microsnot at MUNGED.hotmail.com Mon Oct 24 07:06:39 2005 From: microsnot at MUNGED.hotmail.com (microsnot) Date: Mon, 24 Oct 2005 21:06:39 +1000 Subject: IDE recommendation please References: Message-ID: > Just look in the archives of the Pythonmac mailinglist. We have > discussed this very subject intensively recently, with a pretty > extensive review of the different IDEs available. Looking through the mailing list. Any specific subject/dates I should be looking for? >> Suggestions for plugins for Eclipse would also be nice. > > Err, Eclipse (imho) is a H-O-G. Couldn't agree more... But all so useful for Java. From spe.stani.be at gmail.com Mon Oct 17 14:19:25 2005 From: spe.stani.be at gmail.com (SPE - Stani's Python Editor) Date: 17 Oct 2005 11:19:25 -0700 Subject: Installing Python at Work References: <1129561955.452114.53290@g44g2000cwa.googlegroups.com> Message-ID: <1129573165.311439.104080@g49g2000cwa.googlegroups.com> You even don't have to install Python on your system. Michael Foord created Movable Python (http://www.voidspace.org.uk/python/movpy/), which allows you to carry a full python distribution and more to be carried around on a USB stick. You can copy it to a folder on your harddisk. Just delete the folder when you're done. This is very handy when you're travelling and don't want to carry a laptop around. Stani -- SPE - Stani's Python Editor http://pythonide.stani.be From Tomasik at 2kop.mil.pl Tue Oct 18 11:50:35 2005 From: Tomasik at 2kop.mil.pl (Robert) Date: Tue, 18 Oct 2005 17:50:35 +0200 Subject: wxPython + pyPlot References: Message-ID: Philippe C. Martin wrote: > I think wxWidget comes with a sample > > Philippe Yes I use it, but there is not a sample with pyplot. Robert From steve at holdenweb.com Fri Oct 21 07:39:25 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 21 Oct 2005 12:39:25 +0100 Subject: classmethods, class variables and subclassing In-Reply-To: <4358C7A6.1040907@bakerjaffe.plus.com> References: <4357EE59.1000005@bakerjaffe.plus.com> <43588b5c$0$6536$ed2619ec@ptn-nntp-reader01.plus.net> <4358C7A6.1040907@bakerjaffe.plus.com> Message-ID: Andrew Jaffe wrote: > Steve Holden wrote: > >>Andrew Jaffe wrote: >> >> >>>The problem is that I actually do want to call these methods on the >>>class itself, before I've made any instances. >>> >> >>Except you could use staticmethods with an explicit class argument ... > > > Steve, > > Yep, that would work! Thanks. > > But it does seem like a bit of a kludge: classmethods seems to be almost > exactly what you 'ought' to use here (i.e., I really do want to apply > these methods to the class as an object in its own right). > What's the use case? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From lasse at vkarlsen.no Sun Oct 16 14:31:52 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Sun, 16 Oct 2005 20:31:52 +0200 Subject: How to get a raised exception from other thread In-Reply-To: References: <1129326320.914350.171460@o13g2000cwo.googlegroups.com> <1129434185.879062.61600@o13g2000cwo.googlegroups.com> <1129434873.307336.112030@g47g2000cwa.googlegroups.com> <1129438147.182266.196790@g44g2000cwa.googlegroups.com> Message-ID: Peter Hansen wrote: > themightydoyle at gmail.com wrote: > >> Nevermind. I found a better solution. I used shared memory to create >> a keep-alive flag. I then use the select function with a specified >> timeout, and recheck the keep-alive flag after each timeout. > > > As Dennis points out, your original attempt was destined to fail because > you were calling the method from the main thread, not the one you wanted A similar problem exists in .NET but they "solved" it by creating an Abort method that raises an exception in the thread itself, basically doing what you wanted to do. However, this leads to all sorts of problem, particular when that exception is raised in a finally block in that thread, which could mean that the finally block did not fully execute, leading to resource leaks or similar problems. They pondered a while about constructing non-interruptible blocks of code for .NET 2.0 but I'm not entirely sure how that worked out. In any case, the best way is to use some kind of signal that the thread reacts to, either by having it specifically wait for a signallable object (like an event) or just by checking a boolean variable or similar for a magic value that means "now is a good time for you to terminate". -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From russandheather at gmail.com Wed Oct 19 13:27:12 2005 From: russandheather at gmail.com (Russell Warren) Date: 19 Oct 2005 10:27:12 -0700 Subject: Threads and socket.setdefaulttimeout In-Reply-To: References: <1128030031.130958.185620@z14g2000cwz.googlegroups.com> <1129142005.610543.212180@o13g2000cwo.googlegroups.com> Message-ID: <1129742832.414652.104230@o13g2000cwo.googlegroups.com> Thanks for the detailed repsone... sorry for the lag in responding to it. After reading and further thought, the only reason I was using setdefaulttimeout in the first place (rather then using a direct settimeout on the socket) was because it seemed like the only way (and easy) of getting access to the seemingly deeply buried socket being used by xmlrpclib. That was prior to me using threads of course. I then started trying to make this solution work with thread, but it is now too convoluted as you say. Now I think the best solution is likely to redirect my efforts at getting access to the socket used by xmlrpclib so that I can set it's timeout directly. I'm still unclear how to do this cleanly, though. Getting to some of your comments. > When you say "one thread affects another", I see that your example uses > the same function for both threads. IMHO it's much better to override > the thread's run() method than to provide a callable at thread creating > time. That way you can be sure each thread's execution is firmly in the > context of the particular thread instance's namespace. > > having said all this, I don't think that's your issue. Correct - the bottom code is nothing to do with my code and was only to quickly prove that it was cross-thread. > This seems extremely contorted, and I'm pretty sure we can find a better > way. Couldn't agree more! > The threads' network calls should be yielding process control during > their timeout period to allow other runnable threads to proceed. That's Yep. This is not causing me any problem. > You are aware, I presume, that you can set a timeout on each socket > individually using its settimeout() method? Yes, but I momentarily had forgot about it... as mentioned I ended up making the since-bad choice of using setdefaulttimeout to get timeouts set on the inaccessible sockets. Then I carried it too far... > See above. However, this *does* require you to have access to the > sockets, which is tricky if they are buried deep in some opaque object's > methods. Any help on how to crack the safe would be appreciated. > There are locks! I suspect what you need is a threading.Rlock object, > that a thread has to hold to be able to modify the (global) default > timeout. This isn't a full solution to your problem, though, as you have > correctly deduced. Not quite what I was after I don't think since potentially interfering code needs to check the lock (via acquire) to avoid conflict. What I guess I mean is something general for the process saying "never ever interrupt this block og code by running code on another thread, regardless of whether the other thread(s) check a lock". Thinking more about it it seems unreasonable so I'll drop the question. Russ From bokr at oz.net Sat Oct 29 03:27:34 2005 From: bokr at oz.net (Bengt Richter) Date: Sat, 29 Oct 2005 07:27:34 GMT Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <87y84dix2r.fsf@ieee.org> <1130507496.591640.36260@g44g2000cwa.googlegroups.com> Message-ID: <43631fce.1247046678@news.oz.net> On 28 Oct 2005 06:51:36 -0700, "pinkfloydhomer at gmail.com" wrote: >First of all, this isn't a text file, it is a binary file. Secondly, >substrings can overlap. In the sequence 0010010 the substring 0010 >occurs twice. > ISTM you better let others know exactly what you mean by this, before you use the various solutions suggested or your own ;-) a) Are you talking about bit strings or byte strings? b) Do you want to _count_ overlapping substrings??!! Note result of s.count on your example: >>> s = '0010010' >>> s.count('0010') 1 vs. brute force counting overlapped substrings (not tested beyond what you see ;-) >>> def ovcount(s, sub): ... start = count = 0 ... while True: ... start = s.find(sub, start) + 1 ... if start==0: break ... count += 1 ... return count ... >>> ovcount(s, '0010') 2 Regards, Bengt Richter From steve at REMOVETHIScyber.com.au Mon Oct 24 08:07:26 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 24 Oct 2005 22:07:26 +1000 Subject: Would there be support for a more general cmp/__cmp__ References: Message-ID: On Mon, 24 Oct 2005 09:23:58 +0000, Antoon Pardon wrote: > Op 2005-10-21, Christopher Subich schreef : >> Antoon Pardon wrote: >>> It would be better if cmp would give an indication it >>> can't compare two objects instead of giving incorrect >>> and inconsistent results. >> >> If two objects aren't totally comparable, then using 'cmp' on them is >> ill-defined to begin with. > > Where is that documented? Surely that is so obvious, it doesn't need documenting? If comparisons aren't defined between two things ("which is longer, water or fire?") then comparing them is ill-defined. On second thoughts... no, I don't believe it is so obvious. People are used to thinking about comparisons in the context of numbers and strings, and it won't hurt to remind them that not every pair of objects can be compared. >> The Standard Thing To Do is throw an >> exception; see the Highly Obscure Case of the Complex Numbers. >> >> >>>1 == 1j >> False >> >>>1 != 1j >> True >> >>>1 < 1j >> Traceback (most recent call last): >> File "", line 1, in ? >> TypeError: cannot compare complex numbers using <, <=, >, >= > > I would say this is the wrong answer. The right answer should > be False IMO. I'm afraid that mathematically you are wrong. Greater and less than is not defined for complex numbers. I think I see where you are coming from: you are reading "1 < 1j" as "is one less than one*j", the answer to which is "no". That's a sensible answer to a sensible question, except for two problems: (1) you will upset the mathematical purists, who argue that the English sentence is not quite the same as the mathematical relation; and (2) you will upset the programmers, since your suggestion would create a whole class of gotchas and bugs, where people wrongly assume that since 1<1j is False, 1>1j should be True. This is one case where practicality *is* purity. > Especially in the following case do I think the TypeError is the wrong > answer: > >>>> 3 + 0j < 2 + 0j > Traceback (most recent call last): > File "", line 1, in ? > TypeError: cannot compare complex numbers using <, <=, >, >= That's an interesting case. A mathematical purist might argue that ordering is not defined for complex numbers, even if the imaginary component is zero. A *different* purist might argue: 3 = 3+0j 2 = 2+0j then since 3 > 2 it should also be true that 3+0j > 2+0j. I can see merit in both arguments, but I'm inclined to go with the second argument, if and only if the imaginary component is exactly zero. I take comfort in the fact that mathematicians allow continued fractions with zero terms even though dividing by zero is verboten. > Look at sets: > >>>> set([1]) <= set([2]) > False >>>> set([2]) <= set([1]) > False No, sorry, you are making a mistake. In the context of sets, the < operator doesn't mean "less than", it means "is a subset of". It is correct to say neither "set([1]) is a subset of set([2])" nor vice versa is true. Both are false. By analogy, one can ask, "is the cat inside the box?" and get the answer "No", but this does not imply that therefore the box must be inside the cat. [snip] >> So your use-case is already well-defined, and rather simple. Make >> __cmp__ raise an exception of your choice, > > That is not well defined. It doesn't allow to distinghuish between > something went wrong in __cmp__ and and answer that indicates the only > usefull thing you can say is that they are unequal. Agreed there: there should be a distinct exception for trying to compare incomparable objects, rather than ValueError or TypeError. > Besides I find the following result inconsistent: > >>>> set([1]) <= set([1,2]) > True >>>> cmp(set([1]), set([1,2])) > Traceback (most recent call last): > File "", line 1, in ? > TypeError: cannot compare sets using cmp() > > The first set is smaller than the second so acoording to the > documentation, I should get a negative number as a result. No, the first expression tests whether set([1]) is a subset of set([1,2]), not whether it is "smaller". Smaller and bigger aren't defined for sets. Informally, we can say that one set is smaller than another if it has fewer members, but that's only one possible definition of "smaller" out of many. Think, for example, of the set of all US military forces. That has one member. Compare it to the set of all US presidents whose surname is or was Bush. That set has two members. Do you think it is sensible definition of "smaller" to say that the set of US military forces is smaller than the set of Presidents called Bush? [snip] >> then your >> _ONLY_ choices, no matter your implementation, is to return some >> possibly inconsistent result (a < b == 1, b < c == 1, a < c == 0) or >> raise an exception for unapplicable comparisons. >> >> This isn't a Python problem; this is a problem from formal mathematics. > > I think it is python's problem if python gives the wrong results. > > when a < b then cmp(a,b) should give a negative number as a result. > Python sometimes does not! > > when not a < b then cmp(a,b) should not give a negative number as a > result. Python sometimes does! > > I think those are python problems. I think you need to give examples of where < or > *defined as comparisons* returns the wrong results. The examples from sets do not count, because the operators aren't being used for comparisons. >> Personally, I'd favor the "raise an exception" case, which is exactly >> what will happen if you define rich comparisons and let cmp throw an >> exception. > > But I don't want cmp to raise an exception when the two elements are > comparable. > > That cmp(set([1]), set([2])) would raise an exception, I can understand, > although I would prefer it returned None, but why should cmp(set([1]), > set([1,2])) raise an exception. There is a perfectly well defined answer > for this. Alas, there is not. First you have to define what "less than" and "greater than" means for sets, and there is no well-defined answer to that. They certainly don't mean "is a subset" and "is a superset". Nor is it sensible to define them in terms of the number of elements: def lt(set1, set2): """Defines less than for sets in terms of the number of elements.""" return len(set1) < len(set2) def gt(set1, set2): """Defines greater than for sets in terms of the number of elements.""" return len(set1) > len(set2) py> lt( set([1]), set([1, 2]) ) True py> gt( set([1]), set([1, 2]) ) False So far so good. But now: py> lt( set([1]), set([2]) ) False py> gt( set([1]), set([2]) ) False py> set([1]) == set([2]) False So set([1]) is neither less than, nor greater than, nor equal to set([2]). >> Operators that assume comparable objects, like sort, also almost always >> assume a total order -- inconsistent operations can give weird results, >> while throwing an exception will at least (usually) give some sort of >> error that can be caught. > > No it wont. the sort method will happily sort a list of sets. > >>>> lst > [set([1]), set([2])] >>>> lst.sort() That's an accident of implementation. Sorting nows uses only <, rather than __cmp__, and since < (subset) for sets is defined, sort blindly goes and sorts the list. However, look at this: py> from sets import Set as set py> L1 = [set([1]), set([2]), set([3])] py> L2 = [set([2]), set([3]), set([1])] Notice that L1 and L2 contain the same elements, just in different orders. Sorting those two lists should give the same order, correct? py> L1.sort() py> L2.sort() py> L1 [Set([1]), Set([2]), Set([3])] py> L2 [Set([2]), Set([3]), Set([1])] Should, but doesn't. Oops. That's a bug. Personally, I argue that sorting is something that you do to lists, and that all lists should be sortable regardless of whether the objects within them have a total order or not. If not, the list should impose a sensible ordering on them, such as (perhaps) lexicographical order ("dictionary order"). Look at it this way: books do not have a total ordering. What does it mean to say that Tolstoy's "War and Peace" is less than Tom Clancy's "The Hunt For Red October"? Are we comparing by title? Author? Contents? Cost of the book, dimensions of the book, number of pages, some subjective idea of quality, average word length, maximum sentence length, publication date, number of protagonists, or what? And yet libraries somehow find no difficulty in sorting shelves of hundreds or thousands of books. So in my opinion, sorting is a red-herring. In an ideal world (Python 3 perhaps?) sorting will be divorced from comparisons, or at least seeing other people. But that still leaves the problem of comparisons. -- Steven. From mlist at fastwebnet.it Wed Oct 5 08:16:06 2005 From: mlist at fastwebnet.it (billie) Date: Wed, 5 Oct 2005 14:16:06 +0200 Subject: Build spoofed IP packets References: Message-ID: > Yes, give us the error. And know that you can't build raw IP packets > unless you're root. > > Sybren Sorry. I forgot to paste the error: Traceback (most recent call last): File "C:\test\client.py", line 156, in ? send_pkt() File "C:\test\client.py", line 96, in send_pkt s.sendto(ip.get_packet(), (dst, 0)) # send packet to server socket.error: (10004, 'Interrupted system call') Note: this only happens on Windows XP prof SP2. On Linux I got no problems. I run the program as Administrator. From ms at cerenity.org Mon Oct 3 13:53:59 2005 From: ms at cerenity.org (Michael) Date: Mon, 03 Oct 2005 18:53:59 +0100 Subject: Where to find python c-sources References: <433e7898$0$49766$ed2e19e4@ptn-nntp-reader04.plus.net> Message-ID: <43417009$0$15070$ed2619ec@ptn-nntp-reader02.plus.net> John J. Lee wrote: > [Tor Erik S?nvisen] >> socketmodule.c, but I can't locate this file... Where should I look? > > [John, finding 'socketmodule.c' responds well to "I'm Feeling Lucky"] >> Does google vary in its results across the globe? > > [Michael] >> The search terms might be obvious to you, but it simply means your >> google-fu is strong, and the strong should help the weak. (or not attack >> them at least...) > > You believe that Tor is dumb enough not to think of searching for > "socketmodule.c" when, um, searching for socketmodule.c? He said he had tried google - OK, not in the first post but early in this thread - I don't equate that with being dumb - just dumb luck :-) Message-ID: After all Peter Hansen suggested the search terms "python socketmodule.c" rather than just "socketmodule.c" Message-ID: <5N-dnZny3YyaA6HenZ2dnUVZ_tKdnZ2d at powergate.ca> To you the obvious search term was "socketmodule.c" which to me simply means you're more aligned with Google than Tor :-) These things happen :-) Regards, Michael. From amichail at gmail.com Tue Oct 4 08:47:58 2005 From: amichail at gmail.com (Amir Michail) Date: 4 Oct 2005 05:47:58 -0700 Subject: cgi relay for python cgi script References: <1128411305.541560.90790@g44g2000cwa.googlegroups.com> <1128427778.421720.205370@g43g2000cwa.googlegroups.com> Message-ID: <1128430078.513687.264950@g14g2000cwa.googlegroups.com> Fredrik Lundh wrote: > Amir Michail wrote: > > > Is there an easy way to do this without modifying the configuration of > > the cgi server and without running a cgi server on the other machine > > where the script will actually run? > > > > Perhaps someone wrote a simple server that provides the required > > environment for the cgi script to run? > > > > I'm looking for something simple that does not require root access. > > you could of course use something like > > http://docs.python.org/lib/module-CGIHTTPServer.html > > or some other light-weight web server, but you should probably have in mind > that doing things like this without coordinating with your server administrators > and security architects *before* you start tinkering can be a excellent way to > get fired... > > I would like to do this to improve performance by avoiding nfs. (The required data is not on the cgi server.) The advice I got was to use something like MySQL with a client/server architecture. However, I thought it would be easier to simply run the core part of the script off the cgi server, thereby avoiding nfs for data lookups. So I guess the point is that such a solution is more likely to be a security risk than MySQL? Amir From lycka at carmen.se Wed Oct 12 02:59:02 2005 From: lycka at carmen.se (Magnus Lycka) Date: Wed, 12 Oct 2005 08:59:02 +0200 Subject: List performance and CSV In-Reply-To: References: <1128784783.256285.24680@z14g2000cwz.googlegroups.com> Message-ID: jepler at unpythonic.net wrote: > But a really fast approach is to use a dictionary or other structure > that turns the inner loop into a fast lookup, not a slow loop through > the 'Customers' list. Another approach is to sort both sequences, loop over both in one loop and just update the index for the smaller item. Something like this (below, I'm assuming no duplicates in the lists, and I don't know if that's true for your [2]): >>> l1 = (1,2,4,6,7,8,9) >>> l2 = (2,5,6,7,9,10) >>> i1 = i2 = 0 >>> while 1: ... if l1[i1]==l2[i2]: ... print l1[i1], 'is in both' ... i1 += 1; i2 += 1 ... elif l1[i1]", line 2, in ? IndexError: tuple index out of range Unless I'm terribly confused, this will lead to m+n iterations in the worst case. (Of course, the sort operations are something like O(n log n) I guess.) By the way, you might be able to use sets too: How fast is Set.intersection? From xah at xahlee.org Wed Oct 19 05:48:01 2005 From: xah at xahlee.org (Xah Lee) Date: 19 Oct 2005 02:48:01 -0700 Subject: write a loopin one line; process file paths In-Reply-To: <1129710240.173768.151950@g14g2000cwa.googlegroups.com> References: <1129672592.328278.41490@g14g2000cwa.googlegroups.com> <1129696357.539158.233870@g47g2000cwa.googlegroups.com> <1129699998.324180.56530@f14g2000cwb.googlegroups.com> <1129701270.792327.168620@z14g2000cwz.googlegroups.com> <1129708210.963305.43270@g49g2000cwa.googlegroups.com> <1129710240.173768.151950@g14g2000cwa.googlegroups.com> Message-ID: <1129715281.505043.60640@o13g2000cwo.googlegroups.com> Thanks a lot for various notes. Bonono? I will have to look at the itertools module. Just went to the doc http://www.python.org/doc/2.4.1/lib/module-itertools.html looks interesting. > But I believe Python is designed for easy to code and read and maintain > in mind. > One has to admit that without some training, FP is not very > intuitive, my head spin when I see haskell code. A for loop is easier > to understand. This i'm not sure. Of the past couple of years i increasingly developed a theory (probably well-known among proper experts), that the difficulty of human feats of various forms, are primarily a perception and familiarity thing. This may be getting off topic, but i wrote an essay expresising much of the idea using Juggling as a example: Difficulty Perceptions in Human Feats http://xahlee.org/Periodic_dosage_dir/t2/juggling.html likewise, i think this applies to mental feats as well. In particular, i think that whether imperative code or functional code is easier for the mind is almost ENTIRELY dependent on which one the person is more familiar with, coulped with a innate attitude one may have picked up. > Well, if you want clean FP, you can always try haskell which is getting > better and better in terms of real world module support(file system, > network etc). oh Haskell, my love! I am really going to learn it now. (maybe i'll start A-Java-Haskell-A-Day) This month i just learned and read about how Perl 6 is implemented in Haskell! (because one Taiwaness hacker single-handedly by happenstance tried to do it, as a by-product of learning Haskell) This Pugs (Perl6 in Haskell) really brought two rather incompatible communities together somewhat for mutual exchange. (the learning, on the surface, is politely said to be mutual, but i'm pretty sure it's mostly Perlers learning from the Haskell folks) ... there is a sentiment among the elite tech-geeking morons, early on imbued by the concept of troll, so that they in general don't communicate and learn from any other language except their own. Anything cross-posted is considered as troll, and the inter-language communication has been essentially completely cut off. Basically, the only ones generating all the garbage posts are these troll-criers themselves. (will have to flesh out on this particular point of net-sociology in a essay some other day.) Xah xah at xahlee.org ? http://xahlee.org/ From jparlar at cogeco.ca Fri Oct 14 02:02:23 2005 From: jparlar at cogeco.ca (Jay Parlar) Date: Thu, 13 Oct 2005 23:02:23 -0700 Subject: setuptools, ez_setup over http proxy In-Reply-To: References: Message-ID: <65ebe4ca2322dd26d763d2c442ef492f@cogeco.ca> > I've recently configured my network such that I use squid as a http > proxy. I'd now like to be able to use setuptools and ez_setup via this > proxy. Is this possible? If so, how do I do it? It should work if you sent the environment variable (in your shell) 'http_proxy' to the address of your proxy. Python's urllib will then be able to pull it, and everything should magically work. Something like: export http_proxy='http://some_squid_server' > "....If you are behind an NTLM-based firewall that prevents Python > programs from accessing the net directly, you may wish to first install > and use the APS proxy server, which lets you get past such firewalls in > the same way that your web browser(s) do..... As far as I know, this is only a problem if you're using a particular proxy server from Microsoft. > ps. I'm not sure that this is the right forum for this question. If it > isn't feel free to point me to the right place. The distutils list would be the more appropriate place for setuptools questions in general. Jay P. From robert.kern at gmail.com Mon Oct 3 10:33:25 2005 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 03 Oct 2005 07:33:25 -0700 Subject: morphological image processing in Python In-Reply-To: References: Message-ID: Alexandre Fayolle wrote: > Hello, > > I'm about to start a project which will involve some greyscale image > processing using morphological operators (erosion, dilation, distance > transforms...), and I was wondering if these operators were available in > Python through some open source libraries. > > A quick google search returned pymorphpro[1], which is unfortunately not > free software, and there also seem to be something available in ITK [2]. > Unless I'm mistaken, the PIL does not provide these operations, nore do > Numeric/numarray/scipy. > > Have I missed the one true Python mathematical morphology toolbox? numarray http://stsdas.stsci.edu/numarray/numarray-1.3.html/module-numarray.ndimage.html This will be ported to the new scipy shortly. We could use some help. -- 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 davids at webmaster.com Thu Oct 27 08:59:01 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 05:59:01 -0700 Subject: Microsoft Hatred FAQ References: <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> <20i1m19cup3s8hb4ikqti1monvtf9nb3dv@4ax.com> <1130417740.645004.151310@z14g2000cwz.googlegroups.com> Message-ID: Iain King wrote: > David Schwartz wrote: >> Roedy Green wrote: >> >>> The particular way MS threatened to put me out of business was by >>> threatening to arm twist all wholesalers to refuse to sell MS >>> product to me, which any retailer needed to survive in those days. >> >> Right, I get that. You owed your entire business to Microsoft. >> Without their products, you would have had nothing, by your own >> admission. The way you repay them is by trying to screw them -- >> attract people who come in only because you offer Windows and then >> say "here's an OS that's better and cheaper". > > Oh right. You're actually just a troll. Oh well. > > *plonk* I see, he presents the strongest possible anti-Microsoft argument (including analogizing Microsoft to people who *KILL* people) and that's fine with you. I present the strongest possible pro-Microsoft argument, and I must be a troll. Right ... If you think I'm a troll, why don't you try googling for all my posts on USENET. DS From zanesdad at bellsouth.net Wed Oct 26 08:21:02 2005 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Wed, 26 Oct 2005 08:21:02 -0400 Subject: OT: Re: Windows vs Linux [was: p2exe using wine/cxoffice] In-Reply-To: <9A28C052FF32734DACB0A288A3533991044D22A1@vogbs009.gb.vo.local> References: <9A28C052FF32734DACB0A288A3533991044D22A1@vogbs009.gb.vo.local> Message-ID: <435F74AE.2030201@bellsouth.net> Tim Golden wrote: >As it happens, (and I suspect I'll have to don my flameproof suit here), >I prefer the Windows command line to bash/readline for day-to-day use, >including in Python. Why? Because it does what I can't for the life of >me get readline to do: you can type the first few letters of a >previously-entered command and press F8. This brings up (going backwards > >with further presses) the last command which starts like that. And >*then* >you can just down-arrow to retrieve the commands which followed it. >If someone can tell me how to do this with bash/readline I will be >indebted to them and it will increase my chances of switching to Linux >a bit! > Others have recommended ctrl-r in bash. People's tastes vary, but that has an awkward feel for me. In zsh, you just type in as many letters as you care to match and hit the "up" arrow. But, honestly, this is a bit annoying to me. If I've begun to type in a command, realize it's not what I want, but instead, I want to go back in my history a couple of commands, I hit the "up" arrow to find to my irritation that it's pattern matching rather than going directly back in my history. I guess it comes in handy at times, though.... - jmj From rrr at ronadam.com Tue Oct 25 02:07:17 2005 From: rrr at ronadam.com (Ron Adam) Date: Tue, 25 Oct 2005 06:07:17 GMT Subject: namespace dictionaries ok? In-Reply-To: References: Message-ID: James Stroud wrote: > Oops. Answered before I finished reading the question. > > James Well, the one bad side effect (or feature depending on the circumstance), is it makes a copy. I wonder if there is a way to modify the dictionary in place with a function to do the same thing instead of creating a new object? Cheers, Ron > On Monday 24 October 2005 19:53, Ron Adam wrote: > >>James Stroud wrote: >> >>>Here it goes with a little less overhead: >>> >>> >>>py> class namespace: >>>... def __init__(self, adict): >>>... self.__dict__.update(adict) >>>... >>>py> n = namespace({'bob':1, 'carol':2, 'ted':3, 'alice':4}) >>>py> n.bob >>>1 >>>py> n.ted >>>3 >>> >>>James >> >>But it's not a dictionary anymore so you can't use it in the same places >>you would use a dictionary. >> >> foo(**n) >> >>Would raise an error. >> >>So I couldn't do: >> >> def foo(**kwds): >> kwds = namespace(kwds) >> kwds.bob = 3 >> kwds.alice = 5 >> ... >> bar(**kwds) #<--- do something with changed items >> >>Ron >> >> >>>On Monday 24 October 2005 19:06, Ron Adam wrote: >>> >>>>Hi, I found the following to be a useful way to access arguments after >>>>they are passed to a function that collects them with **kwds. >>>> >>>> >>>> class namespace(dict): >>>> def __getattr__(self, name): >>>> return self.__getitem__(name) >>>> def __setattr__(self, name, value): >>>> self.__setitem__(name, value) >>>> def __delattr__(self, name): >>>> self.__delitem__(name) >>>> >>>> def foo(**kwds): >>>> kwds = namespace(kwds) >>>> print kwds.color, kwds.size, kwds.shape etc.... >>>> >>>> foo( color='red', size='large', shape='ball', .... etc..) >>>> >>>> >>>>It just seems awkward to have to use "string keys" in this situation. >>>>This is easy and still retains the dictionary so it can be modified and >>>>passed to another function or method as kwds again. >>>> >>>>Any thoughts? Any better way to do this? >>>> >>>>Cheers, Ron > > From maketo at norge.freeshell.org Tue Oct 11 12:17:36 2005 From: maketo at norge.freeshell.org (Ognen Duzlevski) Date: Tue, 11 Oct 2005 16:17:36 +0000 (UTC) Subject: Python's Performance References: <20051008040614.47429.qmail@web30607.mail.mud.yahoo.com> <43495259$0$29124$626a14ce@news.free.fr> <178B879D-FDB6-458C-BE00-A03820D98703@advfn.com> Message-ID: Fredrik Lundh wrote: > Alex Stapleton wrote > > Except it is interpreted. > except that it isn't. Python source code is compiled to byte code, which > is then executed by a virtual machine. if the byte code for a module is up > to date, the Python runtime doesn't even look at the source code. I am curious, does this make a difference speed wise (aside from loading time)? The python tutorial would seem to imply that it does not: >From Python-Docs-2.4.2/tut/node8.html#SECTION008120000000000000000 "A program doesn't run any faster when it is read from a .pyc or .pyo file than when it is read from a .py file; the only thing that's faster about .pyc or .pyo files is the speed with which they are loaded." Thanks, Ognen From mekstran at scl.ameslab.gov Thu Oct 13 11:29:35 2005 From: mekstran at scl.ameslab.gov (Michael Ekstrand) Date: Thu, 13 Oct 2005 10:29:35 -0500 Subject: Well written open source Python apps In-Reply-To: <1129214592.342917.100090@g43g2000cwa.googlegroups.com> References: <1129214592.342917.100090@g43g2000cwa.googlegroups.com> Message-ID: <200510131029.35504.mekstran@scl.ameslab.gov> On Thursday 13 October 2005 09:43, Ben wrote: > Could anyone suggest an open source project that has particularly > well written Python? I am especially looking for code that people > would describe as "very Python-ic". (Not trying to start any kind of > war - just wanted some good examples of a well written Python app to > read.) The Python Standard Library. Thousands of lines of quite good Python code. It might not use all the latest features, and there might be a few dark corners here and there, but it's still solid. And quite easy to understand (I had no difficulty understanding and modifying httplib). - Michael From ptb at oboe.it.uc3m.es Sat Oct 15 02:27:41 2005 From: ptb at oboe.it.uc3m.es (Peter T. Breuer) Date: Sat, 15 Oct 2005 08:27:41 +0200 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: In comp.os.linux.misc Jeroen Wenting wrote: > Without Microsoft 90% of us would never have seen a computer more powerful > than a ZX-81 and 90% of the rest of us would never have used only dumb > mainframe terminals. Uh - when microsoft produced dos 1.0, or whatever it was, I was sitting at my Sun 360 workstation (with 4M of RAM, later upgraded to 8M), running SunOS 3.8 or thereabouts. And a mean game of tetris it played too. Chess wasn't worth the humiliation at level 5. I believe every researcher in britain got one as a matter of course, but they only replaced the perq machines that everyone had had to put up with before then. The vaxen running hpux or so were plentiful too, and had fine monitors, tending more to the PC shape. We'd made our own word processor machines and spreadsheet automatons before that. It didn't take that many components, just a good engineer and a room full of lackeys with soddering irons. The BBC were selling kits too (what were they? Ataris?), not that I ever fell for that. Maybe five years earlier I'd designed and built my own computer from scratch using the MC 6802 chip as processor. Somebody really should have told me about assembler - I wrote in machine code, flashing the code into prom with a 100ms pulse from a 16V battery. Goodness knows how much memory I had ... maybe a few KB. I think the Suns were abut $30000 each when they first appeared, but prices dropped rapidly so that after maybe three years the standard price was about $8000. PCs had appeared and came in at about $4000, if I recall right, so there was a price differential but it wasn't huge, especially when a Sun could support a whole research team via vt100 lines, and a PC was a one-person job, thanks to the o/s. Peter From sll_noSpamlicious_z_XXX_m at cc.usu.edu Tue Oct 25 19:47:21 2005 From: sll_noSpamlicious_z_XXX_m at cc.usu.edu (Luc The Perverse) Date: Tue, 25 Oct 2005 17:47:21 -0600 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: <435ec42c$0$8247$3a2ecee9@news.csolutions.net> "Steven D'Aprano" wrote in message news:pan.2005.10.25.23.08.43.351 at REMOVETHIScyber.com.au... > On Tue, 25 Oct 2005 11:51:02 -0700, David Schwartz wrote: > >> >> "Steven D'Aprano" wrote in message >> news:pan.2005.10.25.16.12.33.746996 at REMOVETHIScyber.com.au... >> >>> The first two points are factually wrong, and the third is an opinion >>> based on the concept, as far as I can see, that Microsoft should be >>> allowed to do anything they like, even if those actions harm others. >> >> Of course this alleged "harm" is simply a lack of a benefit. >> >> Why is Burger King allowed to close at 10PM? That harms me when I'm >> hungry after 10. > > Burger King doesn't take actions to prevent you from going to another > vendor who will stay open after 10PM, as you very well know. > > Nor is Burger King a monopoly -- if they refuse to open after 10 in the > face of great demand, they only harm themselves. As I said a few days ago, > it is not the place for either us or the government to care about the > success or failure of any specific vendor, but only about the health of > the entire market. As there is no shortage of competition in the fast food > market, the harm done to you by Burger King's refusal to open after 10PM > is not sufficient for anyone to care. If there is significant demand, then > Burger King will merely harm themselves by refusing to open because they > will lose customers to those vendors who do open, and if there is > insignificant demand, then why should anyone care? NO! There ~is~ a conspiracy by Egg farmers to not make burgers available before 10 am. Burger King used to be one of the last great vestiges of the 24 hour burger, and now it's gone. They know no one would buy the shitty egg McMuffins/equivalent if they had delicious burgers available, so there is something underhanded going on behind the scenes. Same thing with pizza. Don't try to tell me that there are not hungry partiers at 3 am - but are any of the delivery places open? NO! Why is it this way? Who knows! But when in doubt, blame the right wing extremist politicians. -- LTP From my_email_is_posted_on_my_website at munged.invalid Wed Oct 12 19:29:23 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 12 Oct 2005 23:29:23 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> Message-ID: >>I think e-mail should be text only. What if, instead of that crap Outlook produces, which is a mishmash of malformed html, Javascript viruses, self-installing enclosures etc. It were replaced by a rich text that were something like a CSS-style HTML, validated, and preparsed, and compacted for rapid rendering. It would have no hooks in it for viruses or code launching, though it would have clearly marked hypertext links. The question I am getting at is what is bugging you the most? 1. spam which is often associated with formatted mail 2. Trojans that exploit MS email. 3. cutsie pie dancing bears 4. sloppy implementation 5. slow email downloads 6. Puritanical objection to any variation in colour and font. It is unmanly. 7. want it impossible to embed images, not just for you but for everyone. No one has a legitimate interest to embed images. Let us say your answer is all 7. My response is the solution is not to revert to plain text for email. It won't happen. The solution is to move forward and fix the implementations. It is one thing to demand all mail sent to you have no formatting, but quite another to demand all mail sent by anyone to anyone have no formatting or embedded images. I think a modern email system should let your correspondents automatically know of your eccentricity so that mail will automatically be stripped to the bone before sending it to you. My ISP has this quirk and gets irate if I ever slip and send him a formatted mail. I would love it if Eudora remembered that for me and automatically prevented me from doing that. Formatted email has quite legit functions. For example the Health Action Network Society has an optional mailing list that will let you know of any upcoming events relevant to alternative health. The mail looks like a little poster for the event. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From ptb at oboe.it.uc3m.es Tue Oct 25 03:24:08 2005 From: ptb at oboe.it.uc3m.es (Peter T. Breuer) Date: Tue, 25 Oct 2005 09:24:08 +0200 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> Message-ID: In comp.os.linux.misc Antoon Pardon wrote: >> I think you need to look up "extortion" in a dictionary. I can walk up >> to you and say "if you want me to mow your lawn, you must pay me $1 every >> time you smoke a cigarette". So long as you can say "no" and all that >> happens is that I don't mow your lawn (which I have no obligation to do >> anyway), it isn't extortion. > If you would happen to have a monopoly on the mowing business, which > would make it very hard for me to have my lawn mowed unless I took > your offer, it would be. In this case the extortion is over smoking a cigarette (it doesn't seem to me to necessitate a monopoly on mowing for the threat to have been deemed to have been made, but perhaps for it to be deemed likely for you to believe it to have teeth) - money is being demanded with menaces for your continued smoking of cigarettes. The threatened menace is that your lawn will find itself not mown. I can certainly also envisage circumstances in which that threat would be very real by virtue of an effective monpoloy in the garden market. Peter From bj_666 at gmx.net Thu Oct 13 18:30:27 2005 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Fri, 14 Oct 2005 00:30:27 +0200 Subject: python interpreter References: Message-ID: In , g.franzkowiak wrote: > my interest is for the internals of the Python interpreter. > > I've used up to now FORTH for something and this indirect interpreter is > very smart. > --- ASM --------------------------------------------------------------- > > NEXT: LODSW ; WA <- [IP] > ; IP <- IP+2 > MOV T,WA ; T <- WA1 (CFA) > JMP [T] ; JMP [CFA] > > --- C ----------------------------------------------------------------- > > for (;;) > { > w = *ip++; > (**w) (); > } > > ------------------------------------------------------------------------- > > Where can I find informations like this for Python ? I don't really grok the assembler code. The C code seems to assume that there is an infinitive number of function pointers stored at `*ip`!? The Python equivalent might be :: for w in ip: w() if `ip` is a (finite) sequence of functions or callables in general. Ciao, Marc 'BlackJack' Rintsch From kent37 at tds.net Fri Oct 21 22:34:42 2005 From: kent37 at tds.net (Kent Johnson) Date: Fri, 21 Oct 2005 22:34:42 -0400 Subject: coloring a complex number In-Reply-To: References: Message-ID: <4359a337$1_1@newspeer2.tds.net> Arthur wrote: > Spending the morning avoiding responsibilities, and seeing what it would > take to color some complex numbers. > > class color_complex(complex): > def __init__(self,*args,**kws): > complex.__init__(*args) > self.color=kws.get('color', 'BLUE') In general when you subclass an immutable type you have to override __new__ rather than __init__. There is some explanation and example here: http://www.python.org/2.2.3/descrintro.html#__new__ Kent From quiteblack at gmail.com Tue Oct 11 10:16:37 2005 From: quiteblack at gmail.com (quiteblack at gmail.com) Date: 11 Oct 2005 07:16:37 -0700 Subject: how to execute .exe file ? Message-ID: <1129040197.719729.22460@g44g2000cwa.googlegroups.com> hi all~ i used to drive .exe file working by writing a simple batch file, i thin python may do this as well bu i dunno how to, any help ? From en.karpachov at ospaz.ru Mon Oct 3 12:30:35 2005 From: en.karpachov at ospaz.ru (en.karpachov at ospaz.ru) Date: Mon, 3 Oct 2005 20:30:35 +0400 Subject: "no variable or argument declarations are necessary." In-Reply-To: References: <434084 3b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99 f9f10238681bf68f@teranews> Message-ID: <20051003203035.486348a9.jk@ospaz.ru> On 3 Oct 2005 13:58:33 GMT Antoon Pardon wrote: > People often promote unittesting here. Writing all those unittest is > an added burden too. But people think this burden is worth it. > > I think writing declaration is also worth it. The gain is not as > much as with unittesting but neither is the burden, so that > balances out IMO +1 Some people just don't get the simple fact that declarations are essentially kind of unit test you get for free (almost), and the compiler is a testing framework for them. -- jk From my_email_is_posted_on_my_website at munged.invalid Mon Oct 17 20:49:35 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Tue, 18 Oct 2005 00:49:35 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> Message-ID: On Mon, 17 Oct 2005 09:37:35 -0700, Alan Balmer wrote or quoted : >You've been around long enough to learn to recognize this poster and >ignore him. Sounds like your plonk filter is on the fritz then. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From mde at micah.elliott.name Fri Oct 7 13:48:20 2005 From: mde at micah.elliott.name (Micah Elliott) Date: Fri, 7 Oct 2005 10:48:20 -0700 Subject: Why do I get an import error on this? In-Reply-To: <1128703953.497560.47620@z14g2000cwz.googlegroups.com> References: <1128703953.497560.47620@z14g2000cwz.googlegroups.com> Message-ID: <20051007174820.GI32363@kitchen.client.attbi.com> On Oct 07, Steve wrote: > I have a simple program: > ____________________________________________ > > #! /home/fergs/python/bin/python > import sys, os > import cx_Oracle > ____________________________________________ > > If I run it through the Python interpreter, this way: > > >> python test.py > > it runs fine. > > But if I try to run it as an executable script, this way: > > >> test.py > > I get an import error that says it can't find cx_Oracle. Are "which python" and "/home/fergs/python/bin/python" the same? If not, it appears that "which python" can see cx_Oracle, but the latter cannot. You could mess with PYTHONPATH or get /home/.../python into the front of your PATH. -- Micah Elliott From theller at python.net Wed Oct 26 10:32:22 2005 From: theller at python.net (Thomas Heller) Date: Wed, 26 Oct 2005 16:32:22 +0200 Subject: Windows vs Linux [was: p2exe using wine/cxoffice] References: Message-ID: "Tim Golden" writes: > [Sybren Stuvel] >> You can't resize it horizontally > > Well, peculiarly, you can do this (as you're probably aware) from > the Properties menu and it'll work immediately, albeit without > advising the running programs that it's resized, so only new > lines will take advantage of the new width. Now, why they didn't > let you do the same thing by grabbing the border and pulling, I > don't know! FYI, if you don't know this already: You also can resize the console without going through the properties menu with 'mode con cols=... lines=...'. Thomas From david.rasmussen at gmx.net Sat Oct 29 18:35:25 2005 From: david.rasmussen at gmx.net (David Rasmussen) Date: Sun, 30 Oct 2005 00:35:25 +0200 Subject: Scanning a file In-Reply-To: <1130614532.765771.288960@g43g2000cwa.googlegroups.com> References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <1130614532.765771.288960@g43g2000cwa.googlegroups.com> Message-ID: <4363f91d$0$2089$edfadb0f@dtext02.news.tele.dk> netvaibhav at gmail.com wrote: > I think implementing a finite state automaton would be a good (best?) > solution. I have drawn a FSM for you (try viewing the following in > fixed width font). Just increment the count when you reach state 5. > > <---------------| > | | > 0 0 | 1 0 |0 > -->[1]--->[2]--->[3]--->[4]--->[5]-| > ^ | | ^ | | | > 1| |<---| | | |1 |1 > |_| 1 |_| | | > ^ 0 | | > |---------------------|<-----| > > If you don't understand FSM's, try getting a book on computational > theory (the book by Hopcroft & Ullman is great.) > I already have that book. The above solution very slow in practice. None of the solutions presented in this thread is nearly as fast as the print file("filename", "rb").read().count("\x00\x00\x01\x00") /David From kylotan at gmail.com Fri Oct 7 05:13:28 2005 From: kylotan at gmail.com (Ben Sizer) Date: 7 Oct 2005 02:13:28 -0700 Subject: "no variable or argument declarations are necessary." In-Reply-To: <7xr7ax690j.fsf@ruckus.brouhaha.com> References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <3qi8erFf252rU1@uni-berlin.de> <3qkdbrFfgga9U1@uni-berlin.de> <3qkn7qFffkl6U1@uni-berlin.de> <3qkr1hFfgj5uU1@uni-berlin.de> <7xr7ax690j.fsf@ruckus.brouhaha.com> Message-ID: <1128676408.129888.297840@g14g2000cwa.googlegroups.com> Paul Rubin wrote: > Let's see if I understand what you're saying: > > C and Java: you get useful type checking except when you declare > a reference as type ANY. This is a shortcoming compared to: > > Python: where you get no useful type checking at all. > > That is not very convincing logic. It's started to get very misleading - Python gives you plenty of type-checking, as we all know, just not at compile-time. Also comparing Python to C/Java as you have done is not very appropriate unless you want Python to have the same sort of compile times as C and Java do. I think you're doing a small disservice to respond to Steve when not acknowledging the context of the thread, where Diez was explaining that the system used in ML would not work in Python, then Antoon made a suggestion that would fix that particular problem but make others worse. I'm not convinced that the Java route - where you type out lengthy type declarations to get some compile-time typechecking which you usually end up having to bypass later anyway - is at all beneficial, at least not in the context of Python. I can't ever remember a time when I thought "type checking really saved me from a bug there" when using C/C++/Java, but I _can_ remember many times where I've had to consider which cast or conversion to use, or had to write another overloaded function to accommodate a similar-but-different type, or debug a complex template message, or add a superfluous base class or interface, all just to get the kind of genericity that Python gives for free. And it's no good saying that variable declarations will be optional, because as soon as these statically-typed variables enter the standard library, every Python programmer will have to take these considerations on board when writing their code, whether we want to use them or not. -- Ben Sizer From chemag at gmail.com Thu Oct 20 14:55:44 2005 From: chemag at gmail.com (chemag at gmail.com) Date: 20 Oct 2005 11:55:44 -0700 Subject: Question on re.IGNORECASE Message-ID: <1129834544.533189.301780@g14g2000cwa.googlegroups.com> Hi, I'm having some problems with basic RE in python. I was wondering whether somebody could provide a hint on what's going wrong with the following script. Comments are included. TIA. -myself > python2.3 Python 2.3.4 (#1, Nov 18 2004, 13:39:30) [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-39)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> pattern = re.compile('.*HTTP/(\d\.\d) *(\d*) *(.*)$') >>> pattern.search("GGHTTP/1.1 200 OK\r\n", re.IGNORECASE) <_sre.SRE_Match object at 0xb75c6ed0> >>> pattern.search("GHTTP/1.1 200 OK\r\n", re.IGNORECASE) # this makes no sense to me. Why is the previous line matched # and this not? >>> pattern.search("GHTTP/1.1 200 OK\r\n") <_sre.SRE_Match object at 0xb758d020> From prince_amir86 at yahoo.com Thu Oct 6 10:12:26 2005 From: prince_amir86 at yahoo.com (Brandon K) Date: Thu, 06 Oct 2005 09:12:26 -0500 Subject: Absolultely confused... In-Reply-To: References: Message-ID: <1128608102_115255@spool6-east.superfeed.net> > If I take out the "!" in the format string and just use "O", I can at > least get past PyArg_ParseTuple. Is this a compile-time error? Or a runtime error? ----== Posted via Newsgroups.com - Usenet Access to over 100,000 Newsgroups ==---- Get Anonymous, Uncensored, Access to West and East Coast Server Farms! ----== Highest Retention and Completion Rates! HTTP://WWW.NEWSGROUPS.COM ==---- From bobrien18 at yahoo.com Fri Oct 14 16:06:27 2005 From: bobrien18 at yahoo.com (KraftDiner) Date: 14 Oct 2005 13:06:27 -0700 Subject: Inheritance... Message-ID: <1129320387.840646.284580@g14g2000cwa.googlegroups.com> I have a base class class geometry(object): def __init__(self): self.blue = 1 self.red = 2 def render(self): pass class square(geometry): def __init__(self): super(square, self).__init__() def render(self) print 'square' class circle(geometry): def __init__(self): super(square, self).__init__() def render(self) print 'square' objLst = [] objLst.append(square()) objLst.append(circle()) for obj in objLst: obj.render() print obj.blue What is wrong with this... I will not print blue... (1) From bonono at gmail.com Sat Oct 22 00:18:52 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 21 Oct 2005 21:18:52 -0700 Subject: access dictionary with preferred order ? Message-ID: <1129954732.769162.62150@g43g2000cwa.googlegroups.com> Hi, I am wondering if there is a dictionary data type that allows me to define the order of access when iterating it using items/keys etc. ? An example: a=dict(a=dict(), c=dict(), h=dict()) prefer=['e','h', 'a'] for x in a.values: print x would give me {h:dict()}, {a:dict()}, then the rest which I don't care about the order ? From gandalf at designaproduct.biz Wed Oct 12 07:23:48 2005 From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy) Date: Wed, 12 Oct 2005 13:23:48 +0200 Subject: Need a spider library In-Reply-To: References: <434CE752.8030509@designaproduct.biz> Message-ID: <434CF244.2060202@designaproduct.biz> Fredrik Lundh wrote: >Laszlo Zsolt Nagy wrote: > > > >>The question: is there a good library for Python for extraction links and images >>out of (possibly malformed) HTML soucre code? >> >> > >http://www.crummy.com/software/BeautifulSoup/ > > Thanks a lot! This is just what I wanted. Why it is not part of the standard Python library yet? :-) From lasse at vkarlsen.no Thu Oct 27 06:08:38 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Thu, 27 Oct 2005 12:08:38 +0200 Subject: Sorting with only a partial order definition In-Reply-To: References: <7x64rjs4w8.fsf@ruckus.brouhaha.com> Message-ID: Lasse V?gs?ther Karlsen wrote: > Paul Rubin wrote: > >> Lasse V?gs?ther Karlsen writes: >> >>> I have a list of items and a "rule" for ordering them. Ok, managed to implement the algorithm. Might not be the optimal solution (memory and speed-wise) but it worked and doesn't take too long to run either so I'm going to stick with it. I have a different question though, along the same lines, but one that doesn't need a solution, just want to know if something like it exists. A while back I had an application that had a lot of items that it needed to order. The problem, however, was that the rules was not defined at all. Instead it was opted for a visual solution where the user would be presented with images and had to rearrange them in the order that was necessary. The application was one I helped build for a friend which combined images from several cameras and allowed him to sort them according to the contents so that he could get a timeline formed. The date/time stamps on the cameras was not directly usable for various reasons so the visual ordering was what we ended up on. For instance, two of the cameras was not digital ones so they had no timestamp except for the one provided by the scanning software. In that application we talked about presenting the user with two and two images and he just had to click on the image that came first. The problem with this was to try to present the "right" images to the user so that he had to minimize the number of clicks. In other words, try to pick nodes in the graph and ask the user to provide the direction of the edge, and the "picking algorithm" would work in such a way that the number of edges would be minimized. Not sure if I'm explaining it correctly. The solution we ended up with was to present the user with all the images in one big timeline and just let him drag them around. This worked. What I was wondering about is if there is an algorithm that would do what I want? Ie. help me pick the nodes so as to minimize the number of edges. Obviously the answer to the first pair of nodes will influence which nodes will be subsequently picked, so each answer would stear the algorithm in a way, not just go into the final problem. If anyone got the name of such an algorithm or something I would like to look at it at least. Application is built and deployed so I'm not looking for a solution to implement. -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From frank at chagford.com Sun Oct 9 05:22:43 2005 From: frank at chagford.com (Frank Millman) Date: 9 Oct 2005 02:22:43 -0700 Subject: Question about StringIO Message-ID: <1128849763.117104.34370@f14g2000cwb.googlegroups.com> Hi all I understand that StringIO creates a file-like object in memory. Is it possible to invoke another program, using os.system() or os.popen(), and use the < redirect operator, so that the other program reads my StringIO object as its input? I will provide more details if required, but hopefully this is enough for a simple yes or no answer, and if so, how. BTW, I have tried using popen2() and passing my data via stdin, but the other program (psql) does not react well to this - again, I will give more info if necessary. Thanks Frank Millman From fiedzia at fiedzia.prv.pl Mon Oct 31 06:26:30 2005 From: fiedzia at fiedzia.prv.pl (Maciej Dziardziel) Date: Mon, 31 Oct 2005 12:26:30 +0100 Subject: Automatically creating a HOME environ variable on Windows? References: <1130549236.679806.297670@g43g2000cwa.googlegroups.com> <1130590817.728832.291020@g44g2000cwa.googlegroups.com> <20051029164345.54C1.0.NOFFLE@fiedzia.homeip.net> Message-ID: <20051031112631.261A.0.NOFFLE@fiedzia.homeip.net> Jorgen Grahn wrote: >> Best solution would be to have portable function that returns >> user home directory and knows about all platfom quirks. > > Why is that better than Python creating a HOME in os.environ, if it > doesn't > already exist? I can think of a few reasons it's better, and a few > reasons it's worse. First, it is possible that HOME viariable already exists and has different meaning, (if python is used as embedded scripting language it can be defined by application), Second, there is a group of path related functions in os.path (or ntpath), including expanduser, and its better to use function than relay on some interpreter behaviour that may be different on jython or ironpython. -- Maciej "Fiedzia" Dziardziel (fiedzia (at) fiedzia (dot) prv (dot) pl) www.fiedzia.prv.pl How come in Scooby Doo Fred and Daphne were always on the same team and Velma, Scooby and Shaggy were always on the same team? Doesn't seem quite right now that you think about it, does it? From uid09012_ti at collinsrealtime.com Sat Oct 22 13:55:15 2005 From: uid09012_ti at collinsrealtime.com (uid09012_ti at collinsrealtime.com) Date: 22 Oct 2005 10:55:15 -0700 Subject: Missing modules '_ssl', 'ext.IsDOMString', 'ext.SplitQName' Message-ID: <1130003715.743391.237890@f14g2000cwb.googlegroups.com> Hi, i get the following error message when i use py2exe on my application: The following modules appear to be missing ['_ssl', 'ext.IsDOMString', 'ext.SplitQName'] I've installed PyXML-0.8.4.win32-py2.4.exe. My version of python is 2.4 I've checked in the pyxml directories and these modules are not there. Anybody have an idea what I'm doing wrong? Thanks, Martin. From fredrik at pythonware.com Sun Oct 23 11:27:49 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 23 Oct 2005 17:27:49 +0200 Subject: How to separate directory list and file list? References: <0e9nl1tvvgqlhkahkmrrfc810b3ed1unb6@4ax.com> Message-ID: "Gonnasi" wrote: > With > >glob.glob("*") > > or > >os.listdir(cwd) > > I can get a combined file list with directory list, but I just wanna a > bare file list, no directory list. How to get it? use os.path.isfile on the result. for file in glob.glob("*"): if not os.path.isfile(file): continue ... deal with file ... for file in os.listdir(cwd): file = os.path.join(cwd, file) if not os.path.isfile(file): continue ... deal with file ... files = map(os.path.isfile, glob.glob("*")) files = (file for file in os.listdir(cwd) if os.path.isfile(os.path.join(cwd, file))) etc. From my_email_is_posted_on_my_website at munged.invalid Sat Oct 8 18:27:23 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sat, 08 Oct 2005 22:27:23 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> Message-ID: On Sat, 08 Oct 2005 17:41:38 -0400, Mike Meyer wrote or quoted : >If you've got a browser with a better solution, what's the browser, >and what's the solution? Try Opera. You can merge the two. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From michael at stroeder.com Tue Oct 25 17:41:55 2005 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Tue, 25 Oct 2005 23:41:55 +0200 Subject: Web based applications are possible with wxPython? In-Reply-To: <1130273510.778502.107160@g14g2000cwa.googlegroups.com> References: <1129666596.739256.151100@g14g2000cwa.googlegroups.com> <1130273510.778502.107160@g14g2000cwa.googlegroups.com> Message-ID: <4el233-np1.ln1@nb2.stroeder.com> HI! Shameless plug: I'm looking for the opposite way. I'd like to run a web application within a pseudo-browser in wxPython without the need to start a web server. Is that possible with a thin wrapper? Ciao, Michael. From ms at cerenity.org Sun Oct 2 21:22:22 2005 From: ms at cerenity.org (Michael) Date: Mon, 03 Oct 2005 02:22:22 +0100 Subject: [Info] PEP 308 accepted - new conditional expressions References: <3q4ro9Fd770nU3@individual.net> Message-ID: <434087a4$0$49795$ed2e19e4@ptn-nntp-reader04.plus.net> Rocco Moretti wrote: > That is, what would happen with the following constructs: > > A if B else C if D else F > A if B if C else D else F The correct answer should be the person who wrote it would get told off for writing code that a person reading would have no idea what the code was doing (without understanding the precedence). Whilst it's good to have clear understandable, well defined rules for these things, that's no excuse for having unreadable code that other people can't read and understand without having to remember obscure rules. Personally, I'd hope that any code-linting tools would flag such expressions as potentially bad because they're not clear. (Whereas bracketed expressions instantly help here). Best Regards, Michael From gandalf at designaproduct.biz Wed Oct 5 14:51:57 2005 From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy) Date: Wed, 05 Oct 2005 20:51:57 +0200 Subject: Class methods In-Reply-To: <43441FF2.6000002@designaproduct.biz> References: <42C7E766869C42408F0360B7BF0CBD9B01CD75BE@pnlmse27.pnl.gov> <43441FF2.6000002@designaproduct.biz> Message-ID: <434420CD.6060908@designaproduct.biz> >> >> >Oh man, it has been a long time I have read such an disturbing question. > >RTMF here: http://docs.python.org/lib/built-in-funcs.html#l2h-14 > > I feel I was a bit harsh. class A(object): x = 0 @classmethod def f(cls): cls.x += 1 print "x is",cls.x >>> A.f() x is 1 >>> A.f() x is 2 >>> A.f() x is 3 Ashes to my head. :-( Les From fredrik at pythonware.com Mon Oct 3 02:12:33 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 3 Oct 2005 08:12:33 +0200 Subject: Bwidget for tkinter References: <1128318804.997697.127310@g47g2000cwa.googlegroups.com> Message-ID: anil.pundoor at gmail.com wrote: > hi can i use the bwidgets in tkinter? if so from where can i download > the bwidget for tk inter. and i want to know the installation procedure googling for "bwidget for tkinter" gives you a library announcement as the first hit, which points to this page: http://tkinter.unpythonic.net/bwidget/ From axel at white-eagle.invalid.uk Sun Oct 16 05:59:04 2005 From: axel at white-eagle.invalid.uk (axel at white-eagle.invalid.uk) Date: Sun, 16 Oct 2005 09:59:04 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: In comp.lang.perl.misc Matt Garrish wrote: >> Part of their behavior really escape me. The whole thing about browser >> wars confuses me. Web browsers represent a zero billion dollar a year >> market. Why would you risk anything to own it? > It may not be worth loads of money in-and-of itself now (don't forget > Netscape wasn't always free, though), but if you control how people view the > Internet you can make a lot of money in other ways, especially if you build > your browser into your operating system and warp standards so that people > who design sites take advantage of the proprietary features. Eventually the > hope is that your OS and browser will become the only means of accessing the > internet. And if your OS and browser are the only way to access the > Internet, who in their right mind would use another system? There was a time in the early-mid 1990s that Microsoft was making noises about setting up a 'commercial Internet' through which they hoped to control all online trading (with a percentage of each transaction going to themselves of course). I forget the exact details but it seemed a very real suggestion at the time. Axel From salvatore.didio at wanadoo.fr Sat Oct 1 06:42:46 2005 From: salvatore.didio at wanadoo.fr (salvatore.didio at wanadoo.fr) Date: 1 Oct 2005 03:42:46 -0700 Subject: Nufox : Xul + Python Message-ID: <1128163366.631178.74800@o13g2000cwo.googlegroups.com> Hello, You can test Nufox (with Firefox) at : http://artyprog.no-ip.org Regards From rrr at ronadam.com Sun Oct 9 10:26:53 2005 From: rrr at ronadam.com (Ron Adam) Date: Sun, 09 Oct 2005 14:26:53 GMT Subject: Function decorator that caches function results In-Reply-To: References: Message-ID: Steven D'Aprano wrote: > On Sat, 08 Oct 2005 15:20:12 +0200, Lasse V?gs?ther Karlsen wrote: > > >>Ok, so I thought, how about creating a decorator that caches the >>function results and retrieves them from cache if possible, otherwise it >>calls the function and store the value in the cache for the next invokation. >> >>This is what I came up with so far: >> >>def cache_function(fn): >> cache = {} >> def cached_result(*args, **kwargs): >> if args in cache: >> return cache[args] >> result = fn(*args, **kwargs) >> cache[args] = result >> return result >> return cached_result > > > I'm curious... where does cache live after you use cache_function to > memoize some function? It doesn't appear to be an attribute of the newly > memoized function, nor does it look like a global variable. If I understand this correctly... if args in cache: Creates a local binding to the "cache" object that gets returned with the cashed_result function the same as... result = fn(*args, **kwargs) ... the function 'fn' does here. So they remain local bindings to objects in the scope they were first referenced from even after the function is returned. In effect, 'cache' and 'fn' are replaced by the objects they reference before the cached_result function is returned. Is this correct? Cheers, Ron From RedGrittyBrick at SpamWeary.foo Fri Oct 28 15:23:15 2005 From: RedGrittyBrick at SpamWeary.foo (RedGrittyBrick) Date: Fri, 28 Oct 2005 19:23:15 +0000 (UTC) Subject: Typing tutor help script needed, please In-Reply-To: <1130524414.324191.233380@o13g2000cwo.googlegroups.com> References: <1130507926.729061.125850@g43g2000cwa.googlegroups.com> <1130524414.324191.233380@o13g2000cwo.googlegroups.com> Message-ID: > Throw wrote: >> I must be able to extract words which contain only >> certain letters (they need not contain all of those letters, >> but they may not contain any other letters). SPE - Stani's Python Editor wrote: > #---Input data > > #List of words; every word or sentence on one line > #If from file: WORDS = open(fileName).readlines() > WORDS = """\ > Afrikaans > Anna > Bread > red > word > bored > python""".split('\n') > > #---Main program > import re > > PATTERN = ['[^(%s)]+','[%s]+'] > FILENAME = ['not_%s.txt','%s.txt'] > > def filter(letters='bdeor',words=WORDS,contain=True,ignoreCase=True): > pattern = PATTERN[contain]%'|'.join(list(letters)) > if ignoreCase: > allowed = re.compile(pattern,re.IGNORECASE) > else: > allowed = re.compile(pattern) > result = [] > for word in words: > match = allowed.match(word) > if match and match.group(0) == word: result.append(word) > print result > output = open(FILENAME[contain]%letters,'w') > output.write('\n'.join(result)) > output.close() > > > > if __name__ == '__main__': > filter() > > --------------- > This should do it. > Am I underestimating the task, it looks simple enough for the simplest grep? # perl -n -e "print if /^[bdeor]+$/i" words.txt red bored From dotpyFE at gmail.com Tue Oct 18 17:24:29 2005 From: dotpyFE at gmail.com (Lucas Raab) Date: Tue, 18 Oct 2005 21:24:29 GMT Subject: Perl-Python-a-Day: Sorting In-Reply-To: <1129186265.871236.166670@g43g2000cwa.googlegroups.com> References: <1128937897.500935.254770@o13g2000cwo.googlegroups.com> <1129170241.274868.45680@g43g2000cwa.googlegroups.com> <1129186265.871236.166670@g43g2000cwa.googlegroups.com> Message-ID: [snip] > Thanks. I didn't know there's also a sort function in Python (2.4), > besides the method. (i've mentioned your name as acknowledgement at my > website essay) [snip] With his permission, of course... -- -------------------------- Lucas Raab lvraab"@"earthlink.net dotpyFE"@"gmail.com AIM: Phoenix11890 MSN: dotpyfe "@" gmail.com IRC: lvraab ICQ: 324767918 Yahoo: Phoenix11890 From tim at tt1lock.org Sat Oct 8 13:15:11 2005 From: tim at tt1lock.org (Tim Tyler) Date: Sat, 8 Oct 2005 17:15:11 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <91h5k1lt7qf83ce823fhs7ph9to3a4gput@4ax.com> Message-ID: Alan Balmer wrote or quoted: > On Tue, 04 Oct 2005 17:14:45 GMT, Roedy Green > >I try to explain Java each day both on my website on the plaintext > >only newsgroups. It is so much easier to get my point across in HTML. > > > >Program listings are much more readable on my website. > > My copy of javac seems to prefer plain text, and so do I ;-) Plain text is a badly impoverished medium for explaining things in. For one thing, code on my web site tends to get syntax highlighted. There's no way I could do that in plain text. -- __________ |im |yler http://timtyler.org/ tim at tt1lock.org Remove lock to reply. From larry.bates at websafe.com Thu Oct 20 12:29:34 2005 From: larry.bates at websafe.com (Larry Bates) Date: Thu, 20 Oct 2005 11:29:34 -0500 Subject: need some advice on x y plot In-Reply-To: <1129823043.104864.73750@f14g2000cwb.googlegroups.com> References: <1129823043.104864.73750@f14g2000cwb.googlegroups.com> Message-ID: I would try to live with time scale being fixed and insert None (or whatever value is used by charting package) for times where observations were not taken. This will mean that you have to preprocess your data by determining a time step step value that will fit your data. If you get 3 observations each 10 minutes apart then one an hour later, you will need to insert 5 empty observations in the list before the last observation. Example: 1:00 1:10 1:20 2:20 1:00 1:10 1:20 1:30 1:40 1:50 2:00 2:10 2:20 Maybe this will be of some help and I'm sure there are other ways. -Larry nephish at xit.net wrote: > Hey there, > i have tried about every graphing package for python i can get to work > on my system. gnuplot, pychart, biggles, gdchart, etc.. (cant get > matplot to work) > so far, they all are working ok. I need to make an x y chart for some > data that comes in from sensors at different times durring the day. i > need it to show the value in the y and the time in the x . no problem > so far. But what i cannot get to happen is to scale x (time of the > plot) with respect to time. in other words, i get a chart with the > times evenly spaced out along the x axis, with their respective values. > i need the chart to show gaps when there are gaps in the data. i need > it to be able to scale by time. if i have 3 values that come in within > a few minutes, i need them to be displayed close together, as compared > to another value that may come in, say, an hour later. Does this make > sence ? > one of you guys know a charting app that will do this ? or is there > some other way i could do it? > > looking for suggestions, > sk > From deets at nospam.web.de Thu Oct 13 20:17:04 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 14 Oct 2005 02:17:04 +0200 Subject: wxPython & Cygwin In-Reply-To: <434e8dbf$0$452$7a628cd7@news.club-internet.fr> References: <434e8dbf$0$452$7a628cd7@news.club-internet.fr> Message-ID: <3r8bo1Fi9etjU1@uni-berlin.de> Gilles DRIDI wrote: > Does someone has installed wxPython on the Cygwin platform, environment ? Why? Use windows python, wxPython for it - and put it in your path to use it inside cygwin. But maybe you _can_ compile it yourself - I didn't try, though. Diez From noahlt at gmail.com Mon Oct 31 14:12:24 2005 From: noahlt at gmail.com (noahlt at gmail.com) Date: 31 Oct 2005 11:12:24 -0800 Subject: Function returns none Message-ID: <1130785944.632805.156810@o13g2000cwo.googlegroups.com> I'm trying to write a website updating script, but when I run the script, my function to search the DOM tree returns None instead of what it should. I have this program: -------- import sys from xml.dom.minidom import parse # search the tree for an element with a particular class def findelement(current, classtofind, topnode = None): if topnode == None: topnode = current # if it's an xml element... if current.nodeType == 1: print current.nodeName, ':', current.getAttribute('class') if current.getAttribute('class') == classtofind: print 'Returning node:', current return current elif current.hasChildNodes(): findelement(current.firstChild, classtofind, topnode) elif current.nextSibling: findelement(current.nextSibling, classtofind, topnode) elif (current.parentNode != topnode) \ and (current.parentNode.nextSibling != None): findelement(current.parentNode.nextSibling, classtofind, topnode) else: print 'Returning None...' return None # others (text, comment, etc) else: if current.nextSibling: findelement(current.nextSibling, classtofind, topnode) elif (current.parentNode != topnode) \ and (current.parentNode.nextSibling != None): findelement(current.parentNode.nextSibling, classtofind, topnode) else: print 'Returning None...' return None # parse the document blog = parse('/home/noah/dev/blog/template.html') # find a post postexample = findelement(blog.documentElement, 'post') print 'Got node: ', postexample ----- My output is this: ----- html : head : title : body : h1 : ul : li : h2 : ol : li : post Returning node: Got node: None ----- The function finds the right element fine, and says it will return , but the program gets None instead. What's happening here? Any suggestions? From aleax at mail.comcast.net Sat Oct 8 03:09:30 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Sat, 8 Oct 2005 00:09:30 -0700 Subject: Will python never intend to support private, protected and public? References: <311b5ce105092800102da32267@mail.gmail.com> Message-ID: <1h436qg.bo0dpp1gkc4u6N%aleax@mail.comcast.net> Simon Brunning wrote: > On 9/28/05, Steven D'Aprano wrote: > > > If *real* private and protected are *enforced*, Python will be the > > > poorer for it. See > > > . > > > > That's a wonderful, if long, essay. > > That's the Martellibot for you. Never use a word where a paragraph > with explanatory footnotes will do. > > Sigh. I miss him on c.l.py. Why, thanks -- it's sweet to be missed!-) I also had fun rereading that little piece of mine... Unfortunately my current presence is probably a somewhat short-lived phenomenon (I just need a breather right now, but I'll have to plunge back into Google work AND writing the 2nd edition of the Nutshell soon...), but, for a short while, I'm back! Alex From fredrik at pythonware.com Thu Oct 13 11:10:37 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 13 Oct 2005 17:10:37 +0200 Subject: graphic memory & animation References: <001201c5cff3$b2d67990$0a01a8c0@NEWLAT> Message-ID: "Peres" wrote: > Python is great!... but the erasing of the graphic memory is slow (I used > surf.fill from Pygame). define slow. > Does anyone know how to erase the screen faster, in animated graphics? if you're doing animation on modern hardware, there's hardly any reason not to use double buffering. (and if you cannot get pygame to do fast clear and copy operations, you must be using the wrong API) From exarkun at divmod.com Sun Oct 9 23:12:00 2005 From: exarkun at divmod.com (Jp Calderone) Date: Sun, 9 Oct 2005 23:12:00 -0400 Subject: Python reliability In-Reply-To: <4349CF82.7040909@REMOVEMEcyber.com.au> Message-ID: <20051010031200.3914.826437948.divmod.quotient.26178@ohm> On Mon, 10 Oct 2005 12:18:42 +1000, Steven D'Aprano wrote: >George Sakkis wrote: > >> Steven D'Aprano wrote: >> >> >>>On Sun, 09 Oct 2005 23:00:04 +0300, Ville Voipio wrote: >>> >>> >>>>I would need to make some high-reliability software >>>>running on Linux in an embedded system. Performance >>>>(or lack of it) is not an issue, reliability is. >>> >>>[snip] >>> >>> >>>>The software should be running continously for >>>>practically forever (at least a year without a reboot). >>>>Is the Python interpreter (on Linux) stable and >>>>leak-free enough to achieve this? >>> >>>If performance is really not such an issue, would it really matter if you >>>periodically restarted Python? Starting Python takes a tiny amount of time: >> >> >> You must have missed or misinterpreted the "The software should be >> running continously for practically forever" part. The problem of >> restarting python is not the 200 msec lost but putting at stake >> reliability (e.g. for health monitoring devices, avionics, nuclear >> reactor controllers, etc.) and robustness (e.g. a computation that >> takes weeks of cpu time to complete is interrupted without the >> possibility to restart from the point it stopped). > > >Er, no, I didn't miss that at all. I did miss that it >needed continual network connections. I don't know if >there is a way around that issue, although mobile >phones move in and out of network areas, swapping >connections when and as needed. > >But as for reliability, well, tell that to Buzz Aldrin >and Neil Armstrong. The Apollo 11 moon lander rebooted >multiple times on the way down to the surface. It was >designed to recover gracefully when rebooting unexpectedly: > >http://www.hq.nasa.gov/office/pao/History/alsj/a11/a11.1201-pa.html > This reminds me of crash-only software: http://www.stanford.edu/~candea/papers/crashonly/crashonly.html Which seems to have some merits. I have yet to attempt to develop any large scale software explicitly using this technique (although I have worked on several systems that very loosely used this approach; eg, a server which divided tasks into two processes, with one restarting the other whenever it noticed it was gone), but as you point out, there's certainly precedent. Jp From fredrik at pythonware.com Tue Oct 4 08:08:09 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 4 Oct 2005 14:08:09 +0200 Subject: What is executed when in a generator References: Message-ID: Jerzy Karczmarczuk wrote: > Could you tell me please where can I read something in depth about the > semantics of generators? I feel a bit lost. the behaviour is described in the language reference manual: http://docs.python.org/ref/yield.html "When a generator function is called, it returns an iterator known as a generator iterator, or more commonly, a generator. The body of the generator function is executed by calling the generator's next() method repeatedly until it raises an exception." the above page points to the design document, which contains the full story: http://www.python.org/peps/pep-0255.html "When a generator function is called, the actual arguments are bound to function-local formal argument names in the usual way, but no code in the body of the function is executed. Instead a generator-iterator object is returned; this conforms to the iterator protocol /.../ Each time the .next() method of a generator-iterator is invoked, the code in the body of the generator-function is executed until a yield or return statement (see below) is encountered, or until the end of the body is reached." From andreas.zwinkau at googlemail.com Fri Oct 7 12:06:47 2005 From: andreas.zwinkau at googlemail.com (beza1e1) Date: 7 Oct 2005 09:06:47 -0700 Subject: Python 2nd favorite language in Linux Journal poll In-Reply-To: <1128692292.832209.66860@g47g2000cwa.googlegroups.com> References: <1128692292.832209.66860@g47g2000cwa.googlegroups.com> Message-ID: <1128701207.508209.231450@g47g2000cwa.googlegroups.com> Hm, you didn't include a link and my google did not find the final results. The results are fluctuating very much. This suggests a small number of votes. Linux Journal may be a big magazine, but i don't think language opinions change that fast. The vote is all done by email this year, which is another strange thing. From steve at REMOVETHIScyber.com.au Fri Oct 7 23:19:48 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sat, 08 Oct 2005 13:19:48 +1000 Subject: noob question Letters in words? References: Message-ID: On Fri, 07 Oct 2005 22:06:31 -0400, Ivan Shevanski wrote: > Right but see what if the user wants to type Start? I've already used the > number menu but too many people get confused by it. . .Any other ideas? Then let them type either the word or the number. Don't penalise your smart users because of your stupid ones. And don't make the stupid ones suffer because of the smart ones. def make_menu(words): """Takes a list of words and prints a text menu. Items are numbered from 1 onwards, not zero. """ for i in len(words): print ("%d:%s" % i+1, words[i]) def check_response(response, words, default=None): """Tests the user response against the list of words. Accepts either a number, or the entire word, or the first letter of the word *provided it is not ambiguous*. An optional default can be given. Returns the _index_ of the word entered, counting from zero. """ s = response.strip().lower() if s == "": # user just hit Enter if default is not None: s = default.strip().lower() for i in len(words): if s == str(i+1): return i if s == words[i].lower(): return i if s == words[i].lower()[0]: # the user response is a single letter, and it matches # the current word, so we check for ambiguity n = count_matches(s, words) if n == 1: return i # otherwise there could be two or more matches # if we get here, nothing matched return -1 def count_matches(s, words): temp = [word.lower().startswith(s) for word in words] return len(temp) def get_response(commands): make_menu(commands) raw_response = raw_choice("> ") choice = check_response(raw_response, commands, default="start") if choice == -1: # the response matched either nothing, or too many things print "I don't understand your response. Please try again." return get_response(commands) else: return choice Now finally use the whole thing: (warning, code is untested) commands = ["Start", "End", "Scratch head", "Burp"] cmd = get_response(commands) do_some_command(commands[cmd]) This should accept any combination of: 1 "start" 2 "end" "e" 3 "scratch head" 4 "burp" "b" in any mix of upper and lower case. Hope this works for you. -- Steven. From my_email_is_posted_on_my_website at munged.invalid Thu Oct 13 02:07:28 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Thu, 13 Oct 2005 06:07:28 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <868xx3m2ve.fsf@bhuda.mired.org> <86irw6l1mc.fsf@bhuda.mired.org> <86vf02uhae.fsf@bhuda.mired.org> Message-ID: On Thu, 13 Oct 2005 01:17:45 -0400, Mike Meyer wrote or quoted : > >No, that's what makes email a vector for infection. What makes using >the address book - for whatever purpose - possible for viruses is >having an API that allows arbitrary code to access it. But you have to >have that API - your customers are going to insist that they be able >to use their address book from third party applications. An automated change of address is possible today. It would be LESS easy to pull off under the scheme I proposed that requires digital signatures. Yes there are some downsides to a theoretical attack where phony change of address messages are sent out. They don't propagate. They don't corrupt. They are self healing when the original guy gets his virus problem under control. But you must balance that against the REAL downside of people's address books being filled with obsolete email addresses. And of course one of the reasons they are is people keep changing their email addresses to hide on spam. I am just saving as lot of busy work keeping them up to date. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From jason at pengale.com Wed Oct 19 23:12:23 2005 From: jason at pengale.com (Jason Stitt) Date: Wed, 19 Oct 2005 22:12:23 -0500 Subject: sqlstring -- a library to build a SELECT statement In-Reply-To: <1129774730.887128.314960@z14g2000cwz.googlegroups.com> References: <1129774730.887128.314960@z14g2000cwz.googlegroups.com> Message-ID: On Oct 19, 2005, at 9:18 PM, grunar at gmail.com wrote: > My solution is sqlstring. A single-purpose library: to create SQL > statement objects. These objects (such as sqlstring.Select), represent > complex SQL Statements, but as Python objects. First of all, I like this idea. I've been thinking about doing something similar but am stuck with SQLObject for the moment. The ability to construct complex expressions in pieces and then mix and match them would be killer. I think some operator overloading, especially the obvious cases like ==, is cleaner than using only functions because it lets you order things normally. But some of the operator choices are non-intuitive. Personally, I would make something like 'alias' a function or class, rather than overloading XOR. Not sure about ** for where. Using // for 'in' looks really weird, too. It's too bad you can't overload Python's 'in' operator. (Can you? It seems to be hard-coded to iterate through an iterable and look for the value, rather than calling a private method like some other builtins do.) Also, you have to be really careful of operator precedence. Have you ever used Pyparsing? Its use of a combination of classes and operator overloading works pretty well. For SQL function calls, don't you also want to support stored procedures? In that case, you don't want pre-set magic functions so much as a function that takes a string parameter for a function name and then a list of function parameters. >>>> print person_smith("party_id", "first_name") \ >>>> > < < model.address ** (\ > model.address.party_id == model.person.party_id) > SELECT > party_id party_id, > first_name first_name, > address.* > FROM > [person] person > LEFT OUTER JOIN [address] address ON > address.party_id = person.party_id > WHERE person.first_name = 'Smith' See, this is where I'm not sure about operator precedence. If << binds tighter than **, it works, because the << operator would make a 'join' object and then the ** could be interpreted as an 'on' clause. But if ** binds tighter you get an extra 'where' clause on the address table, and then a join... Some functions might be more workable. - Jason From philippknuesel at yahoo.de Tue Oct 4 10:24:34 2005 From: philippknuesel at yahoo.de (Philipp) Date: Tue, 04 Oct 2005 16:24:34 +0200 Subject: Which SQL module to use? In-Reply-To: <1128433394.470896.89770@g44g2000cwa.googlegroups.com> References: <1128433394.470896.89770@g44g2000cwa.googlegroups.com> Message-ID: <43428c0a$1_2@news.cybercity.ch> mrstephengross schrieb: > I'd like to do some basic SQL stuff in Python. It seems like there are > a heck of a lot of SQL modules for Python. What's the simplest and > easiest one to use? > > Thanks, > --Steve (mrstephengross at hotmail.com) > Do you have any DBMS in mind? Philipp From fredrik at pythonware.com Wed Oct 19 16:04:09 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 19 Oct 2005 22:04:09 +0200 Subject: Python variables are bound to types when used? References: <1129751462.061785.124830@g49g2000cwa.googlegroups.com> Message-ID: pranab_bajpai at yahoo.com wrote: > So I want to define a method that takes a "boolean" in a module, eg. > > def getDBName(l2): > ... > > Now, in Python variables are bound to types when used, right? no. variables are bound to objects, and objects have types. > Eg. > x = 10 # makes it an INT no. that binds the name "x" to an integer object. > whereas > x = "hello" # makes it a string no. that (re)binds the name "x" to a string object. > I take it, the parameters to a function (in the above example "l2") are > bound in the definition, rather than as invoked. not sure what you're saying here. when you call a function, each parameter is bound to the object represented by the corresponding argument. > So, if I use "l2" thus: > > if (l2): # only then does it make it a boolean? no. that queries the object to see if it's "true". > and if I did, > > if (l2 = "hello"): # would it become string? no. that's a syntax error; if you fix that, it queries the object to see how compares itself to the given string object. > Elucidate please. reset your brain: http://effbot.org/zone/python-objects.htm From joerg.schuster at gmail.com Tue Oct 25 08:05:45 2005 From: joerg.schuster at gmail.com (Joerg Schuster) Date: 25 Oct 2005 05:05:45 -0700 Subject: more than 100 capturing groups in a regex In-Reply-To: <87ll0hlu4c.fsf@ieee.org> References: <1130160675.270886.208420@z14g2000cwz.googlegroups.com> <1130225565.592108.197670@z14g2000cwz.googlegroups.com> <1130237717.557334.277910@g44g2000cwa.googlegroups.com> <87ll0hlu4c.fsf@ieee.org> Message-ID: <1130241945.093223.25210@z14g2000cwz.googlegroups.com> > but what is the reason for so much capturing groups? I > imagine that coding this and keeping code maintenable is a huge effort. User input is compiled to regular expressions. The user does not have to worry about those groups. From gandalf at designaproduct.biz Wed Oct 5 14:48:18 2005 From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy) Date: Wed, 05 Oct 2005 20:48:18 +0200 Subject: Class methods In-Reply-To: <42C7E766869C42408F0360B7BF0CBD9B01CD75BE@pnlmse27.pnl.gov> References: <42C7E766869C42408F0360B7BF0CBD9B01CD75BE@pnlmse27.pnl.gov> Message-ID: <43441FF2.6000002@designaproduct.biz> Hughes, Chad O wrote: > Is there any way to create a class method? I can create a class > variable like this: > ... > Any ideas? > Oh man, it has been a long time I have read such an disturbing question. RTMF here: http://docs.python.org/lib/built-in-funcs.html#l2h-14 Les From mirandacascade at yahoo.com Fri Oct 28 00:02:00 2005 From: mirandacascade at yahoo.com (mirandacascade at yahoo.com) Date: 27 Oct 2005 21:02:00 -0700 Subject: handling ExpatError exception raised from ElementTree.XML() method In-Reply-To: <1130425257.683957.130440@g43g2000cwa.googlegroups.com> References: <1130386520.772048.117530@o13g2000cwo.googlegroups.com> <1130425257.683957.130440@g43g2000cwa.googlegroups.com> Message-ID: <1130472119.971533.201190@z14g2000cwz.googlegroups.com> Mr. Boddie's suggestions work as indicated...many thanks. It's not clear how a grep of the site-packages directory revealed the most likely location of the ExpatError class is xml.parsers.expat. Using XP's search utility, I searched for any files within the c:\python24\ folder structure that had 'ExpatError' somewhere in the file (I specified a case sensitive search.) That search found nothing. I modified the search to look for any files with 'expat' (not case sensitive.)...it located the file Mr. Boddie mentioned...\lib\xml\parsers\expat.py. That file has only a few lines of code...it appears to import all the objects from what I'm guessing is the pyexpat extension module. I'm guessing that ExpatError is embedded within that extension module...is that a correct guess? It's not clear how Mr. Boddie was able to surmise where ExpatError resides given that a case sensitive search of the folder structure didn't find any files containing 'ExpatError'. From my_email_is_posted_on_my_website at munged.invalid Wed Oct 12 20:22:04 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Thu, 13 Oct 2005 00:22:04 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <868xx3m2ve.fsf@bhuda.mired.org> <86irw6l1mc.fsf@bhuda.mired.org> Message-ID: On Wed, 12 Oct 2005 21:46:12 GMT, Tim Tyler wrote or quoted : >Viruses can mail out change of address messages to everyone in the >compromised machine's address book today. > >Of course, viruses don't bother doing that - since it's stupid and >pointless. A virus is interested in the address book mainly if there as a way it can send itself to other machines, get at their address book in a fission explosion and spread without human intervention. The key that makes that possible is Microsoft's features for running self-executing code in emails. That is the problem. It has nothing to do with formatting or pictures. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From bellman at lysator.liu.se Wed Oct 19 15:53:00 2005 From: bellman at lysator.liu.se (Thomas Bellman) Date: Wed, 19 Oct 2005 19:53:00 +0000 (UTC) Subject: Python Doc Error: os.makedirs References: <1129685449.372717.56900@z14g2000cwz.googlegroups.com> Message-ID: "Xah Lee" wrote: > The "Throws an error exception" should be "Throws an OSError > exception". Both are correct: >>> os.error is OSError True That is even documented in http://python.org/doc/lib/module-os.html: error This exception is raised when a function returns a system-related error (not for illegal argument types or other incidental errors). This is also known as the built-in exception OSError. > i think the function shouldn't complain if dir already exists. How is a > programer to distinguish if the dir already exists, or if there's a > problem creating the dir? Also in the documentation about os.error: The accompanying value is a pair containing the numeric error code from errno and the corresponding string, as would be printed by the C function perror(). See the module errno, which contains names for the error codes defined by the underlying operating system. When exceptions are classes, this exception carries two attributes, errno and strerror. The first holds the value of the C errno variable, and the latter holds the corresponding error message from strerror(). For exceptions that involve a file system path (such as chdir() or unlink()), the exception instance will contain a third attribute, filename, which is the file name passed to the function. Thus, this gives you the behaviour you want: try: os.makedirs("/tmp/trh/spam/norwegian/blue/parrot/cheese") except os.error, e: if e.errno != errno.EEXIST: raise -- Thomas Bellman, Lysator Computer Club, Link?ping University, Sweden "I refuse to have a battle of wits with an ! bellman @ lysator.liu.se unarmed person." ! Make Love -- Nicht Wahr! From bonono at gmail.com Wed Oct 19 23:55:40 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 19 Oct 2005 20:55:40 -0700 Subject: How can I call a subclass method from parent class ? Message-ID: <1129780540.378921.269250@g43g2000cwa.googlegroups.com> Hi, Suppose my class definition is like this : class A: name = "A" @classmethod def foo(cls): cls.__super.foo() cls.bar() @classmethod def bar(cls): print cls.name class B(A): name = "B" class C(B): name = "C" What I want is C.foo() prints 'ABC' B.foo() prints 'BC' A.foo() prints 'A' But when I call C.foo(), it said AttributeError: class C has no attribute '_A__super' How should this be coded ? From j.e.geach at durham.ac.uk Fri Oct 7 16:40:06 2005 From: j.e.geach at durham.ac.uk (jeg) Date: 7 Oct 2005 13:40:06 -0700 Subject: 2d array slicing problem In-Reply-To: References: <1128704653.953332.218930@g47g2000cwa.googlegroups.com> Message-ID: <1128717606.166198.138670@f14g2000cwb.googlegroups.com> thanks, i ran it -- the only difference i got was the numarray version: 1.1.1 on the 686, and 1.3.3 on the 64bit... but i wouldn't have thought that would make too much difference. From apardon at forel.vub.ac.be Tue Oct 4 03:35:07 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 4 Oct 2005 07:35:07 GMT Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> Message-ID: Op 2005-10-03, Steven D'Aprano schreef : > On Mon, 03 Oct 2005 06:59:04 +0000, Antoon Pardon wrote: > >> Well I'm a bit getting sick of those references to standard idioms. >> There are moments those standard idioms don't work, while the >> gist of the OP's remark still stands like: >> >> egold = 0: >> while egold < 10: >> if test(): >> ego1d = egold + 1 > > for item in [x for x in xrange(10) if test()]: > > But it isn't about the idioms. It is about the trade-offs. Python allows > you to do things that you can't do in other languages because you > have much more flexibility than is possible with languages that > require you to declare variables before using them. The cost is, some > tiny subset of possible errors will not be caught by the compiler. But > since the compiler can't catch all errors anyway, you need to test for > errors and not rely on the compiler. No compiler will catch this error: > > x = 12.0 # feet > # three pages of code > y = 15.0 # metres > # three more pages of code > distance = x + y > if distance < 27: > fire_retro_rockets() > > And lo, one multi-billion dollar Mars lander starts braking either too > early or too late. Result: a new crater on Mars, named after the NASA > employee who thought the compiler would catch errors. Using (unit)tests will not guarantee that your programs is error free. So if sooner or later a (unit)tested program causes a problem, will you then argue that we should abondon tests, because tests won't catch all errors. -- Antoon Pardon From twic at urchin.earth.li Thu Oct 20 18:21:59 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Thu, 20 Oct 2005 23:21:59 +0100 Subject: Python vs Ruby In-Reply-To: References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> Message-ID: On Thu, 20 Oct 2005, Amol Vaidya wrote: > "Casey Hawthorne" wrote in message > news:02efl19c4n4994vtlt2ubrs7ulg4mcm8ug at 4ax.com... > >> What languages do you know already? What computer science concepts do >> you know? What computer programming concepts do you know? Have you >> heard of Scheme? Good questions! >> Ruby is a bit Perl like -- so if you like Perl, chances are you might >> like Ruby. I don't think rubyists would appreciate that description. Ruby may be heavier on the funky symbols than python, but it's a very clean, elegant, usable, well-thought-out and deeply object-oriented language - in other words, nothing at all like perl. >> Python is more like Java. Python is *nothing* like java. >> I have heard, but have not been able to verify that if a program is >> about >> 10,000 lines in C++ >> it is about >> 5,000 lines in Java >> and it is about >> 3,000 lines in Python (Ruby to?) ITYM 300. Yes, ruby too. > I've done a lot of studying on my own, and taken the classes that my > high-school offers. I feel that I have a fairly good understanding of > Java, and basic OO concepts due to that. I've created some semi-complex > programs in java, in my opinion, such as networked checkers, 8-player > blackjack, a space-shooter type game, a copy of mario (one level, > anyway), and some other stuff. I've also done a bit of studying on C. > I've done a few projects in C, including another space-shooter type of > game using SDL, an IRC client and some simple database-type programs. I > also gave a shot at assembly using NASM for x86 before, but didn't get > too far. I wrote some trivial code -- wrote to the video buffer, played > with some bios interrupts, stuff like that. The only thing I did in > assembly was create a program that loads at boot-up, and loads another > program that just reiterates whatever you type in. I only did that > because I was curious. That's about as far as my programming > knowledge/experience goes. An excellent start! > Well, I'm not sure what you mean by programming concepts. I'm familiar > with OO through Java, and procedural programming through C. I'd be more > detailed, but I'm not exactly sure what you are asking. Sorry. I think i know what Casey means, but i don't know if i can explain it any better. Do you understand the concept orthogonality? The Once And Only Once principle? Have you ever heard of design patterns? > I have no idea what Scheme is, but I'll cettainly look it up as soon as > I'm done writing this. You won't like it. Give yourself another 5-10 years, and you might start to find it strangely intriguing. > I've never given Perl a shot. It was another language I considered > learning, but my father's friend told me to go with Python or Ruby. Your father has good friends. > Thanks for your help. Hopefully I wasn't too lengthy in this post. Lengthy is fine! Anyway, the upshot of all this is that, yes, you should learn python. Python is dope! tom -- NOW ALL ASS-KICKING UNTIL THE END From usgog at yahoo.com Fri Oct 28 15:34:16 2005 From: usgog at yahoo.com (usgog at yahoo.com) Date: 28 Oct 2005 12:34:16 -0700 Subject: Newbie question: string replace In-Reply-To: <1130527656.685340.235470@g44g2000cwa.googlegroups.com> References: <1130258229.662596.228630@g49g2000cwa.googlegroups.com> <3s7620FlqdmnU1@uni-berlin.de> <1130521026.584455.288370@g44g2000cwa.googlegroups.com> <86slule9vy.fsf@bhuda.mired.org> <1130527656.685340.235470@g44g2000cwa.googlegroups.com> Message-ID: <1130528056.505938.272120@g44g2000cwa.googlegroups.com> Got it, thanks all! From my_email_is_posted_on_my_website at munged.invalid Wed Oct 12 18:11:38 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 12 Oct 2005 22:11:38 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <86ek6ul1c5.fsf@bhuda.mired.org> Message-ID: <3h2rk1t88f5pvpc9smmrid93fae3pcop4p@4ax.com> On Sun, 09 Oct 2005 19:25:46 -0400, Mike Meyer wrote or quoted : >The downside is that I have no idea how many people try to contact me >out of the blue, or from an address other than the one I sent mail to, >but don't bother to answer the response. This is why I wanted a protocol where that was automated. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From bokr at oz.net Thu Oct 6 03:15:17 2005 From: bokr at oz.net (Bengt Richter) Date: Thu, 06 Oct 2005 07:15:17 GMT Subject: dictionary interface References: Message-ID: <4344cb80.3326636800@news.oz.net> On 5 Oct 2005 08:23:53 GMT, Antoon Pardon wrote: >Op 2005-10-05, Tom Anderson schreef : >> On Tue, 4 Oct 2005, Robert Kern wrote: >> >>> Antoon Pardon wrote: >>> >>>> class Tree: >>>> >>>> def __lt__(self, term): >>>> return set(self.iteritems()) < set(term.iteritems()) >>>> >>>> def __eq__(self, term): >>>> return set(self.iteritems()) == set(term.iteritems()) >>>> >>>> Would this be a correct definition of the desired behaviour? >>> >>> No. >>> >>> In [1]: {1:2} < {3:4} >>> Out[1]: True >>> >>> In [2]: set({1:2}.iteritems()) < set({3:4}.iteritems()) >>> Out[2]: False >>> >>>> Anyone a reference? >>> >>> The function dict_compare in dictobject.c . >> >> Well there's a really helpful answer. I'm intrigued, Robert - since you >> know the real answer to this question, why did you choose to tell the >> Antoon that he was wrong, not tell him in what way he was wrong, certainly >> not tell him how to be right, but just tell him to read the source, rather >> than simply telling him what you knew? Still, at least you told him which >> file to look in. And if he knows python but not C, or gets lost in the >> byzantine workings of the interpreter, well, that's his own fault, i >> guess. >> >> So, Antoon, firstly, your implementation of __eq__ is, i believe, correct. >> >> Your implementation of __lt__ is, sadly, not. While sets take "<" to mean >> "is a proper subset of", for dicts, it's a more conventional comparison >> operation, which constitutes a total ordering over all dicts (so you can >> sort with it, for example). However, since dicts don't really have a >> natural total ordering, it is ever so slightly arbitrary. >> >> The rules for ordering on dicts are, AFAICT: >> >> - If one dict has fewer elements than the other, it's the lesser >> - If not, find the smallest key for which the two dicts have different >> values (counting 'not present' as a value) >> -- If there is no such key, the dicts are equal >> -- If the key is present in one dict but not the other, the dict in which >> it is present is the lesser >> -- Otherwise, the dict in which the value is lesser is itself the lesser >> >> In code: >> >> def dict_cmp(a, b): >> diff = cmp(len(a), len(b)) >> if (diff != 0): >> return diff >> for key in sorted(set(a.keys() + b.keys())): >> if (key not in a): >> return 1 >> if (key not in b): >> return -1 >> diff = cmp(a[key], b[key]) >> if (diff != 0): >> return diff >> return 0 >> > >Thanks for the explanation, but you somehow give me too much. > >I have been searching some more and finally stumbled on this: > >http://docs.python.org/ref/comparisons.html > > Mappings (dictionaries) compare equal if and only if their sorted > (key, value) lists compare equal. Outcomes other than equality are > resolved consistently, but are not otherwise defined. > "other outcomes" may not in general mean orderings are defined, even when == and != are well defined. E.g., below >This seems to imply that the specific method to sort the dictionaries >is unimported (as long as it is a total ordering). So I can use whatever >method I want as long as it is achieves this. > >But that is contradicted by the unittest. If you have a unittest for >comparing dictionaries, that means comparing dictionaries has a >testable characteristic and thus is further defined. > >So I don't need a full implementation of dictionary comparison, >I need to know in how far such a comparison is defined and >what I can choose. > A couple of data points that may be of interest: >>> {'a':0j} < {'a':1j} Traceback (most recent call last): File "", line 1, in ? TypeError: cannot compare complex numbers using <, <=, >, >= and >>> cmp(0j, 1j) Traceback (most recent call last): File "", line 1, in ? TypeError: cannot compare complex numbers using <, <=, >, >= but >>> {'a':0j} == {'a':1j} False >>> {'a':1j} == {'a':1j} True Regards, Bengt Richter From peter at engcorp.com Sun Oct 2 18:10:58 2005 From: peter at engcorp.com (Peter Hansen) Date: Sun, 02 Oct 2005 18:10:58 -0400 Subject: what does 0 mean in MyApp(0) In-Reply-To: <1128102240.452942.180890@g44g2000cwa.googlegroups.com> References: <1128089733.684329.101320@o13g2000cwo.googlegroups.com> <1128102240.452942.180890@g44g2000cwa.googlegroups.com> Message-ID: Alex wrote: > Thanks for the replies. It seems that I have three options > 1. app=MyApp() > 2. app=MyApp(0) > 3. app=MyApp('myfile.txt') I just want to emphasize the part of vincent's reply in which he points out that using the keyword arguments makes this more readable. If more examples and actual code would just use the darned "redirect=" keyword argument, you probably wouldn't have had to ask the question. I remember when I had the same question and spent more time than I should have had to digging out the answer. Now I try to make sure that all my wx.Apps are initialized with redirect=False or whatever else I need to make clear to a reader what I'm doing. For some widely used and understood methods and constructors, using positional arguments might be adequate. For ones like wx.App where everyone initializes them but nobody seems to know what the arguments are doing (sometimes they seem to be handed down from earlier generations), keyword arguments are a real blessing. The world needs more keyword arguments. Use them everywhere! ;-) -Peter From fredrik at pythonware.com Fri Oct 7 12:40:54 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 7 Oct 2005 18:40:54 +0200 Subject: Objects with different data views References: Message-ID: Steven D'Aprano wrote: > It is important that there are no privileged attributes, e.g. in the > above example, I can set any of x, y, z, r, theta or phi and all the > others will automatically reflect the changes. http://users.rcn.com/python/download/Descriptor.htm#properties From pclinch at internet-glue.co.uk Wed Oct 19 11:01:43 2005 From: pclinch at internet-glue.co.uk (pclinch at internet-glue.co.uk) Date: 19 Oct 2005 08:01:43 -0700 Subject: path In-Reply-To: References: Message-ID: <1129734103.538404.246610@g43g2000cwa.googlegroups.com> The python help function does not use python23.chm, which is a windows only help file. You must open it from a menu item or the desktop explorer. It does contain an entry for "and". Other platforms usually have documentation in html format, which is why you get a confusing error message. Regards, Paul Clinch From davids at webmaster.com Fri Oct 28 21:17:05 2005 From: davids at webmaster.com (David Schwartz) Date: Fri, 28 Oct 2005 18:17:05 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <66u633-etj.ln1@news.it.uc3m.es> <7xbr1aewtq.fsf@ruckus.brouhaha.com> <86acgulv5z.fsf@localhost.localdomain> <7xvezi8ypy.fsf@ruckus.brouhaha.com> <86y84ehd3j.fsf@bhuda.mired.org> <86hdb2h750.fsf@bhuda.mired.org> <86zmoufiww.fsf@bhuda.mired.org> <86oe59e57v.fsf@bhuda.mired.org> Message-ID: "Mike Meyer" wrote in message news:86oe59e57v.fsf at bhuda.mired.org... > "David Schwartz" writes: >> "Mike Meyer" wrote in message >> news:86zmoufiww.fsf at bhuda.mired.org... >>> The quote about the mafia doesn't compare MS's actions to "actual use >>> of force". >> I'm sorry, that's just absurd. I won't speculate on what motivates >> you >> to engage in such crazy distortion. Of course the quote about the Mafia >> compares MS's actions to actual use of force. > Maybe true, maybe not - but it doesn't matter. The point is that you > respond to *every* comparison of MS with other criminals as a > comparison to "criminals with guns", and then refuse to discuss the > issue, with utter disregard as to what the other person said. That you > might be right in one case is irrelevant - we're talking about a > pattern of behavior. That is not true. I make a serious distinction between crimes that involve the use of force and crimes that don't. Microsoft was convicted of crimes that do *not* involve use of force. I am trying very hard to make sure that distinction is preserved. > If MS had been found guilty of abuse of monopoly power in one > instance, few people would care. People do make mistakes. That they > have been found guilty of such abuse repeatedly, on multiple > continents, and were recently caught doing it yet again - that's what > makes them criminals. It's the pattern of behavior that matters, not > the single instances. Except that none of this behavior involves any use of force or fraud. Actions involving force or fraud are fundamentally different in type from actions that don't. And it's this distinction that I'm trying to preserve. > I'm still waiting for you to come up with an explanation for the > pattern of your behavior other than that you're taking orders from > MS. But I expect yout to deny that it exists. The pattern of my behavior is that it is vital to me to preserve the distinction between force and non-force. Guns and arguments represent two fundamentally different categories of human behavior. And I reject the moral claim that it is okay to respond to arguments with guns. Microsoft's behavior consisted of arguments, that is, did not involve force, the threat of force, fraud, or the threat of fraud. This is perhaps the most vital distinction that there is. DS From pkarjala at paju.oulu.fi Sat Oct 1 08:16:08 2005 From: pkarjala at paju.oulu.fi (Pekka Karjalainen) Date: Sat, 1 Oct 2005 12:16:08 +0000 (UTC) Subject: Not defined References: Message-ID: I looked around a bit and found the answer. At least the change I recommend below worked for me. In article , Rob wrote: >When trying the basic tutorial for cgkit I always seem to get a not defined >error as follows. > >Pythonwin GUI > >>>> from cgkit import * This is "from cgkit.all import *" in the tutorial here: http://cgkit.sourceforge.net/doc2/node6.html It seems the tutorial you are using is out of date vis-a-vis the version of cgkit you use. -- Pekka Henrik Karjalainen From howardrh at westerncom.net Wed Oct 5 23:33:19 2005 From: howardrh at westerncom.net (hrh1818) Date: 5 Oct 2005 20:33:19 -0700 Subject: New Python book References: Message-ID: <1128569599.607011.312760@o13g2000cwo.googlegroups.com> Dick Moores wrote: > Magnus Lie Hetland's new book, _Beginning Python: From Novice to > Professional_ was published by Apress on Sept. 26 (in the U.S.). My copy > arrived in the mail a couple of days ago. Very much worth a look, IMHO. > But what do the experts here think? > > > > Dick Moores > rdm at rcblue.com Along the same line what do the experts think of the new Python book published by Wrox, titled "Beginnig Python" with Peter Norton as the lead author? I was disappointed in the introductory material presented in the first 1/3 of the book but the application information presented in the last 2/3 of the book says to me this book is not a beginning python book. From mwm at mired.org Wed Oct 12 19:55:33 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 12 Oct 2005 19:55:33 -0400 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <86ek6ul1c5.fsf@bhuda.mired.org> Message-ID: <86zmpeuw7e.fsf@bhuda.mired.org> Roedy Green writes: > On Sun, 09 Oct 2005 19:25:46 -0400, Mike Meyer wrote > or quoted : > You don't need 100% spam blocking to effectively solve the spam > problem. You just have to make spam uneconomic. There are good reasons to doubt this. Most notably, there's no proof that spam is economic now. There's also evidence that non-trivial percentages of spam are more a form of ddos attack than any real attempt to send mail. > There was an analogous problem with telephone spam. It was even > easier for the telepest to get addresses, just add one. That was > solved by legal means. It could come back as long distance rates drop > and some country harbours them. Just making it illegal won't do anything. Most spam today is the result of illegal activity, and is part of an illegal or semi-legal activity even if you ignore that. You've got to convince the spammers that large men with guns will show up on their doorstep if they keep it up. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From dcrespo at gmail.com Fri Oct 14 12:01:32 2005 From: dcrespo at gmail.com (dcrespo) Date: 14 Oct 2005 09:01:32 -0700 Subject: Using SRP on TCPServer module Message-ID: <1129305692.176959.82170@g43g2000cwa.googlegroups.com> Hi all, Below, you can see a class that when it receives a host connection, it gets validated. Then, if the validation returns True, then process the request. Also, if I want to stop the server, I simply access the self.QuitFlag in lock mode, and set it to 1. Now that you know what I have, I would like to add SRP functionality to the validation of each new connection. What I need to add to my code to get SRP to work? I don't know where to start. The docs are poor. Thanks Daniel ------------------------------------------------------ class TCPServer(SocketServer.ThreadingTCPServer): def __init__(self,socket,lock): self.socket = socket SocketServer.ThreadingTCPServer.__init__(self, socket,SocketServer.StreamRequestHandler) SocketServer.ThreadingTCPServer.allow_reuse_address = True self.timeout = 0.1 self.lock = lock self.lock.acquire() self.QuitFlag = 0 self.lock.release() def get_request(self): socklist = [self.socket] while 1: # Select with a timeout, then poll a quit flag. An alternate # approach would be to let the master thread "wake us up" # with a socket connection. ready = select.select(socklist, [], [], self.timeout) self.lock.acquire() time_to_quit = self.QuitFlag self.lock.release() if time_to_quit: raise TimeToQuit # Get out now if ready[0]: # A socket was ready to read return SocketServer.ThreadingTCPServer.get_request(self) else: # We timed out, no connection yet pass # Just go back to the select() #Process the request def process_request_thread(self,request,client_address): """ This function gets triggered when the connection is accepted """ pass #Verify the request def verify_request(self,request,client_address): """ This function triggers when some host wants to connect """ if DoValidationOf(client_address): return True else: return False From mlist at fastwebnet.it Thu Oct 6 12:48:25 2005 From: mlist at fastwebnet.it (billie) Date: Thu, 6 Oct 2005 18:48:25 +0200 Subject: Build spoofed IP packets References: Message-ID: > It's SP2. Microsoft decided allowing raw socket access is a security > threat and disabled it in SP2. Uhm.. I heard about that. Damn it. :-\ From apardon at forel.vub.ac.be Wed Oct 5 04:23:53 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 5 Oct 2005 08:23:53 GMT Subject: dictionary interface References: Message-ID: Op 2005-10-05, Tom Anderson schreef : > On Tue, 4 Oct 2005, Robert Kern wrote: > >> Antoon Pardon wrote: >> >>> class Tree: >>> >>> def __lt__(self, term): >>> return set(self.iteritems()) < set(term.iteritems()) >>> >>> def __eq__(self, term): >>> return set(self.iteritems()) == set(term.iteritems()) >>> >>> Would this be a correct definition of the desired behaviour? >> >> No. >> >> In [1]: {1:2} < {3:4} >> Out[1]: True >> >> In [2]: set({1:2}.iteritems()) < set({3:4}.iteritems()) >> Out[2]: False >> >>> Anyone a reference? >> >> The function dict_compare in dictobject.c . > > Well there's a really helpful answer. I'm intrigued, Robert - since you > know the real answer to this question, why did you choose to tell the > Antoon that he was wrong, not tell him in what way he was wrong, certainly > not tell him how to be right, but just tell him to read the source, rather > than simply telling him what you knew? Still, at least you told him which > file to look in. And if he knows python but not C, or gets lost in the > byzantine workings of the interpreter, well, that's his own fault, i > guess. > > So, Antoon, firstly, your implementation of __eq__ is, i believe, correct. > > Your implementation of __lt__ is, sadly, not. While sets take "<" to mean > "is a proper subset of", for dicts, it's a more conventional comparison > operation, which constitutes a total ordering over all dicts (so you can > sort with it, for example). However, since dicts don't really have a > natural total ordering, it is ever so slightly arbitrary. > > The rules for ordering on dicts are, AFAICT: > > - If one dict has fewer elements than the other, it's the lesser > - If not, find the smallest key for which the two dicts have different > values (counting 'not present' as a value) > -- If there is no such key, the dicts are equal > -- If the key is present in one dict but not the other, the dict in which > it is present is the lesser > -- Otherwise, the dict in which the value is lesser is itself the lesser > > In code: > > def dict_cmp(a, b): > diff = cmp(len(a), len(b)) > if (diff != 0): > return diff > for key in sorted(set(a.keys() + b.keys())): > if (key not in a): > return 1 > if (key not in b): > return -1 > diff = cmp(a[key], b[key]) > if (diff != 0): > return diff > return 0 > Thanks for the explanation, but you somehow give me too much. I have been searching some more and finally stumbled on this: http://docs.python.org/ref/comparisons.html Mappings (dictionaries) compare equal if and only if their sorted (key, value) lists compare equal. Outcomes other than equality are resolved consistently, but are not otherwise defined. This seems to imply that the specific method to sort the dictionaries is unimported (as long as it is a total ordering). So I can use whatever method I want as long as it is achieves this. But that is contradicted by the unittest. If you have a unittest for comparing dictionaries, that means comparing dictionaries has a testable characteristic and thus is further defined. So I don't need a full implementation of dictionary comparison, I need to know in how far such a comparison is defined and what I can choose. -- Antoon Pardon From daniel.dang.griffith at gmail.com Sat Oct 8 11:37:15 2005 From: daniel.dang.griffith at gmail.com (Daniel 'Dang' Griffith) Date: 8 Oct 2005 08:37:15 -0700 Subject: MD5 Help Page Message-ID: <1128785834.835655.285820@g47g2000cwa.googlegroups.com> I'm referring to the text in http://www.python.org/doc/2.4.2/lib/module-md5.html, which shows the same thing I see in the Windows version of the help. The two examples show: '\xbbd\x9c\x83\xdd\x1e\xa5\xc9\xd9\xde\xc9\xa1\x8d\xf0\xff\xe9' as the output, and that is indeed what I see when I run the examples. But if I use hexdigest() instead of digest(), I get this result: 'bb649c83dd1ea5c9d9dec9a18df0ffe9' I don't understand the difference. Specifically, in the output of digest, it shows a 'd' where I expect to see \x64. What causes this difference? Thanks, --dang From prince_amir86 at yahoo.com Fri Oct 21 21:55:47 2005 From: prince_amir86 at yahoo.com (Brandon K) Date: Fri, 21 Oct 2005 20:55:47 -0500 Subject: coloring a complex number In-Reply-To: References: Message-ID: <1129946307_147@spool6-east.superfeed.net> I'm not 100% sure about this, but from what it seems like, the reason method B worked, and not method a is because class foo(complex) is subclassing a metaclass. So if you do this, you can't init a meta class (try type(complex), it equals 'type' not 'complex'. type(complex()) yields 'complex'), so you use the new operator to generator a class on the fly which is why it works in method B. I hope that's right. -Brandon > Spending the morning avoiding responsibilities, and seeing what it would > take to color some complex numbers. > > class color_complex(complex): > def __init__(self,*args,**kws): > complex.__init__(*args) > self.color=kws.get('color', 'BLUE') > >>>> a=color_complex(1,7) >>>> print a > (1+7j) #good so far >>>> a=color_complex(1,7,color='BLUE') > Traceback (most recent call last): > File "", line 1, in -toplevel- > a=color_complex(1,7,color='BLUE') > TypeError: 'color' is an invalid keyword argument for this function > > No good... it seems that I am actually subclassing the built_in function > 'complex' when I am hoping to have been subclassing the built_in numeric > type - complex. > > but some googling sends me to lib/test/test_descr.py > > where there a working subclass of complex more in > accordance with my intentions. > > class color_complex(complex): > def __new__(cls,*args,**kws): > result = complex.__new__(cls, *args) > result.color = kws.get('color', 'BLUE') > return result > >>>> a=color_complex(1,7,color='BLUE') >>>> print a > (1+7j) >>>> print a.color > BLUE > > which is very good. > > But on the chance that I end up pursuing this road, it would be good if > I understood what I just did. It would certainly help with my > documentation ;) > > Assistance appreciated. > > NOTE: > > The importance of the asset of the depth and breadth of Python archives > - for learning (and teaching) and real world production - should not be > underestimated, IMO. I could be confident if there was an answer to > getting the functionality I was looking for as above, it would be found > easily enough by a google search. It is only with the major > technologies that one can hope to pose a question of almost any kind to > google and get the kind of relevant hits one gets when doing a Python > related search. Python is certainly a major technology, in that > respect. As these archives serve as an extension to the documentation, > the body of Python documentation is beyond any normal expectation. > > True, this asset is generally better for answers than explanations. > > I got the answer I needed. Pursuing here some explanation of that answer. > > Art > > ----== Posted via Newsgroups.com - Usenet Access to over 100,000 Newsgroups ==---- Get Anonymous, Uncensored, Access to West and East Coast Server Farms! ----== Highest Retention and Completion Rates! HTTP://WWW.NEWSGROUPS.COM ==---- From apardon at forel.vub.ac.be Mon Oct 17 04:24:28 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 17 Oct 2005 08:24:28 GMT Subject: How to get a raised exception from other thread References: <1129326320.914350.171460@o13g2000cwo.googlegroups.com> Message-ID: Op 2005-10-14, dcrespo schreef : > Hi all, > > How can I get a raised exception from other thread that is in an > imported module? > > For example: You could try the following class, it needs ctypes and if the exception is raised while in a C-extention, the exception will be delayed until the extention is left. Some delay is unavoidable. You may also need to fiddle with the length of the sleep at the end of this script or the values in the xrange calls in the Continue threads ---------------------------- except.py -------------------------------- import os import ctypes from time import sleep from random import randint class TimeOut(Exception): pass class Alarm(Exception): pass import threading class Xthread(threading.Thread): def start(self): self.__original_run = self.run self.run = self.__run threading.Thread.start(self) def __run(self): self.__thrd_id = threading._get_ident() try: self.__original_run() finally: self.run = self.__original_run def raize(self, excpt): Nr = ctypes.pythonapi.PyThreadState_SetAsyncExc(self.__thrd_id, ctypes.py_object(excpt)) while Nr > 1: ctypes.pythonapi.PyThreadState_SetAsyncExc(self.__thrd_id, None) sleep(0.1) Nr = ctypes.pythonapi.PyThreadState_SetAsyncExc(self.__thrd_id, ctypes.py_object(excpt)) def alarm(self, tm): alrm = threading.Timer(tm, self.raize, (TimeOut,)) alrm.start() return alrm class Continue(Xthread): def run(self): self.id = os.getpid() print self.id, "Begin" i = 0 try: for _ in xrange(randint(0,20)): for e in xrange(4 * 100000): i = i + e print self.id, "Finished" except Alarm: print self.id, "Interupted" lst = [Continue() for _ in xrange(10)] for T in lst: T.start() try: sleep(15) finally: for T in lst: T.raize(Alarm) From http Mon Oct 10 11:08:50 2005 From: http (Paul Rubin) Date: 10 Oct 2005 08:08:50 -0700 Subject: Send password over TCP connection References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> Message-ID: <7xd5md76kd.fsf@ruckus.brouhaha.com> "dcrespo" writes: > I have a program that serves client programs. The server has a login > password, which has to be used by each client for logging in. So, when > the client connects, it sends a string with a password, which is then > validated on the server side. The problem is obvious: anyone can get > the password just sniffing the network. > > How can I solve this? If you really want to do it right, use SRP, . From bh at intevation.de Wed Oct 26 08:55:18 2005 From: bh at intevation.de (Bernhard Herzog) Date: Wed, 26 Oct 2005 14:55:18 +0200 Subject: Windows vs Linux References: Message-ID: "Tim Golden" writes: > But as far as I can tell > from my experience and from the docs -- and I'm not near a > Linux box at the mo -- having used ctrl-r to recall line x > in the history, you can't just down-arrow to recall x+1, x+2 etc. > Or can you? You can. It works fine on this box, at least. GNU bash, version 2.05a.0(1)-release (i386-pc-linux-gnu) libreadline 4.2a Bernhard -- Intevation GmbH http://intevation.de/ Skencil http://skencil.org/ Thuban http://thuban.intevation.org/ From opengeometry at yahoo.ca Sat Oct 22 01:45:59 2005 From: opengeometry at yahoo.ca (William Park) Date: Sat, 22 Oct 2005 01:45:59 -0400 Subject: best way to replace first word in string? References: <1129822003.246170.303920@f14g2000cwb.googlegroups.com> Message-ID: <88e3c$4359d217$d8fea545$17293@PRIMUS.CA> hagai26 at gmail.com wrote: > I am looking for the best and efficient way to replace the first word > in a str, like this: > "aa to become" -> "/aa/ to become" > I know I can use spilt and than join them > but I can also use regular expressions > and I sure there is a lot ways, but I need realy efficient one I doubt you'll find faster than Sed. man sed -- 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 mwm at mired.org Sat Oct 8 19:38:23 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 08 Oct 2005 19:38:23 -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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> Message-ID: <86u0frmvf4.fsf@bhuda.mired.org> Roedy Green writes: > On Sat, 08 Oct 2005 17:41:38 -0400, Mike Meyer wrote > or quoted : >>If you've got a browser with a better solution, what's the browser, >>and what's the solution? > Try Opera. You can merge the two. Merge the two CSS files? Most browsers do that - that's why they call them "cascading" style sheets. Got a sample style sheet that you use that prevernts authors from overriding things? For the font size problem, Camino has a simple solution: a "minimum size" for fonts. That's why it's my default OS X browser (well, that and that Terminal sucks as a scripting tool). I'm not sure you can do that with CSS. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From steve at REMOVETHIScyber.com.au Sun Oct 16 07:58:52 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 16 Oct 2005 21:58:52 +1000 Subject: "Microsoft has never made a computer in its existence." References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <11l48meji6u4e69@corp.supernews.com> Message-ID: On Sun, 16 Oct 2005 12:54:48 +0200, Fredrik Lundh wrote: > Steven D'Aprano wrote: > >> Microsoft has never made a computer in its existence. Not one. > > http://www.microsoft.com/xbox/ Does Microsoft actually make the Xbox or just sub-contract it out? Either way, your point is taken. But since the OP did explicitly contrast the supposed Microsoft PC revolution with games machines, I think my insignificant error is forgivable and understandable. The Xbox is not a general purpose computer, it has limited software other than games, and Microsoft gets really, really REALLY upset if you try to install another operating system on it. -- Steven. From sherm at dot-app.org Sat Oct 1 14:02:06 2005 From: sherm at dot-app.org (Sherm Pendley) Date: Sat, 01 Oct 2005 14:02:06 -0400 Subject: OT: Phases of the moon References: <1128003857.930444.47650@g14g2000cwa.googlegroups.com> <1128013745.763757.144280@g44g2000cwa.googlegroups.com> <1128015868.201617.153240@g14g2000cwa.googlegroups.com> <0001HW.BF63479501083049F0407550@news.individual.de> Message-ID: Bart Lateur writes: > As a similar example: I've been told by various women independently, > that "there are more babies born near a full moon." > > So... is there a correlation between insanity and babies being born? :) If you weren't insane before the baby was born, you will be soon after. ;-) sherm-- -- Cocoa programming in Perl: http://camelbones.sourceforge.net Hire me! My resume: http://www.dot-app.org From hgk at et.uni-magdeburg.de Thu Oct 13 02:23:55 2005 From: hgk at et.uni-magdeburg.de (Hans Georg Krauthaeuser) Date: Thu, 13 Oct 2005 08:23:55 +0200 Subject: searching python/gui developper in germany In-Reply-To: <1129123713.193715.60780@g14g2000cwa.googlegroups.com> References: <1129123713.193715.60780@g14g2000cwa.googlegroups.com> Message-ID: malv schrieb: > Hans Georg Krauthaeuser wrote: > >>Dear all, >> >>for the measurements in our labs we have developed python scripts that >>are pretty fine for our needs. Basically, we have classes and call the >>appropriate methods from the command line (or by other scripts). So, we >>don't have any GUI. >> >>Now, an external customer want to use our software and -- as you can >>imagine -- we want a pretty GUI. >> >>So, we are looking for someone who can develop such a pretty GUI for us >>(of course for money). OS is Windows (XP). We are not fixed to a special >>toolkit -- it just should look nice and do the job. >> >>Best would be someone from our region (Magdeburg, Germany). >> >>If someone is interested: contact me by email, please. >> >>Best regards >>Hans Georg Krauthaeuser > > http://www.die-offenbachs.de/detlev/eric3.html > If you run SuSE9.3 or SuSE 10.0, everything is there. Simply install > eric or eric3. > There is also a great gui design utility in the installation. > You'll be going in no time. > malv > Sorry for the question, but... Is this a bot? If not, just as a clearification: We are NOT looking for an IDE or an GUI tool. I'm sure, I can build a GUI, with eric3 or an other tool. I simply have not the time. So, we are looking for a person do do the job for us. regards Hans Georg From steve at REMOVETHIScyber.com.au Sat Oct 22 19:44:25 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 23 Oct 2005 09:44:25 +1000 Subject: Python vs Ruby References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> <1129883505.814349.306860@g44g2000cwa.googlegroups.com> Message-ID: On Fri, 21 Oct 2005 13:03:29 +0100, Alex Stapleton wrote: > > On 21 Oct 2005, at 09:31, Harald Armin Massa wrote: > >> Casey, >> >> >> >>> I have heard, but have not been able to verify that if a program is >>> about >>> 10,000 lines in C++ >>> it is about >>> 5,000 lines in Java >>> and it is about >>> 3,000 lines in Python (Ruby to?) I suspect it is considerably less than that, although it depends on the specific code being written. >> BTW: it is normally only 50 lines in Perl. Not that you could read it, >> though >> >> Harald >> >> > Perl is more like a CISC CPU. There are a million different commands. > Python is more RISC like. > Line count comparisons = pointless. Not so. Every line = more labour for the developer = more cost and time. Every line = more places for bugs to exist = more cost and time. I find it sometimes helps to imagine extreme cases. Suppose somebody comes to you and says "Hi, I want you to develop a web scrapping application to run on my custom hardware." You look at the project specifications and realise that the hardware has no OS, no TCP/IP, no file manager, no compiler. So you have to quote the potential customer on writing all these layers of software, potentially tens of millions of lines of code. Even porting an existing OS to the new hardware is not an insignificant job. Think how much time and money it would take. On the other extreme, the client comes to you and asks the same thing, except the hardware is a stock-standard Linux-based PC. Your development environment already contains an operating system, a file manager, TCP/IP, compilers, frameworks... and wget. The work you need to do is potentially as little as writing down the command "man wget" on a slip of paper and pushing it across the table to your customer. As programming languages go, C is closer to the first extreme, C++ a little further away, Java further away still, because Java provides more capabilities already built-in that the C programmer has to create from scratch. For many tasks, Python provides even more capabilities, in a language that demands less syntax scaffolding to make things happen. Every line of code you don't have to write not only is a bug that just can't happen, but it also saves time and labour. -- Steven. From dave at dbmdata.com Sun Oct 30 18:44:32 2005 From: dave at dbmdata.com (David Mitchell) Date: Sun, 30 Oct 2005 18:44:32 -0500 Subject: Problem With Insert with MySQLdb Message-ID: <000001c5ddab$e0bce8b0$0401a8c0@server2005> Hello, I am a complete beginner with Python. I've managed to get mod_python up and running with Apache2 and I'm trying to a simple insert into a table in a MySQL database. I'm using the MySQLdb library for connectivity. I can read from the database no problem, but when I do an insert, the value never gets added to the database, even though there is no error, and the SQL is fine (I print out the SQL statement in the function). When I copy and paste the sql from my browser and insert directly into MySQL, it works fine. Here is the function in question: def add(req): db = MySQLdb.connect(host="intranet", user="root", passwd="", db="intranet") # create a cursor cursor = db.cursor() # execute SQL statement sql = "INSERT INTO category (category_name) VALUES ('" + req.form['category'] + "')" cursor.execute(sql) return sql The SQL it is outputting is: INSERT INTO category (category_name) VALUES ('Test') Am I doing something obviously incorrect here? Thanks, Dave From boyanpn at yahoo.com Sat Oct 15 00:04:17 2005 From: boyanpn at yahoo.com (boyanpn) Date: 14 Oct 2005 21:04:17 -0700 Subject: PyGame & Web hosts Message-ID: <1129349057.116550.219300@g14g2000cwa.googlegroups.com> I a newbie in python so excuse me if my question sounds stupid or something :( I wonder if my web host suports python (with pygame), if I download game from www.pygame.org and upload it to my site, could users access to it with browser and play game ? From steve at REMOVETHIScyber.com.au Tue Oct 11 19:14:01 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Wed, 12 Oct 2005 09:14:01 +1000 Subject: dictionnaries and lookup tables References: <1129053992.141269.149840@z14g2000cwz.googlegroups.com> <1129056624.073937.207160@g44g2000cwa.googlegroups.com> Message-ID: On Tue, 11 Oct 2005 11:50:24 -0700, m.barenco wrote: > Just to build up on that, when I run: > > #start of listing > import random > > A={1:None,2:None,"hello":None,(1,2,3):None} > > def dictcomp(n): > for i in range(n): > B=A.copy() > C=A.copy() > b=random.uniform(0,1) > c=random.uniform(0,1) > B[b]=None > C[c]=None > res=((B>C)==(b>c)) > print res, > > dictcomp(1000) > #end of listing > > I get 1000 True's on the output, which suggests that key-wise ordering > is implemented in some guise. The question is: how do I access that? I don't think your code is showing what you think it is showing. I think you have discovered an accidental invariant that depends on the *specific* details of your code. In fact, I predict that if you run that code again, you will randomly get 1000 Trues, or 1000 Falses, but never mixed Trues and Falses. Does this quote from the Python reference manual help you? "Keys and values are listed in an arbitrary order which is non-random, varies across Python implementations, and depends on the dictionary's history of insertions and deletions." http://docs.python.org/lib/typesmapping.html What about this? "Mappings (dictionaries) compare equal if and only if their sorted (key, value) lists compare equal. Outcomes other than equality are resolved consistently, but are not otherwise defined." http://docs.python.org/ref/comparisons.html In other words, even if you have discovered a consistent invariant of dict behaviour, you can't rely on it -- it may disappear with the next release of Python, or if you use an older version, or a version on a different platform, or even because you've deleted an item from a dict and then put it back in. (And if you know anything about typical implementations of hash tables, you will understand why that last one is quite reasonable.) -- Steven. From phm4 at kent.ac.uk Mon Oct 10 14:15:29 2005 From: phm4 at kent.ac.uk (Philipp H. Mohr) Date: Mon, 10 Oct 2005 19:15:29 +0100 (BST) Subject: convert char to byte representation Message-ID: Hello, I am trying to xor the byte representation of every char in a string with its predecessor. But I don't know how to convert a char into its byte representation. This is to calculate the nmea checksum for gps data. e.g. everything between $ and * needs to be xor: $GPGSV,3,1,10,06,79,187,39,30,59,098,40,25,51,287,00,05,25,103,44* to get the checksum. Thank you for you help. Phil From aleaxit at yahoo.com Sun Oct 23 13:08:44 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 23 Oct 2005 10:08:44 -0700 Subject: Syntax across languages References: <1130052687.396109.145420@o13g2000cwo.googlegroups.com> Message-ID: <1h4vprp.6l0d8o1yvhiyiN%aleaxit@yahoo.com> wrote: ... > - Information about the current line and file as Ruby: > __LINE__ __FILE__ > Instead of the python version: > inspect.stack()[0][2] inspect.stack()[0][1] __file__ is around in Python, too, but there's no __line__ (directly). > - identity function: "identity" as in Common Lisp (probably of little > use in Python). I've seen enough occurrences of "lambda x: x" in Python code with a generally functional style that I'd love to have operator.identity (and a few more trivial functions like that) for readability;-) > - object cloning: obj.copy() obj.deepcopy() Like (say) container.length() versus len(container), I'm perfectly comfortable relying on functions rather than methods. It even makes it easier to allow several alternative ways for an object to provide such functionality (e.g. by implementing __getstate__ and maybe __setstate__ as opposed to __copy__ and maybe __deepcopy__) -- which would be feasible even with a method, of course (Template Method DP), but IS easier when relying on functions (and operators). > - accessing parent method: > super as in Ruby, instead as in Python: > super(Class, self).meth(args) Ruby's syntax may be better for a single-inheritance language, but Python's, while less elegant, may be more appropriate in the presence of multiple inheritance. > - recursive "flatten" as in Ruby (useful) Usage too rare to deserve a built-in method, IMHO, considering the ease of coding the equivalent: def flatten(x): if not isinstance(x, list): yield x for y in x: yield flatten(y) What I _do_ envy Ruby's syntax, a little, is the convention of ending methodnames with exclamation mark to indicate "modifies in-place" (and, secondarily, question mark to indicate predicates). The distinction between, e.g., y = x.sort() and x.sort!() in Ruby is much clearer, IMHO, than that between, say, y = sorted(x) and x.sort() in Python... Alex From qvx3000 at gmail.com Fri Oct 7 19:48:13 2005 From: qvx3000 at gmail.com (qvx) Date: 7 Oct 2005 16:48:13 -0700 Subject: Simulating low bandwidth network on localhost Message-ID: <1128728893.814798.44050@g49g2000cwa.googlegroups.com> I would like to test my CherryPy application in varying network conditions, ranging from localhost full speed to low badwidth (ie. 14.4kbps) and variable latency from milliseconds range to seconds range. How can I simulate this? Are there some tricks to be played with Python or is there a specialized software for this kind of things (preferably free). Thanks, qvx From apardon at forel.vub.ac.be Wed Oct 5 06:19:31 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 5 Oct 2005 10:19:31 GMT Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> <434245F5.6060500@REMOVEMEcyber.com.au> <7xr7b14lk0.fsf@ruckus.brouhaha.com> <7xu0fx9l7y.fsf@ruckus.brouhaha.com> Message-ID: Op 2005-10-05, Duncan Booth schreef : > Antoon Pardon wrote: > >> It also is one possibility to implement writable closures. >> >> One could for instace have a 'declare' have the effect that >> if on a more inner scope such a declared variable is (re)bound it >> will rebind the declared variable instead of binding a local name. > > That is one possibility, but I think that it would be better to use a > keyword at the point of the assigment to indicate assignment to an outer > scope. This fits with the way 'global' works: you declare at (or near) the > assignment that it is going to a global variable, not in some far away part > of the code, so the global nature of the assignment is clearly visible. As far as I understand people don't like global very much so I don't expect that a second keyword with the same kind of behaviour has any chance. > The > 'global' keyword itself would be much improved if it appeared on the same > line as the assignment rather than as a separate declaration. > > e.g. something like: > > var1 = 0 > > def f(): > var2 = 0 > > def g(): > outer var2 = 1 # Assign to outer variable > global var1 = 1 # Assign to global And what would the following do: def f(): var = 0 def g(): var = 1 def h(): outer var = 2 * var + 1 h() print var g() print var f() From gagenellina at softlab.com.ar Wed Oct 26 18:41:18 2005 From: gagenellina at softlab.com.ar (Gabriel Genellina) Date: 26 Oct 2005 15:41:18 -0700 Subject: Pickle to source code In-Reply-To: References: <1130315056.793178.232760@g14g2000cwa.googlegroups.com> <1130332534.999358.152530@g49g2000cwa.googlegroups.com> Message-ID: <1130366478.058655.319720@g14g2000cwa.googlegroups.com> Olivier Dormond ha escrito: > > xxx = new.instance(MyClass, {'a':1,'b':2,'done':1}) > > > > In other words, I need a *string* which, being sent to eval(), would > > return the original object state saved in the pickle. > > Doesn't pickle.loads just do what you need ? e.g.: > > >>> pickled = file('test.dat', 'rb').read() > >>> obj = eval('pickle.loads(%r)'%pickled) > >>> obj > <__main__.MyClass instance at 0xb7bfb76c> > >>> obj.a, obj.b, obj.done > (1, 2, 1) Er... Touch? :) - What year did World War II finish? - Same year the Potsdam Conference was held. - When was that? - The year World War II finished. I should have stated that I need an *explicit* string... Gabriel Genellina Softlab SRL From steve at REMOVETHIScyber.com.au Sun Oct 9 07:01:09 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 09 Oct 2005 21:01:09 +1000 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> <7xvf07a1ro.fsf@ruckus.brouhaha.com> <6eihk1tr0ovtkv5d6ik2lfm7p0i90u0tk5@4ax.com> Message-ID: On Sun, 09 Oct 2005 07:42:18 +0000, Roedy Green wrote: > On 08 Oct 2005 18:59:39 -0700, Paul Rubin > wrote or quoted : > >> >>I read mail over an ssh connection to a Unix shell. I have no easy >>way to read html email with a graphics browser. > > So the rest of the world should forgo rich communication because of > your obsolete software? How could anything every evolve with that > attitude? Hardly obsolete, any more than hammers are obsolete just because we have Concords. (The Concord... now *there* is an obsolete technology.) You may have noticed that even Microsoft have acknowledged the power and flexibility of text-based shells, and will be (if they get the technology right in time) building one into Vista. -- Steven. From kent37 at tds.net Mon Oct 24 07:53:12 2005 From: kent37 at tds.net (Kent Johnson) Date: Mon, 24 Oct 2005 07:53:12 -0400 Subject: output from external commands In-Reply-To: References: <435C6642.8020504@colannino.org> Message-ID: <435cc914$1_2@newspeer2.tds.net> darren kirby wrote: > quoth the James Colannino: >>So, for example, in Perl I could do something like: >> >>@files = `ls`; >> >>So I guess I'm looking for something similiar to the backticks in Perl. >>Forgive me if I've asked something that's a bit basic for this list. >>Any help would be greatly appreciated :) Thanks very much in advance. > > > If all you want is filenames this will work: > >>>>import glob >>>>files = ["%s" % f for f in glob.glob("*")] or import os files = os.listdir('.') Python has built-in support for many file manipulations, see the os, os.path and shutil modules. Kent From pierre.barbier at cirad.fr Tue Oct 4 13:29:37 2005 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Tue, 04 Oct 2005 19:29:37 +0200 Subject: how to debug when "Segmentation fault" In-Reply-To: References: Message-ID: <4342bb72$0$6128$636a15ce@news.free.fr> Maksim Kasimov a ?crit : > > Hello, > > my programm sometime gives "Segmentation fault" message (no matter how > long the programm had run (1 day or 2 weeks). And there is nothing in > log-files that can points the problem. > My question is how it possible to find out where is the problem in the > code? Thanks for any help. > > Python 2.2.3 > FreeBSD > Well, your best bet is to generate a core file ! To do so, in the shell launching the program, you need to accept core files. The command is : $ ulimit -c For example: $ ulimit -c 500000 For a 500MB max file. Then, if your program crash, you should see a file named "core.XXXX" where XXXX is the PID of the process. You can know exactly where the program crashed using gbd : $ gdb --core=core.XXXX Then, depending on the debug information you have in your executables you may (or may not) be able to know what happened :) Pierre From themightydoyle at gmail.com Sat Oct 15 23:54:33 2005 From: themightydoyle at gmail.com (themightydoyle at gmail.com) Date: 15 Oct 2005 20:54:33 -0700 Subject: How to get a raised exception from other thread In-Reply-To: References: <1129326320.914350.171460@o13g2000cwo.googlegroups.com> <1129434185.879062.61600@o13g2000cwo.googlegroups.com> Message-ID: <1129434873.307336.112030@g47g2000cwa.googlegroups.com> Here's a dumbed down version of what i'm doing: import time import threading class threader(threading.Thread): def __init__(self): threading.Thread.__init__(self) pass def run(self): try: while 1: time.sleep(5) except SystemExit: print "Got Exit Message in thread" def killMe(self): raise SystemExit thread1 = threader() thread2 = threader() thread1.start() thread2.start() time.sleep(5) try: print "Killing thread 1" thread1.killMe() print "killing thread 2" thread2.killMe() except SystemExit: print "Got exceptin in main thread" The exception is not propogated to the threads I spawned, but instead comes back in the main thread. From nbg at nbg.invalid Tue Oct 25 11:35:47 2005 From: nbg at nbg.invalid (Not Bill Gates) Date: Tue, 25 Oct 2005 15:35:47 GMT Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: joe at invalid.address wrote... > Not Bill Gates writes: > > > davids at webmaster.com wrote... > > > > > 1) There is no other operating system worth selling. In this > > > case, you are right, you have no choice but to sell the Microsoft > > > OS, but the deal they're offering you harms you in no way. (Unless > > > you intended to sell PCs with no OS at all.) > > > > > > 2) There are other realistic competing operating systems. In > > > this case, you were foolish to agree to Microsoft's deal. You lost > > > out on the realistic competing markets. That is, unless Windows > > > only really was a better deal, in which case you were wise to take > > > the deal and have no reason to be upset. > > > > The flaw with this is that business owners don't get to decide what > > the market wants. And the market wanted the Microsoft OS. Every > > other OS in the market had bit player status, via the economic > > principle called increasing returns. > > > > You either sell what the market wants, or you go out of business. > > I'm hesitant to get into this, but I keep wondering why, if there is > no other competing OS, or not one worth worrying about, the MS > business agreements are so draconian? Why would a company come up with > such heavy handed agreements if it wasn't worried about competition? For the same reason that people put down bug spray, I guess: You don't want any bugs showing up later and ruining your dinner party. > Yes, I know, they can do whatever they want, it's not a crime, > etc. However when they use their market position to disallow > competition, it sounds to me like they're worried about something, and > trying to squelch it. Heck, I dunno. Like you, I don't even really care all that much. Maybe they were trying to protect themselves against all the market momentum they'd created around 0S/2. They'd been big fans of it right up until Windows 3.0 took off. From mwm at mired.org Sat Oct 8 17:41:38 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 08 Oct 2005 17:41: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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> Message-ID: <863bnbofe5.fsf@bhuda.mired.org> Roedy Green writes: > On Wed, 05 Oct 2005 09:38:49 +1000, Steven D'Aprano > wrote or quoted : > >>Yes it is. HTML means that after I've specified my email client use my >>favourite font, in the size I like, people send me emails that over-ride >>my choice. Invariably they use a font I don't even have. > > I would suggest then a better solution is to implement CSS in email, > the way you do in browsers to deal with that same problem. The only way I've seen a browser fix this is to ignore the clients CSS completely. That breaks a lot of HTML, becuase CSS has turned "tag soup" authors into "div soup" authors. If you've got a browser with a better solution, what's the browser, and what's the solution? http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From my_email_is_posted_on_my_website at munged.invalid Tue Oct 25 08:04:41 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Tue, 25 Oct 2005 12:04:41 GMT Subject: Microsoft Hatred FAQ References: <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: <3c7sl11bhsjfk2nuedev7drhbqm8ci8c9o@4ax.com> On Tue, 25 Oct 2005 04:21:45 -0700, "David Schwartz" wrote, quoted or indirectly quoted someone who said : > 2) There are other realistic competing operating systems. In this case, >you were foolish to agree to Microsoft's deal. You lost out on the realistic >competing markets. That is, unless Windows only really was a better deal, in >which case you were wise to take the deal and have no reason to be upset. The actuality at the time was the vast majority of my business was Windows. People would ask about OS/2 and when they asked around town and discovered because of the MS dirty deal it cost way more, they lost interest. I could not have made a living selling only OS/2. It is was a very difficult business to survive in as it was and I was already at a disadvantage because of my insistence on not cutting corners the way my competitors did. Every once in a while I run into one of my machines I built back in the early 90s still going without a hitch over a decade later. I don't think I could make it clearer. What MS did was wrong and I will to my dying day curse them for it. If I were a Christian, I would put it this way. The pressured me into selling my soul. They did not tempt me into it. They threatened to destroy my business and my livelihood if I did not knuckle under. That is extortion. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From mwm at mired.org Fri Oct 28 14:39:04 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 28 Oct 2005 14:39:04 -0400 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> Message-ID: <867jbxfpvb.fsf@bhuda.mired.org> Andrew McCarthy writes: > On 2005-10-28, pinkfloydhomer at gmail.com wrote: >> I'm now down to: >> >> f = open("filename", "rb") >> s = f.read() >> sub = "\x00\x00\x01\x00" >> count = s.count(sub) >> print count >> >> Which is quite fast. The only problems is that the file might be huge. >> I really have no need for reading the entire file into a string as I am >> doing here. All I want is to count occurences this substring. Can I >> somehow count occurences in a file without reading it into a string >> first? > > Yes - use memory mapping (the mmap module). An mmap object is like a > cross between a file and a string, but the data is only read into RAM > when, and for as long as, necessary. An mmap object doesn't have a > count() method, but you can just use find() in a while loop instead. Except if you can't read the file into memory because it's to large, there's a pretty good chance you won't be able to mmap it either. To deal with huge files, the only option is to read the file in in chunks, count the occurences in each chunk, and then do some fiddling to deal with the pattern landing on a boundary. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From duncan.booth at invalid.invalid Tue Oct 18 03:42:18 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 18 Oct 2005 07:42:18 GMT Subject: Don't want to serialize a variable of object References: Message-ID: Iyer, Prasad C wrote: > How do I serialize the object color without serializing the x and > somechar variables? > Is there any modifier which prevents the variable from being serialized. > See the pickle documentation. The example given in the documentation pickles a class while excluding one of its attributes. http://www.python.org/doc/2.4.2/lib/pickle-example.html > Another question: > Is there a concept of private variables? 'private variables' can mean either of two things: hiding the variables to prevent accidental naming conflicts in subclasses, or security to prevent malicious manipulation of a class's internal state. Python provides the former (to a certain extent) when you give an attribute a name prefixed with a double underscore, but makes no attempt to provide the latter. Some other languages (such as C++) make no attempt to provide the former and a completely inadequate attempt at the latter. In other words: Python has a concept of private variables, but it is different than in some other languages, and if you google past threads you can find endless discussions on the pro's and con's of the Python approach. From shane at hathawaymix.org Mon Oct 17 18:14:25 2005 From: shane at hathawaymix.org (Shane Hathaway) Date: Mon, 17 Oct 2005 16:14:25 -0600 Subject: How to get listed on planet.python.org Message-ID: <43542241.1000507@hathawaymix.org> I've been writing Python-related articles on my weblog, and I thought planet.python.org might be interested in including them. Does anyone know how to submit a feed to the aggregator? http://hathawaymix.org/Weblog/rss20.xml?categories:list=Python Shane From donn at drizzle.com Sun Oct 9 15:19:23 2005 From: donn at drizzle.com (Donn Cave) Date: Sun, 09 Oct 2005 19:19:23 -0000 Subject: new forum -- homework help/chit chat/easy communication References: <1128798687.305818.66010@g49g2000cwa.googlegroups.com> <1128810677_124183@spool6-east.superfeed.net> <86r7aulwqd.fsf@bhuda.mired.org> Message-ID: <1128885560.453555@yasure> Quoth Mike Meyer : | Lasse V?gs?ther Karlsen writes: ... |> I think that at one time, scripting languages was something that lived |> within other programs, like Office, and couldn't be used by themselves |> without running it inside that program, and as thus was a way to add |> minor functions and things to that program. | | That's certainly one kind of scripting language. But I don't think | it's ever been the only kind - shells have always been stand-alone | applications. What they have in common with your definition is that | both types of languages are used to capture user actions for later | repetition. And that's what makes a scripting language: it's a | language in which one writes "scripts" that describe actions - | normally taken by a user - so that a series of them can be performed | automatically. I don't think the shell is any exception - I think it's reasonable to see it as a control+UI language embedded in the UNIX operating system. It wouldn't really be a very useful stand-alone application on a computer platform without the same basic properties. Donn Cave, donn at drizzle.com From mikael at isy.liu.se Mon Oct 17 08:10:36 2005 From: mikael at isy.liu.se (Mikael Olofsson) Date: Mon, 17 Oct 2005 14:10:36 +0200 Subject: Dynamic generation of doc-strings of dynamically generated classes Message-ID: Hi! I've asked Google, but have not found any useful information there. Situation: I have a base class, say >>> class base(object): ImportantClassAttribute = None Now, I want to dynamically generate subclasses of base. That's not a problem. However, I very much want those subclasses to have individual doc-strings. More precicely, I want that important class attribute to be reflected in the doc-string. That's the problem. The only way I've managed to accomplish that is something like the following. >>> ImportantClassAttribute = 7 >>> docString = 'The case %s.' % (ImportantClassAttribute,) >>> exec('''class new(base): """%s""" pass ''' % (docString,)) >>> new.ImportantClassAttribute = ImportantClassAttribute >>> new.__doc__ 'The case 7.' This works as intended. The subclasses do get the doc-strings I want them to have, and I can live with this solution. But: This solution does not strike me as especially beautiful or readable. My first na?ve attempt was instead the following. >>> class new(base): pass >>> new.ImportantClassAttribute = 7 >>> new.__doc__ = ('The case %(ImportantClassAttribute)s.' % new.__dict__) Traceback (most recent call last): File "", line 1, in -toplevel- new.__doc__ = ('The case %(ImportantClassAttribute)s.' TypeError: attribute '__doc__' of 'type' objects is not writable This is readable to me, but apparently not the way to go, since I'm not allowed to replace the doc-string like this. I've also tried a number of other ways, but they all stumble on similar reasons. Any ideas? Am I stuck with the clumsy exec-solution, or are there other ways to dynamically generate doc-strings of classes? /MiO From rschroev_nospam_ml at fastmail.fm Sun Oct 16 05:27:00 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Sun, 16 Oct 2005 09:27:00 GMT Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: John Bokma wrote: > joe at invalid.address wrote: > > >>John Bokma writes: >> >> >>>"David Schwartz" wrote: >>> >>>>"Tim Roberts" wrote in message >>>>news:a103l1tkejrc99s0385qjqqhm96d46dpc4 at 4ax.com... >>>> >>>> >>>>>Part of their behavior really escape me. The whole thing about >>>>>browser wars confuses me. Web browsers represent a zero billion >>>>>dollar a year market. Why would you risk anything to own it? >>>> >>>> It really isn't that hard to understand that web-based >>>> applications that work in any browser on any OS threaten >>>> to make it irrelevent what OS you're running. >>> >>>And it's even easier to understand that your statement is nonsense. >>> >>>It doesn't matter which Linux distribution you pick, all use the >>>Linux kernel. On all I can run OpenOffice, and get the same results. >>>Yet people seem to prefer one distribution over one other. >> >>He was talking about the browser war, and gave a pretty good reason >>why it was important. So you respond by pointing out that people >>choose a linux distribution for personal (non-technical, >>non-marketing) reasons. I think I missed the connection. > > > web based applications that work with any browser make OS irrelevant -> > not true, since for OpenOffice it doesn't matter which Linux > distribution one runs (or even if it's Linux), yet people seem to make a > point of which distribution they use. You make the point yourself now: if web based applications work with any browser, people can freely choose their distribution based on their own preferences. - An application works in IE, Firefox, Konqueror, Safari, Lynx, Links, Opera, ... -> users can use it with any browser on any OS - An application only works in IE -> users are forced to use Windows (or one of the other few OS's that IE exists on) -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From wierob at gmx.de Sat Oct 8 11:52:24 2005 From: wierob at gmx.de (Robert Wierschke) Date: Sat, 08 Oct 2005 17:52:24 +0200 Subject: Force flushing buffers In-Reply-To: <4345b6e8$0$49009$14726298@news.sunsite.dk> References: <4345b6e8$0$49009$14726298@news.sunsite.dk> Message-ID: Madhusudan Singh schrieb: > Hi > > I have a python application that writes a lot of data to a bunch of files > from inside a loop. Sometimes, the application has to be interrupted and I > find that a lot of data has not yet been writen (and hence is lost). How do > I flush the buffer and force python to write the buffers to the files ? I > intend to put this inside the loop. > > Thanks. disable the buffer! open( filename[, mode[, bufsize]]) open takes an optional 3ed argument set bufsize = 0 means unbuffered. see the documentation of the in build file() mehtod as open is just another name From alexs at advfn.com Sun Oct 9 14:13:39 2005 From: alexs at advfn.com (Alex Stapleton) Date: Sun, 9 Oct 2005 19:13:39 +0100 Subject: Python's Performance In-Reply-To: <43495259$0$29124$626a14ce@news.free.fr> References: <20051008040614.47429.qmail@web30607.mail.mud.yahoo.com> <43495259$0$29124$626a14ce@news.free.fr> Message-ID: <178B879D-FDB6-458C-BE00-A03820D98703@advfn.com> On 9 Oct 2005, at 19:04, Bruno Desthuilliers wrote: > Laszlo Zsolt Nagy a ?crit : > > >> Dave wrote: >> >> >> >>> Hello All, >>> >>> I would like to gather some information on Python's runtime >>> performance. As far as I understand, it deals with a lot of string >>> objects. Does it require a lot string processing during program >>> execution? How does it handle such time-consuming operations? Is >>> there >>> a way to find out how many string operations (perhaps in the >>> underlying system) ) it does during program execution? >>> >>> >> >> >> Do you want to know how many internal string operations are done >> inside >> the Python interpreter? I believe it is not a useful information. >> There >> are benchmarks testing the *real performance* of Python. >> >> For example: http://www.osnews.com/story.php?news_id=5602 >> >> >> > > A benchmark stating that Python is interpreted is bullshit. > > Except it is interpreted. What is your point? Python != C From twic at urchin.earth.li Wed Oct 12 19:38:41 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Thu, 13 Oct 2005 00:38:41 +0100 Subject: Python's garbage collection was Re: Python reliability In-Reply-To: References: <7xr7au1hr5.fsf@ruckus.brouhaha.com> <7xwtkl21hn.fsf@ruckus.brouhaha.com> <7xll11twc2.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 12 Oct 2005, Jorgen Grahn wrote: > On Mon, 10 Oct 2005 20:37:03 +0100, Tom Anderson wrote: >> On Mon, 10 Oct 2005, it was written: > ... >>> There is no way you can avoid making garbage. Python conses everything, >>> even integers (small positive ones are cached). >> >> So python doesn't use the old SmallTalk 80 SmallInteger hack, or similar? > > If the SmallInteger hack is something like this, it does: > >>>> a = 42 >>>> b = 42 >>>> a is b > True >>>> a = 42000 >>>> b = 42000 >>>> a is b > False >>>> > > ... which I guess is what if referred to above as "small positive > ones are cached". That's not what i meant. In both smalltalk and python, every single variable contains a reference to an object - there isn't the object/primitive distinction you find in less advanced languages like java. Except that in smalltalk, this isn't true: in ST, every variable *appears* to contain a reference to an object, but implementations may not actually work like that. In particular, SmallTalk 80 (and some earlier smalltalks, and all subsequent smalltalks, i think) handles small integers (those that fit in wordsize-1 bits) differently: all variables contain a word, whose bottom bit is a tag bit; if it's one, the word is a genuine reference, and if it's zero, the top bits of the word contain a signed integer. The innards of the VM know about this (where it matters), and do the right thing. All this means that small (well, smallish - up to a billion!) integers can be handled with zero heap space and much reduced instruction counts. Of course, it means that references are more expensive, since they have to be checked for integerness before dereferencing, but since this is a few instructions at most, and since small integers account for a huge fraction of the variables in most programs (as loop counters, array indices, truth values, etc), this is a net win. See the section 'Representation of Small Integers' in: http://users.ipa.net/~dwighth/smalltalk/bluebook/bluebook_chapter26.html#TheObjectMemory26 The precise implementation is sneaky - the tag bit for an integer is zero, so in many cases you can do arithmetic directly on the word, with a few judicious shifts here and there; the tag bit for a pointer is one, and the pointer is stored in two's-complement form *with the bottom bit in the same place as the tag bit*, so you can recover a full-length pointer from the word by complementing the whole thing, rather than having to shift. Since pointers are word-aligned, the bottom bit is always a zero, so in the complement it's always a one, so it can also be the status bit! I think this came from LISP initially (most things do) and was probably invented by Guy Steele (most things were). tom -- That's no moon! From robert.kern at gmail.com Tue Oct 4 09:34:36 2005 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 04 Oct 2005 06:34:36 -0700 Subject: dictionary interface In-Reply-To: References: Message-ID: Antoon Pardon wrote: > I'm writing a Tree class, which should behave a lot like a dictionary. > > In order to test this, I took the unittest from the source distribution > for dictionaries and used it to test against my Tree class. > > Things are working out rather well, but I stumbled on a problem. > > this unittest tries to test for '==' and '<' operators. However I > couldn't find anything in the documentation that defined how > dictionaries should behave with respect to these operators. > > For the moment the best I can come up with is something like > the following: > > class Tree: > > def __lt__(self, term): > return set(self.iteritems()) < set(term.iteritems()) > > def __eq__(self, term): > return set(self.iteritems()) == set(term.iteritems()) > > Would this be a correct definition of the desired behaviour? No. In [1]: {1:2} < {3:4} Out[1]: True In [2]: set({1:2}.iteritems()) < set({3:4}.iteritems()) Out[2]: False > Anyone a reference? The function dict_compare in dictobject.c . -- 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 Fri Oct 14 20:27:00 2005 From: bokr at oz.net (Bengt Richter) Date: Sat, 15 Oct 2005 00:27:00 GMT Subject: updating local() References: <1128530014.323801.290360@g47g2000cwa.googlegroups.com> <1128603314.197733.119160@g47g2000cwa.googlegroups.com> <3qkmjcFfbem9U1@uni-berlin.de> <1128607448.235410.152590@o13g2000cwo.googlegroups.com> Message-ID: <43504a9f.12823268@news.oz.net> On Thu, 06 Oct 2005 07:15:12 -0700, Robert Kern wrote: >Flavio wrote: >> Ok, its not thousands, but more like dozens of variables... >> I am reading a large form from the web which returns a lot of values. >> (I am Using cherrypy) >> >> I know I could pass these variables around as: >> >> def some_function(**variables): >> ... >> >> some_function(**variables) >> >> but its a pain in the neck to have to refer to them as >> variables['whatever']... >> >> dont you think? > >Use a Bunch. > >class Bunch(dict): > def __init__(self, *args, **kwds): > dict.__init__(self, *args, **kwds) > self.__dict__ = self > >-- Or use a version-sensitive byte-code hack to set some preset locals before executing, either with one-time presets via normal decorator, e.g., >>> from ut.presets import presets >>> @presets(x=111, y=222, z='zee') ... def foo(): ... return locals() ... >>> foo() {'y': 222, 'x': 111, 'z': 'zee'} Or the same, just using a predefined dict instead of the keyword format: >>> e = {'a':0, 'b':1} >>> @presets(**e) ... def foo(): ... return locals() ... >>> foo() {'a': 0, 'b': 1} What happened to foo viat the decoration: >>> import dis >>> dis.dis(foo) 1 0 LOAD_CONST 1 ((0, 1)) 3 UNPACK_SEQUENCE 2 6 STORE_FAST 0 (a) 9 STORE_FAST 1 (b) 3 12 LOAD_GLOBAL 0 (locals) 15 CALL_FUNCTION 0 18 RETURN_VALUE To mess with the same base function with different presets more dynamically, use the explicit way of calling the decorator: The base function: >>> def bar(x, y=123): ... return locals() ... decorate and invoke on the fly with particular presets: >>> presets(**e)(bar)('exx') {'a': 0, 'y': 123, 'b': 1, 'x': 'exx'} The keyword way: >>> presets(hey='there')(bar)('exx') {'y': 123, 'x': 'exx', 'hey': 'there'} BTW, @presets does not change the signature of the function whose selected locals are being preset from the decoration-time-generated constant, e.g., >>> presets(hey='there')(bar)() Traceback (most recent call last): File "", line 1, in ? TypeError: bar() takes at least 1 argument (0 given) >>> presets(hey='there')(bar)('exx', 'wye') {'y': 'wye', 'x': 'exx', 'hey': 'there'} >>> presets(hey='there')(bar)('exx', 'wye', 'zee') Traceback (most recent call last): File "", line 1, in ? TypeError: bar() takes at most 2 arguments (3 given) Regards, Bengt Richter From onurb at xiludom.gro Mon Oct 24 04:43:33 2005 From: onurb at xiludom.gro (bruno modulix) Date: Mon, 24 Oct 2005 10:43:33 +0200 Subject: Zope and Persistence In-Reply-To: <1130002447.553341.226500@g47g2000cwa.googlegroups.com> References: <1130002447.553341.226500@g47g2000cwa.googlegroups.com> Message-ID: <435c9eb6$0$664$626a14ce@news.free.fr> ryankaskel at gmail.com wrote: > I don't know if this is the appropriate place to post a Zope question Nope. You'd better use the zope mailing-list for this. > but I figure many here are familiar with it. I'm confused about the > role of the ZMI when it comes to development. As it's name implies, the ZMI is a *management* interface. Real Zope developpement is better made with filesystem "Products" (Zope components). > I want to write a simple > script that logs page hits. That's a typical case of reinventig the square wheel. Ever looked at /log/Z2.log ? It's an apache-like access log. And there are a whole lot of tools for building stats from apache access logs. > I wrote it in what was called a Script > (Python) resource in the ZMI. When I access the page it gives an error > saying that this file cannot import Persistence, etc. Why would you import Persistence in a Python Script ? This is already a persistent object. > This makes sense > but where would I put this script Whereever seems to fit - this depends on your application. > and how would I invoke it? Like any other Zope object. > It is only > supposed to store an integer in Data.fs. Thanks. This is another problem, and I think you'd better start with the zope book. But for you current use case, first have a look at Zope's access log. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From vel.accel at gmail.com Fri Oct 7 14:37:29 2005 From: vel.accel at gmail.com (D.Hering) Date: 7 Oct 2005 11:37:29 -0700 Subject: Objects with different data views References: <7xhdbtdzss.fsf@ruckus.brouhaha.com> Message-ID: <1128710249.776369.176120@g43g2000cwa.googlegroups.com> Paul Rubin wrote: > Steven D'Aprano writes: > > class Parrot(object): > x = property(getx, setx) > y = property(gety, sety) > > def getx(self): > return self.a + self.b > def setx(self, x): > y = self.y # calls gety > self.a, self.b = 2*x - y, y-x > > def gety(self): > return self.a + 2*self.b > def sety(self, y): > x = self.x # calls getx > self.a, self.b = 2*x - y, y-x class Parrot(object): def getx(self): return self.a + self.b def setx(self, x): y = self.y # calls gety self.a, self.b = 2*x - y, y-x def gety(self): return self.a + 2*self.b def sety(self, y): x = self.x # calls getx self.a, self.b = 2*x - y, y-x x = property(getx, setx) y = property(gety, sety) From pd at traxon.com Fri Oct 21 12:55:04 2005 From: pd at traxon.com (Paul Dale) Date: Fri, 21 Oct 2005 18:55:04 +0200 Subject: Binding a variable? Message-ID: <43591D68.50005@traxon.com> Hi everyone, Is it possible to bind a list member or variable to a variable such that temp = 5 list = [ temp ] temp == 6 list would show list = [ 6 ] Thanks in advance? Paul From rrr at ronadam.com Mon Oct 24 23:10:17 2005 From: rrr at ronadam.com (Ron Adam) Date: Tue, 25 Oct 2005 03:10:17 GMT Subject: namespace dictionaries ok? In-Reply-To: <1130207021.408597.322950@g14g2000cwa.googlegroups.com> References: <1130207021.408597.322950@g14g2000cwa.googlegroups.com> Message-ID: Simon Burton wrote: > Yes! > > I do this a lot when i have deeply nested function calls > a->b->c->d->e > and need to pass args to the deep function without changing the > middle functions. Yes, :-) Which is something like what I'm doing also. Get the dictionary, modify it or validate it somehow, then pass it on. I also find that when I'm passing variables as keywords, foo(name=name, address=address, city=city) I really don't want (or like) to have to access the names with dictionary key as *strings* in the function that is called and collects them in a single object. > In this situation I think i would prefer this variation: > > class Context(dict): > def __init__(self,**kwds): > dict.__init__(self,kwds) > def __getattr__(self, name): > return self.__getitem__(name) > def __setattr__(self, name, value): > self.__setitem__(name, value) > def __delattr__(self, name): > self.__delitem__(name) > > def foo(ctx): > print ctx.color, ctx.size, ctx.shape > > foo( Context(color='red', size='large', shape='ball') ) > > > This is looking like foo should be a method of Context now, > but in my situation foo is already a method of another class. > > Simon. I didn't see what you were referring to at first. But yes, I see the similarity. Cheers, Ron From gsakkis at rutgers.edu Sat Oct 8 14:50:47 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: 8 Oct 2005 11:50:47 -0700 Subject: Merging sorted lists/iterators/generators into one stream of values... References: <1128667968.421469.180910@g47g2000cwa.googlegroups.com> <1128691708.c6930b5cb9f3673ed3abe8755178d163@teranews> <1128692196.410209.252100@g14g2000cwa.googlegroups.com> <1128695317.c6a5acb3e62787f011310c96f0c7cc35@teranews> <1h439qe.pz7c451jcec6hN%aleax@mail.comcast.net> <1128795319.09c32ac9943b0580a86b7bcada7facc1@teranews> Message-ID: <1128797447.501582.24560@o13g2000cwo.googlegroups.com> "Lasse V?gs?ther Karlsen" wrote: > George Sakkis wrote: > > > Just added a recipe at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440673. You can try > > both and see if there's any significant performance difference for your data. > > > Thanks, will take a look at it later. The sort solution seems to work > nicely. Might be a big difference if I have a lot of sources though as I > bet the overhead in doing a sort of N items gets higher than doing a > manipulation of a heap to place an item in the right spot, but with 4-5 > or a few more sources might not make an impact at all. Unless you're talking about hundreds or thousands sources, it probably won't. I would still go for the heap solution since IMO the resulting code it's more readable and easier to understand. George From tuvas21 at gmail.com Wed Oct 19 15:10:35 2005 From: tuvas21 at gmail.com (Tuvas) Date: 19 Oct 2005 12:10:35 -0700 Subject: Extention Module/ list of chars-> string Message-ID: <1129749035.667046.98630@g14g2000cwa.googlegroups.com> I am currently writing an extention module that needs to recieve a list of characters that might vary in size from 0 to 8. This is written as a list of characters rather than a string because it's easier to manipulate. However, when I pass this list of characters into the extention module, it keeps giving errors. Is there a way to do one of the following? A. Change a list of chars to a single string or B. Read a list of chars in an extention module Thanks! From carsten at uniqsys.com Mon Oct 3 16:41:48 2005 From: carsten at uniqsys.com (Carsten Haese) Date: Mon, 03 Oct 2005 16:41:48 -0400 Subject: Dynamical loading of modules In-Reply-To: <43418BF5.90504@gmail.com> References: <43418BF5.90504@gmail.com> Message-ID: <1128372108.4070.31.camel@dot.uniqsys.com> On Mon, 2005-10-03 at 15:52, Jacob Kroon wrote: > Hi, I'm having some problems with implementing dynamical module loading. > First let me > describe the scenario with an example: > > modules/ > fruit/ > __init__.py > apple.py > banana.py > > apple.py defines a class 'Apple', banana defines a class 'Banana'. The > problem lies in the > fact that I want to be able to just drop a new .py-file, for instance > peach.py, and not change > __init__.py, and it should automatically pickup the new file in > __init__.py. I've come halfway > by using some imp module magic in __init__.py, but the problem I have is > that the instantiated > objects class-names becomes fruit.apple.Apple/fruit.banana.Banana, whild > I want it to be > fruit.Apple/fruit.Banana. > > Is there a smarter way of accomplishing what I am trying to do ? > If someone could give me a small example of how to achieve this I would > be very grateful. How about something like this in fruit/__init__.py: import os fruit_dir = os.path.dirname(__file__) fruit_files = [x for x in os.listdir(fruit_dir) if (x[-3:]=='.py' and x!='__init__.py')] for fruit_file in fruit_files: module_name = fruit_files[:-3] exec "from %s import *" % module_name HTH, Carsten. From steve at holdenweb.com Fri Oct 7 12:00:59 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 07 Oct 2005 17:00:59 +0100 Subject: Python interpreter bug In-Reply-To: <1128694071.902605.201440@o13g2000cwo.googlegroups.com> References: <1128686833.994339.295780@f14g2000cwb.googlegroups.com> <1128692705.964188.5720@z14g2000cwz.googlegroups.com> <1128694071.902605.201440@o13g2000cwo.googlegroups.com> Message-ID: alainpoint at yahoo.fr wrote: > I understand this, Steve. > I thought the _cmp_ method was a helper for sorting purposes. Why is it > that a membership test needs to call the __cmp__ method? Can you suggest another way to test for set membership, given that instances aren't singletons? The only way to do so is to iterate over the list, asking "are these the same instance", followed (in the case of a "no" answer) by "are these two instances equal?". Consider: >>> a = {1:'one'} >>> b = {2:'two'} >>> c = {1:'one'} >>> a is c False >>> a in [b, c] True >>> What would you have Python do differently in these circumstances? > If this isn't a bug, it is at least unexpected in my eyes. Ah, right. So it's your eyes that need fixing! :-) > Maybe a candidate for inclusion in the FAQ? > Thank you for answering A pleasure. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From mwm at mired.org Thu Oct 6 16:18:03 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 06 Oct 2005 16:18:03 -0400 Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86u0fxi7gf.fsf@bhuda.mired.org> <434545b7$0$662$626a14ce@news.free.fr> <86mzlmpo5r.fsf@bhuda.mired.org> <7xpsqictdq.fsf@ruckus.brouhaha.com> Message-ID: <86fyrepfgk.fsf@bhuda.mired.org> Paul Rubin writes: > Mike Meyer writes: >> I think we're using different definitions of statically typed >> here. A language that is statically typed doesn't *need* type >> inferencing - the types are all declared! Type determines the thypes >> by inferenceing them from an examination of the program. > > I thought static typing simply means the compiler knows the types of > all the expressions (whether through declarations or inference) so it > can do type checking at compile time: > >> So, for instance, it can determine that this function: >> >> def foo(): >> return 1 >> >> Won't ever return anything but an integer. > > Static typing in this case would mean that re.match('a.*b$', foo()) > would get a compile time error, not a runtime error, since re.match > expects two string arguments. This can happen through type inference > w/o declarations. Except for two problems: One you noted: > Note apropos the private variable discussion that CPython can't > guarantee that foo() always returns an integer. Something might > change foo.func_code.co_code or something like that. Two is that dynamic binding means that foo may not refer to the above function when you get there at run time. >> Maybe you're still writing code for a language with declerations? I >> never felt that need. Then again, I came to Python from a language >> that didn't require declerations: Scheme. > I've done a fair amount of Lisp programming and have found the lack of > compile-time type checking to cause about the same nuisance as in > Python. So have I - basically none at all. >> > Well, in the end, I would really like an *option* at the beginning of a >> > module file requiring variable declaration for the module. It would >> > satisfy both the ones who want and the ones who don't want that ... >> Nope. It would just change the argument from "Python should have ..." >> to "You should always use ..." or "Module foo should use ...". > Perl has a feature like that right now, and it doesn't lead to many such > arguments. As noted elsewhere, Perl isn't a good comparison. You don't simply say "This variable exists", you say "this variable is local to this function". Undeclared variables are dynamically bound, which means you can get lots of non-obvious, nasty bugs that won't be caught by unit testing. Making all your variables lexically bound (unless you really need a dynamically bound variable) is a good idea. But that's already true in Python. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From paschalis at interia.pl Mon Oct 31 07:26:20 2005 From: paschalis at interia.pl (dale cooper) Date: 31 Oct 2005 04:26:20 -0800 Subject: Tkinter problem Message-ID: <1130761580.552145.167340@z14g2000cwz.googlegroups.com> Hi everybody! I've recently installed python2.4.2 on Fedora 4 (from downloaded sources), but it appeared, that I can't use Tkinter module: >>> import Tkinter Traceback (most recent call last): File "", line 1, in ? File "/usr/local/lib/python2.4/lib-tk/Tkinter.py", line 38, in ? import _tkinter # If this fails your Python may not be configured for Tk ImportError: libBLT24.so: cannot open shared object file: No such file or directory I tried the solution given in README file for RH9 (./configure --enable-unicode=ucs4) despite they wrote the newer wersion didn't need this hack. This is what I had after make instruction: INFO: Can't locate Tcl/Tk libs and/or headers *** WARNING: renaming "array" since importing it failed: build/lib.linux-i686-2.4/array.so: undefined symbol: PyUnicodeUCS2_FromUnicode *** WARNING: renaming "_testcapi" since importing it failed: build/lib.linux-i686-2.4/_testcapi.so: undefined symbol: PyUnicodeUCS2_Decode *** WARNING: renaming "unicodedata" since importing it failed: build/lib.linux-i686-2.4/unicodedata.so: undefined symbol: PyUnicodeUCS2_FromUnicode *** WARNING: renaming "_locale" since importing it failed: build/lib.linux-i686-2.4/_locale.so: undefined symbol: PyUnicodeUCS2_AsWideChar *** WARNING: renaming "cPickle" since importing it failed: build/lib.linux-i686-2.4/cPickle.so: undefined symbol: PyUnicodeUCS2_AsUTF8String *** WARNING: renaming "pyexpat" since importing it failed: build/lib.linux-i686-2.4/pyexpat.so: undefined symbol: PyUnicodeUCS2_DecodeUTF8 *** WARNING: renaming "_multibytecodec" since importing it failed: build/lib.linux-i686-2.4/_multibytecodec.so: undefined symbol: PyUnicodeUCS2_FromUnicode running build_scripts It seems that --enable-unicode=ucs4 wasn't the right way. I tried another hack: ./configure --enable-shared, but it still couldn't locate Tcl/Tk libs and/or headers. Then I installed RPMs: [root at localhost Python-2.4.2]# rpm -q tk tk-8.4.9-3 [root at localhost Python-2.4.2]# rpm -q tcl tcl-8.4.9-3 [root at localhost Python-2.4.2]# rpm -q tkinter tkinter-2.4.1-2 and tried to do the hacks above, but it still could'nt find these libs. What can I do? From http Tue Oct 11 03:10:01 2005 From: http (Paul Rubin) Date: 11 Oct 2005 00:10:01 -0700 Subject: Batteries Included? References: <1129010199.291968.142720@g47g2000cwa.googlegroups.com> Message-ID: <7xwtkk7cmu.fsf@ruckus.brouhaha.com> Sybren Stuvel writes: > > I might be wrong expecting that a language whose moto is "Batteries > > Included" would be able to produce exe files. > > Indeed, you're wrong. Why would such an ability be included in Python? distutils.exe, included in Python, in fact does have the ability to produce .exe files, just not completely general ones. > It's a cross platform language. What need would Mac, Linux, BSD, > Solaris etc. users have for such a feature? The same need that they have for msvcrt, winreg, winsound, or the SGI IRIX specific functions currently in the library. The same need that Windows users have for the Unix specific parts which are in the library. The same need that non-numeric programmers have for the cmath module, which is also in the library. > And why would it have to be included, when there is an easy solution > just around the corner? You prooved that it was easy enough to > install and use by someone who just learned Python. I really don't > see the problem here. Um, if the TV ad for some Walkman says "batteries included" and the batteries aren't included, you have legitimate reason to ask what's going on. That it's easy enough for you to go to the store and buy batteries separately is irrelevant. You didn't get what was advertised. Now a Windows .exe installer wasn't one of the advertised features of Python and maybe there's good reasons to leave it out, but its platform specificness is not one of those reasons. There's already plenty of platform specific stuff in Python. Personally I think including a .exe packager in Python would be a great idea. As a Linux user I can't easily run Windows-specific utilities like Inno Setup. So I don't have a good way to make .exe's from my Python code that Windows users can easily run. Having a cross platform .exe packager included with Python would be useful the same way cross compilers are useful. I'm using an x86 computer but I can easily configure gcc to produce ARM code. Why shouldn't my Linux Python installation be able to produce Windows .exe's? From greymaus at cableone.net Sat Oct 15 20:07:56 2005 From: greymaus at cableone.net (Greymaus) Date: Sat, 15 Oct 2005 19:07:56 -0500 Subject: Microsoft Hatred FAQ In-Reply-To: <86ll0vs1sw.fsf@bhuda.mired.org> References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> Message-ID: <11l369039d6ppe0@corp.supernews.com> Mike Meyer wrote: > You clearly weren't paying attention to what the rest > of the microcomputer industry was doing while Gates was selling IBM > non-existent software. While IBM was introducing 16-bit processors and > DOS was doing a flat file system, Tandy was selliig systems - for a > fraction of the price of any MS-DOS based system - that were > multitasking, multiuser, had an optional windowing system that came > with a complete (for the time) office suite. Of course, that was while > Tandy still thought they could sell computers by selling better > computers than you could get running MS software. Was that the Color Computer III running OS9 Level II for an operating system, that you're talking about? Motorola 6809 processor? HELLUVA little computer! OS9 was a bit quirky, though, even for a UNIX clone. From claudio.grondi at freenet.de Fri Oct 14 21:09:36 2005 From: claudio.grondi at freenet.de (Claudio Grondi) Date: Sat, 15 Oct 2005 01:09:36 -0000 Subject: UI toolkits for Python References: <7xslv56ud1.fsf@ruckus.brouhaha.com> Message-ID: <3ras6oFit2djU1@individual.net> "Kenneth McDonald" wrote in news:mailman.2032.1129236372.509.python-list at python.org... > Thanks for reminding me of Gtk. OK, add that to the list. > > The Web Browser interface is good for simple things, and will get better > with CSS2's adoption, but they still don't have a good way for important > things like interactive styled text, key bindings, etc. Good for > simple things > (for which I use them), not for more complex stuff. I don't fully understand your attitude here. The Web Browser interface has all I can imagine is required for a GUI, so what is missing when you consider, that you can generate custom images on the fly on the server and let the user shape the page without requesting CPU power from the server using JavaScript. I don't even name here the not really beeing itegral part of Internet Browsers JavaApplets and any other kind of plugin stuff. The only issue I can see with this approach is the speed of responding to user interactions, but for really optimize this one needs a compiled language anyway. What is that complex, that it can't be solved using an Internet Browser as a GUI? Do I miss here something? Claudio From steve at REMOVETHIScyber.com.au Fri Oct 7 22:06:49 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sat, 08 Oct 2005 12:06:49 +1000 Subject: Pythoncard mental block References: <1128705924.303422.31650@o13g2000cwo.googlegroups.com> Message-ID: On Fri, 07 Oct 2005 10:25:24 -0700, jlocc wrote: > Hi!! > > I am working on a school project and I decided to use PythonCard and > wxPython for my GUI development. I need a password window that will > block unwanted users from the system. I got the pop-up password > question to work... I haven't seen any replies to this, so even though I don't actually use Pythoncard I'll take a wild shot in the dark. > def on_openBackground(self, event): > > result = dialog.textEntryDialog(self, > 'System', > 'Please enter your password: ', > '') > > .....but I don't exactly remember how to check if the entered password > is correct. Say I hard code the password to be 'hello', then how would I > check if this was the input or if it wasn't??? Start with looking at result and seeing what is in it. If it is the input string, then just say if result == 'hello': # do whatever you need to else: # put up a dialog saying 'Password does not match!' But I'm guessing from the syntax that the dialog instance itself is stored in result, so perhaps you need to look at some attribute of result: if result.userInput == "hello": # or something like that? Lastly, I might not have used Pythoncard, but years ago I used to use Hypercard rather a lot. In Hypercard, the password dialog would use a one-way hash function to encrypt the typed response into a large integer value. I assume Pythoncard is designed to do the same thing as Hypercard. So, in rusty Hypercard syntax with Python-style comments: # retrieve the numeric value of the password put field "hidden password" into userpassword # put up a dialog asking the user to enter a password ask password "Please enter your password:" if the result is "" then: # the user clicked Cancel, so just abort or go away or something go home else if the result is userpassword: # we have a match! go to card "Secret card" else: # password doesn't match go to card "Password failure" Hope this is of some help to you, and I haven't led you too far astray. -- Steven. From my_email_is_posted_on_my_website at munged.invalid Tue Oct 18 04:34:59 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Tue, 18 Oct 2005 08:34:59 GMT Subject: Microsoft Hatred FAQ References: <%jV4f.3121$tV6.2659@newssvr27.news.prodigy.net> <2u59l1555jubv8qv09q57qh8m4skei9dqi@4ax.com> Message-ID: <3tc9l11oejnq3i2hnrld7akujouk3771tv@4ax.com> On 18 Oct 2005 06:57:47 GMT, John Bokma wrote or quoted : >>>That an HTML standard (ISO/IEC 15445:2000) and an HTML recommendation by >>>w3c (4.01 for example) are two different things, and mixing them up by >>>calling both standards is a bad thing. >> >> Because ... what are the consequences? > >If you mean if you are put in jail for 20 years, and tortured, none. No. ANY consequences. You have not explained the downside. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From steve at holdenweb.com Thu Oct 6 03:11:11 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 06 Oct 2005 08:11:11 +0100 Subject: Class methods In-Reply-To: <20051005200733.GA18786@topjaklont.student.utwente.nl> References: <42C7E766869C42408F0360B7BF0CBD9B01CD75BE@pnlmse27.pnl.gov> <43441FF2.6000002@designaproduct.biz> <434420CD.6060908@designaproduct.biz> <20051005200733.GA18786@topjaklont.student.utwente.nl> Message-ID: Gerrit Holl wrote: > Laszlo Zsolt Nagy wrote: > >>>Oh man, it has been a long time I have read such an disturbing question. >>> >>>RTMF here: http://docs.python.org/lib/built-in-funcs.html#l2h-14 >>> >>> >> >>I feel I was a bit harsh. > > > Of course, those posts do keep the Google count for the famous > four-letter-abbreviation down (-; > > Gerrit. > I'd been thinking it was about time the mucking fanual was updated. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From grante at visi.com Wed Oct 19 16:06:53 2005 From: grante at visi.com (Grant Edwards) Date: Wed, 19 Oct 2005 20:06:53 -0000 Subject: Python variables are bound to types when used? References: <1129751462.061785.124830@g49g2000cwa.googlegroups.com> Message-ID: <11ld9qtgvead8d0@corp.supernews.com> On 2005-10-19, pranab_bajpai at yahoo.com wrote: > So I want to define a method that takes a "boolean" in a module, eg. > > def getDBName(l2): > ... > > Now, in Python variables are bound to types when used, right? Python doesn't have variables. Python has objects of various types. You can bind 0 or more names an object. > Eg. > x = 10 # makes it an INT > whereas > x = "hello" # makes it a string No, not really. There is no "it" that's becoming different types. x = 10 creates an integer object with the value 10 and binds the name "x" to it. x = "hello" creates a string object containing the value "hello" and then unbinds the name "x" from the integer object and re-binds it to the string object. [At that point, the integer object _may_ get deleted if it's not being used any longer (it may have had multiple names).] > I take it, the parameters to a function (in the above example "l2") are > bound in the definition, rather than as invoked. Not sure I understand the question. The function you defined accepts a single object as a parameter. When the function is invoked, that object has the local name "l2" bound to it > So, if I use "l2" thus: > > if (l2): # only then does it make it a boolean? That doesn't affect the type of the object with the name "l2" at all. It checks to see if l2 has a false value or not. Examples of basic objects with false values are an iteger 0, a floating point 0.0, an empty string "", an empty list [], an empty tuple (), or an empty dictionary {}. > and if I did, > > if (l2 = "hello"): # would it become string? That's not legal python. I presume you mean if l2 == "hello": The expression l2 == "hello" checks to see if the object with the name "l2" is a string with the value "hello". If the object you passed to the function is a string object with the value "hello", that experession will be true. The expression will be false for any object that isn't a string, and false for any string object that doesn't have the value "hello". > and what if I never used it in the definition body? Then it doesn't get used. -- Grant Edwards grante Yow! I just forgot my at whole philosophy of life!!! visi.com From roccomoretti at hotpop.com Mon Oct 3 14:52:49 2005 From: roccomoretti at hotpop.com (Rocco Moretti) Date: Mon, 03 Oct 2005 13:52:49 -0500 Subject: Reply-To header In-Reply-To: <7rc0f.11261$Un.585792@phobos.telenet-ops.be> References: <2ECA6FE9-3C8F-4C60-9E89-70CC078B14EF@gmail.com> <7rc0f.11261$Un.585792@phobos.telenet-ops.be> Message-ID: Roel Schroeven wrote: > Peter Decker wrote: > >>On 10/3/05, Roel Schroeven wrote: >> >>On lists like this, where everyone benefits by sharing information, it >>seems pretty lame to hide behind purist arguments about Reply-To: >>headers. The default behavior should be the one most useful to the >>list. Think for a moment how many useful bits of information you've >>missed because the default for this list it to make conversations >>private. > > > The default of this list is not to make conversations private; in fact > the list doesn't have any default. It's you who chooses to send replies > to the original author, to the list, or both, by choosing which button > to press in your mail client. It's a sad but unavoidable fact that most people, in the regular course of emailing, never use (nor have reason to use) the "reply to all" button. In any "normal" email exchange, hitting the reply button does what you want it to. As a consequence of this, a large portion of the e-mail using public never thinks to do more than hit the "reply" button. It's great that *you* and *I* are technically savvy enough to hit the "reply all/list" button when needed, but the other people on the list might not be. I've seen mailing lists reduced to near uselessness because of it: you get people posting questions to the list, but no replies, because all of the people replying are responding by pressing "reply" and sending private messages. FWIW, I use the newsgroup version of this list, and the "reply" button on my mail/newsreader does what I want it too - reply to the list only. (I hate getting an additional personal email for a publicly posted response) From Gerald.Klix at klix.ch Wed Oct 26 04:11:39 2005 From: Gerald.Klix at klix.ch (Gerald Klix) Date: Wed, 26 Oct 2005 10:11:39 +0200 Subject: Listen in promiscuous mode (Sniffer) on UDP port 162 and copy packetsto another port References: <3DC50FF8E8D8CF42983C2ACB9230FA4FA0038A@MNTNRA02-FNP00.telkom.co.za> Message-ID: <002201c5da04$e489fd20$e92d200a@ppp5> Hi Henko, the proper solution to this problem ist to use on libpcap's python bindings, like for example Billy The Kid. Here are some pointers: http://home.student.utwente.nl/g.v.berg/btk/ http://pycap.sourceforge.net/ http://monkey.org/~dugsong/pypcap/ http://www.tcpdump.org/ (libpcap) HTH Gerald ----- Original Message ----- From: Henko Gouws (H) To: python-list at python.org Sent: Tuesday, October 25, 2005 10:26 AM Subject: Listen in promiscuous mode (Sniffer) on UDP port 162 and copy packetsto another port Dear reader An application A opens UDP port 162 and listens for incoming packets. We have another application B that wants to receive the same information from UDP port 162 but this application cannot open the port 162 because it is already opened by application A. We want both A and B to receive information from port 162. Does anyone know how to implement such a solution using Python or give relevant advice? Alternatively does anyone know about any postings that involved Ethernet sniffers or Python programs listening to network traffic in promiscuous mode? Thank you regards Henko Gouws (Pr. Eng.) Senior Engineer: Technical Product Development Telkom Development Lab Tel: +27 12 529 7385 Fax: +27 12 548 0065 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This e-mail and its contents are subject to the Telkom SA Limited e-mail legal notice available at http://www.telkom.co.za/TelkomEMailLegalNotice.PDF ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- http://mail.python.org/mailman/listinfo/python-list From aleaxit at yahoo.com Fri Oct 28 00:34:25 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 27 Oct 2005 21:34:25 -0700 Subject: How to replace all None values with the string "Null" in a dictionary References: <1130444785.353905.85380@g47g2000cwa.googlegroups.com> <867jbyit7b.fsf@bhuda.mired.org> <43618c43.1143739260@news.oz.net> Message-ID: <1h540ra.1b4wj2t1gof1syN%aleaxit@yahoo.com> Bengt Richter wrote: ... > Which is probably more efficient than one-liner updating the dict with > > mydict.update((k,'Null') for k,v in mydict.items() if v is None) ...which in turn is probably better than _auxd = {None: "Null"} newd = dict((k, _auxd.get(k, c) for k, c in mydict.items()) [which might be a nice idea if you wanted to do _several_ substitutions;-)...] Alex From rrr at ronadam.com Thu Oct 6 15:15:48 2005 From: rrr at ronadam.com (Ron Adam) Date: Thu, 06 Oct 2005 19:15:48 GMT Subject: "no variable or argument declarations are necessary." In-Reply-To: <4344c53e.3325034196@news.oz.net> References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <6xO0f.166857$p_1.72982@tornado.tampabay.rr.com> <4344c53e.3325034196@news.oz.net> Message-ID: Bengt Richter wrote: > On Wed, 05 Oct 2005 11:10:58 GMT, Ron Adam wrote: >>Looking at it from a different direction, how about adding a keyword to >>say, "from this point on, in this local name space, disallow new >>names". Then you can do... >> >>def few(x,y): >> a = 'a' >> b = 'b' >> i = j = k = l = None >> no_new_names >> # raise an error after here if a new name is used. >> ... >> for I in range(10): <-- error >> ... >> >>This is more suitable to Pythons style than declaring types or variables >>I think. Add to this explicit name-object locking to implement >>constants and I think you would have most of the features you want. >> > > You can do that now with a decorator, if you are willing to assign something > to no_new_names (so it won't give you a name error if it doesn't exist). E.g., Works for me. __lock_names__ = True It's not too different than __name__ == '__main__'... > >>> def nnn(f): > ... names = f.func_code.co_names > ... assert 'no_new_names' not in names or names[-1]=='no_new_names', 'Bad name:%r'%names[-1] > ... return f > ... > >>> @nnn > ... def few(x,y): > ... a = 'a' > ... b = 'b' > ... i = j = k = l = None > ... no_new_names=None > ... for i in range(10): print i, > ... > Traceback (most recent call last): > File "", line 1, in ? > File "", line 3, in nnn > AssertionError: Bad name:'range' Hmm... To make it work this way, the globals and arguments need to have local references. @nnn def few(x,y): global range range = range x,y = x,y a = 'a' b = 'b' i = j = k = l = None L = 1 __no_new_names__ = True L += 1 for i in range(x,y): print I > >>> @nnn > ... def few(x,y): > ... a = 'a' > ... b = 'b' > ... i = j = k = l = None > ... no_new_names=None > ... return a,b,i,j,k,l > ... > >>> few(123,456) > ('a', 'b', None, None, None, None) > > No guarantees, since this depends on the unguaranteed order of f.func_code.co_names ;-) I had the thought that collecting the names from the 'STORE FAST' lines of dis.dis(f) would work nicely, but... dis.dis() doesn't return a string like I expected, but prints the output as it goes. This seems like it would be easy to fix and it would make the dis module more useful. I'd like to be able to do... D = dis.dis(f) An alternate option to output the disassembly to a list of of tuples. That would make analyzing the output really easy. ;-) Something like... good_names = [] nnnames = False for line in dis.dislist(f): if line[2] = 'SAVE_FAST': if not nnnames: if line[-1] = '(__no_new_names__)': nnnames=True continue good_names.append(line[-1]) else: assert line[-1]in good_names, 'Bad name:%r'% line[-1] So, I wonder what kind of errors can be found by analyzing the disassembly? >>so... >> >> no_new_names # limit any new names >> lock_name name # lock a name to it's current object > > That last one you could probably do with a decorator that imports dis and > checks the disassembly (or does the equivalent check of the byte code) of f > for STORE_FASTs directed to particular names after the lock_name name declaration, > which you would have to spell as a legal dummy statement like > lock_name = 'name' > > or perhaps better, indicating a locked assignment e.g. to x by > > x = lock_name = expr # lock_name is dummy target to notice in disassembly, to lock x from there on Using dis.dis it becomes two sequential 'STORE_FAST' operations. So add (x) to the don't change list, and catch it on the next 'STORE_FAST' for (x). ;-) 28 12 LOAD_GLOBAL 2 (True) 15 DUP_TOP 16 STORE_FAST 0 (x) 19 STORE_FAST 8 (__lock_name__) >>Since names are stored in dictionaries, a dictionary attribute to >>disallow/allow new keys, and a way to set individual elements in a >>dictionary to read only would be needed. Once you can do that and it >>proves useful, then maybe you can propose it as a language feature. > > I would want to explore how to compose functionality with existing elements > before introducing either new elements or new syntax. E.g., the dictionaries > used for instance attribute names and values already exist, and you can already > build all kinds of restrictions on the use of attribute names via properties > and descriptors of other kinds and via __getattribute__ etc. That was more or less what I had in mind, but I think keeping things as passive as possible is what is needed. One thought is to use this type of thing along with __debug__. if __debug__: __nnn__ = True Wouldn't a debug block or suite be better than an if __debug__:? Just a thought. Even if the -0 option is given the if __debug__: check is still there. Which means you still need to comment it out if it's in an inner loop. debug: __nnn__ = True # Is not included if __debug__ is false. or... MAX = 256 MIN = 0 debug: __lock__ = MIN, MAX # helps checker app __no_new_names__ = True # find bugs. for MAX in range(1000): # If __debug__, checker app catches this. if mMAX: print m >>These might also be checked for in the compile stage and would probably >>be better as it wouldn't cause any slow down in the code or need a new >>dictionary type. > > Although note that the nnn decorator above does its checking at run time, > when the decorator is executed just after the _def_ is anonymously _executed_ > to create the function nnn gets handed to check or modify before what it > returns is bound to the def function name. ;-) Yes. ;-) Is there a way to conditionally decorate? For example if __debug__ is True, but not if it's False? I think I've asked this question before. (?) Cheers, Ron From mwm at mired.org Tue Oct 25 16:08:37 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 25 Oct 2005 16:08:37 -0400 Subject: [OT] Re: output from external commands References: <435C6642.8020504@colannino.org> <200510241904.52917.bulliver@badcomputer.org> Message-ID: <868xwh4awq.fsf@bhuda.mired.org> Terry Hancock writes: > I think Mr. Lundh's point was only that the output from glob.glob is already > guaranteed to be strings, so using either '%s'%f or str(f) is superfluous. Just for the record - this was why I asked what the point was in the first place. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From johnandsarah at estragon.freeserve.co.uk Sat Oct 8 19:48:13 2005 From: johnandsarah at estragon.freeserve.co.uk (John Perks and Sarah Mount) Date: Sun, 9 Oct 2005 00:48:13 +0100 Subject: [regex] case-splitting strings in unicode Message-ID: I have to split some identifiers that are casedLikeThis into their component words. In this instance I can safely use [A-Z] to represent uppercase, but what pattern should I use if I wanted it to work more generally? I can envisage walking the string testing the unicodedata.category of each char, but is there a regex'y way to denote "uppercase"? Thanks John From rich.teer at rite-group.com Sat Oct 8 19:33:13 2005 From: rich.teer at rite-group.com (Rich Teer) Date: Sat, 08 Oct 2005 23:33:13 GMT Subject: Jargons of Info Tech industry In-Reply-To: <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> Message-ID: On Sat, 8 Oct 2005, Roedy Green wrote: > Some people use email PRIMARILY for sharing photos. WHat the hell has that got to do with HTML email? Sending photos is an example of what attachments are for. > -- > Canadian Mind Products, Roedy Green. > http://mindprod.com Again taking new Java programming contracts. > -- Rich Teer, SCNA, SCSA, OpenSolaris CAB member President, Rite Online Inc. Voice: +1 (250) 979-1638 URL: http://www.rite-group.com/rich From http Fri Oct 7 08:30:56 2005 From: http (Paul Rubin) Date: 07 Oct 2005 05:30:56 -0700 Subject: "no variable or argument declarations are necessary." References: <3qi8erFf252rU1@uni-berlin.de> <3qkdbrFfgga9U1@uni-berlin.de> <3qkn7qFffkl6U1@uni-berlin.de> <3qkr1hFfgj5uU1@uni-berlin.de> <7xr7ax690j.fsf@ruckus.brouhaha.com> <434651f4$0$11145$626a14ce@news.free.fr> <7xwtkp8rwy.fsf@ruckus.brouhaha.com> <1128687719.783871.50090@f14g2000cwb.googlegroups.com> Message-ID: <7x7jcpzeyn.fsf@ruckus.brouhaha.com> "Diez B. Roggisch" writes: > - FPs share their own set of problems - try writing a server. The > have inherent troubles with event-driven programs. Erlang? > Still, FP is cool. But python too. And just attaching some > type-inference to python won't work. Yeah, I've figured declarations in Python would be more like Common Lisp's, i.e. optional, enforced at compile time only when the compiler can easily figure it out, and at runtime otherwise. From howardrh at westerncom.net Wed Oct 26 14:16:29 2005 From: howardrh at westerncom.net (hrh1818) Date: 26 Oct 2005 11:16:29 -0700 Subject: suggestions between these two books References: Message-ID: <1130350589.728424.193990@o13g2000cwo.googlegroups.com> I suggest you widen your search and you take a look at Chris Fehily's Python book. It is one of Peachpit Press's Visual Quickstart Guide books. The reason I suggest this book is it provides a lot more short examples of basic Python code than the two in your list. Howard John Salerno wrote: > Hi all. I'm fairly new to programming and I thought I'd like to try > Python. I'm trying to decide between these two books: > > Learning Python (O'Reilly) > Beginning Python: From Novice to Professional (APress) > > and I was hoping you might have some suggestions. LP seems to be a good > intro, but the other was published only a month ago and covers 2.4. So > one question would be, is 2.2 different enough from 2.4 to warrant > getting the newer book for that reason? > > I might end up getting both eventually, but to start with I'm not sure > which to choose. > > Thanks! From enleverlesO.OmcO at OmclaveauO.com Sun Oct 2 15:45:00 2005 From: enleverlesO.OmcO at OmclaveauO.com (Do Re Mi chel La Si Do) Date: Sun, 2 Oct 2005 21:45:00 +0200 Subject: Parrot & Python ? Message-ID: <4340393e$0$16536$626a14ce@news.free.fr> Hi ! On the site of Amber : http://xamber.org/index.html We can to view the sentence : "Parrot version of Python" Question : what is "Parrot version of Python" ? @-salutations Michel Claveau From tim.golden at viacom-outdoor.co.uk Wed Oct 26 09:06:46 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Wed, 26 Oct 2005 14:06:46 +0100 Subject: Windows vs Linux [was: p2exe using wine/cxoffice] Message-ID: <9A28C052FF32734DACB0A288A3533991044D22A5@vogbs009.gb.vo.local> Tim Golden enlightened us with: > But as far as I can tell from my experience and from the docs -- and > I'm not near a Linux box at the mo -- having used ctrl-r to recall > line x in the history, you can't just down-arrow to recall x+1, x+2 > etc. Or can you? [Sybren] With bash as well as the Python interactive shell: [.. explanation snipped ..] Thanks very much. 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 davids at webmaster.com Tue Oct 18 23:30:42 2005 From: davids at webmaster.com (David Schwartz) Date: Tue, 18 Oct 2005 20:30:42 -0700 Subject: Microsoft Hatred FAQ References: <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <867jcbzdw9.fsf@bhuda.mired.org> <4vcbl1dkek9kr86embmgrj70vk945t99ho@4ax.com> Message-ID: "Roedy Green" wrote in message news:4vcbl1dkek9kr86embmgrj70vk945t99ho at 4ax.com... > On Tue, 18 Oct 2005 11:53:29 -0700, "David Schwartz" > wrote or quoted : >>The only obligation Microsoft has is to their shareholders. >>> >>> If you genuinely believe that, you are a psychopath. >> >> That's almost as convincing as "that's what you think". > Taken literally, you think MS has no obligation to obey the law, to > its customers, to its employees. No, taken stupidly. Hint: would or would not MS executives disobeying the law constitute a betrayal of their obligation to their shareholders? > I don't think you will find many CEOs espousing those sentiments, > though you will in alt.politics.bush from those who have just read > their first book outside of school reading and picked an Ayn Rand > novel. The validity of an idea does not depend upon who it comes from. This is a sad attempt at guilt by association. DS From salvatore.didio at wanadoo.fr Sun Oct 2 12:56:05 2005 From: salvatore.didio at wanadoo.fr (Salvatore) Date: 2 Oct 2005 09:56:05 -0700 Subject: Nufox : Xul + Python In-Reply-To: References: <1128163366.631178.74800@o13g2000cwo.googlegroups.com> <1128182754.232912.9980@z14g2000cwz.googlegroups.com> <433f051f$0$49786$ed2e19e4@ptn-nntp-reader04.plus.net> <1128249650.166566.81790@g44g2000cwa.googlegroups.com> <1128255017.708134.49380@g14g2000cwa.googlegroups.com> Message-ID: <1128272165.047015.264920@g14g2000cwa.googlegroups.com> As you said this is in early stage 0.1-alpha-alpha :-) I'm not the author of this interesting piece of work it is Tim Stebbing I only wanted to share Tim's work. Don't hesitate to contact him on the nufox mailin list It runs on top of twisted-nevow. Indeed for now the application is not reinitialized on load, but those are simple examples and there is not yet 'session object' Regards From cc at dd.org Thu Oct 20 06:58:52 2005 From: cc at dd.org (cc at dd.org) Date: Thu, 20 Oct 2005 18:58:52 +0800 Subject: =?gb2312?B?1NrP+8+iICJIaSLW0Leiz9ayoba+?= Message-ID: <20051020105910.580A91E4004@bag.python.org> The message contains Unicode characters and has been sent as a binary attachment. From jepler at unpythonic.net Tue Oct 11 22:22:00 2005 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Tue, 11 Oct 2005 21:22:00 -0500 Subject: [PIL]: Question On Changing Colour In-Reply-To: <00fe01c5cf7c$410750e0$69820257@Gavana> References: <00fe01c5cf7c$410750e0$69820257@Gavana> Message-ID: <20051012022200.GJ21569@unpythonic.net> If you're always going from grey to tinted, then the easiest way is to treat it as a 'P' image with a special palette. I believe this function will prepare the palette: def make_palette(tr, tg, tb): l = [] for i in range(255): l.extend([tr*i / 255, tg*i / 255, tb*i / 255]) return l Here's an example: import Image A, B, C = map(chr, [64, 128, 192]) i = Image.fromstring( 'P', (4,4), ''.join([ B,B,B,B, B,C,C,A, B,C,C,A, B,A,A,A])) i.putpalette(make_palette(64,64,255)) i.show() Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From henkjan at xs4all.nl Sun Oct 23 17:09:51 2005 From: henkjan at xs4all.nl (Henk-Jan de Jong) Date: Sun, 23 Oct 2005 23:09:51 +0200 Subject: Hengelsportbeurs Message-ID: <435BFC1F.3090308@xs4all.nl> http://www.drentorganisatiebureau.nl/beurs/indexfront.html Nog zin om te gaan? From fredrik at pythonware.com Sat Oct 8 15:39:40 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 8 Oct 2005 21:39:40 +0200 Subject: new forum -- homework help/chit chat/easy communication References: <1128798687.305818.66010@g49g2000cwa.googlegroups.com> <200510082136.00441.mail@tuxipuxi.org> Message-ID: Michael Goettsche wrote: > Besides that, it's cheap advertising. Would it have been harder to post the > direct forum link than to link to his company's website? company? From bonono at gmail.com Mon Oct 17 06:32:11 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 17 Oct 2005 03:32:11 -0700 Subject: generic xmerge ? Message-ID: <1129545131.875544.122630@f14g2000cwb.googlegroups.com> Hi, I was reading this recipe and am wondering if there is a generic version of it floating around ? My list is a tuple (date, v1, v2, v3) and I would like it to sort on date. The documentation doesn't mention how the items are compared and the example only use integers. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/141934 From jabel at plus.net Wed Oct 19 06:16:33 2005 From: jabel at plus.net (John Abel) Date: Wed, 19 Oct 2005 11:16:33 +0100 Subject: "dynamical" importing In-Reply-To: References: <1129711017.413612.60350@f14g2000cwb.googlegroups.com> <43560961.9070504@plus.net> Message-ID: <43561D01.70700@plus.net> Fredrik Lundh wrote: >John Abel wrote: > > > >>def _importModule( moduleName ): >> modName = __import__ ( moduleName ) >> modComponents = moduleName.split( '.' ) >> for indivComp in modComponents[ 1: ]: >> modName = getattr( modName, indivComp ) >> >> return modName >> >> > >__import__ takes a module name, not an arbitrary file name. > > > > > > > Didn't mean to imply that it did. By pathToModule, I meant spam.ham as in http://localhost/documentation/Python-Docs-2.4.1/lib/built-in-funcs.html#l2h-6 ( hopefully, that should explain things to the OP ). J From donn at u.washington.edu Mon Oct 17 12:58:17 2005 From: donn at u.washington.edu (Donn Cave) Date: Mon, 17 Oct 2005 09:58:17 -0700 Subject: Writing an immutable object in python References: <1129562898.812915.238430@g14g2000cwa.googlegroups.com> Message-ID: In article <1129562898.812915.238430 at g14g2000cwa.googlegroups.com>, "Mapisto" wrote: > I've noticed that if I initialize list of integers in the next manner: > > >>> my_list = [0] * 30 > > It works just fine, even if I'll try to assign one element: > > >>> id( my_list[4] ) > 10900116 > >>> id( my_list[6] ) > 10900116 > >>> my_list[4] = 6 > >>> id( my_list[4] ) > 10900044 > >>> id( my_list[6] ) > 10900116 > > The change in the poision occurs becouse int() is an immutable object. > > if I will do the same with a user-defined object, This reference > manipulating will not happen. So, every entry in the array will refer > to the same instance. Not at all. If you do the same thing, class C: pass c = C() a = [c]*12 ... etc., you should observe the same pattern with respect to object identities. Mutability doesn't really play any role here. > Is there a way to bypass it (or perhaps to write a self-defined > immutable object)? Bypass what? What do you need? Donn Cave, donn at u.washington.edu From sjuranic at gmail.com Tue Oct 25 18:34:37 2005 From: sjuranic at gmail.com (Steve Juranich) Date: Tue, 25 Oct 2005 15:34:37 -0700 Subject: Making "import" *SLIGHTLY* more verbose? Message-ID: <56190b6c0510251534xd69e4c1u443d0d9512df1c62@mail.gmail.com> First of all, just let me say that I'm aware of the "-v" switch for Python, and I don't want anything nearly that verbose. I often long for the following behavior from Python when I'm running interactively: When a new module is imported, I'd like the path to the file providing the module to be printed out to the screen. If the module is already in sys.modules, then don't worry about printing anything. The best thing that I can think of to do is something like: __builtins__.__real_import__ = __builtins__.__import__ def noisy_import(name, globals = globals(), locals = locals(), fromlist = []): printit = name not in sys.modules mod = __real_import__(name, globals, locals, fromlist) if printit: try: print '## Loading %s (%s)' % (mod.__name__, mod.__file__) except AttributeError: print '## Loading %s (built-in)' % mod.__name__ return mod __builtins__.__import__ = noisy_import Which seems to work okay for basic kinds of modules, but doesn't quite work right for modules that belong to a particular class. Any suggestions on what I might be missing here? I would imagine that this is a cookbook type thing, and if there are any references on how to do this, I'd greatly appreciate it (I couldn't come up with the right Google magic words). Thanks in advance for any help. -- Steve Juranich Tucson, AZ USA From apardon at forel.vub.ac.be Thu Oct 20 05:00:48 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 20 Oct 2005 09:00:48 GMT Subject: Would there be support for a more general cmp/__cmp__ References: Message-ID: Op 2005-10-20, Duncan Booth schreef : > Antoon Pardon wrote: > >> The problem now is that the cmp protocol has no way to >> indicate two objects are incomparable, they are not >> equal but neither is one less or greater than the other. > > If that is the case then you implement __eq__ and __ne__ to return > True/False and make cmp throw an exception. I don't see any need to extend > the cmp protocol. That is not sufficient. There are domains where an order exists, but not a total order. So for some couples of elements it is possible to say one is less than the other, but not for all such couples. Your solution wouldn't allow for such a case. -- Antoon Pardon From bulliver at badcomputer.org Wed Oct 26 07:37:56 2005 From: bulliver at badcomputer.org (darren kirby) Date: Wed, 26 Oct 2005 04:37:56 -0700 Subject: Windows vs Linux [was: p2exe using wine/cxoffice] In-Reply-To: <9A28C052FF32734DACB0A288A3533991044D22A1@vogbs009.gb.vo.local> References: <9A28C052FF32734DACB0A288A3533991044D22A1@vogbs009.gb.vo.local> Message-ID: <200510260438.02576.bulliver@badcomputer.org> quoth the Tim Golden: > As it happens, (and I suspect I'll have to don my flameproof suit here), > I prefer the Windows command line to bash/readline for day-to-day use, > including in Python. Why? Because it does what I can't for the life of > me get readline to do: you can type the first few letters of a > previously-entered command and press F8. This brings up (going backwards > > with further presses) the last command which starts like that. And > *then* > you can just down-arrow to retrieve the commands which followed it. > If someone can tell me how to do this with bash/readline I will be > indebted to them and it will increase my chances of switching to Linux > a bit! (Although not at work where I have no choice!) Try ctrl-r in bash, then type your first few letters... -d -- darren kirby :: Part of the problem since 1976 :: http://badcomputer.org "...the number of UNIX installations has grown to 10, with more expected..." - Dennis Ritchie and Ken Thompson, June 1972 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From smadim2 at grads.ece.mcmaster.ca Wed Oct 12 09:11:44 2005 From: smadim2 at grads.ece.mcmaster.ca (Mohammed Smadi) Date: Wed, 12 Oct 2005 09:11:44 -0400 (EDT) Subject: calling matlab Message-ID: Hi; Does anyone know if we can call matlab for a python or bash script while feeding the matlab script some command line arguments? I have an interactive matlab script which i want to automate by feeding the args from a script. I know this is probably more suitable to a matlab group but any ideas will be appreciated. thanks moe smadi From rolf.wester at ilt.fraunhofer.de Fri Oct 21 05:21:43 2005 From: rolf.wester at ilt.fraunhofer.de (Rolf Wester) Date: Fri, 21 Oct 2005 11:21:43 +0200 Subject: Python extension module segmentation fault In-Reply-To: References: <4358a322$1@news.fhg.de> Message-ID: <4358b329@news.fhg.de> Robert Kern wrote: > > > Did you call import_array() in init_mytest()? > No I didn't. Thank you very much for your help. Now it works. With kind regards Rolf Wester From garabik-news-2005-05 at kassiopeia.juls.savba.sk Sun Oct 23 10:02:06 2005 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Sun, 23 Oct 2005 14:02:06 +0000 (UTC) Subject: Syntax across languages References: <1130052687.396109.145420@o13g2000cwo.googlegroups.com> Message-ID: Fredrik Lundh wrote: > >> - comparison returns 4 values (i.e. inferior, equal, superior or not >> comparable), as in Pliant: "compare" > >>>> cmp("a", "b") > -1 >>>> cmp("a", "a") > 0 >>>> cmp("b", "a") > 1 >>>> cmp("?", u"?") > Traceback (most recent call last): > File "", line 1, in ? > UnicodeDecodeError: 'ascii' codec can't decode byte /.../ that is not because of the comparison, but because of the coercion: >>> '?'+u'?' Traceback (most recent call last): File "", line 1, in ? UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128) >>> > > sure looks like four possible outcomes. >>> cmp(1, 1+2j) Traceback (most recent call last): File "", line 1, in ? TypeError: cannot compare complex numbers using <, <=, >, >= a fifth one :-) -- ----------------------------------------------------------- | 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 larry.bates at websafe.com Wed Oct 26 17:04:20 2005 From: larry.bates at websafe.com (Larry Bates) Date: Wed, 26 Oct 2005 16:04:20 -0500 Subject: 64 bit python binaries (or builds) for Xeon and Opteron architectures on Windows platforms In-Reply-To: <1130347953.003322.288350@o13g2000cwo.googlegroups.com> References: <1130347953.003322.288350@o13g2000cwo.googlegroups.com> Message-ID: <435FEF54.8010807@websafe.com> We are running 64 bit compiled python on Red Hat Fedora Core 3. Hardware is 64 bit on Dual Opteron HP servers running SMP. FYI, Larry louis_pastorik at symantec.com wrote: > Does anyone have any information about 64 bit python support for Xeon > and Opteron architectures on Windows platforms? If anyone has built the > python runtime on either of these platforms before I would be really > interested. Thanks. > From rrr at ronadam.com Sun Oct 23 00:52:19 2005 From: rrr at ronadam.com (Ron Adam) Date: Sun, 23 Oct 2005 04:52:19 GMT Subject: Question about inheritance... In-Reply-To: <1130028891.235502.236320@g44g2000cwa.googlegroups.com> References: <1130017209.078943.119990@g43g2000cwa.googlegroups.com> <_My6f.1423$Zd.1063@tornado.tampabay.rr.com> <1130028891.235502.236320@g44g2000cwa.googlegroups.com> Message-ID: <7GE6f.1836$Zd.449@tornado.tampabay.rr.com> KraftDiner wrote: > Well here is a rough sketch of my code... > This is giving my two problems. > > 1) TypeError: super() argument 1 must be type, not classobj > 2) I want to be sure the the draw code calls the inherited classes > outline and not its own... > > class Shape: > def __init__(self): > pass > def render(self): > print self.__class___ > self.outline() > def outline(self): > pass > > class Rect(Shape): > def __init__(self): > super(self.__class__, self).__init__() > def render(self): > super(self.__class__, self).draw() > def outline(self): > print 'outline' + self.__class__ I think Alex probably answered your question. I'm still trying to figure out how use inheritance effectively myself. Are you using this as an way to learn Python or do you want to use Python to render images? What I'm trying to do in relation to this is to build a "small" subset of the SVG standard in tkinter. It looks like the SVG standard is going to be very popular graphic format on the web, hand held devices, and as a general graphics format. http://www.w3.org/TR/SVG/ Python doesn't have good SVG support built in without importing a third party library, and the ones that are available need other libraries, etc... They don't really support using SVG directly in programs. So I'm experimenting with emplimenting some of the SVG functionality in Tkinter for drawing icons in dialog box's. It's an experiment at the moment, but I'd like to see it grow into something more. It doesn't need to be exactly like it, but the closer it is to the way the SVG standard works, the better. That would make it easier to use some 'simple' existing SVG images, and easier to create SVG files as well, as it closes the gap between the canvas object and the VGA standard. Anyway, I'm more than willing to get involved in a group to do this if anyone is interested and also thinks it may be worth while. Cheers, Ron From rschroev_nospam_ml at fastmail.fm Mon Oct 3 09:16:01 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Mon, 03 Oct 2005 13:16:01 GMT Subject: Reply-To header In-Reply-To: References: <2ECA6FE9-3C8F-4C60-9E89-70CC078B14EF@gmail.com> Message-ID: Richie Hindle wrote: > [Andrew] > >>Is it just me, or does python-list at python.org not send with a Reply- >>To header? > > > It's not just you. I don't get one either. Indeed, and that's by design: http://www.unicom.com/pw/reply-to-harmful.html -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From lassevk at gmail.com Thu Oct 20 12:24:45 2005 From: lassevk at gmail.com (=?iso-8859-1?q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: 20 Oct 2005 09:24:45 -0700 Subject: sort problem In-Reply-To: <4357c22d$0$8481$5fc30a8@news.tiscali.it> References: <4357c22d$0$8481$5fc30a8@news.tiscali.it> Message-ID: <1129825485.883210.297890@f14g2000cwb.googlegroups.com> How about: list.sort(key=lambda x: x[3]) Does that work? From gh at ghaering.de Mon Oct 17 04:42:40 2005 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 17 Oct 2005 10:42:40 +0200 Subject: subtyping a builtin type in a C extension In-Reply-To: <1129522775.678995.80090@z14g2000cwz.googlegroups.com> References: <1129522775.678995.80090@z14g2000cwz.googlegroups.com> Message-ID: <43536400.7090703@ghaering.de> shawn wrote: > I am trying to make a subtype of a string. Initially it will have no > new methods or attributes, the C equivalent of: > > class myStr(str): > pass > > I have experimented a bit, but am currently making a mess of it. Does > anybody have an example they can point to of inheriting from a builtin, > or a suggestion to point me in the right direction? The Python source distribution contains an example module xxsubtype that shows how to subclass builtins: http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Modules/xxsubtype.c?rev=2.15.2.1&view=markup -- Gerhard From steve at REMOVETHIScyber.com.au Sun Oct 16 19:36:11 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 17 Oct 2005 09:36:11 +1000 Subject: Comparing lists - somewhat OT, but still ... References: <1129216693.445956.155490@g47g2000cwa.googlegroups.com> <7xk6gdyxuu.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 16 Oct 2005 14:07:37 -0700, Paul Rubin wrote: > The complexity of hashing depends intricately on the the data and if > the data is carefully constructed by someone with detailed knowledge > of the hash implementation, it may be as bad as O(n) rather than O(1) > or O(sqrt(n)) or anything like that. Experimentation in the normal > will not discover something like that. You have to actually > understand what's going on. See for example: Yes, that is a very good point, and I suppose if a hostile user wanted to deliberately construct a data set that showed off your algorithm to its worst behaviour, they might do so. But if you are unlikely to discover this worst case behaviour by experimentation, you are equally unlikely to discover it in day to day usage. Most algorithms have "worst case" behaviour significantly slower than their best case or average case, and are still perfectly useful. -- Steven. From notrealaddress at all.com Tue Oct 11 05:26:58 2005 From: notrealaddress at all.com (Chris Dewin) Date: Tue, 11 Oct 2005 18:26:58 +0900 Subject: Learning Python References: Message-ID: On Mon, 10 Oct 2005 17:20:35 +0000, dannypatterso wrote: [snip] >> I'm a hobby programmer using mostly BASIC(s) and some Java. I know >> procedural programming and I know what encapsulation, inheritance and >> polymorphism are but I have very little experience in using them as >> I've written just a few Java programs (i.e., I guess I could use a >> primer in OO programming). There was an excellent such primer on devshed, by Icarus, but they appear to have taken it down. I saved a copy of it to my HD. Would there be anything morally, or legally wrong with me uploading it to my site? -- www.wintergreen.in From mscottschilling at hotmail.com Tue Oct 18 16:14:58 2005 From: mscottschilling at hotmail.com (Mike Schilling) Date: Tue, 18 Oct 2005 20:14:58 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86fyqzzskt.fsf@bhuda.mired.org> <86y84rxryr.fsf@bhuda.mired.org> <2R75f.2005$dO2.1121@newssvr29.news.prodigy.net> <86mzl6yfko.fsf@bhuda.mired.org> <861x2iy4vs.fsf@bhuda.mired.org> Message-ID: <6Jc5f.4734$Zv5.2558@newssvr25.news.prodigy.net> "Mike Meyer" wrote in message news:861x2iy4vs.fsf at bhuda.mired.org... > One alternative, as I've said, is to write to the standards, and then > work around bugs in the popular browsers. If the public whim changes > which browser is most popular - I am not holding my breath. > it only has minimal impact on > you. Should you decide to move into a different market, your existing > development process works with only minor changes. From Sk8xHAnDiCApx69 at wmconnect.com Fri Oct 14 23:32:24 2005 From: Sk8xHAnDiCApx69 at wmconnect.com (Sk8xHAnDiCApx69 at wmconnect.com) Date: Fri, 14 Oct 2005 23:32:24 EDT Subject: SAFE CYBER SEX LESSONS Message-ID: <65.4fd3f511.3081d248@wmconnect.com> hi there imhappily married and me and my wife are looking to cyber -------------- next part -------------- An HTML attachment was scrubbed... URL: From my_email_is_posted_on_my_website at munged.invalid Sun Oct 9 03:19:29 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sun, 09 Oct 2005 07:19:29 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> Message-ID: <41hhk195gcipfarnqu85ggs606aqi89ea1@4ax.com> On Sat, 08 Oct 2005 23:33:13 GMT, Rich Teer wrote or quoted : >WHat the hell has that got to do with HTML email? Sending photos >is an example of what attachments are for. Normally you send photos to grandma with captions under each photo. That is far more convenient for the technopeasant receiver than dealing with multiple attachments. People keep thinking of email as a techie preserve. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From my_email_is_posted_on_my_website at munged.invalid Wed Oct 12 18:00:04 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 12 Oct 2005 22:00:04 GMT Subject: Jargons of Info Tech industry References: <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <41hhk195gcipfarnqu85ggs606aqi89ea1@4ax.com> <2dadnfArEfWwvdTeRVnzvA@telenor.com> <0trik1ldrtvuhsdvoai4a7h34q7la1pehl@4ax.com> Message-ID: On Mon, 10 Oct 2005 08:58:42 +1000, Steven D'Aprano wrote or quoted : >Sheesh Roedy, to listen to you go anyone would think that human >communication was impossible before HTML email was invented. People got along fine wearing untanned moosehides too. I don't see any advantage in wearing a hair shirt. That is an unnatural way to talk. I know hundreds of people who would have not the tiniest clue what that email meant. You are indeed fortunate to have landed such a wife. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From robert.kern at gmail.com Wed Oct 19 19:47:26 2005 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 19 Oct 2005 16:47:26 -0700 Subject: Python variables are bound to types when used? In-Reply-To: References: <1129751462.061785.124830@g49g2000cwa.googlegroups.com> <11ld9qtgvead8d0@corp.supernews.com> Message-ID: Steven D'Aprano wrote: > On Wed, 19 Oct 2005 20:06:53 +0000, Grant Edwards wrote: > >>>Now, in Python variables are bound to types when used, right? >> >>Python doesn't have variables. >> >>Python has objects of various types. You can bind 0 or more >>names an object. > > I frequently use "variable" as a synonym for "name" when talking about > Python code. Do people think I am wrong to do so? It depends on context and audience. If you're talking about Python code with other relatively experienced Pythonistas, no I don't think it's wrong. When you're talking about Python versus other languages where "variable" corresponds with "a possibly typed memory location", or you're talking with someone who is coming from such a language, then it's probably best to talk about names and objects. Such pedantry is useful in the latter cases but not so much in the former. -- 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 marcus.ekelund at gmail.com Wed Oct 26 05:15:30 2005 From: marcus.ekelund at gmail.com (Marcus Ekelund) Date: 26 Oct 2005 02:15:30 -0700 Subject: Looping Problem (Generating files - only the last record generates a file) In-Reply-To: <1130316544.381673.209190@g44g2000cwa.googlegroups.com> References: <1130316544.381673.209190@g44g2000cwa.googlegroups.com> Message-ID: <1130318129.981649.312710@f14g2000cwb.googlegroups.com> vasilijepetkovic at yahoo.com wrote: > Hello All, > > I have a problem with the program that should generate x number of txt > files (x is the number of records in the file datafile.txt). > > Once I execute the program (see below) only one file (instead of x > files) is created. The file created is based on the last record in > datafile.txt. > > The program is as follows: > ==================================== > #! python > > HEADER = "This page displays longitude-latitude information" > SUBHEADER = "City" > > for line in open("datafile.txt"): > > > town, latlong = line.split('\t') > > f = open(town + ".txt", "w+") > > f.write(HEADER + "\n") > f.write(SUBHEADER + ": " + town + "\n") > f.write("LAT/LONG" + ": " + latlong + "\n") > f.close() > > > # end > ==================================== > > > > > The datafile.txt is as follows (tab separated columns): > ==================================== > > NYC 1111-2222 > Lima 3333-4444 > Rome 5555-6666 > > ==================================== > > Once executed, the program will create a single file (named Rome.txt) > and it would not create files NYC.txt and Lima.txt as I would expect it > to do. > > I'd appreciate if you can pinpoint my error. Since the lines that handle writing to the file aren't indented as far as the line that splits the data, they are not part of the loop. They are only executed once after the loop has completed, with town and latlong set to the values they got at the last iteration of the loop. It should look more like this: for line in open("datafile.txt"): town, latlong = line.split('\t') f = open(town + ".txt", "w+") f.write(HEADER + "\n") f.write(SUBHEADER + ": " + town + "\n") f.write("LAT/LONG" + ": " + latlong + "\n") f.close() From larry.bates at websafe.com Thu Oct 6 09:20:12 2005 From: larry.bates at websafe.com (Larry Bates) Date: Thu, 06 Oct 2005 08:20:12 -0500 Subject: Copy files to Linux server through ssh tunnel In-Reply-To: References: Message-ID: <4345248C.6050308@websafe.com> You might want to install copy of Cygwin on your Windows box. Then you can use scp or maybe rsync over ssh to do the copying. Works great for me. -Larry Bates durumdara at mailpont.hu wrote: > Hi ! > > I have some backup files on a server farm. > I want to store these local backup files on a backup file server for > "safety's snake". > > These files are compressed zip files with 12 character length password. > But my system admin asked me, how can I improve the safety of the copy > operation, and the storing (now I use Samba share to store these files. I > map the SMB share on the client, copy these files, and unmap SMB). > > Then I thinking to ssh protocol to improve protection. > > The backup script is a py script. I see that Winscp can copy files through > ssh tunnel. Can I do it too ? > How ? How to I do it in pythonic way ? > > Please help me with some examples or urls or other infos ! > > Thanks * 1000: > dd > > > > > > > > ---------------------------------------------- > 1 Gbyte Ingyenes E-Mail T?rhely a MailPont-t?l > http://www.mailpont.hu/ > From steve at holdenweb.com Fri Oct 21 11:17:35 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 21 Oct 2005 16:17:35 +0100 Subject: Compile C program -> .pyc file In-Reply-To: <1129905417.451369.114840@o13g2000cwo.googlegroups.com> References: <1129905417.451369.114840@o13g2000cwo.googlegroups.com> Message-ID: Ernesto wrote: > Is there a way to compile a C program into a .pyc file that has the > same behavior as the compiled C program? > > Thanks! > Here's a start: http://codespeak.net/pipermail/pypy-dev/2003q1/000198.html regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From jason at pengale.com Sat Oct 15 00:58:06 2005 From: jason at pengale.com (Jason Stitt) Date: Fri, 14 Oct 2005 23:58:06 -0500 Subject: Problem splitting a string In-Reply-To: <20051015045208.28476.qmail@web35811.mail.mud.yahoo.com> References: <20051015045208.28476.qmail@web35811.mail.mud.yahoo.com> Message-ID: On Oct 14, 2005, at 11:52 PM, Anthony Liu wrote: > I have this simple string: > > mystr = 'this_NP is_VL funny_JJ' > > I want to split it and give me a list as > > ['this', 'NP', 'is', 'VL', 'funny', 'JJ'] > > 1. I tried mystr.split('_| '), but this gave me: > > ['this_NP is_VL funny_JJ'] Try re.split, as in: import re re.split('_| ', mystr) -Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From heel_spain_scarlet at yahoo.com Mon Oct 10 20:25:44 2005 From: heel_spain_scarlet at yahoo.com (heel_spain_scarlet at yahoo.com) Date: 10 Oct 2005 17:25:44 -0700 Subject: Form Filling in XML Message-ID: <1128990344.387800.174420@g44g2000cwa.googlegroups.com> if i have the following chunck of code how can I look at the Text Nodes of Fillin and compare them with the Element Nodes of Form and if they are equal put the Text Node of Fillin into the Text Node of Form ie)=Monday so put maandag it between
  • and
  • so
  • maantag
  • thanks for the insight import xml.dom.minidom form = """ My Sample Web Page

    What are the weekdays?

    1. Monday
    2. Tuesday
    3. Wednesday
    4. Thursday
    5. Friday

    """ fillin = """ maandagdinsdag woensdagdonderdag vrijdagzaterdag zondag """ For = xml.dom.minidom.parseString(form) # parse some XML into a DOM object Fill = xml.dom.minidom.parseString(fillin) # parse some XML into a DOM object def xmlForm(formstr=None, fillinstr=None): From xah at xahlee.org Tue Oct 18 21:30:49 2005 From: xah at xahlee.org (Xah Lee) Date: 18 Oct 2005 18:30:49 -0700 Subject: Python Doc Error: os.makedirs Message-ID: <1129685449.372717.56900@z14g2000cwz.googlegroups.com> Python doc problem: http://python.org/doc/2.4.2/lib/os-file-dir.html makedirs( path[, mode]) Recursive directory creation function. Like mkdir(), but makes all intermediate-level directories needed to contain the leaf directory. Throws an error exception if the leaf directory already exists or cannot be created. The default mode is 0777 (octal). This function does not properly handle UNC paths (only relevant on Windows systems; Universal Naming Convention paths are those that use the `\\host\path' syntax). New in version 1.5.2. The ?Throws an error exception? should be ?Throws an OSError exception?. -------- i think the function shouldn't complain if dir already exists. How is a programer to distinguish if the dir already exists, or if there's a problem creating the dir? Xah xah at xahlee.org ? http://xahlee.org/ From mlist at fastwebnet.it Tue Oct 18 08:16:45 2005 From: mlist at fastwebnet.it (billie) Date: Tue, 18 Oct 2005 14:16:45 +0200 Subject: popen4 References: Message-ID: Piet van Oostrum wrote: > I think you need something like pyexpect for this. PyExpect seems to be no more mantained. From fredrik at pythonware.com Sat Oct 15 16:11:40 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 15 Oct 2005 22:11:40 +0200 Subject: how to improve simple python shell script (to compile list offiles) References: Message-ID: Jari Aalto wrote: > Thanks, but that will not work. The files are gathered from discrete > places really? so what is that "find" command doing in your code ? compile $(find path/to -type f -name "*.py") seems to me as if python -mcompileall path/to would do exactly what your script does... (if you really think that find does something that compileall or os.walk cannot do, you can fix your script by fixing the identation. the quickest way to do that is to insert an if-statement: ... function compile () { python -c ' if 1: # python code has to start in column 0 import os, sys, py_compile i = 0 ... ) From scott.daniels at acm.org Sat Oct 15 09:20:03 2005 From: scott.daniels at acm.org (Scott David Daniels) Date: Sat, 15 Oct 2005 06:20:03 -0700 Subject: Help with creating a dict from list and range In-Reply-To: References: <910885da0510140626p2f395ae6rbdf69b62cb55a2@mail.gmail.com> Message-ID: <43510186$1@nntp0.pdx.net> James Stroud wrote: > On Friday 14 October 2005 08:37, Steve Holden wrote: >> >>> dct = dict((x[1], x[0]) for x in enumerate(description)) To make the code a breath more obvious: >>> dct = dict((name, seq) for seq, name in enumerate(description)) has the same results. >> >>> dct >> >>{'second': 1, 'third': 2, 'first': 0} >> -- -Scott David Daniels scott.daniels at acm.org From alainpoint at yahoo.fr Fri Oct 7 09:32:32 2005 From: alainpoint at yahoo.fr (alainpoint at yahoo.fr) Date: 7 Oct 2005 06:32:32 -0700 Subject: Python interpreter bug References: <1128686833.994339.295780@f14g2000cwb.googlegroups.com> <1128691014.275838.84750@g44g2000cwa.googlegroups.com> Message-ID: <1128691952.265393.168870@g44g2000cwa.googlegroups.com> There is definitely a bug. Maybe the follownig snippet is more clear: class OBJ: def __init__(self,identifier): self.id=identifier self.allocated=0 #def __cmp__(self,other): # return cmp(other.allocated,self.allocated) mylist=[OBJ(i) for i in range(10)] excluded=[obj for obj in mylist if obj.id in [2,4,6,8]] exclusion_list_by_id=[2,4,6,8] print 'exclusion list by id=',exclusion_list_by_id for obj in mylist: print 'current obj=',obj.id, if obj in excluded: print ' ---> THIS OBJECT IS EXCLUDED' assert obj.id in exclusion_list_by_id continue print If you uncomment the two lines, the assert will be erroneously triggered. Alain From zanesdad at bellsouth.net Wed Oct 5 11:01:43 2005 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Wed, 05 Oct 2005 11:01:43 -0400 Subject: How to create temp file in memory??? In-Reply-To: References: Message-ID: <4343EAD7.9050008@bellsouth.net> Wenhua Zhao wrote: >A.T.T > >Thanks a lot. > > If you could elaborate a bit more, it might be helpful. I'm guessing you want something like StringIO or cStringIO. - jmj From nemesis at nowhere.invalid Fri Oct 14 13:02:27 2005 From: nemesis at nowhere.invalid (Nemesis) Date: Fri, 14 Oct 2005 17:02:27 GMT Subject: [ANN] XPN 0.5.5 released References: <20051013194207.1700.5269.XPN@orion.homeinvalid> <1129300207_2667@spool6-east.superfeed.net> Message-ID: <20051014170644.1803.75237.XPN@orion.homeinvalid> Mentre io pensavo ad una intro simpatica "Cousin Stanley" scriveva: >> XPN (X Python Newsreader) is a multi-platform newsreader >> with Unicode support. >> .... >> .... > > Cousin Nemesis .... > Are the new xpn 5.5 config & data files compatible > with the older xpn 5.0 files ? I'm not 100% sure but I think that they could work. The only thing is changed is the outgoing articles format, so if you have article in the oubox delete them > Can I install the newer xpn version > and move the older data files into it > without reconfiguring & reloading data files ? > > o config.txt > o server_logs.dat > o dats > o groups_info > o groups_list It should work, anyway just make a copy of these files to be sure not to lose them. -- Quidquid latine dictum sit, altum viditur. |\ | |HomePage : http://nem01.altervista.org | \|emesis |XPN (my nr): http://xpn.altervista.org From aleax at mail.comcast.net Sat Oct 15 16:55:46 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Sat, 15 Oct 2005 22:55:46 +0200 Subject: Some set operators References: <1129408019.100885.323870@g47g2000cwa.googlegroups.com> Message-ID: <1h4hwtl.np9wjhchw3duN%aleax@mail.comcast.net> wrote: > Sometimes I suggest to add things to the language (like adding some set > methods to dicts), but I've seen that I tend to forget the meaning of > six set/frozenset operators: > > s & t s &= t > s | t s |= t > s ^ t s ^= t > > My suggestion is to remove them, and keep them only as explicit > non-operator versions (.symmetric_difference(), .update(), > .intersection_update(), etc). But maybe now it's too much late to > remove them... Maybe someone gentle can explain me the advantage of > having/keeping them. Helen:~ alex$ python2.4 -mtimeit -s's1=s2=set()' 's1&s2' 1000000 loops, best of 3: 0.929 usec per loop Helen:~ alex$ python2.4 -mtimeit -s's1=s2=set()' 's1.intersection(s2)' 1000000 loops, best of 3: 1.28 usec per loop Besides avoiding the need for a name look-up, and thus extracting a tiny speed-up of about 0.35 microseconds or so, I can't think of advantages for the infix operator form (but then, I can't think of any advantages for type *int* having the same operators, with bitwise-logic semantics, rather than placing them only in some library module). I still vaguely hope that in 3.0, where backwards incompatibilities can be introduced, Python may shed some rarely used operators such as these (for all types, of course). As long as the operators are there for ints, it makes sense to have them apply to sets as well, of course. Alex From cs at totallybogus.com.invalid Fri Oct 14 15:06:54 2005 From: cs at totallybogus.com.invalid (Cousin Stanley) Date: Fri, 14 Oct 2005 14:06:54 -0500 Subject: [ANN] XPN 0.5.5 released References: <20051013194207.1700.5269.XPN@orion.homeinvalid> <1129300207_2667@spool6-east.superfeed.net> <20051014170644.1803.75237.XPN@orion.homeinvalid> Message-ID: <1129316814_3173@spool6-east.superfeed.net> >> Can I install the newer xpn version >> and move the older data files into it >> without reconfiguring & reloading data files ? Cousin Nemesis .... This worked OK with no problems and I'm posting this reply via xpn-0.5.5 .... I copied the following from the older xpn-0.5.0 version to the newer xpn-0.5.5 version .... dirs .... o dats o groups_info o outbox files .... o custom_headers.txt o groups_list o server_logs.dat No initial configuration, downloading newsrc file, or re-subscribing to newsgroups was required and all of my previously kept & watched messages seem to be in place .... Thanks for the update .... -- Stanley C. Kitching Human Being Phoenix, Arizona ----== 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 codecraig at gmail.com Tue Oct 11 14:00:25 2005 From: codecraig at gmail.com (Java and Swing) Date: 11 Oct 2005 11:00:25 -0700 Subject: Wrapper function In-Reply-To: <3r2c91FhamghU1@uni-berlin.de> References: <1129052312.444144.142950@g44g2000cwa.googlegroups.com> <3r2c91FhamghU1@uni-berlin.de> Message-ID: <1129053625.591216.116340@z14g2000cwz.googlegroups.com> Diez, yes you were right! But I have other problems now. I now have... #include #include #include "Python.h" int doStuff(const char *input, const char *d) {...} static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { int result; char *input = 0; char *d = 0; int ok = PyArg_ParseTuple(args, "ss", &input, &d); if (!ok) return 0; result = doStuff(input, d); return PyBuildValue("i", result); } static PyMethodDef myMethods[] = { {"PyDoStuff", wrap_doStuff, METH_VARARGS, "some documentation"}, {NULL, NULL} }; extern PyMODINIT_FUNC initMyDLL(void) { Py_InitModule4( "MyDLL", myMethods, "my doStuff function", NULL, PYTHON_API_VERSION ); } When I compile, I get two warnings..which are ok. Then when I build my DLL I get.. Linking... Creating library Release/MyDLL.lib and object Release/MyDLL.exp test.obj : error LNK2001: unresolved external symbol _PyBuildValue Release/MyDLL.dll : fatal error LNK1120: 1 unresolved externals Error executing link.exe. MyDLL.dll - 2 error(s), 0 warning(s) ..Any ideas? Diez B. Roggisch wrote: > > PyObject *wrap_doStuff(PyObject *, PyObject *args) { > ^^^^^ > I guess you need a parameter name here.... > > > Diez From steve at holdenweb.com Mon Oct 31 19:39:30 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 01 Nov 2005 00:39:30 +0000 Subject: Asyncore Loop Question In-Reply-To: References: Message-ID: John W wrote: > On 10/31/05, Steve Holden wrote: > >>John W wrote: >> >>>Hello, >>> >>>I have a gui application where I am trying to use the asyncore module to >>>gather data from other computers. I am able to connect, but I am getting >>>constant handle_write_event method calls into my application. It is >>>obviously slowing down the gui processing significantly. >>> >>>My understanding is that the handle_write_event and handle_read_event >> >>are >> >>>both edge notifications and I should just get the method call >> >>essentially >> >>>just once. >>> >>>I think the problem is how I have my loop() call configured. All I am >> >>trying >> >>>to do with the code below is to open the socket (that works) and then >>>receive a single handle_write_event method call. Instead, I am getting >>>constantly barraged with them. >>> >>>I have tried several different types of the loop() call (using poll, >>>timeout...) but with no luck. If anyone can explain what I should be >> >>doing >> >>>to get a single handle_write_event call until I actually write something >> >>to >> >>>the socket (which my code is not presently doing yet), I would >> >>appreciate >> >>>Below is some code showing what I am doing: >>> >>>-------------------------------------------------------------- >>>class Connection(asyncore.dispatcher): >>>def __init__ (self, server_name, port_num ): >>>self.message_queue = [] >>> >>>asyncore.dispatcher.__init__(self) >>>self.create_socket( socket.AF_INET, socket.SOCK_STREAM ) >>>self.connect(( server_name, port_num )) >>> >>> >>>def handle_read_event( self ): >>>print "handle_read_event received" >>> >>> >>>def handle_write_event( self ): >>>print "Asking for a write" >>> >>>if len( self.message_queue ) > 0: >>># Pop the first message off the queue >>>self.send_next_message() >>> >>> >>>class TestApp: >>>def __init__( self, server_name, port_number ): >>> >>>self.nomad = Connection( server_name, port_number ) >>>asyncore.loop() >>> >>> >>>Output ends up being a constant stream of: >>>Asking for a write >>>Asking for a write >>>Asking for a write >>>Asking for a write >>>Asking for a write >>>.... >>>... >>>... >>> >>> >> >>Normally if a socket channel asks for a write and you have no data you >>should respond by removing it from the list of write-enabled channels >>for the asyncore loop until you *do* have some data for it. Otherwise >>every time the loop scans the channels expecting notification it will >>tell you again that you can write to that channel. >> > > Steve, > > Ar you saying that I should close the connection until I have data to write? > Or should I be using the readable and writable methods to turn it off? > > Thanks for your help, unfortunatly, I have struggled with the documentation > and getting a clear understanding of everything. This is my first socket > program as well. > I was actually mis-remembering my asyncore documentation, which is a little sad given that I wrote it :-) What you need is to implement a writable() method. Suppose your output generation creates a buffer is self.buffer, a suitable implementation would look like this: def writable(self): return (len(self.buffer) > 0) As I wrote in the documentation: """ writable( ) Called each time around the asynchronous loop to determine whether a channel's socket should be added to the list on which write events can occur. The default method simply returns True, indicating that by default, all channels will be interested in write events. """ regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From uval at rz.uni-karlsruhe.de Tue Oct 11 13:46:05 2005 From: uval at rz.uni-karlsruhe.de (=?ISO-8859-1?Q?Daniel_Sch=FCle?=) Date: Tue, 11 Oct 2005 19:46:05 +0200 Subject: Learning Python In-Reply-To: <7e6dnQAA36FTBtfeRVn-rg@rogers.com> References: <7e6dnQAA36FTBtfeRVn-rg@rogers.com> Message-ID: Paul DiRezze wrote: > I'm spending the next two weeks off and I'm looking to take a crack at > learning how to program in Python. Here's a list of the places I've > bookmarked: > > http://www.python.org/doc/ and more specifically > http://wiki.python.org/moin/ > http://wiki.python.org/moin/BeginnersGuide > http://www.python.org/doc/Intros.html > http://www.python.org/topics/ > > I'm looking for additional resources (links, names of books, > whatever...) that you think may help me out. > > I'm a hobby programmer using mostly BASIC(s) and some Java. I know > procedural programming and I know what encapsulation, inheritance and > polymorphism are but I have very little experience in using them as I've > written just a few Java programs (i.e., I guess I could use a primer in > OO programming). > > Any ideas? just play a little with interactive python interpreter this is how I made my first steps hth From steve at holdenweb.com Wed Oct 12 10:40:59 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 12 Oct 2005 15:40:59 +0100 Subject: can we save print msg into a file when script running ? In-Reply-To: <1129126067.252195.315080@o13g2000cwo.googlegroups.com> References: <1129079641.137785.320000@g44g2000cwa.googlegroups.com> <1129126067.252195.315080@o13g2000cwo.googlegroups.com> Message-ID: black wrote: > quote: > ======================= > script.py >> script.log 2>&1 > ======================= > > what does 2>&1 mean pls ? > It's Unix shell-speak for "send the standard error stream to the same place as the standard output". Probably a syntax error on Windows ... regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From toufeeqh at gmail.com Wed Oct 5 03:44:26 2005 From: toufeeqh at gmail.com (Toufeeq Hussain) Date: Wed, 5 Oct 2005 13:14:26 +0530 Subject: Help needed in OOP-Python In-Reply-To: References: Message-ID: Fredrik, sigh! I see the problem you mention and I agree. Should have posted the orginal code without edits. :( Anyway I'll try to fill in whereever required. On 10/5/05, Fredrik Lundh wrote: > > > $ python test.py > condition satisfied > Traceback (most recent call last): > File "test.py", line 4, in ? > Test_Case.Option1_constraint() > File "module3.py", line 11, in Option1_constraint > self.FOO_warning.Fire() > AttributeError: Option1_Rule1 instance has no attribute 'FOO_warning' > > FOO_warning? there's no FOO_warning anywhere in the code. FOO_warning is "Option1_warning" from Module3. And, in Module1 comment out the line: "common_subs.write_to_out_file( 'FOO_OUT',self.Warn_text)" ::: > > so, after four attempts, I've found four problems, three of which was > present > in your posted code, but I still haven't seen the problem you reported: > > Traceback (most recent call last): > File "test_case.py", line 7, in ? > TH = constraint.Option1_Rule1() > File "constraint.py", line 13, in __init__ > declaration.Option1.__init__(self) > TypeError: __init__() takes no arguments (1 given) But the script when given as individual commands works fine in IDLE. While executing the script it throws that error. :( which, in itself, looks like you've forgotten the self argument in some init > method somewhere (but the code you posted doesn't have that problem). Yes,I've doubled checked this. if you want to post code, 1) try to reduce the problem to as little code as > you > possibly can, and 2) make sure that the code you post really has the > problem > you're seeing... (i.e. run it at least once before you post it) All points noted and will follow the same. Thanks and my sincere apologies. -toufeeq -- Get Firefox:http://www.mozilla.org/products/firefox/ The fastest, safest and best Browser !! -------------- next part -------------- An HTML attachment was scrubbed... URL: From bobrien18 at yahoo.com Sat Oct 22 20:54:51 2005 From: bobrien18 at yahoo.com (KraftDiner) Date: 22 Oct 2005 17:54:51 -0700 Subject: Question about inheritance... In-Reply-To: <_My6f.1423$Zd.1063@tornado.tampabay.rr.com> References: <1130017209.078943.119990@g43g2000cwa.googlegroups.com> <_My6f.1423$Zd.1063@tornado.tampabay.rr.com> Message-ID: <1130028891.235502.236320@g44g2000cwa.googlegroups.com> Well here is a rough sketch of my code... This is giving my two problems. 1) TypeError: super() argument 1 must be type, not classobj 2) I want to be sure the the draw code calls the inherited classes outline and not its own... class Shape: def __init__(self): pass def render(self): print self.__class___ self.outline() def outline(self): pass class Rect(Shape): def __init__(self): super(self.__class__, self).__init__() def render(self): super(self.__class__, self).draw() def outline(self): print 'outline' + self.__class__ From rrr at ronadam.com Fri Oct 28 10:55:33 2005 From: rrr at ronadam.com (Ron Adam) Date: Fri, 28 Oct 2005 14:55:33 GMT Subject: Would there be support for a more general cmp/__cmp__ In-Reply-To: References: Message-ID: Antoon Pardon wrote: > Op 2005-10-26, Ron Adam schreef : > >>Adding complexity to cmp may not break code, but it could probably slow >>down sorting in general. So I would think what ever improvements or >>alternatives needs to be careful not to slow down existing sorting cases. > > As a result of Bengt's post, I rewrote my test program, this is the > program now. ... > These are the results. > > : 1000 repeats, 1000 long, 10.061425 secs > : 1000 repeats, 1000 long, 9.544035 secs > : 1000 repeats, 1000 long, 10.450864 secs > : 1000 repeats, 1000 long, 15.566061 secs > : 1000 repeats, 1000 long, 15.776443 secs > > Results on a longer sequence were: > > : 1000 repeats, 10000 long, 146.722443 secs > : 1000 repeats, 10000 long, 139.480863 secs > : 1000 repeats, 10000 long, 152.623424 secs > : 1000 repeats, 10000 long, 224.630926 secs > : 1000 repeats, 10000 long, 228.663825 secs > > The most interesting result of this test is the difference between > cld and cle. IMO this difference is an indication of the cost > that my idea would have on sorting, should it be implemented. > That would be around 2%. I think that is bearable. Especially > since this were very simple routines. The moment the comparison > calculation become heavier, the relative contribution of the > try: except will diminuish. class cle: def __init__(self, i): self.value = int(i) def __comp__(self, other): return self.value - other.value def __lt__(self, other): try: return self.__comp__(other) < 0 except UnequalValues: return False This would only work with numeric types. I believe that cmp is closer to the following. return ( self.value < other.value and -1 or self.value > self.value and 1 or 0 ) I don't think it effects the speed a great deal however. > If you are concerned about sorting times, I think you should > be more concerned about Guido's idea of doing away with __cmp__. > Sure __lt__ is faster. But in a number of cases writing __cmp__ > is of the same complexity as writing __lt__. So if you then > need a __lt__, __le__, __eq__, __ne__, __gt__ and __ge__ it > would be a lot easier to write a __cmp__ and have all rich > comparisons methods call this instead of duplicating the code > about six times. So you would be more or less forced to write > your class as class cld or cle. This would have a bigger > impact on sorting times than my suggestion. I haven't heard he was removing __cmp__, but I would think the sort or sorted functions would just use the available comparisons methods or equivalent C code for base types. So I expect it would only matter if you need a custom or modified sort. Although It is a thought that these cases could be improved by making the sort value available to the underlying C sort function. Something on the order of: __sortvalue__ == self.value. Cheers, Ron From gandalf at designaproduct.biz Wed Oct 5 07:11:28 2005 From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy) Date: Wed, 05 Oct 2005 13:11:28 +0200 Subject: Python, Mysql, insert NULL In-Reply-To: <1128509544.189126.51090@g44g2000cwa.googlegroups.com> References: <1128509544.189126.51090@g44g2000cwa.googlegroups.com> Message-ID: <4343B4E0.1040902@designaproduct.biz> Python_it wrote: >Python 2.4 >MySQL-python.exe-1.2.0.win32-py2.4.zip > >How can I insert a NULL value in a table (MySQL-database). >I can't set a var to NULL? Or is there a other possibility? >My var must be variable string or NULL. >Becaus i have a if statement: >if .... > cursor.execute(".................insert NULL ..............") >if .... > cursor.execute(".................insert "string" ..............") > > > Use parameters! For example, did you try: cursor.execute(" insert into tablename(fieldname) values (%s)",[value]) None will be converted to NULL, any other value will be quoted as neccesary. BTW, you did not write which driver are you using. Usage of parameters is different for each driver, but it is standardized. If it is DB API 2.0 compatible, then parametrized queries should work as desicribed in PEP 0249: http://www.python.org/peps/pep-0249.html Under 'cursor objects' section, look for the '.execute' method. From waldbie at yahoo.com Mon Oct 10 19:46:15 2005 From: waldbie at yahoo.com (Carl Waldbieser) Date: Mon, 10 Oct 2005 19:46:15 -0400 Subject: Python, COM Servers, and Multi-Threading Message-ID: I have been considering using Python and the Reportlab library for generating PDF reports for the back-end of a web based application. The application runs most of its background tasks on a dedicated server that is Windows based (Win2K or Win2k3). The program that launches the tasks requires a COM-based interface, so I wrote a Python COM server using Mark Hammond's PythonCom libraries and import and run the reporlab modules from there. I had been reading up on Python and it's handling of the multiple threads, specifically the Global Interpreter Lock (GIL). I got to wondering if a multi-processor machine machine would be able to take advantage of its extra processing power using this setup. I am guessing that the GIL is global with respect to each instance of a running Python interpreter, so if say 4 interpreters were running, a 4 processor machine would be able to take advantage of this. However, I am not quite sure how launching my reports via COM behaves-- if I launched 4 reports this way, would that be like launching 4 seperate instances of the Python interpreter, or would it be just a single instance, and therefore run into the limitations of the GIL? If so, can anybody offer suggestions as to a design that would be better able to take advantage of a multi-processor machine? Thanks, Carl Waldbieser From mwm at mired.org Mon Oct 17 00:17:03 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 17 Oct 2005 00:17:03 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <1129491006.021102.43920@g14g2000cwa.googlegroups.com> Message-ID: <86zmp8zsjk.fsf@bhuda.mired.org> John Bokma writes: > Which standards? Again: w3c is not an official standards organization. > Moreover, Netscape added LiveScript, oh wait, I mean JavaScript, and the > *cough* blink element. >> By contracting with sites to include non-standard IE features to >> deliberately break NS. > NS also added features to HTML. Yup. When NS was the 800 lb gorilla on they acted like MS, and did whatever they thought would be best for their bottom line, never mind ethics, legality, morality, the effect it had on their users, their business partners, or the web as a whole. People bitched about NS back then. Some of us predicted what would happen when they tangled with MS, which had - and has - much more experience at this game. Now that NS is no longer the 800 lb gorilla, they can see the advantages of interoperability, and try and implement the same languages that everyone else does. It would be funny if I didn't have to live with the aftermath. "Everybody else does it" is not a defense for criminal behavior. On the off chance you haven't heard, two wrongs do *not* make a right. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From jabel at plus.net Wed Oct 12 11:11:04 2005 From: jabel at plus.net (John Abel) Date: Wed, 12 Oct 2005 16:11:04 +0100 Subject: Make SimpleXMLRPCServer Require Auth? In-Reply-To: <434CC1B9.2030005@plus.net> References: <434CC1B9.2030005@plus.net> Message-ID: <434D2788.8070601@plus.net> John Abel wrote: >Hi, > >I implemented a SimpleXMLRPCServer, modified it slightly to restrict >clients based on their IP, but I need to take it a stage further, and >add user authentication. I would appreciate any pointers as to how I >might go about this, or any packages which already provide this. I'm >guessing that I'll need to make changes to BaseHTTPServer. > >Thanks > >J > > Never mind, managed to modify SimpleXMLRPCServer with code from the digest examples in Python sandbox. J From fredrik at pythonware.com Tue Oct 25 04:44:07 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 25 Oct 2005 10:44:07 +0200 Subject: Tricky Areas in Python References: <1130097286.772836.94930@g44g2000cwa.googlegroups.com><1h4wbvb.1dblc4317zeuw2N%aleaxit@yahoo.com><435CA1DE.2060101@REMOVEMEcyber.com.au> <1h4xfdx.azxzrkhr5xukN%aleaxit@yahoo.com> Message-ID: Alex Martelli wrote: >> my hard-won ignorance, and admit that I don't see the >> problem with the property examples: >> >> > class Sic: >> > def getFoo(self): ... >> > def setFoo(self): ... >> > foo = property(getFoo, setFoo) > > Sorry for skipping the 2nd argument to setFoo, that was accidental in my > post. The problem here is: class Sic is "classic" ("legacy", > "old-style") so property won't really work for it (the setter will NOT > trigger when you assign to s.foo and s is an instance of Sic). what's slightly confusing is that the getter works, at least until you attempt to use the setter: >>> class Sic: ... def getFoo(self): ... print "GET" ... return "FOO" ... def setFoo(self, value): ... print "SET", value ... foo = property(getFoo, setFoo) ... >>> sic = Sic() >>> print sic.foo GET FOO >>> sic.foo = 10 >>> print sic.foo 10 (a "setter isn't part of an new-style object hierarchy" exception would have been nice, I think...) From crankycoder at gmail.com Sun Oct 23 18:58:08 2005 From: crankycoder at gmail.com (Victor Ng) Date: Sun, 23 Oct 2005 18:58:08 -0400 Subject: calling a dylib in python on OS X In-Reply-To: <1130049617.186896.237650@g14g2000cwa.googlegroups.com> References: <1130049617.186896.237650@g14g2000cwa.googlegroups.com> Message-ID: You can use Pyrex which will generate a C module for you. vic On 22 Oct 2005 23:40:17 -0700, robspychala at gmail.com wrote: > Hi > > Is there something similar to python's windll for calling DLLs on win32 > but meant for calling dylib's on OS X? > > thanks, > > r.s. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- "Never attribute to malice that which can be adequately explained by stupidity." - Hanlon's Razor From bokr at oz.net Sat Oct 15 19:34:51 2005 From: bokr at oz.net (Bengt Richter) Date: Sat, 15 Oct 2005 23:34:51 GMT Subject: When someone from Britain speaks, Americans hear a "British accent"... References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <4h5ck1hkqq0ls83pq0lodkb51tsda4053k@4ax.com> Message-ID: <43519190.96520569@news.oz.net> On Fri, 7 Oct 2005 15:28:24 -0500, Terry Hancock wrote: >On Friday 07 October 2005 03:01 am, Steve Holden wrote: >> OK, so how do you account for the execresence "That will give you a >> savings of 20%", which usage is common in America? > >In America, anyway, "savings" is a collective abstract noun >(like "physics" or "mechanics"), there's no such >noun as "saving" (that's present participle of "to save" >only). How did you expect that sentence to be rendered? >Why is it an "execresence"? > >By the way, dict.org doesn't think "execresence" is a word, >although I interpret the neologism as meaning something like >"execrable utterance": > >dict.org said: >> No definitions found for 'execresence'! > Gotta be something to do with .exe ;-) Regards, Bengt Richter From steve at REMOVETHIScyber.com.au Fri Oct 7 12:52:22 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sat, 08 Oct 2005 02:52:22 +1000 Subject: Objects with different data views Message-ID: I'm not sure how to do this, or where to start looking for the right information, so any advice would be appreciated. I want to implement a class with two (or more) different ways of looking at its attributes. One example of this might be complex numbers, which can be written in Cartesian form (x+yi) or polar form (r cis theta). (Yes, I know Python already has complex numbers. That was just an example.) Another might be 3D vectors, which can be written in Cartesian form [x, y, z], polar form [r, theta, z] or spherical polar [r, theta, phi]. It is important that there are no privileged attributes, e.g. in the above example, I can set any of x, y, z, r, theta or phi and all the others will automatically reflect the changes. A concrete, if simple, example will make it clear. Suppose I have a transformation (a,b) <-> (x,y) where: x = a+b y = a+2*b I create an instance spam, and set a and b: spam.a = 1 spam.b = 2 Now I should be able to read x and y: print spam.x, spam.y # prints 3 5 If I set attribute y: spam.y = 0 a and b automatically change to match: print spam.a, spam.b # prints 6, -3 Anyone have any good ideas for how I should implement this? Thanks, -- Steven. From kewlcorey04 at yahoo.com Wed Oct 26 18:11:43 2005 From: kewlcorey04 at yahoo.com (brenden) Date: 26 Oct 2005 15:11:43 -0700 Subject: NEWBIE Message-ID: <1130364703.849883.109300@z14g2000cwz.googlegroups.com> hey everyone....i'm new to all this programming and all this stuff and i just wanted to learn how to do it... does anyone think they can teach me how to work with python? i've been reading up a lot on it and i've downloaded the program and all that i'm just not quite following the whole thing... if you can just post here and i'll get back 2 u From spe.stani.be at gmail.com Sat Oct 29 23:04:47 2005 From: spe.stani.be at gmail.com (SPE - Stani's Python Editor) Date: 29 Oct 2005 20:04:47 -0700 Subject: Expanding Python as a macro language References: <1130545600.925061.287390@g49g2000cwa.googlegroups.com> <1130592935.839750.322930@g14g2000cwa.googlegroups.com> <1h56rdh.1lgzv2op15fcpN%aleaxit@yahoo.com> Message-ID: <1130641487.526899.299360@z14g2000cwz.googlegroups.com> > some future Firefox version might perhaps integrate a Python engine For those who never heard about Firefox 1.9, check the following urls. It looks very promising: 1) http://wiki.mozilla.org/Roadmap_Scratchpad#Python_for_XUL Python for XUL Significant potential contributors in both the Python and XUL application development communities have long wanted access to Python's set of libraries and its capabilities as an application development language. So in addition to JavaScript, which is the default web and XUL scripting language, we plan to extend the reach of Gecko and XUL to the Python world. Mark Hammond's work on PyXPCOM and a language-neutral DOM is well under way as of October 2005, and we believe that the glue code and bindings will be slim enough to be part of a default XULRunner or Firefox distribution when the 1.9 cycle is complete. (N.B.: Mozilla does not intend to distribute the C-Python runtime with its applications or frameworks, and application developers who wish to take advantage of these capabilities will need to provide for this dependency in their installers or packaging. Stub or streaming installer capabilities in the Firefox/XULRunner based on Gecko 1.9 will probably help a great deal to ease the extra download for Python-less users.) 2) http://weblogs.mozillazine.org/roadmap/archives/008865.html Given evolving JS, why Python? Simple: different programming languages, of different ages, have their strengths, and one of the greatest strength of any solid language is its community. We want to support Python as well as JS for XUL scripting in order to engage a large, creative community of hackers that is mostly disjoint from the web-standards-savvy XUL hackers who are already engaged with Mozilla and Firefox. * Stani -- http://pythonide.stani.be http://pythonide.stani.be/manual/html/manual.html From lsumnler at gmail.com Tue Oct 4 14:32:59 2005 From: lsumnler at gmail.com (len) Date: 4 Oct 2005 11:32:59 -0700 Subject: Newbie regular expression ? Message-ID: <1128450779.107011.5370@z14g2000cwz.googlegroups.com> I have the following statement and it works fine; list1 = glob.glob('*.dat') however I now have an additional requirement the the string must begin with any form of "UNQ,Unq,unq,..." as an example if I had the following four files in the directory: unq123abc.dat xy4223.dat myfile.dat UNQxyc123489-24.dat only unq123abc.dat and UNQxyc123489-24.dat would be selected I have read through the documentation and I am now sooooo confussedddddd!! Len Sumnler From deets at nospam.web.de Tue Oct 18 13:16:00 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 18 Oct 2005 19:16:00 +0200 Subject: PEP: Adding decorators for everything In-Reply-To: <1129612612.320897.151650@g14g2000cwa.googlegroups.com> References: <1129612612.320897.151650@g14g2000cwa.googlegroups.com> Message-ID: <3rkouiFjm4q4U1@uni-berlin.de> > @GuardedClass > class Foo: The functionality can be done using a meta-class, in a similarily declarative way. > @Transient > a = 'a transient field, ignored when serializing' > > @Const > PI = 22.0 / 7 > > @TypeSafe(int) > count = 10 These are tricky, as the implicitly change the nature of the values - they become properties. And the decorator protocol has to change, as the passed value is obviously not a callable, but a random value. So in the end, you could simply do something like this: @Const(3.24) def PI(self): pass with Const basically ignoring its callable-argument and simply returning a get-only-property. I have to admit that I was tempted to use such a thingy just the other day. But it is not exactly nice, and using PI = Const(3.14) as you suggested is even more pleasing. Additionally, the first @Transient-decorator can't be done that way, as the decorator protocol doesn't know about the _name_ a thing is bound to later. And you'd need that to actually set up e.g. __getstate__ operate properly. And it doesn't mkae much sense anyway, as "a" is a class variable, not a instance variable. So - I'm not very much in favour of these enhancements. > It would also be better if multiple decorators could be written on the > same line. E.g.: > @A @B(x, y) @C > def foo(): ... That one I like. Diez From rrr at ronadam.com Wed Oct 12 16:26:30 2005 From: rrr at ronadam.com (Ron Adam) Date: Wed, 12 Oct 2005 20:26:30 GMT Subject: non descriptive error In-Reply-To: <434C8FE2.2090505@REMOVEMEcyber.com.au> References: <4346002C.3080504@open-networks.net><200510070240.56350.hancock@anansispaceworks.com> <4349A55C.90203@open-networks.net> <434C8FE2.2090505@REMOVEMEcyber.com.au> Message-ID: Steven D'Aprano wrote: > Timothy Smith wrote: > >>>> i have NO idea what in there could be making it have such a strange >>>> error. it just says "error" when you try run it. there nothing terribly >>>> strange being done. > > >> i am still coming across this error it's driving me nuts. usually i >> can find what's wrong, but it is becoming an increasingly annoying >> problem. i also get the same problem on a windows machine with the >> same installed. this time it's nothing to do with the decimal module. >> help! > > > Go back to first principles. Can you grab all the modules being used, > and search them for the string "error"? Ignore any hits which are in a > comment. One of the others is almost certainly responsible. > > You can test that by changing the string to "this is a PITA" and see if > your mysterious error message changes or not. Maybe there's a way he can examine the traceback to find it. I think there's probably a better way, but it may be a start. #### def seetrace(): import inspect print inspect.trace() print ''.join(inspect.trace(5)[0][4]) try: try: #### suspect code block a = 15+'c' print 'hello' for x in range(10): a = x #### except: seetrace() raise "my error" # you never see this # This is why bare excepts are not a good idea. except: raise "Error: your error" #### In this example you never see "my error" because the outer try over rides it. but the prints's still print and give you information about the actual error in this case. [(, 'gen.py', 17, '?', [" a = 15+'c'\n"], 0)] try: #### suspect code block a = 15+'c' print 'hello' for x in range(10): Traceback (most recent call last): File "gen.py", line 26, in ? raise "your error" Error: your error Hope this helps, Ron From news at nportal.net Tue Oct 25 11:04:26 2005 From: news at nportal.net (News Reader) Date: Tue, 25 Oct 2005 09:04:26 -0600 Subject: Has anybody used cx_bsdiff? Message-ID: <435E497A.6050906@nportal.net> Hello, I am trying to use cx_bsdiff (http://starship.python.net/crew/atuining/cx_bsdiff/index.html) to to make a diff and patch some files. It appears that I can make the diff, but when I apply the patch, the result is not the same. As far as I understand the documentation, I am using this correctly. Can anyone help me find what is wrong in the code below? Thanks. Please reply to the list. NR. ========================================================= import bsdiff, bz2 import cPickle as pickle from filecmp import dircmp def diffdir(comparator, basepath=''): return [os.path.join(basepath, fname) for fname in comparator.diff_files] def descend(comparator, basepath=''): print 'Examining "%s"...' % basepath yield diffdir(comparator, basepath) for subdir in comparator.subdirs: subname = os.path.join(basepath, subdir) subcmp = comparator.subdirs[subdir] for subresult in descend(subcmp, subname): yield subresult def compare_all(orig_dir, fix_dir): patch = {} comparator = dircmp(orig_dir, fix_dir, []) for diff_list in descend(comparator): for diff_file in diff_list: orig_fname = os.path.join(orig_dir, diff_file) fix_fname = os.path.join(fix_dir, diff_file) print 'Making diff of %s...' % diff_file orig_data = open(orig_fname, 'rb').read() fix_data = open(fix_fname, 'rb').read() dl = len(fix_data) ctrl, dblock, xblock = bsdiff.Diff(orig_data, fix_data) patch[diff_file] = (dl, ctrl, dblock, xblock) print 'Done.' return patch def fix_all(tofix_dir, patch): for fname in patch: orig_fname = os.path.join(tofix_dir, fname) print 'Fixing %s...' % orig_fname datafile = open(orig_fname, 'rb') orig_data = datafile.read() datafile.close() fix_data = bsdiff.Patch(orig_data, *patch[fname]) datafile = open('%s-fixed' % orig_fname, 'wb') datafile.write(fix_data) datafile.close() os.remove(orig_fname) os.rename('%s-fixed' % orig_fname, orig_fname) def save(object, filename, protocol=-1): compressed = bz2.BZ2File(filename, 'wb') compressed.write(pickle.dumps(object, protocol)) compressed.close() def load(filename): compressed = bz2.BZ2File(filename, 'rb') object = pickle.loads(compressed.read()) compressed.close() return object def make_patch(): orig_dir = raw_input('Original Directory: ') fix_dir = raw_input('Fixed Directory: ') savepatch = raw_input('Save result? (y/n): ') if savepatch == 'y': patchname = raw_input('Patch file name: ') else: savepatch = '' patch = compare_all(orig_dir, fix_dir) if savepatch: save(patch, patchname) From http Sun Oct 2 15:05:53 2005 From: http (Paul Rubin) Date: 02 Oct 2005 12:05:53 -0700 Subject: Will python never intend to support private, protected and public? References: <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xll1gvk7w.fsf@ruckus.brouhaha.com> <1128001308.905398.321670@g44g2000cwa.googlegroups.com> <311b5ce105092908332c12164c@mail.gmail.com> <7xbr2btv84.fsf@ruckus.brouhaha.com> <7xy85fvxny.fsf@ruckus.brouhaha.com> <86vf0inlt3.fsf@bhuda.mired.org> <7xd5mq9ir9.fsf@ruckus.brouhaha.com> <86wtkym33t.fsf@bhuda.mired.org> <7xll1d7l2c.fsf@ruckus.brouhaha.com> <86slvlmdnv.fsf@bhuda.mired.org> Message-ID: <7xr7b3spri.fsf@ruckus.brouhaha.com> Mike Meyer writes: > > Yes, the point is that it's something that you can check for by > > examining the class in question without having to examine any other > > classes. > > That's a pretty restrictive convention to follow. What convention? It just makes it possible to write code with some specific invariants if there's a need to do so. > For instance, I might want an error dialog to be a private variable > of a class representing a window - after all, I don't want anyone > else writing to it, or using it in any way. Except, of course, for > any GUI framework routines I have to pass it to in order to use > it. This problem crops up for every utility routine in every library > I might want to use. Opening files by name, concatenatting strings > (or are we going to have a convention that implicit invocation of > functions with the operator syntax don't count, and another one that > you don't overload operators with destructive functions, and so on), etc. I just don't understand your point here. Yes, you can do all those things and leak any variable. However, if you want to NOT leak some particular variable, "private" lets you code in a way that lets you easily confirm that you didn't leak it. > So it turns out that getting the behavior you desire involves > following a lot of conventions. That improves on the current situation. Right now the behavior is impossible to obtain in Python no matter how many conventions you follow, unless you follow them through a whole program of arbitrary size instead of just in the class that you're trying to protect a variable in. And when you do it through that much code, it becomes extremely hard to confirm by inspection that they're followed. That's why we have things like the principle of least privilege. > File scope isn't good enough for python. > > import madhouse > madhouse.len = my_len_breaker Ugh, yeah. IIRC, rexec dealt with this using a special import hook that stopped you from importing. For an unrestricted client, maybe there would have to be some special import that restores the builtins. > In other words, by adding private to python, you're making it so that > bugs involving overwriting a private attribute will involve only the > owning classes code so long as everyone follows the conventions that > exist about the use of such variables. Not everyone, just the author of the class that uses the private variable. That's the point. > > I don't see how pylint could know which instances to flag, > > I was thinking it would flag any use of such a variable where the > target variable wasn't "self". That may be a stronger constraint than > you wanted - but that's good, right? Shrug. That might be of some limited usefulness, but all it tries to do is prevent accidents. And it does nothing about setattr/getattr. From gsakkis at rutgers.edu Mon Oct 17 10:01:58 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Mon, 17 Oct 2005 10:01:58 -0400 Subject: Dynamic generation of doc-strings of dynamically generated classes References: Message-ID: <1129557719.c29494246cc8deda636cbf9c849b7133@teranews> "Mikael Olofsson" wrote: > Hi! > > I've asked Google, but have not found any useful information there. > > Situation: I have a base class, say > > >>> class base(object): > ImportantClassAttribute = None > > Now, I want to dynamically generate subclasses of base. That's not a > problem. However, I very much want those subclasses to have individual > doc-strings. More precicely, I want that important class attribute to be > reflected in the doc-string. That's the problem. The only way I've > managed to accomplish that is something like the following. > > >>> ImportantClassAttribute = 7 > >>> docString = 'The case %s.' % (ImportantClassAttribute,) > >>> exec('''class new(base): > """%s""" > pass ''' % (docString,)) > >>> new.ImportantClassAttribute = ImportantClassAttribute > >>> new.__doc__ > 'The case 7.' > > This works as intended. The subclasses do get the doc-strings I want > them to have, and I can live with this solution. But: This solution does > not strike me as especially beautiful or readable. My first na?ve > attempt was instead the following. > > >>> class new(base): > pass > > >>> new.ImportantClassAttribute = 7 > >>> new.__doc__ = ('The case %(ImportantClassAttribute)s.' > % new.__dict__) > > Traceback (most recent call last): > File "", line 1, in -toplevel- > new.__doc__ = ('The case %(ImportantClassAttribute)s.' > TypeError: attribute '__doc__' of 'type' objects is not writable > > This is readable to me, but apparently not the way to go, since I'm not > allowed to replace the doc-string like this. I've also tried a number of > other ways, but they all stumble on similar reasons. > > Any ideas? Am I stuck with the clumsy exec-solution, or are there other > ways to dynamically generate doc-strings of classes? There's nothing specifically about doc-strings, but you can create and customise a whole class dynamically: def makeBaseSubclass(impClassAttr): return type('new_%s' % impClassAttr, (base,object), {'ImportantClassAttribute': impClassAttr, '__doc__': 'The case %s' % impClassAttr}) >>> new = makeBaseSubclass(7) >>> new.ImportantClassAttribute 7 >>> new.__doc__ 'The case 7' HTH, George From martin at v.loewis.de Sun Oct 16 06:16:58 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 16 Oct 2005 12:16:58 +0200 Subject: Why asci-only symbols? In-Reply-To: <4351cef6.112238340@news.oz.net> References: <86vf04zx0k.fsf@bhuda.mired.org> <434ccfcd$0$28021$9b622d9e@news.freenet.de> <4351cef6.112238340@news.oz.net> Message-ID: <4352289a$0$15038$9b622d9e@news.freenet.de> Bengt Richter wrote: > Perhaps string equivalence in keys will be treated like numeric equivalence? > I.e., a key/name representation is established by the initial key/name binding, but > values can be retrieved by "equivalent" key/names with different representations > like unicode vs ascii or latin-1 etc.? That would require that you know the encoding of a byte string; this information is not available at run-time. You could also try all possible encodings to see whether the strings are equal if you chose the right encoding for each one. This would be both expensive and unlike numeric equivalence: in numeric equivalence, you don't give a sequence of bytes all possible interpretations to find some interpretation in which they are equivalent, either. There is one special case, though: when comparing a byte string and a Unicode string, the system default encoding (i.e. ASCII) is assumed. This only really works if the default encoding really *is* ASCII. Otherwise, equal strings might not hash equal, in which case you wouldn't find them properly in a dictionary. Regards, Martin From http Sun Oct 9 06:29:14 2005 From: http (Paul Rubin) Date: 09 Oct 2005 03:29:14 -0700 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> <7xvf07a1ro.fsf@ruckus.brouhaha.com> <6eihk1tr0ovtkv5d6ik2lfm7p0i90u0tk5@4ax.com> Message-ID: <7x8xx3htl1.fsf@ruckus.brouhaha.com> Roedy Green writes: > >I read mail over an ssh connection to a Unix shell. I have no easy > >way to read html email with a graphics browser. > > So the rest of the world should forgo rich communication because of > your obsolete software? How could anything every evolve with that > attitude? There is nothing obsolete about lynx. It completely conforms to the w3 standard. Anyway, email is a text medium and attempts to "evolve" it almost always make it worse. From andrew at voicent.com Thu Oct 13 17:23:18 2005 From: andrew at voicent.com (andrew at voicent.com) Date: 13 Oct 2005 14:23:18 -0700 Subject: ANNOUNCE: Python interface for making telephone calls using Voicent Gateway Message-ID: <1129238598.829231.14090@z14g2000cwz.googlegroups.com> The Voicent Python Simple Interface class contains the following functions. callText callAudio callStatus callRemove callTillConfirm These functions are used to invoke telephone calls from your Python program. For example, callText is used to call a specified number and automatically play your text message using text-to-speech engine. In order for this class to work, you'll need to have Voicent Gateway installed somewhere in your network. This class simply sends HTTP request for telephone calls to the gateway. Voicent has a free edition for the gateway. You can download it from http://www.voicent.com More information can be found at: http://www.voicent.com/devnet/docs/pyapi.htm Thank you and have fun From shannonlayland at gmail.com Mon Oct 31 13:28:51 2005 From: shannonlayland at gmail.com (shannonl) Date: 31 Oct 2005 10:28:51 -0800 Subject: textwidget.tag_bind("name", "", self.donothing) not working In-Reply-To: <1130358397.324451.125750@z14g2000cwz.googlegroups.com> References: <1130266889.246361.268610@g47g2000cwa.googlegroups.com> <1130356366.749611.148240@g14g2000cwa.googlegroups.com> <1130356709.694069.295350@f14g2000cwb.googlegroups.com> <1130358397.324451.125750@z14g2000cwz.googlegroups.com> Message-ID: <1130783331.517705.179260@g49g2000cwa.googlegroups.com> Thanks for your help and the link. From the link it sounds like no one is sure how this is supposed to act. I will dig around in the tcl forum and see what I can find. From rune.strand at gmail.com Thu Oct 13 15:15:50 2005 From: rune.strand at gmail.com (Rune Strand) Date: 13 Oct 2005 12:15:50 -0700 Subject: Adding a __filename__ predefined attribute to 2.5? In-Reply-To: References: <1129098667.336115.303060@g47g2000cwa.googlegroups.com> <1129150883.303899.259570@g43g2000cwa.googlegroups.com> Message-ID: <1129230950.305013.302200@g49g2000cwa.googlegroups.com> I've read a lot of your comments the last years. Your friendliness always strikes me. From sybrenUSE at YOURthirdtower.com.imagination Wed Oct 12 01:55:22 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Wed, 12 Oct 2005 07:55:22 +0200 Subject: TurboGears /.-ed, >new == True< or >new == "True"< References: Message-ID: Andy Leszczynski enlightened us with: > should not it be: > > 2 def save(self, pagename, data, submit, new): > 3 hub.begin() > 4 if new == True: > 5 page = Page(pagename=pagename, data=data) > 6 else: > 7 page = Page.byPagename(pagename) > 8 page.data = data > > instead of: > > 4 if new == "True": No it should not. The values passed to the function are the strings passed by the GET request, hence all strings. There are methods of dealing with this - read the rest of 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 xah at xahlee.org Wed Oct 19 03:50:11 2005 From: xah at xahlee.org (Xah Lee) Date: 19 Oct 2005 00:50:11 -0700 Subject: write a loopin one line; process file paths In-Reply-To: <1129701270.792327.168620@z14g2000cwz.googlegroups.com> References: <1129672592.328278.41490@g14g2000cwa.googlegroups.com> <1129696357.539158.233870@g47g2000cwa.googlegroups.com> <1129699998.324180.56530@f14g2000cwb.googlegroups.com> <1129701270.792327.168620@z14g2000cwz.googlegroups.com> Message-ID: <1129708210.963305.43270@g49g2000cwa.googlegroups.com> bonono at gmail.com wrote: > it will be added in 2.5 I beleve. At the moment, you can: > > predicate and or Ah, i see. Here's the full code again: # -*- coding: utf-8 -*- # python import re, os.path imgPaths=[u'/Users/t/t4/oh/DSCN2059m-s.jpg', u'/Users/t/t4/oh/DSCN2062m-s.jpg', u'/Users/t/t4/oh/DSCN2097m-s.jpg', u'/Users/t/t4/oh/DSCN2099m-s.jpg', u'/Users/t/Icons_dir/icon_sum.gif'] # change the image path to the full sized image, if it exists # that is, if image ends in -s.jpg, find one without the '-s'. imgPaths2=[] for myPath in imgPaths: p=myPath (dirName, fileName) = os.path.split(myPath) (fileBaseName, fileExtension)=os.path.splitext(fileName) if(re.search(r'-s$',fileBaseName,re.U)): p2=os.path.join(dirName,fileBaseName[0:-2]) + fileExtension if os.path.exists(p2): p=p2 imgPaths2.append(p) imgPaths3 = map( lambda x: os.path.exists(x[1]) and x[1] or x[0], map(lambda x: (x, re.sub( r"^(.+?)-s(\.[^.]+)$",r"\1\2", x)), imgPaths)) print imgPaths2 == imgPaths3 ------------------ > A few things I don't like about python for FP is that it relies heavily > on exception which make these one liners not possible in many case. > ... yeah i know how it feels. I haven't had much experience with Python yet... but doing it in Perl gets all twisted. (especially when one tries to use trees as data structure (nested lists) in Perl) besides syntactical issues, another thing with doing functional programing in imperative languages is that they become very inefficent. Functional languages are optimized by various means of functional programings styles. Doing them in imperative languages usually comes with a order of execution penalty because imperative language compilers are usually dumb. though, one can't totally blame for Python's lack of ability to do functional programing. Its language's syntax of using indentations for blocks by design, pretty much is in odds with functional programing's sequencing of functions and other ways. (such as generic mechanism for prefix/postfix syntax, or macros or other transformations and patterns, or heavy reliance on the free flow of expressions/values) I don't blame Python that it doesn't cater to functional programing BY DESIGN. But i do hate the mother fucking fuckheads Pythoners for one thing that they don't know what functional programing really is, and on the other hand fucking trumpet their righteousness and lies thru their teeth of their ignorance. (that Guido guy with his Python 3000 article on his blog is one example, possibly forgivable in that particular instance. (http://xahlee.org/perl-python/python_3000.html)) (excuse me for lashing out) Xah xah at xahlee.org ? http://xahlee.org/ > like : > >>> os.paths.exists(something) and "print it is there" or "file not found" > > I am practicing FP in python and it is in general doable with the help > of itertools and add the needed functions as needed, like scanl/scanl1 > etc. > > A few things I don't like about python for FP is that it relies heavily > on exception which make these one liners not possible in many case. > > Example: > > a=[] > a[0] would raise exception > > I usually prefer None as a special value which can be handled in normal > flow(filter out, may be "x is None and something or otherthing"). But > the liberal use of Exception force you to structure the program either > in a very odd way(test with hasattr/haskey etc. before use) or needs > lots of try/except blocks. I am using a python XHTML template Kid which > relies on one-liner and found it very difficult. > > However, if you don't really need one-liner but just FP style to > shorten the program, it is fine but I just find the try/except block > quite ugly. > > Then there is the side effect of iterators/generators which unless you > know can burn you badly(especially when you are chaining these objects > in these multiple map/filter calls), as mentioned in another post. > From rbt at athop1.ath.vt.edu Fri Oct 7 11:34:07 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Fri, 07 Oct 2005 11:34:07 -0400 Subject: socketServer questions Message-ID: <1128699247.9040.15.camel@athop1.ath.vt.edu> I have written a python socketServer program and I have a few questions that I hope the group can answer... here is a simple version of the server: class tr_handler(SocketServer.StreamRequestHandler): def handle(self): data = self.rfile.readline(300) data = str.strip(data) bytes = str(len(data)) public_ip = self.client_address[0] serv_date = time.strftime('%Y-%m-%d', time.localtime()) serv_time = time.strftime('%H:%M:%S', time.localtime()) # Note that 'data; comes from the client. fp = file('/home/rbt/Desktop/tr_report.txt', 'a') fp.write(data+"\t"+serv_date+"\t"+serv_time+"\t"+public_ip+"\t"+bytes+"\n") fp.close() if __name__=='__main__': server = SocketServer.TCPServer( ('', 55503), tr_handler) server.serve_forever() --------------------------------------- 1. Do I need to use threads to handle requests, if so, how would I incorporate them? The clients are light and fast never sending more than 270 bytes of data and never connecting for more than 10 seconds at a time. There are currently 500 clients and potentially there could be a few thousand... how high does the current version scale? 2. What's the proper way to handle server exceptions (server stops, fails to run at boot, etc.)? 3. How do I keep people from tampering with the server? The clients send strings of data to the server. All the strings start with x and end with y and have z in the middle. Is requiring x at the front and y at the back and z someplace in the middle enough to keep people out? I'm open to suggestions. Thanks! rbt From strombrg at dcs.nac.uci.edu Mon Oct 10 20:27:06 2005 From: strombrg at dcs.nac.uci.edu (Dan Stromberg) Date: Tue, 11 Oct 2005 00:27:06 GMT Subject: Send password over TCP connection References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> <1128979760.251637.316480@o13g2000cwo.googlegroups.com> <7xk6glhvgl.fsf@ruckus.brouhaha.com> Message-ID: On Tue, 11 Oct 2005 01:21:55 +0200, Michael Str?der wrote: > Dan Stromberg wrote: >> [quoted text muted] > > http://www.faqs.org/rfcs/rfc2945.html > > Ciao, Michael. OK, thanks for the reference. I guess I neglected to stress that we're talking about using random strings of characters, not dictionary words or other weak forms of user-chosen passwords. Is there something easily attacked about the original algorithm, if you use a long, quite random password in combination with a hash algorithm that hasn't been broken? If you look over my fallback-reboot package at: http://dcs.nac.uci.edu/~strombrg/fallback-reboot/ you'll see that there's a small python script that generates a 32 character hex string for the passwords. I suppose I probably should rewrite it to not use whrandom though. Thanks! From nephish at xit.net Fri Oct 21 19:01:18 2005 From: nephish at xit.net (nephish at xit.net) Date: 21 Oct 2005 16:01:18 -0700 Subject: need some advice on x y plot In-Reply-To: <11lilpklp9mib0f@corp.supernews.com> References: <1129823043.104864.73750@f14g2000cwb.googlegroups.com> <11lfgebn85liq1b@corp.supernews.com> <1129825379.218308.242010@g47g2000cwa.googlegroups.com> <4357d998$1_2@newspeer2.tds.net> <1129831950.926154.196420@g47g2000cwa.googlegroups.com> <1129912485.866312.298390@g47g2000cwa.googlegroups.com> <4359244e$1_2@newspeer2.tds.net> <1129916685.172187.224140@o13g2000cwo.googlegroups.com> <11lietgq0m60f66@corp.supernews.com> <1129927722.835095.191620@g49g2000cwa.googlegroups.com> <11lilpklp9mib0f@corp.supernews.com> Message-ID: <1129935678.372329.107850@z14g2000cwz.googlegroups.com> this is great, because the docs on gnuplots website are a bit easier for me to grasp. thanks so much for your time on this one. you really have helped me a lot. i will not get a change to work on this till monday. so i may have more questions then. This is sure a point in the right direction. thanks much. shawn From lsumnler at uniqueinsuranceco.com Fri Oct 28 17:23:56 2005 From: lsumnler at uniqueinsuranceco.com (LenS) Date: 28 Oct 2005 14:23:56 -0700 Subject: ? Pythoncard In-Reply-To: <1130530479.983395.118810@f14g2000cwb.googlegroups.com> References: <1130530479.983395.118810@f14g2000cwb.googlegroups.com> Message-ID: <1130534636.368702.277230@g49g2000cwa.googlegroups.com> Never mind I figured out my on stupid mistake Thanks From spammers-go-here at spam.invalid Mon Oct 17 12:35:24 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Mon, 17 Oct 2005 12:35:24 -0400 Subject: List of strings to list of floats ? References: <4351d29e$0$41148$14726298@news.sunsite.dk> Message-ID: <4353d2a2$0$41138$14726298@news.sunsite.dk> skip at pobox.com wrote: > > Madhusudan> Is it possible to convert a very long list of strings to a > Madhusudan> list of floats in a single statement ? > > Madhusudan> I have tried float(x) and float(x[:]) but neither work. I > Madhusudan> guess I would have to write a loop if there isn't a way. > > Try: > > >>> los = ["123.0", "2", "1e-6"] > >>> map(float, los) > [123.0, 2.0, 9.9999999999999995e-07] > >>> [float(s) for s in los] > [123.0, 2.0, 9.9999999999999995e-07] > > Skip Thanks. Now, a slightly more complicated question. Say I have two lists of floats. And I wish to generate a list of floats that is a user defined function of the two lists. I tried : def rpyth(x,y): r=sqrt(pow(x,2.0)+pow(y,2.0)) return r r1n=map(rpyth,x2n[1:len(x2n)-1],y2n[1:len(y2n)-1]) And I get an error complaining about floats. From qwweeeit at yahoo.it Sat Oct 29 09:35:39 2005 From: qwweeeit at yahoo.it (qwweeeit at yahoo.it) Date: 29 Oct 2005 06:35:39 -0700 Subject: Expanding Python as a macro language References: <1130545600.925061.287390@g49g2000cwa.googlegroups.com> Message-ID: <1130592939.784904.155370@g44g2000cwa.googlegroups.com> Thank you for your replays (both for WMI and AutoIt beta-release) but I would be satisfied if I had in Linux something similar to the standard version of AutoIt! Concerning WMI, a part the fact that it works only under Windows, from the examples I have seen, IMHO it is much less powerful than AutoIt. In Linux you can easily obtain almost the same results by using shell programming or by emulation of the shell by means of os.system("shell command string") in Python. But the problem is that in Linux you can't even send a keystroke to a running GUI application! I want to find a solution in Linux, with the help of experts (if they don't use only Windows...) for two reasons: - the reduced availability in Windows of "free" or "open" applications - the more severe security problems in Windows. Concerning the second point, you can correctly argue that this is, at least partly, due to the wider market share of Windows but IMHO Linux is more robust in this field, and ...at the present times the situation is like that! As I want to use automation mainly in Internet, I am worried of security and I don't want to spend time and money in anti-virus and firewalls... I want to give you an idea of possible applications of automation. Imagine you want to access a big database from a html server which only allows you to access such data in chunks pressing a "next" button on an ASP file. It will take several hours to click the button and then save the new data supplied by the server! That is a typical task of AutoIt, very easily programmable, a part that, during the script execution, you are under virus or other security treat! Another example of application is to emulate a spider program to make searches or downloads in Internet. By emulating a user you can bypass the restrictions imposed by search engines or html servers on automatic operations (like wget or urlib). A last example is for protecting the privacy using several "anonymizers". That can only be possible with a macro language for automatic connection to the web anonymizers. Also the subsequent web operations must be carried out (IMHO!) in an automatic manner. There are of course plenty of possible application of a macro language and above all it can save me from be obliged to learn C++ (for Qt). For example, to make a graph you are not obliged to make a program in C++ or PyQt to draw and possibly print the graph of your data, but you need only to program the data preparation then send the data to a drawing application... Bye. From qwweeeit at yahoo.it Fri Oct 28 20:26:40 2005 From: qwweeeit at yahoo.it (qwweeeit at yahoo.it) Date: 28 Oct 2005 17:26:40 -0700 Subject: Expanding Python as a macro language Message-ID: <1130545600.925061.287390@g49g2000cwa.googlegroups.com> Hi all, when I moved from Windows to Linux I choosed Python as my language of reference and as GUI, Qt (not much investigated up to now). Till now I didn't regret but one thing: Python can't act as a macro language and so you are obliged to revert to Windows to use programs like AutoIt, Macro Express or Macro Scheduler or even the macro features of Office with VBA. Claudio Grondi expressed almost the same ideas in answering to a post: > What I can point you to is not Python, but embedding it in Python > is a question of executing one line of Python code triggering its > execution. > I think you will be fascinated by its features and ease of use > and how well it is suited to fit into your needs: > http://www.autoitscript.com/autoit3/index.php > With it you will start to see, that forcing to obey to Windows way > of doing things has not only bad sides. In answering to him I expressed the idea to use Windows and AutoIt 3 for automation purposes. But then I changed idea... Also if it is already one year that I try to find a solution in Linux (mainly with Python or DCOP and KDE), I am still confident that there is a solution (in Python we have big experts...). Instead of merely "batteries included" we have plenty of already made applications (from graphics to browsing or editing etc.) that can be easily accessed emulating users operations (mainly keystrokes or mouse operations)... Bye. From aleaxit at yahoo.com Mon Oct 24 22:38:12 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 24 Oct 2005 19:38:12 -0700 Subject: Python vs Ruby References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> <1129883505.814349.306860@g44g2000cwa.googlegroups.com> <86fyqt9j9x.fsf@bhuda.mired.org> <1h4ukde.1gc4cgu1a252ggN%aleaxit@yahoo.com> <86y84k95c5.fsf@bhuda.mired.org> <1h4vl5j.1sg46l1irzgfmN%aleaxit@yahoo.com> <1130154629.382286.33090@g43g2000cwa.googlegroups.com> <1h4xfpb.1oh4ntjwcvubfN%aleaxit@yahoo.com> <87acgyly4k.fsf@ieee.org> Message-ID: <1h4yalo.tv773719vmtliN%aleaxit@yahoo.com> Jorge Godoy wrote: > aleaxit at yahoo.com (Alex Martelli) writes: > > > forwards a lot to Python 3.0!-). But -- the "dream" solution would be > > to work closely with customers from the start, XP-style, so features go > > into the code in descending order of urgence and importance and it's > > hardly ever necessary to remove them. > > We do that often with two of our customers here. After the first changes, > they asked for more. And them some other and when it finally ended, the > project was like we had suggested, but instead of doing this directly, the > client wanted to waste more money... :-( Even if we earnt more money, I'd > rather have the first proposal accepted instead of wasting time working on > what they called "essential features". The customer is part of the team; if any player in the team is not performing well, the whole team's performance will suffer -- that's hardly surprising. You may want to focus more on _teaching_ the customer to best play his part in the feature-selection game, in the future... not easy, but important. > > But if I had do nominate ONE use case for "making code smaller" it would > > be: "Once, And Only Once" (aka "Don't Repeat Yourself"). Scan your code > > ceaselessly mercilessly looking for duplications and refactor just as > > mercilessly when you find them, "abstracting the up" into functions, > > base classes, etc... > > And I'd second that. Code can be drastically reduced this way and even > better: it can be made more generic, more useful and robustness is improved. I'll second all of your observations on this!-) Alex From steve at holdenweb.com Fri Oct 7 04:45:08 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 07 Oct 2005 09:45:08 +0100 Subject: "no variable or argument declarations are necessary." In-Reply-To: <7xr7ax690j.fsf@ruckus.brouhaha.com> References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <3qi8erFf252rU1@uni-berlin.de> <3qkdbrFfgga9U1@uni-berlin.de> <3qkn7qFffkl6U1@uni-berlin.de> <3qkr1hFfgj5uU1@uni-berlin.de> Message-ID: Paul Rubin wrote: > Steve Holden writes: > >>In other words, you want Python to be strongly-typed, but sometimes >>you want to allow a reference to be to any object whatsoever. In which >>case you can't possibly do any sensible type-checking on it, so this >>new Python+ or whatever you want to call it will suffer from the same >>shortcomings that C++ and java do, which is to say type checking can't >>possibly do anything useful when the acceptable type of a reference is >>specified as ANY. > > > Let's see if I understand what you're saying: > > C and Java: you get useful type checking except when you declare > a reference as type ANY. This is a shortcoming compared to: > > Python: where you get no useful type checking at all. > > That is not very convincing logic. As we say in Yorkshire, "There's none as thick as them that wants to be". Let's try to get this in context. Antoon: > Suppose we have a typesystem which has the type ANY, which would mean > such an object could be any type. You could then have homogenous lists > in the sense that all elements should be of the same declared type and > at the same time mix all kind of type in a particular list, just > as python does. Diez: > The you have JAVA Object or C void*. Which cause all kinds of runtime > troubles.... because they essentially circumvene the typechecking! Antoon: > Why do you call this a JAVA Object or C void*? Why don't you call > it a PYTHON object. It is this kind of reaction that IMO tells most > opponents can't think outside the typesystems they have already > seen and project the problems with those type systems on what > would happen with python should it acquire a type system. Me: > Diez' intention seemed fairly clear > to me: he is pointing out that strongly-typed systems invariably fall > back on generic declarations when they want to allow objects of any type > (which, it seems to me, is what you were proposing as well). You: > C and Java: you get useful type checking except when you declare > a reference as type ANY. This is a shortcoming compared to: > > Python: where you get no useful type checking at all. > The points that have repeatedly been made are: 1. That even the strict typings required by languages like Java and C++ actually end up getting in the way when the pragmatic requirements of real-world problems have to be taken into account. 2. That the benefits of declarations are overstated by many of their proponents. 3. That Python as it is today allows the dynamic creation of names, which are therefore inherently not available for declaration. On existing evidence it's extremely unlikely that this post will end the thread, but I certainly wish *something* would. Unfortunately I seem to have become part of the problem in that respect :-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From gene.tani at gmail.com Mon Oct 10 16:37:40 2005 From: gene.tani at gmail.com (gene tani) Date: 10 Oct 2005 13:37:40 -0700 Subject: Learning Python In-Reply-To: <7e6dnQAA36FTBtfeRVn-rg@rogers.com> References: <7e6dnQAA36FTBtfeRVn-rg@rogers.com> Message-ID: <1128976660.264371.186100@g43g2000cwa.googlegroups.com> This should be good for a couple weeks http://www.awaretek.com/tutorials.html http://www.rexx.com/~dkuhlman/python_101/python_101.html http://www.rexx.com/~dkuhlman/python_201/python_201.html http://www.ibiblio.org/obp/py4fun/ http://the.taoofmac.com/space/Python/Grimoire http://mail.python.org/pipermail/tutor/ http://rgruet.free.fr/#QuickRef Paul DiRezze wrote: > I'm spending the next two weeks off and I'm looking to take a crack at > learning how to program in Python. Here's a list of the places I've > bookmarked: > > http://www.python.org/doc/ and more specifically > http://wiki.python.org/moin/ > http://wiki.python.org/moin/BeginnersGuide > http://www.python.org/doc/Intros.html > http://www.python.org/topics/ > > I'm looking for additional resources (links, names of books, > whatever...) that you think may help me out. > > I'm a hobby programmer using mostly BASIC(s) and some Java. I know > procedural programming and I know what encapsulation, inheritance and > polymorphism are but I have very little experience in using them as I've > written just a few Java programs (i.e., I guess I could use a primer in > OO programming). > > Any ideas? > > paul From fredrik at pythonware.com Sun Oct 9 05:24:51 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 9 Oct 2005 11:24:51 +0200 Subject: "import socket" error References: <1128849129.254683.155420@g43g2000cwa.googlegroups.com> Message-ID: akbarhome at gmail.com wrote: > I am following this tutorial > https://www14.software.ibm.com/webapp/iwm/web/preLogin.do?source=dw-linux-pysocks&S_TACT=105AGX59&S_CMP=GR&ca=dgr-lnxw07PythonSockets > ( free reg. req. ) > > The article told me to do this: > > [camus]$ python > Python 2.4 (#1, Feb 20 2005, 11:25:45) > [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2 > Type "help", "copyright", "credits" or "license" for more > information. > >>> import socket > >>> socket.gethostbyname('www.ibm.com') > '129.42.19.99' > >>> > > When I try it, I get this error: > >>> import socket > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/lib/python2.4/socket.py", line 1, in ? > # Wrapper module for _socket, providing some additional facilities > File "/usr/lib/python2.4/SocketServer.py", line 274, in ? > class TCPServer(BaseServer): > File "/usr/lib/python2.4/SocketServer.py", line 317, in TCPServer > address_family = socket.AF_INET > AttributeError: 'module' object has no attribute 'AF_INET' > >>> > > Why? Thank you. your Python installation is broken. what OS are you using? From xah at xahlee.org Tue Oct 18 17:56:32 2005 From: xah at xahlee.org (Xah Lee) Date: 18 Oct 2005 14:56:32 -0700 Subject: write a loopin one line; process file paths Message-ID: <1129672592.328278.41490@g14g2000cwa.googlegroups.com> is there a way to condense the following loop into one line? # -*- coding: utf-8 -*- # python import re, os.path imgPaths=[u'/Users/t/web/Periodic_dosage_dir/lanci/t4/oh/DSCN2059m-s.jpg', u'/Users/t/web/Periodic_dosage_dir/lanci/t4/oh/DSCN2062m-s.jpg', u'/Users/t/web/Periodic_dosage_dir/lanci/t4/oh/DSCN2097m-s.jpg', u'/Users/t/web/Periodic_dosage_dir/lanci/t4/oh/DSCN2099m-s.jpg', u'/Users/t/web/Icons_dir/icon_sum.gif'] # change the image path to the full sized image, if it exists # that is, if image ends in -s.jpg, find one without the '-s'. temp=imgPaths[:] imgPaths=[] for myPath in temp: p=myPath (dirName, fileName) = os.path.split(myPath) (fileBaseName, fileExtension)=os.path.splitext(fileName) if(re.search(r'-s$',fileBaseName,re.U)): p2=os.path.join(dirName,fileBaseName[0:-2]) + fileExtension if os.path.exists(p2): p=p2 imgPaths.append(p) temp=[] print imgPaths Xah xah at xahlee.org ? http://xahlee.org/ From deets at nospam.web.de Wed Oct 5 17:04:04 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 05 Oct 2005 23:04:04 +0200 Subject: how to keep collection of existing instances and return one on instantiation In-Reply-To: <3qit8lFf749gU1@uni-berlin.de> References: <1128529206.4560.13.camel@blackwidow> <3qid8sFeigdeU1@uni-berlin.de> <1128532128.4560.21.camel@blackwidow> <3qihbfFerdqjU1@uni-berlin.de> <1128542791.4560.34.camel@blackwidow> <3qit8lFf749gU1@uni-berlin.de> Message-ID: <3qite4Ff749gU2@uni-berlin.de> Diez B. Roggisch wrote: > >>> Read the comments. What you say is essentially the same - the data >>> matters, after all. What do you care if there are several instances >>> around? >>> >> In my case it matters more that the objects are the same. >> >> For example I want set([Spam(1), Spam(2), >> Spam(3)]).intersect(set([Spam(1), Spam(2)]) to contain two items instead >> of 0. >> >> For this and many other reasons it's important that Spam(n) is Spam(n). > > > Ah, ok. Well, you could always use the __hash__ method to ensure that - > might be better anyway, because then _you_ define what equality means. > But YMMV. And the __cmp__ or __eq__/__ne__ methdos of course.... Diez From fredrik at pythonware.com Wed Oct 5 07:16:40 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 5 Oct 2005 13:16:40 +0200 Subject: bug or feature? References: <1128508770.727391.313300@f14g2000cwb.googlegroups.com> Message-ID: Steve Holden wrote: > Interestingly I couldn't find this in the FAQ, though it *is* a > frequently-asked question [note: my not finding it doesn't guarantee > it's not there]. it's there: http://www.python.org/doc/faq/general.html#why-are-default-values-shared-between-objects (maybe "default values" should be changed to "default argument values") it's also mentioned in chapter 4 of the tutorial: http://docs.python.org/tut/node6.html#SECTION006710000000000000000 "*Important warning*: The default value is evaluated only once. This makes a difference when the default is a mutable object such as a list, dictionary, or instances of most classes. " (the text then illustrates this with examples, and shows how to do things instead) and in the description of "def" in the language reference: http://docs.python.org/ref/function.html "*Default parameter values are evaluated when the function definition is executed*. This means that the expression is evaluated once, when the function is defined, and that that same "pre-computed" value is used for each call. This is especially important to understand when a default para- meter is a mutable object, such as a list or a dictionary: if the function modifies the object (e.g. by appending an item to a list), the default value is in effect modified." (the text then shows how to do things instead) From dinamo99 at lycos.com Thu Oct 20 01:35:05 2005 From: dinamo99 at lycos.com (Joe) Date: Thu, 20 Oct 2005 05:35:05 GMT Subject: How to extract a part of html file Message-ID: I'm trying to extract part of html code from a tag to a tag code begins with and ends with TD> I was thinking of using a regular expression however I having hard time getting the desired string. I use htmlSource = urllib.urlopen("http://address/") s = htmlSource.read() htmlSource.close() to get the html into a string, now I want to match string s from a and store that into a new string. Thanks From dezmodue at gmail.com Fri Oct 14 09:09:14 2005 From: dezmodue at gmail.com (Simone) Date: Fri, 14 Oct 2005 15:09:14 +0200 Subject: Text not showing up Message-ID: <434FADFA.8050302@gmail.com> Hi all, I am new to python and trying to write a simple GUI that would call 2 growisofs processes (dvd burning) at the same time, and retrive the exit code to be printed on a text box (couldn't find any program that could use multiple dvd burners, not even k3b). Excuse me if this is really a simple problem, but two days of googling didn't help. The program is really simple, I developed the GUI using glade and it works. The only thing I would like to improve is that I'd like it to show in the text boxes messages like "Waiting for use input" or "Burning dvd please wait", but it looks like even though I don't have any error, the message won't show up until the burning process is finished (showing either "burning successfully" or "an error occurred"). I am not sure I made myself clear on this, but I will post the relevant code trying to explain it: import os, sys import gtk.glade class DVD: def __init__(self): print "Initializing the Graphic User Interface: This may take some time" self.xml=gtk.glade.XML("./dvd2.xml") self.window=self.xml.get_widget("dvd") self.xml.signal_connect('on_quit_clicked', self.Quit) self.xml.signal_connect('on_burn_clicked', self.Burn) self.OrdKeys=["comboentry1","entry1","spinbutton1","entry2","esitotext","esitotext1"] # here esitotext is the box I want the text to show up def Quit(self, *args): gtk.mainquit() def Burn(self, *args): comand="" comand2="" name=self.xml.get_widget("entry1").get_text() #name for the dvd path=self.xml.get_widget("comboentry1").get_text() #path to dvd AUDIO_TS and VIDEO_TS num=self.xml.get_widget("spinbutton1").get_text() #chosing the number of dvd to burn pub=self.xml.get_widget("entry2").get_text() #publisher self.xml.get_widget("esitotext").set_text("Waiting for input") # THIS NEVER SHOWS UP dvd1="/dev/hda" # this is the first dvd burner, edit as needed dvd2="/dev/hdc" # this is the second dvd burner, edit as needed comand+="growisofs -dvd-compat -Z "+dvd1+" -dvd-video -V "+name+" -publisher "+pub+" "+path comand2+="growisofs -dvd-compat -Z "+dvd2+" -dvd-video -V "+name+" -publisher "+pub+" "+path if num == "1": self.xml.get_widget("esitotext").set_text("Burning the dvd, please wait") # THIS NEVER SHOWS UP, unless i have an error and the program # quits before executing the command self.xml.get_widget("esitotext").show() # don't know if this is correct, but it doesn't work either f = os.popen(comand, 'r') line = f.readline() error_in_prog = f.close() if error_in_prog: error=str(error_in_prog) self.xml.get_widget("esitotext").set_text("An error occurred. Burn not completed") # THIS COMES UP as it should self.xml.get_widget("esitotext").show() else: self.xml.get_widget("esitotext").set_text("Burn completed successfully") # THIS COMES UP as it should self.xml.get_widget("esitotext").show() if __name__=='__main__': main=DVD() gtk.main() Any comment, help, url, really appreciated. Have a nice day Simone From fredrik at pythonware.com Thu Oct 20 03:16:27 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 20 Oct 2005 09:16:27 +0200 Subject: Abstract Methods & Abstract Class References: <20051020065644.GA10206@heaven.kostyrka.org> Message-ID: Andreas Kostyrka wrote: > > Do we have something like abstract methods & Abstract class. > > > > So that my class would just define the method. And the implementation > > would be defined by somebody else. > > class AbstractBase: > def method(self): > raise TypeError("abstract method called") > > But basically, Python does not have abstract methods, and usually doesn't > need them. the NotImplementedError exception is usually a better choice: class AbstractBase: def method(self): raise NotImplementedError("'method' implementation missing") From nszabolcs at gmail.com Mon Oct 3 15:51:43 2005 From: nszabolcs at gmail.com (Szabolcs Nagy) Date: 3 Oct 2005 12:51:43 -0700 Subject: Where to find python c-sources In-Reply-To: <5N-dnZny3YyaA6HenZ2dnUVZ_tKdnZ2d@powergate.ca> References: <0LZ_e.19644$Ix4.10480@okepread03> <5N-dnZny3YyaA6HenZ2dnUVZ_tKdnZ2d@powergate.ca> Message-ID: <1128369103.275097.258880@g44g2000cwa.googlegroups.com> if u just want to browse the code online then use this: http://fisheye.cenqua.com/viewrep/python/python/dist/src *much* nicer than sourceforge cvs viewer nsz From fredrik at pythonware.com Sat Oct 8 11:29:58 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 8 Oct 2005 17:29:58 +0200 Subject: Function decorator that caches function results References: Message-ID: Lasse V?gs?ther Karlsen wrote: > Yeah, but as far as I can see it, this one too fails to recognize > situations where the function is called twice with essentially the same > values, except that in one call it uses named arguments: > > k1 = fibonacci(100) > k2 = fibonacci(idx = 100) > > this is essentially the same call, except the second one uses a named > argument, which means the function will be invoked and a second cache > entry will be stored. whoever writes code like that deserves to be punished. I'd say this thread points to a misunderstanding of what keyword arguments are, and how they should be used. the basic rule is that you shouldn't mix and match; use positional arguments for things that are documented to be positional parameters, and keyword arguments for keyword parameters. if you don't, you'll end up with code that depends on implementation details. and that's never a good idea... From bdesth.quelquechose at free.quelquepart.fr Tue Oct 25 16:54:00 2005 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Tue, 25 Oct 2005 22:54:00 +0200 Subject: Setting Class Attributes In-Reply-To: <1130263774.719830.6230@f14g2000cwb.googlegroups.com> References: <1130263774.719830.6230@f14g2000cwb.googlegroups.com> Message-ID: <435e91b1$0$21322$626a54ce@news.free.fr> the.theorist a ?crit : > I have a small, simple class which contains a dictionary (and some > other stuff, not shown). I then have a container class (Big) that holds > some instances of the simple class. When I try to edit the elements of > the dictionary, all instances obtain those changes; I want each > instance to hold separate entries. > > #----------Begin module test.py > class ex: class ex(object): # oldstyle classes are deprecated > def __init__(self, val={}): > self.value = val You didn't search very long. This is one of the most (in)famous Python gotchas: default args are evaluated *only once*, when the function definition is evaluated (at load time). This is also a dirty trick to have a 'static' (as in C) like variable. The solution is quite simple: class ex(object): def __init__(self, val=None): if val is None: val = {} self.value = val (snip) From bokr at oz.net Fri Oct 21 22:44:20 2005 From: bokr at oz.net (Bengt Richter) Date: Sat, 22 Oct 2005 02:44:20 GMT Subject: coloring a complex number References: <1129946307_147@spool6-east.superfeed.net> Message-ID: <4359a1a7.624927418@news.oz.net> On Fri, 21 Oct 2005 20:55:47 -0500, Brandon K wrote: >I'm not 100% sure about this, but from what it seems like, the reason >method B worked, and not method a is because class foo(complex) is >subclassing a metaclass. So if you do this, you can't init a meta class >(try type(complex), it equals 'type' not 'complex'. type(complex()) >yields 'complex'), so you use the new operator to generator a class on >the fly which is why it works in method B. I hope that's right. > >-Brandon >> Spending the morning avoiding responsibilities, and seeing what it would >> take to color some complex numbers. >> >> class color_complex(complex): >> def __init__(self,*args,**kws): >> complex.__init__(*args) >> self.color=kws.get('color', 'BLUE') >> >>>>> a=color_complex(1,7) >>>>> print a >> (1+7j) #good so far >>>>> a=color_complex(1,7,color='BLUE') >> Traceback (most recent call last): >> File "", line 1, in -toplevel- >> a=color_complex(1,7,color='BLUE') >> TypeError: 'color' is an invalid keyword argument for this function >> >> No good... it seems that I am actually subclassing the built_in function No, complex is callable, but it's a type: >>> complex >> 'complex' when I am hoping to have been subclassing the built_in numeric >> type - complex. >> You need to override __new__ for immutable types, since the args that build the base object are already used by the time __init__ is called, and UIAM the default __init__ inherited from object is a noop. However, if you define __init__ you can choose to process the other args in either place, e.g.: >>> class color_complex(complex): ... def __new__(cls, *args, **kws): ... return complex.__new__(cls, *args) ... def __init__(self, *args, **kws): ... self.color=kws.get('color', 'BLUE') ... >>> a=color_complex(1,7) >>> a (1+7j) >>> a=color_complex(1,7, color='BLUE') >>> a (1+7j) >>> a.color 'BLUE' Or as in what you found, below: >> but some googling sends me to lib/test/test_descr.py >> >> where there a working subclass of complex more in >> accordance with my intentions. >> >> class color_complex(complex): >> def __new__(cls,*args,**kws): >> result = complex.__new__(cls, *args) >> result.color = kws.get('color', 'BLUE') >> return result >> >>>>> a=color_complex(1,7,color='BLUE') >>>>> print a >> (1+7j) >>>>> print a.color >> BLUE >> >> which is very good. >>> a=color_complex(1,7, color='RED') >>> a (1+7j) >>> a.color 'RED' (just to convince yourself that the default is just a default ;-) >> >> But on the chance that I end up pursuing this road, it would be good if >> I understood what I just did. It would certainly help with my >> documentation ;) >> >> Assistance appreciated. >> >> NOTE: >> >> The importance of the asset of the depth and breadth of Python archives >> - for learning (and teaching) and real world production - should not be >> underestimated, IMO. I could be confident if there was an answer to >> getting the functionality I was looking for as above, it would be found >> easily enough by a google search. It is only with the major >> technologies that one can hope to pose a question of almost any kind to >> google and get the kind of relevant hits one gets when doing a Python >> related search. Python is certainly a major technology, in that >> respect. As these archives serve as an extension to the documentation, >> the body of Python documentation is beyond any normal expectation. >> >> True, this asset is generally better for answers than explanations. >> >> I got the answer I needed. Pursuing here some explanation of that answer. >> HTH Regards, Bengt Richter From fredrik at pythonware.com Wed Oct 26 11:49:59 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 26 Oct 2005 17:49:59 +0200 Subject: WinXP vs. Win98 References: <1130331088.292656.213430@g47g2000cwa.googlegroups.com> Message-ID: sidanko at scientist.com wrote: > I use Python 2.3.3 (Enthought edition) with wxPython and it is > installed on both WinXP and Win98. On Win98 machine I have the > following error: > File "C:\PYTHON23\lib\site-packages\freetype\font_lookup.py", line > 24, in ? > font_dirs.append(os.path.join(os.environ[ 'systemroot' ],'fonts')) > File "C:\PYTHON23\lib\os.py", line 417, in __getitem__ > return self.data[key.upper()] > KeyError: 'SYSTEMROOT' > >>> > Hovewer running very the same script on WinXP machine I have no > problems at all. What's wrong? Kiva package (as well as others) is > installed properly. Where to dig? Windows XP has SystemDrive and SystemRoot environment variables, while Windows 98 don't seem to have them. a quick workaround is to set the SystemRoot environment by hand (it should point to the Windows system directory; usually c:\windows. iirc, you have to edit AUTOEXEC.BAT or run the MSCONFIG utility to set them). alternatively, you can add the following fix to your application code: import os os.environ["SystemRoot"] = os.environ.get("windir", "c:\\windows") (put it *before* the wxplot import code) a better fix is to make the freetype font_lookup code a bit more robust. From steve at REMOVETHIScyber.com.au Thu Oct 13 10:41:04 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Fri, 14 Oct 2005 00:41:04 +1000 Subject: Adding methods to an object References: <1129208780.605763.218110@g43g2000cwa.googlegroups.com> Message-ID: On Thu, 13 Oct 2005 06:06:20 -0700, Gabriele *darkbard* Farina wrote: > Hi, there is a way to add methods to an object dynamically? Yes. There are three different sorts of methods, and three ways of adding them. py> class Parrot: ... def __init__(self): ... pass py> # Parrot is the class. py> # Parrot() is an instance of the class. Firstly, you want an ordinary method with a "self" parameter, as if you had defined it when you created the class. py> def spam(self): ... return "Spam comes from %s" % self ... py> Parrot.spam = spam Now we try calling it from an instance: py> Parrot().spam() 'Spam comes from <__main__.Parrot instance at 0xed498fec>' If you try to call spam direct from the class, it fails: py> Parrot.spam() TypeError: unbound method spam() must be called with Parrot instance as first argument (got nothing instead) The second way of adding a method is a class method. Class methods don't know about the instance you call them from, only the class. py> def fjords(cls): ... return "I'm pining for the fjords at %s." % cls ... py> Parrot.fjords = classmethod(fjords) Now we can call it from either the class or any instance, and get the exact same result. fjords just can't see the instance, only the class: py> Parrot.fjords() "I'm pining for the fjords at __main__.Parrot" py> Parrot().fjords() "I'm pining for the fjords at __main__.Parrot" Lastly, we can add a static method, that doesn't know about either the class or the instance: py> def ham(): ... return "Genuine pig product." ... py> Parrot.ham = staticmethod(ham) py> Parrot.ham() 'Genuine pig product' py> Parrot().ham() 'Genuine pig product' Summary: If you write the function with a "self" argument, and just add it to the class, you must call that method using an instance. This is an ordinary instance method, as if you had created the class with it. If you write the function with a "cls" argument, you must add it to the class with a classmethod() call, and then call it from either the class or an instance. This method cannot access the instance that calls it, only the class. If you write the function without a "self" or "cls" argument, you must add it to the class with a staticmethod() call. This method cannot access either the class or the instance object. -- Steven. From peck at spss.com Mon Oct 3 08:14:02 2005 From: peck at spss.com (Peck, Jon) Date: Mon, 3 Oct 2005 07:14:02 -0500 Subject: Finding the Process Path Message-ID: <5CFEFDB5226CB54CBB4328B9563A12EE02C62153@hqemail2.spss.com> I have Python code running in an application, and I would like to find the full path of the process executable where it is running. I can do this with win32api.GetModuleFileName(0) on Windows, but I would like a solution that uses only standard modules and works cross platform. Any suggestions? TIA. Jon K Peck (Kim) peck at spss.com 312-651-3435 233 S Wacker Dr Chicago, IL 60606 -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Mon Oct 17 17:25:54 2005 From: john at castleamber.com (John Bokma) Date: 17 Oct 2005 21:25:54 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: "Mike Schilling" wrote: > "John Bokma" wrote in message > news:Xns96F1E4E128EA8castleamber at 130.133.1.4... >> Yup, but ISO C++ is a standard, and XML is a recommendation. > > And the practical difference between the two is.... > > That's right, nil. If you both read them as a collection of words, you're right. However, as a (freelance) programmer, things like this *do* make a difference to me, and my customers. Otherwise I can suck on my thumb, write some words on a piece of paper, and call them standards myself. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From mscottschilling at hotmail.com Tue Oct 18 01:36:49 2005 From: mscottschilling at hotmail.com (Mike Schilling) Date: Tue, 18 Oct 2005 05:36:49 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: "John Bokma" wrote in message news:Xns96F2D6EAAC3BBcastleamber at 130.133.1.4... > "Mike Schilling" wrote: > >> >> "John Bokma" wrote in message >> news:Xns96F1E574E6873castleamber at 130.133.1.4... >>> Roedy Green wrote: >>> >>>> On 16 Oct 2005 05:22:47 GMT, John Bokma wrote >>>> or quoted : >>>> >>>>>No, it's a recommendation, an advise, nothing else. Otherwise they >>>>>would call it a standard. Why do you think W3C calls it >>>>>recommendations? Because it are no standards. There is an ISO HTML >>>>>standard though, but when people babble about HTML standards they >>>>>talk about W3C *recommendations*. >>>> >>>> What do you think the Internet is based on? RFCs. >>> >>> Yup, I know. Hence no standards. >>> >>> Like I said: there is ISO HTML, and there is a w3c HTML 4.01 >>> recommendation. The former is a standard, the latter is a defacto >>> standard. >>> For some the difference does matter. >> >> What matters in generating HTML is which browsers you want to support >> and what they understand. Standards and recommendations are both >> irrelevant. > > So how do you develop a browser? I assume you have some experience with > programming, or is that trial and error programming? Hack until it > works? > A browser that's perfectly compliant but can't render the pages actually found would be of only academic interest. So, yes, the standards (and recommendations) are one source of requirements, but the actual contents of the internet is another. From gene.tani at gmail.com Tue Oct 11 23:07:07 2005 From: gene.tani at gmail.com (gene tani) Date: 11 Oct 2005 20:07:07 -0700 Subject: where to get modules for python In-Reply-To: <1129080870.418774.76390@f14g2000cwb.googlegroups.com> References: <1129080870.418774.76390@f14g2000cwb.googlegroups.com> Message-ID: <1129086427.651616.192970@g47g2000cwa.googlegroups.com> http://www.python.org/doc/faq/library.html#how-do-i-find-a-module-or-application-to-perform-task-x eight02645999 at yahoo.com wrote: > hi > i am new to python and was wondering where can i find modules for > python? > Something very much like what CPAN has for Perl. > I am searching for SSL/SSH modules for use in Python. > thanks From iddw at hotmail.com Fri Oct 7 17:29:53 2005 From: iddw at hotmail.com (Dave Hansen) Date: Fri, 07 Oct 2005 21:29:53 GMT Subject: When someone from Britain speaks, Americans hear a "British accent"... References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kd19ajdtkoi6f@corp.supernews.com> <1128709915.677e761b4ee3431140a6964c46a02b82@teranews> Message-ID: <1128720597.ce996e0843e491943d346255fc679cce@teranews> On Fri, 7 Oct 2005 16:18:57 -0500, Terry Hancock wrote: >On Friday 07 October 2005 01:31 pm, Dave Hansen wrote: Actually, I didn't, though I did respond to it. Please watch your attributions. Thanks, -=Dave -- Change is inevitable, progress is not. From vbfoobar at gmail.com Tue Oct 18 08:02:10 2005 From: vbfoobar at gmail.com (vbfoobar at gmail.com) Date: 18 Oct 2005 05:02:10 -0700 Subject: How to make command history persistent? In-Reply-To: <1129631441.629180.191200@g14g2000cwa.googlegroups.com> References: <1129627265.021498.146390@g14g2000cwa.googlegroups.com> <1129631441.629180.191200@g14g2000cwa.googlegroups.com> Message-ID: <1129636197.448855.179520@g44g2000cwa.googlegroups.com> Great! The indicated "history save" works! Thanks From kent37 at tds.net Fri Oct 21 13:33:11 2005 From: kent37 at tds.net (Kent Johnson) Date: Fri, 21 Oct 2005 13:33:11 -0400 Subject: need some advice on x y plot In-Reply-To: <1129912485.866312.298390@g47g2000cwa.googlegroups.com> References: <1129823043.104864.73750@f14g2000cwb.googlegroups.com> <11lfgebn85liq1b@corp.supernews.com> <1129825379.218308.242010@g47g2000cwa.googlegroups.com> <4357d998$1_2@newspeer2.tds.net> <1129831950.926154.196420@g47g2000cwa.googlegroups.com> <1129912485.866312.298390@g47g2000cwa.googlegroups.com> Message-ID: <4359244e$1_2@newspeer2.tds.net> nephish at xit.net wrote: > i am running a query on a database and making a list of time, value > pairs > kinda like this > plot_points = ([time, value], [time, value], [time, value]) > gnuplot complains that it needs a float for one of the values. > i can plot just the value, and it shows up ( no x value found) > > how should i proceed? Convert one of the values to a float? What are your time and value numbers? Kent From http Tue Oct 11 17:45:46 2005 From: http (Paul Rubin) Date: 11 Oct 2005 14:45:46 -0700 Subject: Nicer way of strip and replace? References: Message-ID: <7xpsqb6839.fsf@ruckus.brouhaha.com> Markus Rosenstihl writes: > This looks ugly (I htink) and I wonder if there is a nicer way to > strip commata and change the comma to a dot already when reading in. > Or should i do it with a shell script before processing in python? First of all you should just set your locale to use comma instead of dot as the numeric decimal, instead of translating commas to dots. Second, for the field separation, see if you can configure the csv module to do it for you. From free.condiments at gmail.com Sun Oct 16 16:35:40 2005 From: free.condiments at gmail.com (Sam Pointon) Date: 16 Oct 2005 13:35:40 -0700 Subject: Calling an exe from Python? In-Reply-To: <1129492892.037665.123590@g44g2000cwa.googlegroups.com> References: <1129492892.037665.123590@g44g2000cwa.googlegroups.com> Message-ID: <1129494940.848238.305130@g44g2000cwa.googlegroups.com> from subprocess import Popen proc = Popen('my_programme.exe') Use proc.communicate(input) to send input to stdin, and get a tuple of (stdout, stderr) back. If you need the returncode, use proc.poll() or proc.wait(), depending on if you want it to block or not. From edhotchkiss at gmail.com Tue Oct 4 11:10:34 2005 From: edhotchkiss at gmail.com (Ed Hotchkiss) Date: Tue, 4 Oct 2005 11:10:34 -0400 Subject: Which SQL module to use? In-Reply-To: <4342925A.1040807@ghaering.de> References: <1128433394.470896.89770@g44g2000cwa.googlegroups.com> <4342925A.1040807@ghaering.de> Message-ID: I'm using MySQLdb. I use a FREE MySQL server at freesql.org. I also have an example class and some functions that use the module. even a simple script that turns a .cvs into a mysql table. contact me if interested. -edward -------------- next part -------------- An HTML attachment was scrubbed... URL: From istvan.albert at gmail.com Tue Oct 4 14:58:13 2005 From: istvan.albert at gmail.com (Istvan Albert) Date: 4 Oct 2005 11:58:13 -0700 Subject: Controlling who can run an executable In-Reply-To: <1128449405.776337.251380@g44g2000cwa.googlegroups.com> References: <1128395422.904212.318930@g44g2000cwa.googlegroups.com> <1128432188.408503.309280@f14g2000cwb.googlegroups.com> <1128449405.776337.251380@g44g2000cwa.googlegroups.com> Message-ID: <1128452293.752325.242520@g49g2000cwa.googlegroups.com> > I could ask her, "If you can't break it is that good enough security?" Guess not. Most non-programmers think everyone else who knows some programming is a some sort of hacker genius. Instead come up with a simple solution then explain her how it will works. I think in the ensuing conversation you'll find out more on what approach would put her mind at ease. Istvan. From mwm at mired.org Thu Oct 13 19:53:58 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 13 Oct 2005 19:53:58 -0400 Subject: Jargons of Info Tech industry References: <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1124804082_1011@spool6-east.superfeed.net> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <86y853mzmr.fsf@bhuda.mired.org> <86mzlil269.fsf@bhuda.mired.org> <86slv8xdkw.fsf@bhuda.mired.org> Message-ID: <86zmpdt1m1.fsf@bhuda.mired.org> Brendan Guild writes: >> 2. flipping to a sender pays system so that the Internet does not >> subsidise spam. > > This is very promising. Our ISPs should put limits on how much email we > can send. The limits should be rather insane, nothing that any > nonspammer would ever come close to, but low enough to stop spam dead. > If we want to send more than that, we'd better be charged extra. > > We could make each mail server responsible for the spam that it sends > out. It seems that currently mail servers are swamped and spending big > money on handling the vast loads of spam that gets pumped into them > from other mail servers, so I'm sure they wouldn't mind having a rule > like: Refuse to allow email to be transported from any server that > spews more than 50% spam. Servers could be audited occasionally to > check if they are spammers. Except that lots of spam doesn't *go* through the ISPs server. It's running on some Windows zombie, and delivering mail directly to the recipients server. It'll only go through the ownee's mail server if the ISP blocks outbound SMTP connections. > I don't know exactly how spammers send spam, but a rule like that would > sure stop ISPs from allowing any one person to send a thousand emails a > day. And that would work if spammers needed an ISPs permissions to send email. But they don't. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From mauriceling at acm.org Fri Oct 7 06:29:56 2005 From: mauriceling at acm.org (Maurice LING) Date: Fri, 07 Oct 2005 18:29:56 +0800 Subject: New Python book In-Reply-To: References: Message-ID: <43464E24.3050609@acm.org> I had the opportunity to glance through the book in Borders yesterday. On the whole, I think it is well covered and is very readable. Perhaps I was looking for a specific aspect, and I find that threads did not get enough attention. Looking at the index pages, the topics on threads (about 4-5 pages) is mainly found in the context of GUI programming. maurice Dick Moores wrote: > (Sorry, my previous post should not have had "Tutor" in the subject > header.) > > Magnus Lie Hetland's new book, _Beginning Python: From Novice to > Professional_ was published by Apress on Sept. 26 (in the U.S.). My copy > arrived in the mail a couple of days ago. Very much worth a look, IMHO. > But what do the experts here think? > > > > Dick Moores > rdm at rcblue.com > > From eurleif at ecritters.biz Sun Oct 2 13:23:21 2005 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sun, 02 Oct 2005 17:23:21 GMT Subject: Distributing programs In-Reply-To: References: Message-ID: Jeff Schwab wrote: > Sorta, but not really. Typically, you might distribute the source (.py) > files, but if you don't want to do that, you can distribute the > compiled .pyc files instead. Python creates these files automatically > when your modules are imported. But remember that Python bytecode can be easily decompiled with a publicly-available program. From fredrik at pythonware.com Mon Oct 24 07:22:54 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 24 Oct 2005 13:22:54 +0200 Subject: ABOUT FIND References: <1d987df30510240357r7a557822h9af6d5720da2c8b@mail.gmail.com> Message-ID: Shi Mu wrote: >I got confused by the following information from the help for "FIND": > find(s, *args) what "FIND" ? >>> help(str.find) Help on method_descriptor: find(...) 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. maybe it's string.find? (that's a backwards compatibility thing; new code should use the corresponding method instead). >>> help(string.find) Help on function find in module string: find(s, *args) find(s, sub [,start [,end]]) -> in 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. > what does *args mean (especially the '*')? help() uses introspection to find the function signature, so the first find() you're seeing is probably how the function is declared, while the second one comes from the help string itself. I guess string.find looks like this: def find(s, *args): return s.find(*args) here, the first "*args" means "take a variable number of arguments, and put the extra arguments in the args variable", the second means "call this method with arguments taken from the args variable") but this is an implementation detail (and a limitation in the help system), and nothing you need to bother with when *using* the find method/function. > also, in the sub, why put a comma before start? it means that you should put a comma *between* sub and start if you provide a start argument, but not add an extra comma if you're only providing a sub argument. this would probably be easier to read: S.find(sub, [start, [end]]) -> int but if the help text looked like that, some nincompoop would most likely complain that it was broken since you're not really supposed to write: S.find(sub,) (not that it matters in this case; Python ignores trailing commas in function calls, but they look a bit silly). > what does 'in' mean? the method help text says "int", so it looks like a typo, or a cut/paste error. From rich.teer at rite-group.com Sat Oct 8 19:35:40 2005 From: rich.teer at rite-group.com (Rich Teer) Date: Sat, 08 Oct 2005 23:35:40 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> Message-ID: On Sun, 9 Oct 2005, Lasse V?gs?ther Karlsen wrote: > But trying to keep your email world into a pure text-based > no-formatting-whatsoever world, that's a fantasy bubble that is bound to > burst, sooner rather than later. Not here. I've configured my email server to reject HTML emails before I even see them, and more often tham not I'll delete any others that sneak through the gate. If people want me to read their email, they should send it to me in an open, universal format, which for email is plain text. It's as simple as that. -- Rich Teer, SCNA, SCSA, OpenSolaris CAB member President, Rite Online Inc. Voice: +1 (250) 979-1638 URL: http://www.rite-group.com/rich From grante at visi.com Tue Oct 4 17:38:02 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 04 Oct 2005 21:38:02 -0000 Subject: how to get any available port References: Message-ID: <11k5thqpr7m3q5d@corp.supernews.com> On 2005-10-04, Mohammed Smadi wrote: > On Tue, 4 Oct 2005, Grant Edwards wrote: > >> On 2005-10-04, ncf wrote: >> >> > Hmm...perhaps he is trying to do a transfer thing like many chat >> > programs do. Instead of sending large files across a server, you >> > "Direct Connect" and send the file directly. :shrugs: >> >> So how does that require binding the client end of a TCP >> connection? > > what else would you do? Just call connect(): > I am using examples from the web and they all bind to a port > at the localhost before connecting to the remote host. I don't know who wrote those examles, but I've never seen it done that way before. Take a look at the examples from the python socket module docs: http://docs.python.org/lib/socket-example.html > my code is like this > > #transmission socket > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) > s.bind(("",hp_port)) # do some error checking > > > data="HI" > print data > s.connect(('192.168.2.13',port)) > s.send(data) > print "\n" > > which is working fine for me after putting the > s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) statement Just skip the bind() call. It's useless. #transmission socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('192.168.2.13',port)) s.send(data) -- Grant Edwards grante Yow! Are you still an at ALCOHOLIC? visi.com From spammers-go-here at spam.invalid Thu Oct 6 19:45:02 2005 From: spammers-go-here at spam.invalid (Madhusudan Singh) Date: Thu, 06 Oct 2005 19:45:02 -0400 Subject: Force flushing buffers Message-ID: <4345b6e8$0$49009$14726298@news.sunsite.dk> Hi I have a python application that writes a lot of data to a bunch of files from inside a loop. Sometimes, the application has to be interrupted and I find that a lot of data has not yet been writen (and hence is lost). How do I flush the buffer and force python to write the buffers to the files ? I intend to put this inside the loop. Thanks. From jadedgamer at hotmail.com Wed Oct 26 12:05:45 2005 From: jadedgamer at hotmail.com (Tor Iver Wilhelmsen) Date: 26 Oct 2005 18:05:45 +0200 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> <11lsopl4qpg9gc2@corp.supernews.com> Message-ID: entropy writes: > IBM seems to have had a history of squeezing out competition in the > same way Microsoft has, if I recall correctly. ... and were told not to by a court. Which is the whole reason for the existence of IBM clones, whether PCs or mainframes. From jon_usenet at capisco.com Thu Oct 13 11:18:13 2005 From: jon_usenet at capisco.com (jon) Date: 13 Oct 2005 08:18:13 -0700 Subject: Comparing lists In-Reply-To: References: <1128930699.799657.146210@g47g2000cwa.googlegroups.com> <1128952417.0544cc73190bbbd4e683448c137969c8@teranews> <434ba977@nntp0.pdx.net> Message-ID: <1129216693.445956.155490@g47g2000cwa.googlegroups.com> To take the heat out of the discussion: sets are blazingly fast. From mde at micah.elliott.name Sat Oct 8 21:25:16 2005 From: mde at micah.elliott.name (Micah Elliott) Date: Sat, 8 Oct 2005 18:25:16 -0700 Subject: [regex] case-splitting strings in unicode In-Reply-To: References: Message-ID: <20051009012516.GB26320@kitchen.client.attbi.com> On Oct 09, John Perks and Sarah Mount wrote: > I have to split some identifiers that are casedLikeThis into their > component words. In this instance I can safely use [A-Z] to represent > uppercase, but what pattern should I use if I wanted it to work more > generally? I can envisage walking the string testing the > unicodedata.category of each char, but is there a regex'y way to > denote "uppercase"? Not sure what your output should look like but something like this could work: >>> import re >>> re.sub(r'([A-Z])', r' \1', 'theFirstTest theSecondTest') 'the First Test the Second Test' This can be adapted for multiline, etc, but maybe '[A-Z]' is sufficiently general. The regex module does have an understanding of unicode (but I don't, sorry); you could add (?u) make it unicode aware. For programming language identifiers I wouldn't think that unicode should be an issue. Sorry I'm no help with unicode specifics. Some useful links: http://www.python.org/doc/2.4.2/lib/module-re.html http://www.amk.ca/python/howto/regex/regex.html -- Micah Elliott From sxn02 at yahoo.com Thu Oct 27 12:57:06 2005 From: sxn02 at yahoo.com (Sori Schwimmer) Date: Thu, 27 Oct 2005 09:57:06 -0700 (PDT) Subject: help with concurrency control (threads/processes & signals) Message-ID: <20051027165706.21653.qmail@web33002.mail.mud.yahoo.com> Hi, I am working on an application which involves interprocess communication. More to the point, processes should be able to notify other processes about certain situations, so the "notifyees" would be able to act in certain ways. As processes are distributed on several machines, in different physical locations, my thinking was: a) set a message manager (MM) b) all the participants will register with MM, so MM will have their host address and their pid on host c) when someone needs to send a notification, it is sent to MM, and MM it's doing the job To start with, I created processes, psrv.py and clnt.py, and tried to sketch the above scenario. Here is the server, psrv.py: #! /usr/bin/python from socket import * from os import * from signal import * from cPickle import * #import pdb import thread #pdb.set_trace() def process(ms): global c,regtab,mssgs print 'ms[0]=',ms[0] if ms[0]=='0': regtab.append(ms[1]) mssgs.append([]) elif ms[0]=='1': for i in range(len(regtab)): mssgs[i].append(ms[1]) kill(regtab[i],SIGUSR1) elif ms[0]=='2': for i in range(len(regtab)): if regtab[i]!=ms[2]: mssgs[i].append(ms[1]) kill(regtab[i],SIGUSR1) elif ms[0]=='3': print 'executing ms[0]==3' for i in range(len(regtab)): if regtab[i]==ms[1]: c,p=s.accept() for j in mssgs[i]: c.send(dumps(j,True)) c.close() print 'connection closed' regtab=[] mssgs=[] s=socket() s.bind(('127.0.0.1',9691)) s.listen(5) while True: print 'listening ...' c,p=s.accept() while True: m=c.recv(1024) if not m: break ms=loads(m) c.close() thread.start_new_thread(process,(ms,)) # *************************************************** And here is the client side, clnt.py: #! /usr/bin/python from socket import * from os import * from signal import * from cPickle import * #import pdb #pdb.set_trace() def k3(a,b): print 'Executing k3' s=socket() s.connect(('127.0.0.1',9691)) s.send(dumps(('3',getpid()),True)) while True: print '"3" sent' m1=s.recv(1024) print m1 if not m1: break m=loads(m1) s.close() print 'connection closed in k3' print 'm is ',m signal(SIGUSR1,k3) m='' k=raw_input() while k!='4': s=socket() s.connect(('127.0.0.1',9691)) if k=='0': s.send(dumps(('0',getpid()),True)) elif k=='1': s.send(dumps(('1','For all'),True)) elif k=='2': s.send(dumps(('2','For some',getpid()),True)) elif k=='3': s.send(dumps(('3',getpid()),True)) while True: m1=s.recv(1024) if not m1: break m=loads(m1) s.close() print 'connection closed in main' print 'm is',m k=raw_input() # *************************************************** Comments: Clients register themselves with server by sending a message of type '0'. If they want to broadcast a message, clients will ask nicely the server to do it for them through a message of type '1'. The message is supposed to be kept in eachclient's "mailbox", then the server should notify each client by sending a SIGUSR1 signal, and then waiting for each clientto ask for its own copy of the notification. When a client is ready to do it, will just send a message of type '3' to the server. Messages of type '2' are just a variation of type '1' which dosen't include the sender in the list of receivers. My first version was forking a new process in the server to serve requests, but I soon realized that, as each process receives a copy of the original data, updating the "mailboxes" won't work (the "mailboxes" updated are local copies). In the threads version the "mailboxes" are shared, but so are the sockets, which will force me to add some locks and make sure that an open socket in the server will talk only with a certain client. For the moment I am toying with one server, and one client. Still, it is not working as expected. '0' goes through, so does'1', but not '3' ('3' as a result of '1', or '3' requested from keyboard). Life is a struggle. Programming in Python shouldn't be. Ergo, I'm doing something wrong. Any advice? Thanks, Sorin Environment: Gentoo Linux, Python 2.4.1 __________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com From kevin.bell at slcgov.com Thu Oct 6 16:51:45 2005 From: kevin.bell at slcgov.com (Bell, Kevin) Date: Thu, 6 Oct 2005 14:51:45 -0600 Subject: interactive window vs. script: inconsistent behavior Message-ID: <2387F0EED10A4545A840B231BBAAC722607F1B@slcimail1.slcgov.com> Oops! Sorry about that post. I'm pulling data from excel, and needed to convert the object I pulled into a string before slicing. I guess I should look (more thoroughly) before I leap. -----Original Message----- From: python-list-bounces+kevin.bell=slcgov.com at python.org [mailto:python-list-bounces+kevin.bell=slcgov.com at python.org] On Behalf Of Bell, Kevin Sent: Thursday, October 06, 2005 2:44 PM To: python-list at python.org Subject: interactive window vs. script: inconsistent behavior The following works in the interactive window of PythonWin, but fails in a script. TypeError: Objects of type 'slice' can not be converted to a COM VARIANT I just need to parse out these dates, but it's making me crazy. Shouldn't it work in both the interactive window and a script? >>> d = "5-18-05 to 5-31-05" >>> print d[0:d.find("to")-1] 5-18-05 >>> print d[d.find("to")+3:] 5-31-05 >>> Kev -- http://mail.python.org/mailman/listinfo/python-list From my_email_is_posted_on_my_website at munged.invalid Sun Oct 16 12:35:38 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sun, 16 Oct 2005 16:35:38 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <11l48meji6u4e69@corp.supernews.com> Message-ID: <8a05l117hv2p71r329kj7a1geq6vva84ak@4ax.com> On Sun, 16 Oct 2005 11:49:58 +0200, "Jeroen Wenting" wrote or quoted : >They are the ones who lowered the price of shrinkwrapped software for home >and office application from thousands or tens of thousands to hundreds of >dollars. Come now. While software generally has reduced in price, MS software has increased. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From steve at holdenweb.com Mon Oct 10 11:19:36 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 10 Oct 2005 16:19:36 +0100 Subject: Default argument to __init__ In-Reply-To: <1128955812.913224.150760@z14g2000cwz.googlegroups.com> References: <1128955812.913224.150760@z14g2000cwz.googlegroups.com> Message-ID: netvaibhav at gmail.com wrote: > Hi All: > > Here's a piece of Python code and it's output. The output that Python > shows is not as per my expectation. Hope someone can explain to me this > behaviour: > > [code] > class MyClass: > def __init__(self, myarr=[]): > self.myarr = myarr > > myobj1 = MyClass() > myobj2 = MyClass() > > myobj1.myarr += [1,2,3] > > myobj2.myarr += [4,5,6] > > print myobj1.myarr > print myobj2.myarr > [/code] > > The output is: > [1, 2, 3, 4, 5, 6] > [1, 2, 3, 4, 5, 6] > > Why do myobj1.myarr and myobj2.myarr point to the same list? The > default value to __init__ for the myarr argument is [], so I expect > that every time an object of MyClass is created, a new empty list is > created and assigned to myarr, but it seems that the same empty list > object is assigned to myarr on every invocation of MyClass.__init__ > > It this behaviour by design? If so, what is the reason, as the > behaviour I expect seems pretty logical. > The default value of the keyword argument is evaluated once, at function declaration time. The idiom usually used to avoid this gotcha is: def __init__(self, myarr=None): if myarr is None: myarr = [] This ensures each call with the default myarr gets its own list. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From tuvas21 at gmail.com Wed Oct 26 13:53:43 2005 From: tuvas21 at gmail.com (Tuvas) Date: 26 Oct 2005 10:53:43 -0700 Subject: Jpg Message-ID: <1130349223.948333.83230@g49g2000cwa.googlegroups.com> I am building a GUI interface at the moment, and would like to have support for displaying a jpg file, and a FITS file if possible. Is there any way to do this? My interface has been written in Tkinter at the moment, especially because of it's great portability, I wouldn't have to install the other interface software on every computer that I use (At the moment it is 3, and will signifigantly increase). I'd prefer to only use built-in functions, but if it can't be done, I'm willing to look for something else. Is there any way I can do this? Thanks! From steve at REMOVETHIScyber.com.au Sun Oct 9 19:20:30 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 10 Oct 2005 09:20:30 +1000 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <41hhk195gcipfarnqu85ggs606aqi89ea1@4ax.com> Message-ID: On Sun, 09 Oct 2005 20:01:28 +0000, Roedy Green wrote: > You might say what about those free 10 mb websites? That's not very > many images with today's megapixel digital cameras. My system admins have a number of names for people who try to send multi-megabyte files by email. The names start with "accursed of God" and rapidly get worse. Email is not designed to cope with such large file sizes, and if you are running virus scanners and spam filters -- and you should be -- performance rapidly goes downhill from there. > I think we computer folk owe the public We don't owe the public *anything* if they don't pay for it. We might *choose* to build it for free, but that's our choice, not a duty. [snip] > I wrote an essay years ago on how such an email system might work. Ah, I see. Another pie-in-the-sky replacement for email. Well, good luck with it. I wish you every success, but don't ask me to buy shares in your startup. -- Steven. From lycka at carmen.se Wed Oct 5 04:12:51 2005 From: lycka at carmen.se (Magnus Lycka) Date: Wed, 05 Oct 2005 10:12:51 +0200 Subject: "no variable or argument declarations are necessary." In-Reply-To: References: Message-ID: James A. Donald wrote: > What can one do to swiftly detect this type of bug? Unit tests. In my experience the edit - test cycle in Python is typically roughly as fast as the edit - compile cycle in e.g. C++, and much faster than the full edit - compile - link - test cycle in C++. You do use automated tests for your programs don't you? Otherwise I think you are sifting out gnats while you are are swallowing camels. There are also lint-like tools such as pylint and pychecker if you think static tests are useful for you. Here at Carmen, we've actually skipped the unit test step, and run functional tests at once, using the Texttest framework--and that fits well with our type of apps. See http://texttest.carmen.se/ From iainking at gmail.com Wed Oct 26 07:15:34 2005 From: iainking at gmail.com (Iain King) Date: 26 Oct 2005 04:15:34 -0700 Subject: Top-quoting defined [was: namespace dictionaries ok?] In-Reply-To: References: Message-ID: <1130325334.351987.144060@g49g2000cwa.googlegroups.com> Duncan Booth wrote: > James Stroud wrote: > > > On Tuesday 25 October 2005 00:31, Duncan Booth wrote: > >> P.S. James, *please* could you avoid top-quoting > > > > Were it not for Steve Holden's providing me with a link off the list, > > I would have never known to what it is you are referring. I have read > > some relevant literature to find that this is more widely known as > > "top-posting". I'll go with majority rules here, but I would like to > > say that my lack of "netiquette" in this matter comes from > > practicality and not malice. > > No, I didn't think it was malice which is why I just added what I > considered to be a polite request at the end of my message. I assumed that > most people either knew the phrase or could find out in a few seconds using > Google so there wasn't much point in rehashing the arguments. Probably I > should have equally lambasted Ron for the heinous crime of bottom-quoting. > > In general, there are three ways to quote a message: top-quoting, which > forces people to read the message out of order; bottom-quoting which is > nearly as bad because it hides the new comments; and proper quoting in > context where you trim the message and put specific points under brief bits > of context. > Just to continue this off-topic argument :) - I've never heard the terms top-quoting, bottom-quoting. I've heard top-posting and bottom-posting before (lots). But regardless of however many people use top-quoting and bottom-quoting, surely you're using them the wrong way around? If I top-post, then that means that the quote is at the bottom, no? To quote someone's sig block: "To top-post is human, to bottom-post and snip is sublime." Iain From theller at python.net Fri Oct 14 14:56:14 2005 From: theller at python.net (Thomas Heller) Date: Fri, 14 Oct 2005 20:56:14 +0200 Subject: Moving to Win XP as a Python developer References: <434fdd3b$1@nntp0.pdx.net> Message-ID: Scott David Daniels writes: > Christian Stapfer wrote: >> "John J. Lee" wrote in message >> news:mailman.2039.1129247775.509.python-list at python.org... >> >>>cmd.exe can be made bearable.... >>> >>>0. Make a shortcut to cmd.exe, stick it somewhere get-at-able, >>> eg. quick launch toolbar > I put it on my desktop. Once having made it, fiddle with > "Start in" to be your favorite python code directory (that is > why I usually have several), and append a space and /D /X /F:ON > to the "Target" line. I have an elisp function bound to a key in XEmacs that starts cmd in the directory where the current buffer is. IMO this is very convenient. To access explorer from that command prompt (in the rare cases that I need it) I use 'start .'. Thomas From apardon at forel.vub.ac.be Wed Oct 12 09:14:35 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 12 Oct 2005 13:14:35 GMT Subject: C Wrapper Function, crashing Python? References: <1129122046.417746.100120@g47g2000cwa.googlegroups.com> Message-ID: Op 2005-10-12, Java and Swing schreef : > static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { > // this will store the result in a Python object > PyObject *finalResult; > > // get arguments from Python > char *result = 0; > char *in= 0; > char *aString = 0; > char *bString = 0; > MY_NUM *a; > MY_NUM *b; > int ok = PyArg_ParseTuple(args, "sss", &in, &aString, &bString); > if (!ok) return 0; > > // do work to get a and b > // count - returns an int; GetVal - returns a char * > a = GetVal(aString, count(aString, ",")); > b = GetVal(bString, count(bString, ",")); > > // make function call, which returns a char * > result = doStuff(in, a, b); > > // save result in Python string > finalResult = PyString_FromString(result); > > // free memory > PyMem_Free(result); > PyMem_Free(a); > PyMem_Free(b); > > // return the result as a Python string > return finalResult; > } > > ...from python I can call this function 4 times...works fine. WHen I > call it for the fifth time python.exe crashes. im thinking some memory > problem in the wrapper function perhaps...but I am not sure. The > actually C function, doStuff can be called 5, 6,7...N times without a > problem > so i know its gotta be my wrapper. > > Any ideas? Thanks! Well assuming your doStuff is a C function that knows nothing of python. it might be the PyMem_Free(result). http://docs.python.org/api/memoryInterface.html says the following: void PyMem_Free(void *p) Frees the memory block pointed to by p, which must have been returned by a previous call to PyMem_Malloc() or PyMem_Realloc(). Otherwise, or if PyMem_Free(p) has been called before, undefined behavior occurs. If p is NULL, no operation is performed. But your result wasn't allocated by a PyMem_Malloc, it was returned to you by a C function. -- Antoon Pardon From http Thu Oct 13 19:30:17 2005 From: http (Paul Rubin) Date: 13 Oct 2005 16:30:17 -0700 Subject: 1-liner to iterate over infinite sequence of integers? References: Message-ID: <7xmzld571y.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Others have given answers involving xrange() and itertools.count(), but I > thought I'd just mention that in my opinion, what you have written is > pretty elegant and concise and best of all, doesn't have the same problems > xrange() and itertools.count() have when then hit maxint. Not everything > needs to be a one-liner or a mysterious blackbox. When you say "problems" with xrange or itertools.count hitting maxint, the correct word is "bugs". The right thing to do with library bugs is fix them, not clutter up your application code to circumvent them. xrange, at least, raises an error if you give it too large an argument, but what itertools.count does is just plain dangerous. I just opened SF bug 1326277 about itertools.count. From borell at nytimes.com Fri Oct 14 14:51:01 2005 From: borell at nytimes.com (Frank Borell) Date: 14 Oct 2005 11:51:01 -0700 Subject: win32api.FindFiles Win2003, problem with Short Name In-Reply-To: References: <1129245942.185252.171220@o13g2000cwo.googlegroups.com> Message-ID: <1129315861.886705.116980@g44g2000cwa.googlegroups.com> Neil, On all three types of PC/Servers they are set to 0. For now I'll have to process this script on non 2003 servers?!? Thanks, Frank From nun at example.com Fri Oct 21 17:56:33 2005 From: nun at example.com (Mitja Trampus) Date: Fri, 21 Oct 2005 23:56:33 +0200 Subject: Python cgi In-Reply-To: <1129930246.435616.291660@g44g2000cwa.googlegroups.com> References: <1129930246.435616.291660@g44g2000cwa.googlegroups.com> Message-ID: jbrewer wrote: > I'm currently writing my first CGI script (in Python), and I keep > getting an error I don't know how to address. I'm not sure if this is > a Python or Apache error, but I suspect it's an Apache config thing. I suspect it's neither :) Make sure your HTML form looks like
    From case.nelson at gmail.com Fri Oct 14 17:08:59 2005 From: case.nelson at gmail.com (snoe) Date: 14 Oct 2005 14:08:59 -0700 Subject: Function to execute only once In-Reply-To: <1129322058.901077.90680@o13g2000cwo.googlegroups.com> References: <1129317118.937439.159550@g43g2000cwa.googlegroups.com> <1129322058.901077.90680@o13g2000cwo.googlegroups.com> Message-ID: <1129324139.891942.3710@g47g2000cwa.googlegroups.com> The problem seemed to be because I was rebinding result inside executor. Can someone explain why it works below but not in the first one? Also why is it if I set tmp as a global and don't pass it as a paremeter to the various functions as per the OP that I get an "UnboundLocalError: local variable 'tmp' referenced before assignment"? def execute_once(fn): print "in execute_once" result = {} def executor(*args, **kwargs): if fn not in result: result[fn] = fn(*args, **kwargs) return result[fn] return executor @execute_once def execute(tmp): print "in execute" tmp = tmp+1 return tmp def func1(tmp): return execute(tmp) def func2(tmp): return execute(tmp) tmp = 0 print 'init tmp:', tmp tmp = func1(tmp) print 'ran func1 tmp:', tmp tmp = func2(tmp) print 'ran func2 tmp:', tmp tmp = func1(tmp) print 'ran func1 tmp:', tmp OUTPUT: in execute_once init tmp: 0 in execute ran func1 tmp: 1 ran func2 tmp: 1 ran func1 tmp: 1 From my_email_is_posted_on_my_website at munged.invalid Fri Oct 21 21:07:29 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sat, 22 Oct 2005 01:07:29 GMT Subject: Microsoft Hatred FAQ References: <35jbl1dprs4v1o87i0tapc2husjqiqm6fi@4ax.com> <4355ea72$1_3@news.melbourne.pipenetworks.com> Message-ID: On Thu, 20 Oct 2005 22:07:51 GMT, "Mike Schilling" wrote or quoted : >his status >as employee gives him no additional rights or responsibilities in this >respect. It may not be so in law, but I think most moral codes put more onus on the employee than the average citizen. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From no.mail.here.at.here at gmail.com Fri Oct 7 12:06:47 2005 From: no.mail.here.at.here at gmail.com (mike) Date: 7 Oct 2005 09:06:47 -0700 Subject: os.access with wildcards In-Reply-To: References: <1128665933.923295.95580@f14g2000cwb.googlegroups.com> <1128698336.836590.96080@g44g2000cwa.googlegroups.com> Message-ID: <1128701207.675536.126370@z14g2000cwz.googlegroups.com> dude, you are the sap that wrote "it's not clear". get a life. From fredrik at pythonware.com Fri Oct 14 12:20:10 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 14 Oct 2005 18:20:10 +0200 Subject: getting the path in a cgi script References: <0001HW.BF759D88004280C3F0284550@news.individual.de> Message-ID: Kalle Anke wrote: > I know I've done this once before ... I think ... but now I can't figure out > how to do it > > I've set my web server to use an alias similar to this > > ScriptAlias /xx/ "/Library/WebServer/CGI-Executables/xxx.cgi/" > > which makes it possible for me to write > > http://127.0.0.1/xx/some/kind/of/path > > my problem is that I don't know how to get the 'some/kind/of/path' part of > the URL in my script. > > I know that I can do like this in perl > > $documentRoot.path_info(); > > but how do I do it in python? import os path_info = os.environ.get("PATH_INFO") From russandheather at gmail.com Wed Oct 12 14:33:25 2005 From: russandheather at gmail.com (Russell Warren) Date: 12 Oct 2005 11:33:25 -0700 Subject: Threads and socket.setdefaulttimeout References: <1128030031.130958.185620@z14g2000cwz.googlegroups.com> Message-ID: <1129142005.610543.212180@o13g2000cwo.googlegroups.com> It appears that the timeout setting is contained within a process (thanks for the confirmation), but I've realized that the function doesn't play friendly with threads. If I have multiple threads using sockets and one (or more) is using timeouts, one thread affects the other and you get unpredictable behavior sometimes. I included a short script at the end of this that demonstrates the threading problem. I'm trying to get around this by forcing all locations that want to set a timeout to use a 'safe' call immediately prior to socket creation that locks out setting the timeout again until the lock is released. Something like this: try: SafeSetSocketTimeout(Timeout_s) #lock currently acquired to prevent other threads sneaking in here CreateSocket() finally: ReleaseSocketTimeoutSettingLock() UseSocket() However - this is getting increasingly painful because I don't have easy access to all of the socket creations where I'd like to do this. The biggest pain right now is that I'm using xmlrpclib which has some seriously/frustratingly heavy use of __ prefixes that makes getting inside to do this at socket creation near impossible (at least I think so). Right now the best I can do is surround the xmlrpclib calls with this (effectively putting the lock release after the UseSocket), but then other threads get hung up for the duration of the call or timeout, rather than just the simple socket creation. It would be nice if the timeout were implemented as an argument in the socket constructor rather than having this global method. Is there a reason for this? I tried sifting through the cvs source and got lost - couldn't even find the call definition for socket(family, type, proto) and gave up... Does anybody have any idea of another way to do what I need (indpendent socket timeouts per thread), or have suggestions on how to break into xmlrpclib (actually down into httplib) to do the methdo I was trying? Related question: Is there some global way that I'm unaware of to make it so that some few lines of code are atomic/uninterruptable and no other thread can sneak in between? All suggestions appreciated! Hopefully I'm just missing something obvious. Russ #--- This script confirms that settimeout's affect is across threads import threading, xmlrpclib, socket def st(): socket.setdefaulttimeout(0.1) try: proxy = xmlrpclib.ServerProxy("http://localhost:10000") print proxy.NonExistentCallThatShouldTimeout() except Exception, E: print "Exception caught: %s" % (E,) cbThread = threading.Thread(target = st) cbThread.start() try: print proxy.NonExistentCallThatShouldTimeout() except Exception, E: print "Exception caught: %s" % (E,) #Output is: #Exception caught: (10061, 'Connection refused') #Exception caught: timed out From eternalsquire at comcast.net Mon Oct 17 02:40:49 2005 From: eternalsquire at comcast.net (The Eternal Squire) Date: 16 Oct 2005 23:40:49 -0700 Subject: can a cut-down Python still be Python? Message-ID: <1129531249.605353.204280@f14g2000cwb.googlegroups.com> All, Regardless of the technical difficulties involved (and I know they are legion), I am considering developing a very limited subset of Python fit to run on embedded systems using 80188 or 68332 microchips. My main question regarding this is: even if I am successful, would the results be rejected out of hand by y'all as not meeting the Zen of Python? Please advise, The Eternal Squire From daniel at bowettsolutions.com Sat Oct 29 14:48:02 2005 From: daniel at bowettsolutions.com (Daniel Bowett) Date: Sat, 29 Oct 2005 19:48:02 +0100 Subject: extracting numbers from a file, excluding fixed words In-Reply-To: <1130608130.154921.47840@g49g2000cwa.googlegroups.com> References: <1130608130.154921.47840@g49g2000cwa.googlegroups.com> Message-ID: dawenliu wrote: > Hi, I have a file with this content: > xxxxxxx xxxxxxxxxx xxxxx xxxxxxx > 1 > 0 > 0 > 0 > 1 > 1 > 0 > (many more 1's and 0's to follow) > yyyyy yyyyyy yyy yyyyyy yyyyy yyy > > The x's and y's are FIXED and known words which I will ignore, such as > "This is the start of the file" and "This is the end of the file". The > digits 1 and 0 have UNKNOWN length. I want to extract the digits and > store them in a file. Any suggestions will be appreciated. > Open the file and read each line 1 at a time. If the line doesn't equal x or y then add the line to a list f = open("file.txt") numbers = [] for eachline in f.xreadlines(): if (eachline <> x) or (eachline <> y): numbers.append(eachline) From free.condiments at gmail.com Mon Oct 10 19:04:15 2005 From: free.condiments at gmail.com (Sam Pointon) Date: 10 Oct 2005 16:04:15 -0700 Subject: Works only in interactive mode In-Reply-To: <1128978917.143125.68230@g43g2000cwa.googlegroups.com> References: <1128978917.143125.68230@g43g2000cwa.googlegroups.com> Message-ID: <1128985455.433816.8710@g43g2000cwa.googlegroups.com> That looks like a different module named pcop getting in the way. If there's another pcop.py in the directory where you're running it as a script, then that gets priority and you'll end up with an error like the one you got. However, if you run it interactively, then that directory is not checked, or is (normally) checked lower-down than, say, Python's standard library. Try checking if help(pcop) and dir(pcop) are what you expect in the script, and looking at where sys.path is looking for scripts. From joe at invalid.address Tue Oct 18 13:34:18 2005 From: joe at invalid.address (joe at invalid.address) Date: 18 Oct 2005 12:34:18 -0500 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <11l48meji6u4e69@corp.supernews.com> <2X95f.14513$vV4.3483@fe08.lga> Message-ID: "John W. Kennedy" writes: > Michael Heiming wrote: > > Let's not forget about the Internet, they invented together with > > Al Gore and of course the wheel! > > No fair picking on Al Gore. All he ever claimed was that he was the > Congressional point man for the "Information Superhighway", which he > was. Well, what he said was "During my service in the United States Congress, I took the initiative in creating the Internet." What you say he did is what he actually did, but what he said gives a different impression. I don't think he's careless or stupid, so I think he said that in order to create the impression in the minds of the people listening to the interview that he's responsible for the internet. That's just what politicians do, regardless of party affiliation. joe -- Gort, klatu barada nikto From bokr at oz.net Mon Oct 31 14:59:34 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 31 Oct 2005 19:59:34 GMT Subject: frozenset/subclassing/keyword args References: Message-ID: <43667401.1468809015@news.oz.net> On Mon, 31 Oct 2005 19:31:33 GMT, "Mark E. Fenner" wrote: >Hello all, > >I was migrating some code from sets.ImmutableSet to frozenset and noticed >the following: > >******code******** >#!/usr/bin/env python > >from sets import ImmutableSet > > >class MSet1(ImmutableSet): > def __init__(self, iterArg, myName="foo"): > ImmutableSet.__init__(self, iterArg) > self.name = myName > > >class MSet2(frozenset): > def __init__(self, iterArg, myName="foo"): > frozenset.__init__(self, iterArg) > self.name = myName > > >m1 = MSet1([1,2,3], myName = "donkey") >print m1 >print m1.name > >m2 = MSet2([1,2,3], myName = "kong") >print m2 >print m2.name >*********end code********** > >*********run********** >MSet1([1, 2, 3]) >donkey >Traceback (most recent call last): > File "./setTest.py", line 22, in ? > m2 = MSet2([1,2,3], myName = "kong") >TypeError: frozenset() does not take keyword arguments >*********end run******** > >I'm missing something and couldn't find it in the docs. Without researching it, I would guess that you have to override __new__ so as not to pass through the myName arg to the otherwise inherited and called-with-all-arguments __new__ of the base class. You could take care of the myName arg in the __new__ method too (by temporarily binding the instance returned by frozenset.__new__ and assigning the name attribute before returning the instance), or you can define __init__ to do that part. See many various posted examples of subclassing immutable types. Regards, Bengt Richter From rvtol+news at isolution.nl Mon Oct 17 07:50:47 2005 From: rvtol+news at isolution.nl (Dr.Ruud) Date: Mon, 17 Oct 2005 13:50:47 +0200 Subject: Perl-Python-a-Day: split a file full path References: <1129514458.420045.75670@g44g2000cwa.googlegroups.com> Message-ID: Xah Lee: > In Perl, spliting a full path into parts is done like this: And then follows Perl-code that only works with an optional .html "extension", which is similar to the code in the File::Basename description. http://www.perl.com/doc/manual/html/lib/File/Basename.html It is best practice to derive and store the normalized (or absolute) path, because relative paths can get loose so will get loose. Consider this: $myPath = './example/basename.ext'; and this: $myPath = './example/filename.1.23.45-beta'; and this: $myPath = 'x:.\example\basename.ext'; (some platforms have a wd per device) -- Affijn, Ruud "Gewoon is een tijger." From sybrenUSE at YOURthirdtower.com.imagination Wed Oct 26 06:26:12 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Wed, 26 Oct 2005 12:26:12 +0200 Subject: assignment to reference References: Message-ID: Loris Caren enlightened us with: > If > > a = 'apple' > b = 'banana' > c = 'cabbage' > > How can I get something like:- > > for i in 'abc': > r = eval(i) > if r == 'cabbage': r = 'coconut' > > actually change the object referenced by r rather > than creating a new object temporarily referenced by it? Use: x = { 'a': 'apple', 'b': 'banana', 'c': 'cabbage' } for key, value in x.iteritems(): if value == 'cabbage': x[key] = 'coconut' NOTE: I haven't tested this code > I've tried playing with eval and exec without the desired effect. If you notice yourself using such functions, it's ususally a lot better to simply stash your data in a dictionary, and use that instead. 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 hancock at anansispaceworks.com Fri Oct 7 03:40:56 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Fri, 7 Oct 2005 02:40:56 -0500 Subject: non descriptive error In-Reply-To: <4346002C.3080504@open-networks.net> References: <4346002C.3080504@open-networks.net> Message-ID: <200510070240.56350.hancock@anansispaceworks.com> On Thursday 06 October 2005 11:57 pm, Timothy Smith wrote: > i try to run my app and i get this > > %python DutyShift.py > error > > thats it. thats the error. mya pp was previously working, and i did make > some fairly large changes to it, but i'd expect a more descriptive > message then just "error". anyidea where i need to start looking? By looking at the source code for DutyShift.py? -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From my_email_is_posted_on_my_website at munged.invalid Tue Oct 18 22:55:23 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 19 Oct 2005 02:55:23 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <11l48meji6u4e69@corp.supernews.com> <2X95f.14513$vV4.3483@fe08.lga> Message-ID: <28dbl1p8iq581iklr87d0ugre9q3lgitvl@4ax.com> On 18 Oct 2005 12:34:18 -0500, joe at invalid.address wrote or quoted : > > "During my service in the United States Congress, I took the > initiative in creating the Internet." He did just that. Think about it. Without Gore, the Internet would never have been delayed perhaps indefinitely. Without any of he technical people, someone else would have done the same work. Even the guys who did the low level protocols credit Gore. Your forget how much abuse folk like you heaped on Gore when he was pushing the "information super highway" as it was known back then. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From aleaxit at yahoo.com Sun Oct 30 10:35:12 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 30 Oct 2005 08:35:12 -0700 Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <87ek65kbw5.fsf@lucien.dreaming> <1h57cu1.1jywbjibu87obN%aleaxit@yahoo.com> Message-ID: <1h58jkz.1byi9q5qwo1owN%aleaxit@yahoo.com> Steven D'Aprano wrote: ... > > Don't ever catch and ``handle'' exceptions in such ways. In particular, > > each time you're thinking of writing a bare 'except:' clause, think > > again, and you'll most likely find a much better approach. > > What would you -- or anyone else -- recommend as a better approach? That depends on your application, and what you're trying to accomplish at this point. > Is there a canonical list somewhere that states every possible exception > from a file open or close? No. But if you get a totally unexpected exception, something that shows the world has gone crazy and most likely any further action you perform would run the risk of damaging the user's persistent data since the macchine appears to be careening wildly out of control... WHY would you want to perform any further action? Crashing and burning (ideally leaving as detailed a core-dump as feasible for later post-mortem) appears to be preferable. (Detailed information for post-mortem purposes is best dumped in a sys.excepthook handler, since wild unexpected exceptions may occur anywhere and it's impractical to pepper your application code with bare except clauses for such purposes). Obviously, if your program is so life-crucial that it cannot be missing for a long period of time, you will have separately set up a "hot spare" system, ready to take over at the behest of a separate monitor program as soon as your program develops problems of such magnitude (a "heartbeat" system helps with monitoring). You do need redundant hardware for that, since the root cause of unexpected problems may well be in a hardware fault -- the disk has crashed, a memory chip just melted, the CPU's on strike, locusts...! Not stuff any program can do much about in the short term, except by switching to a different machine. Alex From my_email_is_posted_on_my_website at munged.invalid Wed Oct 19 06:08:43 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Wed, 19 Oct 2005 10:08:43 GMT Subject: Microsoft Hatred FAQ References: <867jcbzdw9.fsf@bhuda.mired.org> <4vcbl1dkek9kr86embmgrj70vk945t99ho@4ax.com> <35jbl1dprs4v1o87i0tapc2husjqiqm6fi@4ax.com> <4355ea72$1_3@news.melbourne.pipenetworks.com> Message-ID: On Wed, 19 Oct 2005 01:54:14 -0700, "David Schwartz" wrote or quoted : > They have obligations to their clients because (and only because) >failure to provide the services they contract to provide will result in >lawsuits and harm to the shareholders. All other obligations come from the >harm these failures will do to the shareholders. That's the view of Republican, but it is not the only view. Some might say the law trumps that. It does not matter if breaking the law would be more profitable, you still don't do it. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From fredrik at pythonware.com Sun Oct 23 14:41:14 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 23 Oct 2005 20:41:14 +0200 Subject: Localized strftime() References: Message-ID: Sebastjan Trepca wrote: > I'm trying to get a localized date format from strftime() but it seems > that is doesn't have any parameters for that or any information about > this issue in Python docs. > > For example I want to turn this: > 19 Oct, 2005 > to this(slovene language): > 19 Okt, 2005 you must call locale.setlocale first, to switch from the default C locale to a locale of your choice. http://docs.python.org/lib/module-locale.html >>> import time >>> print time.strftime("%a, %d %b %Y %H:%M:%S") Sun, 23 Oct 2005 20:38:56 >>> import locale >>> locale.setlocale(locale.LC_TIME, "sv_SE") # swedish 'sv_SE' >>> print time.strftime("%a, %d %b %Y %H:%M:%S") s?n, 23 okt 2005 20:39:15 >>> locale.setlocale(locale.LC_TIME, "sl_SI") 'sl_SI' >>> print time.strftime("%a, %d %b %Y %H:%M:%S") ned, 23 okt 2005 20:39:32 From grante at visi.com Thu Oct 20 13:43:02 2005 From: grante at visi.com (Grant Edwards) Date: Thu, 20 Oct 2005 17:43:02 -0000 Subject: need some advice on x y plot References: <1129823043.104864.73750@f14g2000cwb.googlegroups.com> <11lfgebn85liq1b@corp.supernews.com> <1129825379.218308.242010@g47g2000cwa.googlegroups.com> Message-ID: <11lflp6e7godi29@corp.supernews.com> On 2005-10-20, nephish at xit.net wrote: > i have tried to use unix timestamps, That has always worked for me. What happened? > and i have also tried with DateTime objects Never tried that. > do i need to use a scale that isn't linear (default in most) ? No. > how do i putt this off ? Huh? Gnuplot by default does exactly what you seem to want if you just pass it x,y values. -- Grant Edwards grante Yow! I always liked FLAG at DAY!! visi.com From onurb at xiludom.gro Tue Oct 25 04:26:10 2005 From: onurb at xiludom.gro (bruno modulix) Date: Tue, 25 Oct 2005 10:26:10 +0200 Subject: [OT] Python vs Ruby In-Reply-To: <435cbbd6$1@nntp0.pdx.net> References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> <4358d9f6$0$19694$626a14ce@news.free.fr> <43593468$1@nntp0.pdx.net> <435c9906$0$14034$636a15ce@news.free.fr> <435cbbd6$1@nntp0.pdx.net> Message-ID: <435dec24$0$652$626a14ce@news.free.fr> Scott David Daniels wrote: > bruno modulix wrote: > >> Scott David Daniels wrote: >> >>> bruno modulix wrote: >>> >>>> ... Another language that failed to make it to the mainstream but is >>>> worth giving a try is Smalltalk - the father of OOPLs (Simula being the >>>> GrandFather). >>> >>> I would say Simula is the forefather of modern OOPLs, and Smalltalk is >>> the toofather. >> >> Err... I'm afraid I don't understand this last word (and google have not >> been of much help here) > > > Sorry, I was being too cute by half. tss... > If Simula is the fore father > (4 away) then Smalltalk is half as far (2) away. Hence the "toofather." > "Toofather" by analogy with the homophones "fore" and "four" we use the > homophones "two" and "too". My my my... -- bruno desthuilliers ruby -e "print 'onurb at xiludom.gro'.split('@').collect{|p| p.split('.').collect{|w| w.reverse}.join('.')}.join('@')" From simon.brunning at gmail.com Wed Oct 12 12:45:39 2005 From: simon.brunning at gmail.com (Simon Brunning) Date: Wed, 12 Oct 2005 17:45:39 +0100 Subject: slots? SLOTS? In-Reply-To: <3r4s3cFhndjpU1@individual.net> References: <3r4s3cFhndjpU1@individual.net> Message-ID: <8c7f10c60510120945q6affa930u@mail.gmail.com> On 12/10/05, tin gherdanarra wrote: > what is a "slot" in python? -- Cheers, Simon B, simon at brunningonline.net, http://www.brunningonline.net/simon/blog/ From donn at u.washington.edu Mon Oct 17 12:51:40 2005 From: donn at u.washington.edu (Donn Cave) Date: Mon, 17 Oct 2005 09:51:40 -0700 Subject: tuple versus list References: <1129460775.484350.209520@g44g2000cwa.googlegroups.com> <1129475300.537237.131090@f14g2000cwb.googlegroups.com> Message-ID: In article , Bryan wrote: > bonono at gmail.com wrote: > > In this particular case, it seems that (width,height) looks nicer. But > > I think otherwise, list constuct is easier to read, even though it is > > supposed to be slower. > > > > With list you can : > > [a] + [ x for x in something ] > > > > With tuple it looks like this : > > (a,) + tuple(x for x in something) > > > > I think the list looks cleaner. And since you cannot concat tuple with > > list, I think unless it looks obvious and natural(as in your case), use > > list. > > > > > i always use the structure analogy. if you view (width, height) as a > structure, > use a tuple. if you view it a sequence, use a list. in this example, i view > it > as a stucture, so i would use (width, height) as a tuple. Right, but there's an unfortunate ambiguity in the term "sequence", since in Python it is defined to include tuple. I gather you meant more in the abstract sense of a data collection whose interesting properties are of a sequential nature, as opposed to the way we are typically more interested in positional access to a tuple. Maybe a more computer literate reader will have a better word for this, that doesn't collide with Python terminology. My semi-formal operational definition is "a is similar to a[x:y], where x is not 0 or y is not -1, and `similar' means `could be a legal value in the same context.'" Donn Cave, donn at u.washington.edu From http Thu Oct 27 04:17:40 2005 From: http (Paul Rubin) Date: 27 Oct 2005 01:17:40 -0700 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <3s6l8mFmj3fjU1@individual.net> <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> <7xwtjz3jc9.fsf@ruckus.brouhaha.com> <7xwtjzcyxo.fsf@ruckus.brouhaha.com> Message-ID: <7xbr1b74rf.fsf@ruckus.brouhaha.com> "David Schwartz" writes: > But there is no law against that type of conduct, *unless* you are a > monopolist. So your conclusion hinges on the determination that Microsoft > had a monopoly, and that hinges on the definition of the "market". That's a > different can of worms for a different part of this thread. The trial court determined and two different appeals courts upheld that MS had an illegal monopoly. I think they have more experience and knowledge of these things than you do. MS's illegal monopoly is an established legal fact regardless of your irrelevant opinion. From davids at webmaster.com Thu Oct 27 08:50:12 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 05:50:12 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <66u633-etj.ln1@news.it.uc3m.es> Message-ID: Peter T. Breuer wrote: > That's UP TO THE FRIGGING STORE (in contrast to the MS situation). No, it's not up to the store. In all the cases I mentioned, it's the manufacturer of the product that imposes the restrictions and the manufacturer of the product is not the store owner. >> I don't know why you think >> that's an attempt to subvert market economics, > Because "it is". Then every franchise on the planet and every company that sells wholesale only to "authorized resellers" and has non-compete in their authorization terms, is subverting the market. >> it's actually just a normal >> part of the way the market works. > > No it isn't. Yes, it is. > I think I'll just plonk you. Absurd and outlandish statements like > that put you beyond the pale. The law has spoken on the matter - the > courts have judged, and "that is illegal" and "that is a monopoly" > and "that is an illegal trade practice" are its judgments. I defy you to find any court that has ruled this practice illegal for a company that does not have a monopoly. Because if they did, I'm going after Doctor's Associates and Kenmore. What do you have to agree to in order to get OSX wholesale for resale? What about Solaris? DS From mwm at mired.org Sat Oct 29 01:33:37 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 29 Oct 2005 01:33:37 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <66u633-etj.ln1@news.it.uc3m.es> <7xbr1aewtq.fsf@ruckus.brouhaha.com> <86acgulv5z.fsf@localhost.localdomain> <7xvezi8ypy.fsf@ruckus.brouhaha.com> <86y84ehd3j.fsf@bhuda.mired.org> <86hdb2h750.fsf@bhuda.mired.org> <86zmoufiww.fsf@bhuda.mired.org> <86oe59e57v.fsf@bhuda.mired.org> Message-ID: <868xwcevke.fsf@bhuda.mired.org> "David Schwartz" writes: > "Mike Meyer" wrote in message > news:86oe59e57v.fsf at bhuda.mired.org... >> "David Schwartz" writes: >>> "Mike Meyer" wrote in message >>> news:86zmoufiww.fsf at bhuda.mired.org... >> Maybe true, maybe not - but it doesn't matter. The point is that you >> respond to *every* comparison of MS with other criminals as a >> comparison to "criminals with guns", and then refuse to discuss the >> issue, with utter disregard as to what the other person said. That you >> might be right in one case is irrelevant - we're talking about a >> pattern of behavior. > That is not true. I make a serious distinction between crimes that > involve the use of force and crimes that don't. Microsoft was convicted of > crimes that do *not* involve use of force. I am trying very hard to make > sure that distinction is preserved. Except you treat *every* mention of any crime other than abuse of monopoly power as a crime that involves the use of force - whether it does or not. In the example I quoted, you did it with "theft" - without reference to how the theft happened. There are lots of forms of theft that don't involve use of force - abuse of monopoly power is one of them, but so is embezzlement. Yet you accused me of equating arguments with guns. >> I'm still waiting for you to come up with an explanation for the >> pattern of your behavior other than that you're taking orders from >> MS. But I expect yout to deny that it exists. > The pattern of my behavior is that it is vital to me to preserve the > distinction between force and non-force. If it that vital, then you need to make the distinction yourself, and quit treating *any* crime not committed by MS as if it involved the use of force. > Guns and arguments represent two > fundamentally different categories of human behavior. And I reject the moral > claim that it is okay to respond to arguments with guns. Oh, we know you reject it. You never miss an opportunity to say so - even if it's not at all relevant. As predicted, you denied the truth of what I said, then provided an excuse for a behavior that you don't follow. So we're still waiting for an explanation for your actual behavior other than your being a shill for MS. > Microsoft's behavior consisted of arguments, that is, did not > involve force, the threat of force, fraud, or the threat of > fraud. This is perhaps the most vital distinction that there is. Wrong. Either your definition of force is to narrow, or you're wrong that it's the distinction is even vaguely vital. If I convince everyone who might make food available to you not to do so - for example, by paying them more than their interaction with you is worth to them, I can starve you to death. I'd say I've used force against you - an economic force. This is the kind of force that MS wields illegally. I'm willing to admit this isn't a usual definition of force, and won't argue if you want to say that it isn't force. But in that case, the fact that I didn't use "force" against you is irrelevant to you - you're just as dead. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From riplin at Azonic.co.nz Sun Oct 16 15:30:06 2005 From: riplin at Azonic.co.nz (riplin at Azonic.co.nz) Date: 16 Oct 2005 12:30:06 -0700 Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: <1129491006.021102.43920@g14g2000cwa.googlegroups.com> John Bokma wrote: > No: the historical fact is that MS whiped Netscape of the planet. By giving IE away for free, by ripping off spyglass, by _paying_ OEMs to not include Netscape. By bundling IE. By abusing standards. By contracting with sites to include non-standard IE features to deliberately break NS. If an OEM was shipping Netscape on machines MS paid them $5 a copy not to. > That > you come up with "They were afraid that everybody would be running NS > Office online using Netscape" is just a guess. No. Netscape had announced that they were working on building network applications that just required a browser. XUL is the latest version of this. > MS just seems to ignore a certain development for some time, then state > it's not significant, and next they are an important player. This is not > limited to "MS missed the Internet, almost...". They don't miss > anything, they just don't jump on every hype. No. You are wrong again. In edition 1 of "The Way Ahead" there was _no_ mention of the Internet. MS did not notice it, and when they did they attempted to replace it with MSN which did not link to the internet initially. MSN was free with Win95, but most users ignored it and downloaded Netscape. > and next they are an important player Once they notice that there is a revenue stream then they will buy in a product, rebrand it MS and claim it is the best, and use their monopoly leverage to drive the other players out of business so that they can have all the revenue. The only reason that Linux/OpenOffice/GIMP/Apachee/MySQL/.. have survived this process is that MS haven't worked out how to kill them off. Natural selection at work. If MS kills off everything that it can then what is left is what it can't. From dimitri.pater at gmail.com Thu Oct 20 18:50:53 2005 From: dimitri.pater at gmail.com (dimitri pater) Date: Fri, 21 Oct 2005 00:50:53 +0200 Subject: Fund raising for SPE (Python IDE) on Mac Os X is great success!! In-Reply-To: <1129837084.074460.51840@f14g2000cwb.googlegroups.com> References: <1129837084.074460.51840@f14g2000cwb.googlegroups.com> Message-ID: Dear Stani, It is good to hear that the donation was a success. And you deserve it, your contribution to the Python community is an example fot others and I am convinced that every donation, be it large or small, is well spent! A lot of us use SPE, don't we? greetz, Dimitri On 20 Oct 2005 12:38:04 -0700, SPE - Stani's Python Editor < spe.stani.be at gmail.com> wrote: > > Hi, > > I'd like to thank everyone who contributed, especially Richard Brown > from Dartware and Rick Thomas. I'm highly impressed that the smallest > user base of SPE collected the largest donation ever to SPE. Now it's > my turn to impress the SPE Mac users. > > As such the light is green for SPE on the Mac. First I will buy a Mac > and get used to it. Then I will optimize SPE for the Mac and try to > release simultaneously. Be patient as this will take some time. The > next releases (0.7) will be based on work I did before. But from 0.8 > releases SPE will also be tested & developed on Mac. > > Please subscribe to the mailing list as a developer, user and/or mac > user. Of course donations are still welcome. > > Stani > > http://pythonide.stani.be > http://pythonide.stani.be/manual/html/manual.html > > -- > http://mail.python.org/mailman/listinfo/python-list > -- "Some scientists claim that hydrogen, because it is so plentiful, is the basic building block of the universe. I dispute that. I say there is more stupidity than hydrogen, and that is the basic building block of the universe." -Frank Zappa ----- Please visit dimitri's website: www.serpia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From tuvas21 at gmail.com Tue Oct 18 00:20:15 2005 From: tuvas21 at gmail.com (Tuvas) Date: 17 Oct 2005 21:20:15 -0700 Subject: Mutual module imports In-Reply-To: <*firstname*nlsnews-B5E898.23113017102005@news.verizon.net> References: <*firstname*nlsnews-B5E898.23113017102005@news.verizon.net> Message-ID: <1129609215.608627.131910@g49g2000cwa.googlegroups.com> The trick is via something called Extending. Pyrex just makes extending a bit easier, but, depending on the complexity of the function, it might be easier just to extend it yourself. Basically you make a function that translates python into C. There are some instructions on the Python website, http://www.python.org . Look around, and you'll find lots of cool stuff on it. From roy at panix.com Fri Oct 7 06:01:00 2005 From: roy at panix.com (Roy Smith) Date: Fri, 07 Oct 2005 06:01:00 -0400 Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <3qi8erFf252rU1@uni-berlin.de> <3qkdbrFfgga9U1@uni-berlin.de> <3qkn7qFffkl6U1@uni-berlin.de> <3qkr1hFfgj5uU1@uni-berlin.de> <7xr7ax690j.fsf@ruckus.brouhaha.com> <1128676408.129888.297840@g14g2000cwa.googlegroups.com> Message-ID: "Ben Sizer" wrote: > It's started to get very misleading - Python gives you plenty of > type-checking, as we all know, just not at compile-time. There's more to it than just that. Python's type checking is not just not done at compile time, it's done as late in run time as possible. One might call it just-in-time type checking. It's not hard to imagine a Python-like language which included (perhaps optional) variable declarations. A declaration would essentially be an assertion which was checked after each assignment to that name. So, you could write: int i = 5 i = 5.6 and the second statement would throw TypeError. This would give you C++/Java style type safety, but it still wouldn't be compile time. Perhaps a better way to describe it is that the checking isn't an is-a assertion, but an acts-like assertion (sort of like Java's interfaces). To take an example, in the function: def first3(y): if len(y) < 3: return y return y[0:3] all I really need from the argument is that I can call len() on it and it can be sliced. An easy way to describe this would be to say that y must be a sequence, but that's not strictly accurate, since I can easily declare my own class which meets those requirements without being a subclass of sequence (even ignoring for the moment that 'sequence', while talked about in the documentation, doesn't actually exist as something you can subclass). From mline at abilitec.com Thu Oct 20 12:02:03 2005 From: mline at abilitec.com (Mark Line) Date: Thu, 20 Oct 2005 16:02:03 +0000 (UTC) Subject: Searching for txt file and importing to ms access Message-ID: Hello! I'm a python n00b! I've been writing in c++ for a few years so programming's not new to me, just python that I don't know the syntax! What I'm trying to do is get an email from an pop3 account, and then search the email for some CVS data and import that information into MS Access. I'm managed to get some code to download a message from the email account and save it to a text file, does any one have a link to some sample code to search though a file until a string of characters is matched? Or could point me to some functions that may help me with this? I've also managed to connect to my access database, and just print out a field in a table, but I cant find anywhere on the web that will help me to import data? Any help would be great?! By the way I'm running on windows, and have installed the windows add on's. Thanks in advance Mark email code import sys, poplib f = open('c:\\myfile.txt', 'w') mailserver = 'pop3.abilitec.com' mailuser = 'bookings at pop3.abilitec.com' mailpasswd = '***********' print 'Connecting...' server = poplib.POP3(mailserver) server.user(mailuser) # connect, login to mail server server.pass_(mailpasswd) # pass is a reserved word try: print server.getwelcome() # print returned greeting message msgCount, msgBytes = server.stat() print 'There are', msgCount, 'mail messages in', msgBytes, 'bytes' print server.list() print '-'*80 for i in range(msgCount): hdr, message, octets = server.retr(i+1) # octets is byte count for line in message: # retrieve, print all mail f.write(line) f.write('\n') print '-'*80 # mail box locked till quit if i < msgCount - 1: raw_input('[Press Enter key]') finally: # make sure we unlock mbox server.quit() # else locked till timeout print 'Bye.' f.close() access import sys, win32com.client print 'start' connection = win32com.client.Dispatch(r'ADODB.Connection') DSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=c:\\booking.mdb;/root/blackcomb' connection.Open(DSN) recordset = win32com.client.Dispatch(r'ADODB.Recordset') recordset.Open('SELECT * FROM tblBooking', connection, 1, 3) fields_dict = {} for x in range(recordset.Fields.Count): fields_dict[x] = recordset.Fields.Item(x).Name print fields_dict[x], recordset.Fields.Item(x).Value print 'end' From mwm at mired.org Wed Oct 26 09:22:21 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 26 Oct 2005 09:22:21 -0400 Subject: Double replace or single re.sub? References: <1130322073.666179.49350@g44g2000cwa.googlegroups.com> Message-ID: <86vezk1khe.fsf@bhuda.mired.org> "Iain King" writes: > I have some code that converts html into xhtml. For example, convert > all tags into . Right now I need to do to string.replace calls > for every tag: > > html = html.replace('','') > html = html.replace('','') > > I can change this to a single call to re.sub: > > html = re.sub('<([/]*)i>', r'<\1em>', html) > > Would this be a quicker/better way of doing it? Maybe. You could measure it and see. But neither will work in the face of attributes or whitespace in the tag. If you're going to parse [X]HTML, you really should use tools that are designed for the job. If you have well-formed HTML, you can use the htmllib parser in the standard library. If you have the usual crap one finds on the web, I recommend BeautifulSoup. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From http Thu Oct 27 01:26:59 2005 From: http (Paul Rubin) Date: 26 Oct 2005 22:26:59 -0700 Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <3s6l8mFmj3fjU1@individual.net> <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> <7xwtjz3jc9.fsf@ruckus.brouhaha.com> Message-ID: <7xwtjzcyxo.fsf@ruckus.brouhaha.com> "David Schwartz" writes: > > So, your observations about Burger King are irrelevant to Microsoft. > > Because the error I'm correcting is the belief that Microsoft's conduct > was extremely unusual (unlike anything any reputable company had ever done, > essentially). MS's monopolistic conduct was uncommon, but not so extremely unusual as to be unheard of. Congress had indeed seen conduct like that before, which is why it saw the need for passing laws against it. From eurleif at ecritters.biz Sat Oct 1 03:05:57 2005 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sat, 01 Oct 2005 07:05:57 GMT Subject: [Info] PEP 308 accepted - new conditional expressions In-Reply-To: References: <3q4ro9Fd770nU3@individual.net> Message-ID: Sam wrote: > And "foo if bar" is Perl-ish; yet, even Perl has the ? : operators. What _isn't_ Perl-ish? From kaiser.vocote at gmail.com Mon Oct 31 05:07:33 2005 From: kaiser.vocote at gmail.com (Andreas Kaiser) Date: 31 Oct 2005 02:07:33 -0800 Subject: tachometer diagram Message-ID: <1130753253.564379.63190@g47g2000cwa.googlegroups.com> Hello, I'am searching for a python solution for display a tachometer diagram. I prefer a solution for wxPython. The plot libraries I've found do not implement this diagram type. Any hints welcome! Thanks Andreas From dcrespo at gmail.com Thu Oct 27 11:51:36 2005 From: dcrespo at gmail.com (dcrespo) Date: 27 Oct 2005 08:51:36 -0700 Subject: socket.error: (32, 'Broken pipe'): need help In-Reply-To: References: Message-ID: <1130428296.311975.65080@f14g2000cwb.googlegroups.com> When enabling the server, note that you put '' as the IP, and not 'localhost'. if you put an ip: '172.16.1.2', your server will listen on that IP (if it's valid) if you put '', your server will listen on all IPs defined on that computer. of you put 'localhost', it will listen for local connections only. Maybe that's the problem. From __peter__ at web.de Mon Oct 3 07:17:48 2005 From: __peter__ at web.de (Peter Otten) Date: Mon, 03 Oct 2005 13:17:48 +0200 Subject: struct.unpack References: Message-ID: g.franzkowiak wrote: > The dataObject was read from a named pipe as an byte stream > > state, dataObject = win32file.ReadFile(handle, nbytes, None) > print repr(dataObject) > ==> '\x01\x02\x03\x04\x00\x00\x00\x00\x00\x00\x0..... > > With Frederiks help operates this fine I do not doubt that. My point was that instead of the suggested # Fredrik obj?=?"".join(list(dataObject[:4])) the simpler # me obj = dataObject[:4] might work as well. I cannot test it here, but judging from http://aspn.activestate.com/ASPN/docs/ActivePython/2.3/pywin32/win32file__ReadFile_meth.html the resulting dataObject is a buffer and buffer slices seem to be just strings. > print repr(dataObject) > ==> '\x01\x02\x03\x04\x00\x00\x00\x00\x00\x00\x0..... Hmm, that looks as if dataObject were a string -- please post the result of print type(dataObject) just to help me restore my peace of mind :-) Peter From gh at ghaering.de Wed Oct 26 09:03:47 2005 From: gh at ghaering.de (=?UTF-8?B?R2VyaGFyZCBIw6RyaW5n?=) Date: Wed, 26 Oct 2005 15:03:47 +0200 Subject: tool for syntax coloring in html In-Reply-To: <1130330426.059794.282450@g49g2000cwa.googlegroups.com> References: <1130330426.059794.282450@g49g2000cwa.googlegroups.com> Message-ID: <435F7EB3.7010301@ghaering.de> Xah Lee wrote: > in some online documentations, for examples: > > http://perldoc.perl.org/perlref.html > http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z-H-17.html > http://www.haskell.org/hawiki/HaskellDemo > > the codes are syntax colored. > > Is there a tool that produce codes in html with syntax coloring? I use SilverCity and this recipe to produce colored code listings for the pysqlite documentation: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252170 This is the documentation source: http://initd.org/svn/pysqlite/pysqlite/trunk/doc/usage-guide.txt This is the result: http://initd.org/pub/software/pysqlite/doc/usage-guide.html HTH, -- Gerhard From jgrahn-nntq at algonet.se Thu Oct 27 12:32:57 2005 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: 27 Oct 2005 16:32:57 GMT Subject: Set an environment variable References: <43573022$0$155$edfadb0f@dread16.news.tele.dk> <1129798724.366618.194650@g44g2000cwa.googlegroups.com> <43589205$0$125$edfadb0f@dread16.news.tele.dk> <11lhv31li8sgm0c@corp.supernews.com> <86ll0mu6px.fsf@bhuda.mired.org> <11lifp8r4kipi5c@corp.supernews.com> <868xwmu07g.fsf@bhuda.mired.org> <11liivcbmeops4b@corp.supernews.com> <11lps3jj9a7h62c@corp.supernews.com> <1h4zleu.115juj63s01m9N%aleaxit@yahoo.com> <86r7a8hwnp.fsf@bhuda.mired.org> Message-ID: On Wed, 26 Oct 2005 16:04:58 -0400, Mike Meyer wrote: > Jorgen Grahn writes: >> On Wed, 26 Oct 2005 07:42:19 -0700, Alex Martelli wrote: >>> Grant Edwards wrote: >>>> On 2005-10-24, Eric Brunel wrote: >>>> >> The only think you can export an environment variable to is a >>>> >> child process >>>> > Well, you know that, and I know that too. From my experience, >>>> > many people don't... >>>> True. Using Unix for 20+ years probably warps one's perception >>>> of what's obvious and what isn't. >>> This specific issue is identical in Windows, isn't it? I do not know >>> any OS which does have the concept of "environment variable" yet lets >>> such variables be ``exported'' to anything but a child process. >> AmigaDOS, if I recall correctly. Its "ENV:" drive/namespace is global, and >> that's its closest thing to Unix environment variables. > > AmigaDOS had both global environment variables (using the ENV: device) > and local environment variables, that worked like the Unix > version. As I recalled it, the latter type was shell-local and not accessible to normal processes ... > You manipulated them in a similar way in the shell, and they > had a similar API for programmers: one call with a flag to indicate > which you wanted. ... but if there were system calls to access them, I must have remembered incorrecly. Possibly I was too stupid back then to find enviroment variables very useful ;-) > Of course, this is now 10+ year old memory, and I may not RC. I think I remember /you/ though, from the Amiga newsgroups in the early nineties. And now I feel old -- and offtopic. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! From xah at xahlee.org Tue Oct 4 20:44:02 2005 From: xah at xahlee.org (Xah Lee) Date: 4 Oct 2005 17:44:02 -0700 Subject: check html file size Message-ID: <1128473042.653989.175990@o13g2000cwo.googlegroups.com> would anyone like to translate the following perl script to Python or Scheme (scsh)? the file takes a inpath, and report all html files in it above certain size. (counting inline images) also print a sorted report of html files and their size. (a copy of the script is here: http://xahlee.org/_scripts/check_file_size.pl ) Xah xah at xahlee.org ? http://xahlee.org/ # perl # Tue Oct 4 14:36:48 PDT 2005 # given a dir, report all html file's size. (counting inline images) # XahLee.org use Data::Dumper; use File::Find; use File::Basename; $inpath = '/Users/t/web/mydirectory/'; $sizeLimit = 800 * 1000; # $inpath = $ARGV[0]; # should give a full path; else the $File::Find::dir won't give full path. while ($inpath =~ m@^(.+)/$@) { $inpath = $1;} # get rid of trailing slash die "dir $inpath doesn't exist! $!" unless -e $inpath; ################################################## # subroutines # getInlineImg($file_full_path) returns a array that is a list of inline images. For example, it may return ('xx.jpg','../image.png') sub getInlineImg ($) { $full_file_name= $_[0]; @linx =(); open (FF, "<$full_file_name") or die "error: can not open $full_file_name $!"; while () { @txt_segs = split(m/img/, $_); shift @txt_segs; for $lin (@txt_segs) { if ($lin =~ m@ src\s*=\s*\"([^\"]+)\"@i) { push @linx, $1; }} } close FF; return @linx; } # linkFullPath($dir,$locallink) returns a string that is the full path to the local link. For example, linkFullPath('/Users/t/public_html/a/b', '../image/t.png') returns 'Users/t/public_html/a/image/t.png'. The returned result will not contain double slash or '../' string. sub linkFullPath($$){ $result=$_[0] . $_[1]; while ($result =~ s@\/\/@\/@) {}; while ($result =~ s@/[^\/]+\/\.\.@@) {}; return $result;} # listLocalLinks($html_file_full_path) returns a array where each element is a full path of local links in the html. sub listLocalLinks($) { my $htmlfile= $_[0]; my ($name, $dir, $suffix) = fileparse($htmlfile, ('\.html') ); my @aa = getlinks($htmlfile); @aa = grep(!m/\#/, @aa); @aa = grep (!m/^mailto:/, @aa); @aa = grep (!m/^http:/, @aa); my @linkedFiles=(); foreach my $lix (@aa) { push @linkedFiles, linkFullPath($dir,$lix);} return @linkedFiles; } # listInlineImg($html_file_full_path) returns a array where each element is a full path to inline images in the html. sub listInlineImg($) { my $htmlfile= $_[0]; my ($name, $dir, $suffix) = fileparse($htmlfile, ('\.html') ); my @aa = getInlineImg($htmlfile); my @result=(); foreach my $ele (@aa) { push @result, linkFullPath($dir,$ele);} return @result; } ################################################## sub checkLink { if ( -T $File::Find::name && $File::Find::name =~ m@\.html$@ ) { $total= -s $File::Find::name; @h2 = listInlineImg($File::Find::name); for my $ln (@h2) {$total += -s $ln;}; if ( $total > $sizeLimit) {print "problem: file: $File::Find::name, size: $total\n";} push (@result, [$total, $File::Find::name]); }; } find(\&checkLink, $inpath); @result = sort { $b->[0] <=> $a->[0]} @result; print Dumper(\@result); print "done reporting. (any file above size are printed above.)"; __END__ From Tracy.Beck at Infineon.com Thu Oct 20 12:47:43 2005 From: Tracy.Beck at Infineon.com (T Beck) Date: 20 Oct 2005 09:47:43 -0700 Subject: Microsoft Hatred FAQ In-Reply-To: References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <33sj23-6om.ln1@news.it.uc3m.es> Message-ID: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> Peter T. Breuer wrote: > In comp.os.linux.misc David Schwartz wrote: > > > "Peter T. Breuer" wrote in message > > news:33sj23-6om.ln1 at news.it.uc3m.es... > > >> Not if they abuse a monopoly position in doing so, which is where we > >> started. [snip] > O/ses on PC platforms, as determined by the courts. Thanks to their > initial agreement with IBM, and subsequent nasty tactics. So what I'm getting here is, that they abused their monopoly power to secure their initial deal with IBM. Which is what made them a monopoly. MS didn't have a monopoly before IBM, so what kind of draw did they have to make IBM sign the paper, except that they were offering something that IBM wanted, and IBM was willing to pay that much for it? Nobody made IBM sign that deal, IBM thought that it worked out OK for both parties. As for later deals with OEM manufacturers, if it's OK for MS to make that deal with IBM, then why does it suddenly become an "abuse of their power" if they're using the same business model? Don't get me wrong, I'm sure MS has done plenty of shady stuff, and I'm sure most every other sucessful company has. Just because we got a lawsuit to watch for MS doesn't mean other companies like Sony or IBM haven't done similar stuff we've never heard of. I'm just trying to figure out how offering their contract changed from OK to not OK, based purely on how well they were doing... --T Beck From realgagnon_ at _yahooSpamIsBadSstripunderscore.com Sat Oct 15 12:43:05 2005 From: realgagnon_ at _yahooSpamIsBadSstripunderscore.com (Real Gagnon) Date: Sat, 15 Oct 2005 16:43:05 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: > I'd be VERY surprised if IBM predicted that there would be only 5 > COMPUTERS in *2000* - perhaps you mean 5 *manufacturers* of computers? > - unless the prediction was made a VERY long time ago. I think you are > giving a badly-mangled version of something I saw when I worked at > IBM. "I think there is a world market for maybe five computers." ~ IBM Chairman Thomas Watson, 1943. ref : http://en.wikiquote.org/wiki/Computers Bye. -- Real Gagnon from Quebec, Canada * Looking for Java or PB code examples ? Visit Real's How-to * http://www.rgagnon.com/howto.html From howardrh at westerncom.net Sun Oct 9 13:30:54 2005 From: howardrh at westerncom.net (hrh1818) Date: 9 Oct 2005 10:30:54 -0700 Subject: New Python book References: Message-ID: <1128879054.054226.7220@f14g2000cwb.googlegroups.com> This book is not a new book. It is an updated version of Magnus's 2002 Practical Python book. Dick Moores wrote: > (Sorry, my previous post should not have had "Tutor" in the subject header.) > > Magnus Lie Hetland's new book, _Beginning Python: From Novice to > Professional_ was published by Apress on Sept. 26 (in the U.S.). My copy > arrived in the mail a couple of days ago. Very much worth a look, IMHO. > But what do the experts here think? > > > > Dick Moores > rdm at rcblue.com From tim.peters at gmail.com Mon Oct 17 16:49:22 2005 From: tim.peters at gmail.com (Tim Peters) Date: Mon, 17 Oct 2005 16:49:22 -0400 Subject: Queue question In-Reply-To: <1h4knxw.1s6kxw4l9w7yN%aleaxit@yahoo.com> References: <1129413036.271162.279880@g43g2000cwa.googlegroups.com> <1129419092.954592.59630@z14g2000cwz.googlegroups.com> <1h4knxw.1s6kxw4l9w7yN%aleaxit@yahoo.com> Message-ID: <1f7befae0510171349w1d8f6dc7y5eb9ace2d6589d2c@mail.gmail.com> [Alex Martelli] > ... > not_empty and not_full are not methods but rather instances of the > threading.Condition class, which gets waited on and notified > appropriately. I'm not entirely sure exactly WHAT one is supposed to do > with the Condition instances in question (I'm sure there is some design > intent there, because their names indicate they're public); presumably, > like for the Lock instance named 'mutex', they can be used in subclasses > that do particularly fiendish things... but I keep planning not to cover > them in the 2nd edition of the Nutshell (though there I _will_ cover the > idea of subclassing Queue to implement queueing disciplines other than > FIFO without needing to worry about synchronization, which I had skipped > in the 1st edition). Last time it was rewritten, I put as much thought into the names of Queue instance variables as Guido put into them originally: none. They have always "looked like" public names, but I'm at a loss to think of anythng sane a Queue client or extender could do with them. Of course that's why the docs don't mention them. I suppose an extender could make good use of `mutex` if they wanted to add an entirely new method, say: def get_and_put_nowait(self, new_item) : """Pop existing item, and push new item, atomically [blah blah blah].""" I don't know of anyone who has done so, though. I kept the name `mutex` intact during the last rewrite, but didn't hesitate to get rid of the former `esema` and `fsema` attributes. Since no complaints resulted, it's a pretty safe bet nobody was mucking with esema or fsema before. From codecraig at gmail.com Wed Oct 26 10:31:00 2005 From: codecraig at gmail.com (jas) Date: 26 Oct 2005 07:31:00 -0700 Subject: DrPython - auto complete Message-ID: <1130337060.967707.262390@g14g2000cwa.googlegroups.com> Hi, I just started to use DrPython and I have installed the CodeCompletion plugin. I am using DrPython 161 (on windows) with wxPython 2.6.1. Anyhow, when I try something like x = [] x. ...it pops up "x.filename", "x.prepend" and "x.word". Shouldn't it show "x.append", "x.pop", etc? Just curious if anyone else uses this and has this problem. Or maybe the code completion doesn't work like I expect. From martin at v.loewis.de Mon Oct 3 06:59:38 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 03 Oct 2005 12:59:38 +0200 Subject: Unicode charmap decoders slow In-Reply-To: <*firstname*nlsnews-69AACB.23331402102005@news.verizon.net> References: <*firstname*nlsnews-69AACB.23331402102005@news.verizon.net> Message-ID: <43410f1b$0$7019$9b622d9e@news.freenet.de> Tony Nelson wrote: > Is there a faster way to decode from charmaps to utf-8 than unicode()? You could try the iconv codec, if your system supports iconv: http://cvs.sourceforge.net/viewcvs.py/python-codecs/practicecodecs/iconv/ Regards, Martin From kent37 at tds.net Mon Oct 31 14:42:43 2005 From: kent37 at tds.net (Kent Johnson) Date: Mon, 31 Oct 2005 14:42:43 -0500 Subject: frozenset/subclassing/keyword args In-Reply-To: References: Message-ID: <43667178$1_3@newspeer2.tds.net> Mark E. Fenner wrote: > Speaking of which, in the docs at the bottom of the description of the > builtin set/frozenset, there is a link to a page describing differences > between the builtin sets and the sets module sets. This link is broken > locally and on the python.org docs. > Locally, it reads: > file:///usr/share/doc/python-docs-2.4.2/html/lib/module-comparison-to-builtin-set.html > > While it should read: > file:///usr/share/doc/python-docs-2.4.2/html/lib/comparison-to-builtin-set.html A little further down the page it says "See About this document... for information on suggesting changes." If you click the link there it will tell you how to submit a doc bug which is the best way to get this fixed. Kent From adsheehan at eircom.net Fri Oct 21 08:18:14 2005 From: adsheehan at eircom.net (adsheehan at eircom.net) Date: 21 Oct 2005 05:18:14 -0700 Subject: Embedded Python - Sharing memory among scripts, threads Message-ID: <1129897094.417949.181120@g47g2000cwa.googlegroups.com> Hi, I have a multi-threaded C++ software app that embeds Python. When multi-threading (native system threads) it is possible that multiple instances of a Python script are active. I have a requirement to 'share' some data values between these script instances (e.g. counters, file handles etc). I notice that 'global' variables are NOT visible or shared among these script instances. Does Python offer a solution to this ? What are my options ? Thanks for helping. Alan From rrr at ronadam.com Fri Oct 14 17:32:05 2005 From: rrr at ronadam.com (Ron Adam) Date: Fri, 14 Oct 2005 21:32:05 GMT Subject: object inheritance and default values In-Reply-To: <1129320301.22b6eac21f6406269fe235d5ba702f24@teranews> References: <1129320301.22b6eac21f6406269fe235d5ba702f24@teranews> Message-ID: George Sakkis wrote: > "Ron Adam" wrote: > > >>I'm trying to implement simple svg style colored complex objects in >>tkinter and want to be able to inherit default values from other >>previously defined objects. >> >>I want to something roughly similar to ... >> >> class shape(object): >> def __init__(self, **kwds): >> # set a bunch of general defaults here. >> self.__dict__.update(kwds) >>def draw(self, x=0, y=0, scale=1.0): >> # draw the object >> >> hello = shape(text='hello') >> redhello = hello(color='red') >> largeredhello = redhello(size=100) >> largeredhiya = largeredhello(text='Hiya!') >> largeredhiya.draw(c, 20, 50) >> >> >>I think this will need to require __new__ or some other way to do it. >>But I'm not use how to get this kind of behavior. Maybe the simplest >>way is to call a method. >> >> redhello = hello.makenew( color='red' ) > > > Just name it '__call__' instead of makenew and you have the syntax sugar you want: > > def __call__(self, **kwds): > new = self.__class__(**self.__dict__) > new.__dict__.update(kwds) > return new > > Personally I would prefer an explicit method name, e.g. 'copy'; hiding the fact that 'shape' is a > class while the rest are instances is likely to cause more trouble than it's worth. > > George Just got it to work with __call__ as a matter of fact. ;-) def __call__(self,**kwds): for key in self.__dict__: if key not in kwds: kwds[key] = self.__dict__[key] return shape(**kwds) The purpose having the objects not call the methods explicityly in this case is to simplify the data structure in a way that it doesn't care. The point is to create as much consistancy in the data structure as possible without having to special case some objects as base objects, and some as instances. # Triangle triangle = shape( obj='regpolygon', points=getrpoly(3), fill='grey', size=75 ) # Text text = shape( obj='text', fill='black', size=10 ) # CAUTION ICON caution = group( triangle(x=6, y=5), triangle(fill='yellow'), text( text='!', x=39, y=32, size=35, font='times', style='bold' ) ) I can use a shape() in the group exactly like triangle(), or text(). They are all the same thing to group. It's just a matter of what the defaults are. This keeps things very simple. ;-) Then when it needs to be drawn... caution.draw(canvas, x, y, scale) I still need to work on reusing and nesting groups and having them set default values. Maybe I need to make group a sub shape which contains a list of shapes, etc... This is another work it out as I go project. ;-) Cheers, Ron From mwm at mired.org Mon Oct 3 15:27:47 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 03 Oct 2005 15:27:47 -0400 Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> Message-ID: <86slvijt8s.fsf@bhuda.mired.org> Steven D'Aprano writes: > On Mon, 03 Oct 2005 06:59:04 +0000, Antoon Pardon wrote: > Declared variables have considerable labour costs, and only marginal > gains. Since the steps you take to protect against other errors will also > protect against mistyping variables, declarations of variables is of > little practical benefit. As far as I can tell, this is as much hearsay and personal experience as the alternate claim that not having them costs you lots of debugging time and errors. If anyone has pointers to real research into this area (I've heard the TRAK folks did some, but haven't been able to turn any up), I'd love to hear it. My gut reaction is that it's a wash. The time taken to declare variables in well-written code in a well-designed language - meaning the declarations and use will be close together - isn't all that great, but neither are the savings. The other win from declaring variables is that if you compile the code you can make assumptions about the types of variables and thus save doing (some of) the type determination at run time. But there are type inferencing languages and systems - and they've been around since the 70s - that can do that for you without having to declare the variables, so that doesn't buy you much. If I'm going to get compiler support for semantic checking like this, I want it to serious levels. I want function pre/post conditions checked. I want loop and class invariant checked. I want subsumption in my inheritance tree. Nuts - I want a complete, well-designed inheritance tree. Duck typing is great stuff, but if I'm going to be doing the work to declare everything, I want *everything* that can be checked checked. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From andreas.zwinkau at googlemail.com Thu Oct 20 11:56:47 2005 From: andreas.zwinkau at googlemail.com (beza1e1) Date: 20 Oct 2005 08:56:47 -0700 Subject: Popularity of blogging tools used by python programmers In-Reply-To: <1129823566.831075.73770@g47g2000cwa.googlegroups.com> References: <1129823566.831075.73770@g47g2000cwa.googlegroups.com> Message-ID: <1129823807.066283.151990@z14g2000cwz.googlegroups.com> Uh, no good style to comment myself, sorry. I just found why i could't see your blog entry. Since i read your message through groups.google.de i just clicked on the link. Your Google Highlight plugin seems to be confused about that: Warning: Unknown modifier '/' in /var/www/html/wp/wp-content/plugins/google-hilite.php on line 107 Warning: Unknown modifier 'w' in /var/www/html/wp/wp-content/plugins/google-hilite.php on line 105 Not everybody who comes from google has a search query in his referer ;) From jussij at zeusedit.com Tue Oct 25 23:38:11 2005 From: jussij at zeusedit.com (jussij at zeusedit.com) Date: 25 Oct 2005 20:38:11 -0700 Subject: Embedded Python interpreter, runtime libs, and crashing References: Message-ID: <1130297891.232991.92120@o13g2000cwo.googlegroups.com> > It all runs great in the "Debug" configuration, but > everything gets scary when I switch to "Release". My suggestion would be to turn on debug information for the release build. That would at least let you run the release build inside the debugger, allowing you to see the call stack of the offending crash. Jussi Jumppanen Author: Zeus for Windows Programmer's IDE http://www.zeusedit.com From davids at webmaster.com Thu Oct 27 07:06:16 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 04:06:16 -0700 Subject: Microsoft Hatred FAQ References: <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> Message-ID: Roedy Green wrote: > On Thu, 27 Oct 2005 00:49:27 -0700, "David Schwartz" > wrote, quoted or indirectly quoted someone who > said : >> I guess I don't understand what you're saying. Are you saying that >> Microsoft demanded you pay them per machine you sold under the table >> in the absence of a written contract that said that? Or are you >> simply saying that they changed the terms of your agreement when it >> came up for renewal? > They were demanding I sell a copy of windows with every machine I > constructed, whether the customer wanted or not, even if the customer > had us install some other OS. Right I understand that. You could have complied simply by only selling computers with Windows preinstalled. In other words, you could have treated this the same as a demand for franchise or exclusivity if you had wanted to. > The threat was that I did not comply, they would put me out of > business by arranging that my wholesalers would stop selling any MS > product to me, with veiled threat of even worse strangulation. Well shit, how surprising that they wouldn't want to do business with you if you broke your agreements with them. > What I don't think you understand this threat would was just as > effective in putting he out of business as threatening to sending in > goons every week to smash my shop to pieces. I understand that it is just as effective, but that's not the issue. If I'm hungry, a person who refuses to give me a loaf of bread for free may be just as effective at killing me as a person who shoots me. But that doesn't change the fact that there is no obligation to feed a person and there is an obligation not to shoot them. > I could at least have a chance of legal recourse with the vandals. Only because their actions are unreasonable and Microsoft's are not. > It will be very hard to prosecute MS for their crimes because they > commit them much the way the Mafia does. Right, they send gun-wielding thugs to use force against people. That's a lot like refusing to do business with people who won't uphold their contractual obligations. > No one has any paper. Everyone was terrified of MS and would never > dream of going public. I have talked about this publicly many times > because it always looked as if I were going to die in a few years > anyway. I think you're starting to go off the deep end. > To put this in perspective, IBM's salespeople made much nastier > threats in their heyday. Dick Toewes, head of Inland Natural Gas, was > in charge of a tender for a new mainframe to do billing. I was > working on the Univac bid at the time. He said that the IBM salesman > said to him, "We know you have an eight year old little girl. We know > she walks along X street every day on her way to school. It would be > a terrible thing if somebody hurt her." Yep, way off the deep end. > I wrote a tender for about $1 million in computer equipment for BC > Hydro gas. There were many bidders hoping to get a foothold in a > solidly IBM shop. IBM sent a weird chap to see me, dressed as a > gangster, talking in a gangster accent, with a strange tic like Dustin > Hoffman's Ratso Rizzo in midnight cowboy. He made no specific > threats, but his act was straight out of Hollywood,"you knows what I > means" warning me about the "consequences" of picking anything but > IBM, how I might get the reputation as unreliable..." > There were the standard tactics on $1 million contracts. Imagine the > dirty tricks for the big ones. Mind you, back then $1 million was > serious money, especially when you considered the no-bid followons > over the years. If that kind of thing ever happened (which I seriously doubt), it's absolutely reprehensible. I find it almost possible to believe that individuals on commission might do this kind of thing with no knowledge of their corporate higher ups, or perhaps even that people one level up or so might do it if they are also on commission. But I find it almost impossible to believe that any major corporation could do this as a policy. Of course, the individuals who use actual force or threats of fraud (and blacklisting because they didn't buy from you is fraud), deserve to be prosecuted and imprisoned. Do you have any documentation or evidence to support these claims? Or am I supposed to take your word for it? (Honestly, it seems like you're just trying to mess with me.) DS From Ido.Yehieli at gmail.com Sun Oct 9 16:20:31 2005 From: Ido.Yehieli at gmail.com (Clint Norton) Date: 9 Oct 2005 13:20:31 -0700 Subject: how do you pronounce wxpython In-Reply-To: <1128775425.507351.312980@f14g2000cwb.googlegroups.com> References: <1128775425.507351.312980@f14g2000cwb.googlegroups.com> Message-ID: <1128889231.371101.306620@g44g2000cwa.googlegroups.com> 2nd one indeed From mwm at mired.org Sat Oct 22 20:19:54 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 22 Oct 2005 20:19:54 -0400 Subject: Python vs Ruby References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> <1129883505.814349.306860@g44g2000cwa.googlegroups.com> Message-ID: <86fyqt9j9x.fsf@bhuda.mired.org> Steven D'Aprano writes: > On Fri, 21 Oct 2005 13:03:29 +0100, Alex Stapleton wrote: >> Perl is more like a CISC CPU. There are a million different commands. >> Python is more RISC like. >> Line count comparisons = pointless. > > Not so. > > Every line = more labour for the developer = more cost and time. > Every line = more places for bugs to exist = more cost and time. There were studies done in the 70s that showed that programmers produced the same number of debugged lines of code a day no matter what language they used. So a language that lets you build the same program with fewer lines of code will let you build the program in less time. > I find it sometimes helps to imagine extreme cases. Suppose somebody comes > to you and says "Hi, I want you to develop a web scrapping application to > run on my custom hardware." You look at the project specifications and > realise that the hardware has no OS, no TCP/IP, no file manager, no > compiler. So you have to quote the potential customer on writing all these > layers of software, potentially tens of millions of lines of code. > Even porting an existing OS to the new hardware is not an insignificant > job. Think how much time and money it would take. Then factor in the profits to be reaped from selling the ported OS/compilers :-). http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From reply-and-ask at nospam.thanks Thu Oct 20 07:16:49 2005 From: reply-and-ask at nospam.thanks (James Buchanan) Date: Thu, 20 Oct 2005 21:16:49 +1000 Subject: make: circular dependency for Modules/signalmodule.o References: <4354a3f4$0$28047$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <1129696883.760079.323170@g49g2000cwa.googlegroups.com> Message-ID: <43577ccd$0$28031$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Neal Norwitz wrote: > I've never heard of this problem. The Makefile is generated by > configure so this is possibly a configure issue. In my (generated) > Makefile, signalmodule.o is listed in MODOBJS, but not in SIGNAL_OBJS. > Maybe your signalmodule.o is listed in both? > > Search through the Makefile for signalmodule and see what you can > find. > > Mine has two long lines for the rules which cause signalmodule.c to be > compiled. > > Modules/signalmodule.o: $(srcdir)/Modules/signalmodule.c; $(CC) > $(PY_CFLAGS) -c $(srcdir)/Modules/signalmodule.c -o > Modules/signalmodule.o > > Modules/signalmodule$(SO): Modules/signalmodule.o; $(LDSHARED) > Modules/signalmodule.o -o Modules/signalmodule$(SO) Hi Neal, Thanks very much for your tip. I've been studying makefiles to find out exactly what all this means. It may be because the Minix make program is less capable than gmake. gmake and other make programs can obviously handle this. Configure might have run incorrectly or both rules are one and the same on Minix, because there is no LDSHARED or signalmodule$(SO). Maybe... Still working on it, but this has narrowed it down for me, so thanks heaps. :) James From g.franzkowiak at onlinehome.de Mon Oct 3 06:14:38 2005 From: g.franzkowiak at onlinehome.de (g.franzkowiak) Date: Mon, 03 Oct 2005 12:14:38 +0200 Subject: struct.unpack In-Reply-To: References: Message-ID: Peter Otten schrieb: > g.franzkowiak wrote: > > >>tmpList = list(dataObject)[:4]) >>obj = tmpList[0]+tmpList[1]+tmpList[2]+tmpList[3]. > > > Have you tried just > > obj = dataObject[:4] > > without the intermediate list? If that failed, can you tell us the type of > the dataObject? E. g. > > >>>>print type(dataObject) > > > > Peter > The dataObject was read from a named pipe as an byte stream state, dataObject = win32file.ReadFile(handle, nbytes, None) print repr(dataObject) ==> '\x01\x02\x03\x04\x00\x00\x00\x00\x00\x00\x0..... With Frederiks help operates this fine gerd From gsakkis at rutgers.edu Tue Oct 18 19:23:55 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Tue, 18 Oct 2005 19:23:55 -0400 Subject: how best to split into singleton and sequence References: Message-ID: <1129677836.16d6b1477bf1d9ae9ea8a47c839d33f0@teranews> "Randy Bush" wrote: > >>> l = [] > >>> s = 'a|b' > >>> t, l = s.split('|') > >>> t > 'a' > >>> l > 'b' > >>> s = 'a|b|c|d' > >>> t, l = s.split('|') > Traceback (most recent call last): > File "", line 1, in ? > ValueError: too many values to unpack > >>> > > so, i imagine what is happening is the lhs, t,l, is really > (t, (l)), i.e. only two items. > > so how should i have done this readably and simply? >>> s = 'a|b|c|d' >>> l = s.split('|') >>> t = l.pop(0) By the way, don't use 'l' as an identifier; it is very close to '1' visually. George From pwatson at redlinepy.com Tue Oct 18 10:57:53 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Tue, 18 Oct 2005 09:57:53 -0500 Subject: Installing Python at Work References: <1129561955.452114.53290@g44g2000cwa.googlegroups.com> Message-ID: <3rkgrlFjtv2qU1@individual.net> "Nikola" wrote in message news:1129561955.452114.53290 at g44g2000cwa.googlegroups.com... > I'm currently learning Python for my own use. > I'm considering installing it on a work laptop, knowing that it is > non-licensed, distributable software. > > However, does it access communication ports? I know the company checks > their ports regularly for activity. > > I won't be doing anything very serious; I'm just trying out Python, > learning the basics from 'Learning Python' by O'Reilly. Are you asking if it is ok to install Python on your company machine or if Python does anything that might cause you to get caught doing something the company has already said not to do? From davids at webmaster.com Sun Oct 23 14:51:35 2005 From: davids at webmaster.com (David Schwartz) Date: Sun, 23 Oct 2005 11:51:35 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <33sj23-6om.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <86k6g59ke6.fsf@bhuda.mired.org> <3EI6f.43974$MF6.5922@fe1.news.blueyonder.co.uk> Message-ID: wrote in message news:3EI6f.43974$MF6.5922 at fe1.news.blueyonder.co.uk... > In comp.lang.perl.misc David Schwartz wrote: >> "Mike Meyer" wrote in message >>> Sorry, but nobody but the government actually owns property. In most >>> places, you can't make non-trivial changes to "your" property without >>> permission from the government. They even charge you rent on "your" >>> property, only they call it "property tax". >> I see you are a totalitarianist or perhaps a communist. If you want to >> live in America and discuss things that are relevent to America, let me >> know. > Why would you say that - Mike Meyer made a point to which you have > obviously no answer. Or do you deny that his comments on this matter > of property are true? His comments are not applicable to America. They are applicable to a country where the government owns the economy. No reply is needed to his comments except to point out that they only apply to a communist or totalitarian state. We don't have one here, so his argument doesn't apply. I am not saying "because you are a communist, your argument is wrong". I am saying, "because your argument is based upon communist or totalitarian premises about the relationship between the government and the economy, it does not apply to the United States, and we were talking about the United States." I really felt that this was obvious, but I guess it wasn't. DS From timr at probo.com Sun Oct 9 04:25:04 2005 From: timr at probo.com (Tim Roberts) Date: Sun, 09 Oct 2005 08:25:04 GMT Subject: Using command line args on Windows References: <1128544715.139551.15960@g43g2000cwa.googlegroups.com> Message-ID: <7pkhk1p02r0h1qjjtb3qk12isf9al7iofm@4ax.com> Duncan Booth wrote: >Fredrik Lundh wrote: > >> footnote: if you'd prefer to type "myscript myarg" instead, you might >> want to check out this tool: >> >> http://effbot.org/zone/exemaker.htm > >or even just do: > > SET PATHEXT=.py;%PATHEXT% > >and then "myscript myarg" will work for all scripts on your path without >compiling (if you don't set PATHEXT then "myscript.py myarg" will still >work, and tab completion means you don't generally need to type the .py for >scripts in the current directory). The downside to this is that there is a bug in the NT/2K/XP command interpreter which will prevent redirecting from stdin in that case. That is: C:\Tmp>type x.py import sys print sys.stdin.readline() C:\Tmp>echo 123 | python x.py 123 C:\Tmp>echo 123 | x.py The process tried to write to a nonexistent pipe. C:\Tmp>python x.py < x.py import sys C:\Tmp>x.py < x.py C:\Tmp> -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From lasse at vkarlsen.no Sat Oct 1 14:02:17 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Sat, 01 Oct 2005 20:02:17 +0200 Subject: Question about stdin and PATHEXT on Windows XP Message-ID: I got a loop like this: while True: line = sys.stdin.readline() if not line: break line = line.rstrip() log_message(options.channel_name, line) print line this loop will read text if I execute it from a command prompt like this: dir | python.exe log.py however, since I've set PATHEXT to contain .PY, I tried this: dir | log.py which ended up with the loop just skipping. Does anyone know how to fix this problem ? Being able to use PATHEXT execution (just execute python file directly) and still being able to grab stdin? I assume that since there is some magic involved in invoking python.exe here, stdin gets munged on the way. -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From mscottschilling at hotmail.com Tue Oct 18 16:14:15 2005 From: mscottschilling at hotmail.com (Mike Schilling) Date: Tue, 18 Oct 2005 20:14:15 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <%jV4f.3121$tV6.2659@newssvr27.news.prodigy.net> Message-ID: "John Bokma" wrote in message news:Xns96F395263F33castleamber at 130.133.1.4... > "Mike Schilling" wrote: > >> Now, once more, why are standards" *more valuable* than >> "recommendations"? > > standards are written by internationally recognized independent > organisations, v.s. everyone can write a recommendation. For you, and > others this doesn't matter, for others it does. Why do you think Microsoft > made part of .NET a standard? Marketing. It lets them claim that .NET is open and Java is proprietary. SOAP, which is also part of their "open" story, is a recommendation. From my_email_is_posted_on_my_website at munged.invalid Thu Oct 27 02:11:24 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Thu, 27 Oct 2005 06:11:24 GMT Subject: Microsoft Hatred FAQ References: <3s6l8mFmj3fjU1@individual.net> <0hm233-0ut.ln1@news.it.uc3m.es> <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> Message-ID: On Thu, 27 Oct 2005 02:28:46 +0200, "Peter T. Breuer" wrote, quoted or indirectly quoted someone who said : >I'm a bit curious about this. If I were a business person, I would >simply have created two busineses (two accounts, etc.). One business >sells only machines with MS on and pays the MS tax on all its machines. >One business sells only machines without MS on and pays the MS tax on >none of its machines. > >What's up with that? Try the same thing to deal with a Mafia extortion racket. We are not talking about legal agreements. We are talking junior Mafia style enforcement. -- Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching. From jmm-list.AXSPAMGN at sohnen-moe.com Sat Oct 15 02:20:45 2005 From: jmm-list.AXSPAMGN at sohnen-moe.com (Jim Moe) Date: Fri, 14 Oct 2005 23:20:45 -0700 Subject: Microsoft Hatred FAQ In-Reply-To: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> Message-ID: Xah Lee wrote: > > Question: U.S. Judges are not morons, and quite a few others are > not morons. They find MS guilty, so it must be true. > > Answer: so did the German population thought Jews are morons by > heritage, to the point that Jews should be exterminated from earth. > Apparently, the entire German population cannot be morons, they must be > right. > Extremely lame. -- jmm (hyphen) list (at) sohnen-moe (dot) com (Remove .AXSPAMGN for email) From mwilliams at mgreg.com Sat Oct 22 17:23:23 2005 From: mwilliams at mgreg.com (Michael Williams) Date: Sat, 22 Oct 2005 17:23:23 -0400 Subject: PID and/or handle assistance. . .? In-Reply-To: References: Message-ID: <9D1F0446-AEC1-4F77-A9F6-0EA57E574900@mgreg.com> On Oct 22, 2005, at 1:16 PM, python-list-request at python.org wrote: > Michael Williams wrote: > >> Hi All, >> Can anyone explain how to both spawn processes from PYTHON and >> acquire their process IDs or a handle to them for use later? I'd >> also like to acquire the stdout of each spawned process. >> > > Google dead today? Well, check out the modules subprocess, popen2 > and os. > > Regards, > > Diez > No, Google certainly isn't dead. I simply figured I'd ask those in the know instead of mindlessly meandering the web. Anyway, I've checked out the OS module and although I can find examples of say .fork, and .popen, they aren't extremely informative or straightforward. Any other ideas/examples? Regards -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan at wolf.com Wed Oct 26 15:38:33 2005 From: dan at wolf.com (Dan M) Date: Wed, 26 Oct 2005 12:38:33 -0700 Subject: Python 2.3.4, Berkeley db 1.85, db file format not recognized References: Message-ID: On Wed, 26 Oct 2005 14:23:49 -0500, skip wrote: > > Dan> import bsddb > Dan> bsddb.hashopen("access.db") > > Dan> but I get: > Dan> bsddb._db.DBInvalidArgError: (22, 'Invalid argument -- access.db: unexpected file type or format') > > Dan> .... Any suggestions on how to read this file? > > See if the bsddb185 module is available: It is, and it works. Thanks so much! From sutram at gmail.com Wed Oct 5 23:36:47 2005 From: sutram at gmail.com (Mahesh Padmanabhan) Date: Wed, 05 Oct 2005 21:36:47 -0600 Subject: Perl's documentation come of age References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1124736189.749363.32160@g47g2000cwa.googlegroups.com> <1125179974.483320.116780@g49g2000cwa.googlegroups.com> <1127299284.748225.68560@g14g2000cwa.googlegroups.com> Message-ID: In article <1127299284.748225.68560 at g14g2000cwa.googlegroups.com>, "Xah Lee" wrote: While I don't like to feed the trolls, I do find his posts amusing. He is like a spoilt child seeking attention. From rrr at ronadam.com Wed Oct 5 07:10:58 2005 From: rrr at ronadam.com (Ron Adam) Date: Wed, 05 Oct 2005 11:10:58 GMT Subject: "no variable or argument declarations are necessary." In-Reply-To: References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> Message-ID: <6xO0f.166857$p_1.72982@tornado.tampabay.rr.com> Antoon Pardon wrote: > Op 2005-10-04, Ron Adam schreef : > >>Antoon Pardon wrote: >> >>>Op 2005-10-03, Steven D'Aprano schreef : >>> >>>>And lo, one multi-billion dollar Mars lander starts braking either too >>>>early or too late. Result: a new crater on Mars, named after the NASA >>>>employee who thought the compiler would catch errors. >>> >>> >>>Using (unit)tests will not guarantee that your programs is error free. >>> >>>So if sooner or later a (unit)tested program causes a problem, will you >>>then argue that we should abondon tests, because tests won't catch >>>all errors. >> >>Maybe you need to specify what kind of errors you want to catch. >>Different types of errors require different approaches. > > > I want to catch all errors of course. Yes, of course, and so do other programmers. What I mean is to try and break it down into specific instances and then see what the best approach is for each one is. When I first started leaning Python I looked for these features as well, but after a while my programming style changed and I don't depend on types and names to check my data near as much now. But instead write better organized code and data structures with more explicit value checks where I need them. My concern now is having reusable code and modules I can depend on. And also separating my data and data management operations from the user interface. Having functions and names that don't care what type the objects are, makes doing this separation easier. Another situation where typeless names are useful is routines that explicitly check the type, then depending on the type does different things. For example if you have a list with a lot of different type objects stored in it, you can sort the contents into sublists by type. Looking at it from a different direction, how about adding a keyword to say, "from this point on, in this local name space, disallow new names". Then you can do... def few(x,y): a = 'a' b = 'b' i = j = k = l = None no_new_names # raise an error after here if a new name is used. ... for I in range(10): <-- error ... This is more suitable to Pythons style than declaring types or variables I think. Add to this explicit name-object locking to implement constants and I think you would have most of the features you want. so... no_new_names # limit any new names lock_name name # lock a name to it's current object Since names are stored in dictionaries, a dictionary attribute to disallow/allow new keys, and a way to set individual elements in a dictionary to read only would be needed. Once you can do that and it proves useful, then maybe you can propose it as a language feature. These might also be checked for in the compile stage and would probably be better as it wouldn't cause any slow down in the code or need a new dictionary type. An external checker could possibly work as well if a suitable marker is used such as a bare string. ... x = y = z = None "No_New_Names" # checker looks for this ... X = y/z # and reports this as an error return x,y and.. ... Author = "Fred" "Name_Lock Author" # checker sees this... ... Author = "John" # then checker catches this ... So there are a number of ways to possibly add these features. Finding common use cases where these would make a real difference would also help. Cheers, Ron From tiang_ono at yahoo.com Fri Oct 28 05:11:30 2005 From: tiang_ono at yahoo.com (Titi Anggono) Date: Fri, 28 Oct 2005 02:11:30 -0700 (PDT) Subject: problem with gnuplot in XP In-Reply-To: Message-ID: <20051028091130.43563.qmail@web30708.mail.mud.yahoo.com> Hi all, I made 2 arrays, which are i and uzuy (both are float). And I want to plot the graph between those arrays. I followed from the manual ================== from Gnuplot import Gnuplot, Data g=Gnuplot() results=Data(i,uzuy) g.plot(results) ================= here I got the message ============================ Traceback (most recent call last): File "", line 1, in -toplevel- g.plot(i,uzuy) File "C:\Python23\Lib\site-packages\Gnuplot\_Gnuplot.py", line 274, in plot self.refresh() File "C:\Python23\Lib\site-packages\Gnuplot\_Gnuplot.py", line 215, in refresh self(self.plotcmd + ' ' + string.join(plotcmds, ', ')) File "C:\Python23\Lib\site-packages\Gnuplot\_Gnuplot.py", line 199, in __call__ self.gnuplot(s) File "C:\Python23\Lib\site-packages\Gnuplot\gp_win32.py", line 125, in __call__ self.write(s + '\n') IOError: [Errno 22] Invalid argument ====================================== FYI, I use python2.3 and Gnuplot-py-1.7. Any problems with my code ?? Thanks __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com From mwm at mired.org Mon Oct 24 01:44:05 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 24 Oct 2005 01:44:05 -0400 Subject: Syntax across languages References: <1130052687.396109.145420@o13g2000cwo.googlegroups.com> <86ll0j7mrh.fsf@bhuda.mired.org> <3ppol1pkh4he35r9uaemgldv0ch8n1nln6@4ax.com> Message-ID: <86d5lv79lm.fsf@bhuda.mired.org> Dennis Lee Bieber writes: > On Sun, 23 Oct 2005 20:59:46 -0400, Mike Meyer declaimed > the following in comp.lang.python: > >> Hopefully user defined. Rexx has a global control that lets you set >> the number of digits to be considered significant in doing an FP >> equality test. >> > That's the good part about the REXX model... > > The bad part? It's based on the number of significant digits... > Rather than a true epsilon. Depends on what you mean by "a true epsilon". If you mean "I want the two values to differ by at most 10^-5", then number of significant digits is a better option. If you mean "I want the two values to differ by at most 1 part in 10^5", then number of significant digits is a slightly less flexible option. You really, *really* don't want to specify the acceptable difference as a fixed value. You want it to be relative to the size of objects being compared. The latter is what number of significant digits gives you. The downside is that you're restricted to values that are a power of 10, and can't specify things like "I want the two values to differ by at most one part in 34,000" or some such oddity. On the up side, number of significant digits is (maybe was - been a long time since I did any serious number crunching) a common form for expressing the accuracy of a calculation. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From jdhunter at ace.bsd.uchicago.edu Tue Oct 11 22:27:05 2005 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Tue, 11 Oct 2005 21:27:05 -0500 Subject: scipy.plt legend? References: <1129046539.630460.326290@g49g2000cwa.googlegroups.com> <1129064947.475029.78260@g14g2000cwa.googlegroups.com> Message-ID: <87br1vii6e.fsf@peds-pc311.bsd.uchicago.edu> >>>>> "gurkesaft" == gurkesaft writes: gurkesaft> Thank you, Robert. I noticed how obsolete it is! gurkesaft> There is no documentation. gurkesaft> Matplotlib freezes my system if I close a plot and make gurkesaft> a new one :(. Bah. Windows :) Have you seen the documentation on http://matplotlib.sf.net/installing.html In particular, you need to make sure that your backend, shell, and interactive setting all are harmonious. One suggestion: in your rc file, try setting 'backend : TkAgg' and 'interactive : True' in your http://matplotlib.sf.net/matplotlibrc file. Also, beware of using matplotlib from a GUI IDE which uses a different GUI toolkit than the one you've selected in your rc file. I realize this is complex -- but I think it is part and parcel of the curse of python. python supports 6+ GUI toolkits and so matplotlib does too! If the GUI mainloop and matplotlib mainloop don't agree, bad things can happen. JDH From brian at sweetapp.com Wed Oct 5 07:27:51 2005 From: brian at sweetapp.com (Brian Quinlan) Date: Wed, 05 Oct 2005 13:27:51 +0200 Subject: "no variable or argument declarations are necessary." In-Reply-To: <7xwtks2tnw.fsf@ruckus.brouhaha.com> References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> <434245F5.6060500@REMOVEMEcyber.com.au> <7xr7b14lk0.fsf@ruckus.brouhaha.com> <7xu0fx9l7y.fsf@ruckus.brouhaha.com> <7xwtks2tnw.fsf@ruckus.brouhaha.com> Message-ID: <4343B8B7.1070603@sweetapp.com> Paul Rubin wrote: >>Which is evaluated at runtime, does not require that the actual global >>variable be pre-existing, and does not create the global variable if >>not actually assigned. I think that is pretty different than your >>proposal semantics. > > > Different how? Aren't you looking for some of compile-time checking that ensures that only declared variables are actually used? If so, how does global help? >>Your making this feature "optional" contradicts the subject of this >>thread i.e. declarations being necessary. > > They're necessary if you enable the option. OK. Would it work on a per-module basis or globally? > def do_add(x->str, y->str): > return '%s://%s' % (x, y) > > def do_something(node->Node): > if node.namespace == XML_NAMESPACE: > return do_add('http://', node.namespace) > elif node.namespace == ... Wouldn't an error be generated because XML_NAMESPACE is not declared? And I notice that you are not doing any checking that "namespace" is a valid attribute of the node object. Aren't the typos class of error that you are looking to catch just as likely to occur for attributes as variables? Cheers, Brian From hipertracker at gmail.com Sun Oct 23 07:00:08 2005 From: hipertracker at gmail.com (Jaroslaw Zabiello) Date: Sun, 23 Oct 2005 13:00:08 +0200 Subject: IDE recommendation please References: Message-ID: <1km2me5ltd4xm$.2hz1vh3pgu03$.dlg@40tude.net> Dnia Sun, 23 Oct 2005 14:54:38 +1000, microsnot napisa?(a): > Eclipse don't seem to support Python out of the box. It is very easy to add excelent python plugin http://pydev.sourceforge.net/ Fast install: just go to the update manager (inside the help menu) and add update site: http://pydev.sf.net/updates/ (eclipse should do the rest) An alternative is just getting the zip file and extracting it yourself in eclipse. If you choose to do it, just make sure the plugins folder is extracted on top of the eclipse plugins folder. -- JZ From http Thu Oct 13 16:50:57 2005 From: http (Paul Rubin) Date: 13 Oct 2005 13:50:57 -0700 Subject: Send password over TCP connection References: <1128956787.454699.239210@z14g2000cwz.googlegroups.com> <1128979760.251637.316480@o13g2000cwo.googlegroups.com> <1129033311.936104.140960@g14g2000cwa.googlegroups.com> <1129235140.938321.134990@g49g2000cwa.googlegroups.com> Message-ID: <7xfyr56szy.fsf@ruckus.brouhaha.com> "dcrespo" writes: > Ok, I understand... What about the MD5? Is it good enough to use when > saving a hashed password on the database? > > For example: > user_input = raw_input("Type your password: ") > password = md5.md5(user_input).hexdigest() > SavePasswordInDatabase(user,password) The usual way to do it is something more like: import os,binascii salt = binascii.b2a_base64(os.urandom(6))[:6] user_input = raw_input("Type your password: ") password = md5.md5(salt + user_input).hexdigest() SavePasswordInDatabase(user,salt,password) The random salt slows down offline dictionary attacks against the database. Say you have 1000 accounts on your system and the attacker needs just one password to log in and mess with stuff. With your scheme, he hashes each word in a large dictionary (say a million words), sorts on the hash values, sorts your hashed password list on its hash values, then compares the two sorted lists and if there's even one match, you're cooked. Each hash he computes can be compared against all your accounts in parallel. The salt means he has to do them one by one, slowing him down by a factor of 1000. However, computers are now fast enough that dictionary attacks against every single password are a serious threat. If you have a way of storing a secret key K, then rather than using unkeyed md5(whatever), use hmac(K, whatever). But revealing K effectively turns the hmac into an unkeyed hash. Can you say what your application is? That will help figure out how far you need to go to protect these passwords, and what alternatives might be possible. I highly recommend the book "Security Engineering" by Ross Anderson for a good cultural introduction to what you're getting into when you program this stuff. It's a fun book to read, too. From sherm at dot-app.org Sat Oct 1 00:18:44 2005 From: sherm at dot-app.org (Sherm Pendley) Date: Sat, 01 Oct 2005 00:18:44 -0400 Subject: OT: Phases of the moon References: <1128003857.930444.47650@g14g2000cwa.googlegroups.com> <1128013745.763757.144280@g44g2000cwa.googlegroups.com> <1128015868.201617.153240@g14g2000cwa.googlegroups.com> <0001HW.BF63479501083049F0407550@news.individual.de> Message-ID: Steven D'Aprano writes: > On Fri, 30 Sep 2005 18:02:14 -0400, Sherm Pendley wrote: > >> axel at white-eagle.invalid.uk writes: >> >>> I wonder if his postings are related to the phases of the moon? It >>> might explain a lot. >> >> Yes, it would. Note that the word lunatic is derived from the Latin word >> luna, meaning moon. > > Yes, lunatic is derived from luna, but that doesn't mean the two are > connected. The ancients believed a lot of crap *whoosh* That, my friend, was the sound of a joke flying past and completely missing you. ;-) sherm-- -- Cocoa programming in Perl: http://camelbones.sourceforge.net Hire me! My resume: http://www.dot-app.org From aleaxit at yahoo.com Sun Oct 30 21:10:29 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 30 Oct 2005 19:10:29 -0700 Subject: putting a string in Mac Address form References: <1130725458.938638.221840@z14g2000cwz.googlegroups.com> Message-ID: <1h59ei1.17rlu1r15svrd1N%aleaxit@yahoo.com> kyle.tk wrote: ... > new_mac = '' > c = 0 > while len(new_mac) < 16: > new_mac += mac[c:c+2] + ':' > c=c+2 > return new_mac[:-1].upper() ... > The part I think is bad is the while loop part. Could it be better? What about replacing this whole block with, say...: return ':'.join(mac[c:c+2] for c in range(0, 12, 2)).upper() (as you did already check that len(mac) is 12...) Alex From duncan.booth at invalid.invalid Fri Oct 14 16:24:03 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 14 Oct 2005 20:24:03 GMT Subject: Inheritance... References: <1129320387.840646.284580@g14g2000cwa.googlegroups.com> Message-ID: KraftDiner wrote: > I have a base class > > class geometry(object): > def __init__(self): > self.blue = 1 > self.red = 2 > def render(self): > pass > > class square(geometry): > def __init__(self): > super(square, self).__init__() > def render(self) > print 'square' > > class circle(geometry): > def __init__(self): > super(square, self).__init__() > def render(self) > print 'square' > > objLst = [] > objLst.append(square()) > objLst.append(circle()) > > for obj in objLst: > obj.render() > print obj.blue > > What is wrong with this... I will not print blue... (1) > > a) No need to post your question twice. b) When posting your code, you should post the actual code you have a problem with. The code you posted here contains syntax errors, so I presume you miscopied, or paraphrased it. So, first fix your syntax errors. Then correct the occurrences of the word 'square' in the class 'circle'. Then your code will print 1. From sam at email-scan.com Fri Oct 7 20:50:26 2005 From: sam at email-scan.com (Sam) Date: Fri, 07 Oct 2005 19:50:26 -0500 Subject: C/API Clarification References: Message-ID: Jeremy Moles writes: > in the world I got the idea from! According to the docs, METH_VARARGS is > (PyObject*, PyObject*)? Right. > My prototype shouldn't even compile... but it Why wouldn't it compile? > 2. No where in the docs does it show how to "correctly" create an > instance of your custom PyTypeObject in C (rather than in the > interpreter). I'm using: That's what tp_alloc is for. Then you call tp_init to initialize it. But, your tp_new handler should already invoke tp_alloc, so it's cleaner to call tp_new, followed by tp_init. > 3. I'm not able to return the "self" argument (useful, for instance, > when you want to chain a group of method calls) without screwing things > up really, really bad. For example: > > PyObject* somefunc(cstruct* self, PyObject* args, PyObject* kargs) { > self->pointerToData->doSomeStuff(); > > return (PyObject*)(self); > } > > ...returns "something"; it has the methods you would expect, but trying > to use the object when it gets back to the interpreter is pretty much > undefined behavior. :) It's seen as a "" instance in the > interpreter, even though a dir() shows it still has the methods you > would expect. You need to increment the reference count of the object, in this case. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From samschul at pacbell.net Mon Oct 10 19:28:37 2005 From: samschul at pacbell.net (sam) Date: 10 Oct 2005 16:28:37 -0700 Subject: Wanted: Python module allowing direct access to raw sectors ofharddrives (MFT, boot sector, etc.) in MS Windows In-Reply-To: <3r09niFh717sU1@individual.net> References: <3r04p5Fh4lshU1@individual.net> <3r09niFh717sU1@individual.net> Message-ID: <1128986917.703980.35230@z14g2000cwz.googlegroups.com> The following site contains my routines to access information from the Microsoft SCSIPASSTHROUGH layer under windows. These routines allow you to access the storage devices mounted under windows using SCSI commands. The dll that I provide will work with Python 2.3 http://starship.python.net/crew/samschul/ Sam Schulenburg Claudio Grondi wrote: > Thank you Jeff very much for your quick reply. > It saved me really much time of digging in the wrong direction. > > wrote in > news:... > >> I took the advice from this web page: > >> http://support.microsoft.com/kb/q100027/ > Ok, I had found this page myself during Googling, but I have missed just > to try to use the described way of addressing physical devices with file > opening in Python. > It works as expected with harddrives so you are right that you are getting > the MBR with the proposed code. > > After some not always happy end adventures with Python > scripting I am impressed by the power of the concept behind > the language once again. > > Claudio > > >>(I don't know how this extends to floppies, and the 9x family of OSes > isn't > >>listed in "applies to", so this may not help your case) > >>Here, I open "physical drive 0" and see that the magic number indicates a > valid > >>boot record. I believe it is the MBR. > >>>>> f = open('\\\\.\\PhysicalDrive0', 'rb') > >>>>> f.read(512)[-2:] > >>'U\xaa' # that is, hex 55 AA > >>I don't know much about low-level filesystem or partition details--I got > the > >>tidbit about the 55 AA magic number from > >>http://www-uxsup.csx.cam.ac.uk/pub/doc/suse/sles9/adminguide-sles9/ch08.ht > ml > >>Jeff > >> schrieb im Newsbeitrag > news:mailman.1864.1128983425.509.python-list at python.org... From apardon at forel.vub.ac.be Wed Oct 19 05:41:09 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 19 Oct 2005 09:41:09 GMT Subject: Microsoft Hatred FAQ References: <86ll0vs1sw.fsf@bhuda.mired.org> <867jcbzdw9.fsf@bhuda.mired.org> <4vcbl1dkek9kr86embmgrj70vk945t99ho@4ax.com> <35jbl1dprs4v1o87i0tapc2husjqiqm6fi@4ax.com> <4355ea72$1_3@news.melbourne.pipenetworks.com> Message-ID: Op 2005-10-19, David Schwartz schreef : > > "Luke Webber" wrote in message > news:4355ea72$1_3 at news.melbourne.pipenetworks.com... > >> As much as I hate to jump in on this thread, well I'm gonna... > >> I think you'll find that companies have all manner of legal obligations. >> Certainly to their shareholders, but beyond that they have an obligation >> to their clients, who pay them for their services, and to any individual >> or entity which might be harmed by their actions. > > They have obligations to their clients because (and only because) > failure to provide the services they contract to provide will result in > lawsuits and harm to the shareholders. All other obligations come from the > harm these failures will do to the shareholders. First and formost, > companies exist to do the will of their shareholders. Do I understand correctly. Lets take the following situation: A company figures out something is wrong with one of their new models. They have two options. They can repair the problem or they can leave it as is and brace the laswsuits that will likely follow. An analysis shows that the first option is likely to cost more than the second. As far as I understand you, the company should ship the faulty model. -- Antoon Pardon From kent37 at tds.net Sat Oct 29 14:49:33 2005 From: kent37 at tds.net (Kent Johnson) Date: Sat, 29 Oct 2005 14:49:33 -0400 Subject: extracting numbers from a file, excluding fixed words In-Reply-To: <1130608130.154921.47840@g49g2000cwa.googlegroups.com> References: <1130608130.154921.47840@g49g2000cwa.googlegroups.com> Message-ID: <4363c20c$1_1@newspeer2.tds.net> dawenliu wrote: > Hi, I have a file with this content: > xxxxxxx xxxxxxxxxx xxxxx xxxxxxx > 1 > 0 > 0 > 0 > 1 > 1 > 0 > (many more 1's and 0's to follow) > yyyyy yyyyyy yyy yyyyyy yyyyy yyy > > The x's and y's are FIXED and known words which I will ignore, such as > "This is the start of the file" and "This is the end of the file". The > digits 1 and 0 have UNKNOWN length. I want to extract the digits and > store them in a file. Any suggestions will be appreciated. > Off the top of my head (not tested): inf = open('input.txt') out = open('output.txt', 'w') skips = [ 'xxxxxxx xxxxxxxxxx xxxxx xxxxxxx', 'yyyyy yyyyyy yyy yyyyyy yyyyy yyy', ] for line in inf: for skip in skips: if skip in line: continue out.write(line) inf.close() out.close() Kent From fredrik at pythonware.com Sun Oct 30 12:14:03 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 30 Oct 2005 18:14:03 +0100 Subject: process and spinning slash References: <1130690731.654048.157590@g14g2000cwa.googlegroups.com> <1h58mez.1jo7cnd1lilqm2N%aleaxit@yahoo.com> Message-ID: Alex Martelli wrote: > Have the spin function accept the pid argument and exit the loop if said > pid has terminated; to check the latter, e.g., os.kill(pid, 0) -- this > will raise an OSError if no process with that pid exists, so you can use > a try/except OSError: to catch that and break as appropriate. or use the subprocess module instead of fork/exec, pass the Popen instance to spin, and use the poll() method to check if the process is still running. From gregpinero at gmail.com Wed Oct 12 23:25:45 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Wed, 12 Oct 2005 23:25:45 -0400 Subject: Looking for a Python mentor In-Reply-To: <1129167866.253155.157850@g43g2000cwa.googlegroups.com> References: <1129167866.253155.157850@g43g2000cwa.googlegroups.com> Message-ID: <312cfe2b0510122025i6bd1f372h5c1428d5a7a9f417@mail.gmail.com> What kind of programming do you do, Len? I'm by no means an expert Python programmer but I could look over a few of your programs anyway. I'd reccomend to always try to challenge yourself. Don't just program something one way just because it's all you know. Take 20 minutes now and then to learn a new skill even if it breaks old coding habits. Perhaps a simple anecdote would illustrate this. My first year programming Python I was always building strings as: str1=var1 + 'greg' + somethingelse + "more chars" + anothervar However I always saw everyone else doing: str1="%s greg %s more chars %s" % (var1,somethingelse,anothervar) But I always figured it wasn't worth learning and my style was just fine! Finally one day I got curious and took the 20 minutes and learned how the formatting operaters work. It's really helped my programming and just made my programs more intuitive. And I find it more attractive to see the whole string almost as it will end up instead of broken up by '+'s everywhere. I'm sure there are lots of examples of little things like that, that you can pick up here and there. -Greg On 12 Oct 2005 18:44:26 -0700, LenS wrote: > > Hello > > Was wandering if there is any place where some one could go to get > mentoring on python coding. I have started coding in python but I am > the only one in the shop using it. So there is no one around to look > over my code give suggestions on improvement, in style, logic, easier > ways of doing things etc. I am not really looking for hand holding as > much mentoring. I have purchased about every python book out and have > a list a mile long on my internet bookmarks. I believe I have a good > grasp of the fundamentals procedurally and I am fighting my way through > OOP. I am more at the stage of trying to pull things together into > programs that perform real world tasks. At one point I thought I saw > some place on one of the web site that did this kind of thing but I > can't find it now. > > Any help or suggestions welcomed > Len Sumnler > > -- > 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 samrobertsmith at gmail.com Mon Oct 10 03:10:56 2005 From: samrobertsmith at gmail.com (Shi Mu) Date: Mon, 10 Oct 2005 00:10:56 -0700 Subject: line In-Reply-To: <1128927863.163722.310000@o13g2000cwo.googlegroups.com> References: <1128927863.163722.310000@o13g2000cwo.googlegroups.com> Message-ID: <1d987df30510100010j180bc15er18224390ddbfe7be@mail.gmail.com> it is not a homework, just interested. On 10 Oct 2005 00:04:23 -0700, gsteff wrote: > Why do you want to know? This list isn't a tool to get others to do > your homework. > > Greg > > -- > http://mail.python.org/mailman/listinfo/python-list > From twic at urchin.earth.li Wed Oct 12 20:30:23 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Thu, 13 Oct 2005 01:30:23 +0100 Subject: Python's garbage collection was Re: Python reliability In-Reply-To: <1h4a5l4.13vx8k7etyxy1N%aleax@mail.comcast.net> References: <7xr7au1hr5.fsf@ruckus.brouhaha.com> <7xwtkl21hn.fsf@ruckus.brouhaha.com> <7xll11twc2.fsf@ruckus.brouhaha.com> <1h4a5l4.13vx8k7etyxy1N%aleax@mail.comcast.net> Message-ID: On Tue, 11 Oct 2005, Alex Martelli wrote: > Tom Anderson wrote: > ... >> Has anyone looked into using a real GC for python? I realise it would be a > > If you mean mark-and-sweep, with generational twists, Yes, more or less. > that's what gc uses for cyclic garbage. Do you mean what python uses for cyclic garbage? If so, i hadn't realised that. There are algorithms for extending refcounting to cyclic structures (i forget the details, but you sort of go round and experimentally decrement an object's count and see it ends up with a negative count or something), so i assumed python used one of those. Mind you, those are probably more complex than mark-and-sweep! >> lot more complexity in the interpreter itself, but it would be faster, >> more reliable, and would reduce the complexity of extensions. > > ??? It adds no complexity (it's already there), it's slower, Ah. That would be why all those java, .net, LISP, smalltalk and assorted other VMs out there, with decades of development, hojillions of dollars and the serried ranks of some of the greatest figures in computer science behind them all use reference counting rather than garbage collection, then. No, wait ... > it is, if anything, LESS reliable than reference counting (which is way > simpler!), Reliability is a red herring - in the absence of ill-behaved native extensions, and with correct implementations, both refcounting and GC are perfectly reliable. And you can rely on the implementation being correct, since any incorrectness will be detected very quickly! > and (if generalized to deal with ALL garbage) it might make it almost > impossible to write some kinds of extensions (ones which need to > interface existing C libraries that don't cooperate with whatever GC > collection you choose). Lucky those existing C libraries were written to use python's refcounting! Oh, you have to write a wrapper round the library to interface with the automatic memory management? Well, as it happens, the stuff you need to do is more or less identical for refcounting and GC - the extension has to tell the VM which of the VM's objects it holds references to, so that the VM knows that they aren't garbage. > Are we talking about the same thing?! Doesn't look like it, does it? >> So python doesn't use the old SmallTalk 80 SmallInteger hack, or similar? >> Fair enough - the performance gain is nice, but the extra complexity would >> be a huge pain, i imagine. > > CPython currently is implemented on a strict "minimize all tricks" > strategy. A very, very sound principle. If you have the aforementioned decades, hojillions and serried ranks, an all-tricks-turned-up-to-eleven strategy can be made to work. If you're a relatively small non-profit outfit like the python dev team, minimising tricks buys you reliability and agility, which is, really, what we all want. tom -- That's no moon! From mlh at selje.idi.ntnu.no Wed Oct 19 09:11:14 2005 From: mlh at selje.idi.ntnu.no (Magnus Lie Hetland) Date: Wed, 19 Oct 2005 13:11:14 +0000 (UTC) Subject: ANN: Beginning Python (Practical Python 2.0) Message-ID: I guess it has actually been out for a while -- I just haven't received my copies yet... Anyways: My book, "Beginning Python: From Novice to Professional" (Apress, 2005) is now out. It is an expanded and revised version of "Practical Python" (Apress, 2002). More information can be found at http://hetland.org/writing/beginning-python Thanks, - Magnus -- Magnus Lie Hetland "Preparing to stand by." http://hetland.org -- Microsoft Windows From bearophileHUGS at lycos.com Sun Oct 30 03:30:22 2005 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 30 Oct 2005 01:30:22 -0700 Subject: How do I sort these? References: <1130524906.918612.38540@g49g2000cwa.googlegroups.com> Message-ID: <1130661022.955974.262620@f14g2000cwb.googlegroups.com> # This can be a solution: from operator import itemgetter seq1a = ([2] * 4) + ([1] * 4) seq2a = [complex(3-el,7-el) for el in range(1, 9)] assert len(seq1a) == len(seq2a) print seq1a, seq2a, "\n" mix = zip(seq1a, seq2a) # mix.sort() # Not possible mix.sort(key=itemgetter(0)) # If you need tuples output: seq1b, seq2b = zip(*mix) print seq1b, seq2b, "\n" # Alternative, lists output: seq1b = [el[0] for el in mix] seq2b = [el[1] for el in mix] print seq1b, seq2b, "\n" Bye, bearophile From mblume at socha.net Fri Oct 21 10:04:13 2005 From: mblume at socha.net (Martin Blume) Date: Fri, 21 Oct 2005 16:04:13 +0200 Subject: finding a number... References: Message-ID: <4358f55d$0$1146$5402220f@news.sunrise.ch> "Enrique Palomo Jim?nez" > > After ftp a file from mvs to windows, i find: > is an offset, so up to 2GB, a commercial application > drives crazy > [...] > ??? I didn't understand your question, but 2 GB is popular limit for the maximal size of a file for some filesystems (e.g. ext2, FAT [???]). Maybe this helps, otherwise you'd have to reformulate the question. HTH. YMMV. Martin From nicogrubert at gmail.com Mon Oct 10 03:53:35 2005 From: nicogrubert at gmail.com (Nico Grubert) Date: Mon, 10 Oct 2005 09:53:35 +0200 Subject: Question about parsing a string Message-ID: <434A1DFF.7080203@gmail.com> Hi there, I would like to parse a string in Python. If the string is e.g. '[url=http://www.whatever.org][/url]' I would like to generate this string: 'http://www.whatever.org' If the string is e.g. '[url=http://www.whatever.org]My link[/url]' I would like to generate this string: 'My link' Any idea how I can do this? Maybe with regular expressions? Thanks in advance, Nico From gsakkis at rutgers.edu Thu Oct 20 21:54:52 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Thu, 20 Oct 2005 21:54:52 -0400 Subject: DBM scalability Message-ID: <1129859697.05de93f92162ac35884e384d6b4d3df1@teranews> I'm trying to create a dbm database with around 4.5 million entries but the existing dbm modules (dbhash, gdbm) don't seem to cut it. What happens is that the more entries are added, the more time per new entry is required, so the complexity seems to be much worse than linear. Is this to be expected and if so, should I expect better performance (i.e. linear or almost linear) from a real database, e.g. sqlite ? George From steve at REMOVETHIScyber.com.au Sun Oct 16 03:49:50 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 16 Oct 2005 17:49:50 +1000 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: On Sun, 16 Oct 2005 05:26:51 +0000, John Bokma wrote: > Steven D'Aprano wrote: > >> On Sun, 16 Oct 2005 00:47:09 +0000, John Bokma wrote: >> >>> Ok, let me spell it out for you: If all your applications are web >>> based, and the OS shouldn't matter, why do Linux distributions >>> matter? It doesn't matter which one you use to run, for example, >>> OpenOffice. Yet people pick a certain distribution. Why? Well, one >>> reason is that people like to belong to a group. So even if it really >>> doesn't matter which OS you are going to use to access a web >>> application, or even which browser, people will pick a certain >>> browser, and a certain OS, just because. >> >> Dude, do you think that Microsoft gives a rat's tail[1] for what a >> handful of computer enthusiasts and geek programmers pick? > > So you missed the point again. "Again"? What exactly *is* your point? You seem to be oscillating from "Microsoft doesn't care what browser people use" to "Microsoft cares deeply what browser people use". I don't understand what you are trying to say. >> They want >> to control the business world, and believe me, corporations don't pick >> the OS of their computer because they want to join a community, they >> pick the OS that lets them run the applications that their business >> needs to run. > > So basically you're saying that even if web based applications become > the shit, everybody keeps running Microsoft? So I am right :-) No. My point is, IF web-based apps become popular, and back in the 1990s people thought that they would, and they would run on any browser, then you could run your browser on any operating system on any hardware. That's what Microsoft wanted to stop, by gluing the browser to the OS. >> Operating-system independent browser-based applications threaten the >> ability of Microsoft to tie that choice to Windows. > > Ah, sure, you really think that a business is going to run office > applications on a web server? Are they already moving to Linux with > OpenOffice (free as in speech?). As I said, back in the 90s that's what people thought, including Microsoft. As for OpenOffice, yes, there is a slow migration away from MS Office. If you are in the US, the UK or Australia, you probably won't have noticed it, since it is a tiny trickle in those countries. But in the emerging IT markets of Asia (especially China), Europe and South America, that trickle has become a steady stream. Especially now that Gartner has claimed that migrating from current versions of Office to Office 12 will cost ten times more for training alone than migrating to OpenOffice, I think we can expect to see that trickle start gushing in the next twelve months or so. >> That is why MS >> decided to bundle IE with Windows and (try to) kill off Netscape as a >> competitor. > > So and when exactly do we see the web based office? Rumour has it that Google is preparing to do exactly that. Personally, I don't see the point. I would never use a web-based office suite, but then I don't even like web mail. What's more important these days from Microsoft's strategic planning is multimedia. Yes, they want -- need -- to keep control of the office suite, Office gives them something like 1/2 their revenue. But for the long-term, they want to lock folks into their proprietary Internet-based multimedia systems (e.g. streaming wmv over mms) because they think that this will give them control of a very lucrative business. I can't really disagree with them. -- Steven. From cowie.rob at gmail.com Thu Oct 13 03:57:34 2005 From: cowie.rob at gmail.com (Rob Cowie) Date: 13 Oct 2005 00:57:34 -0700 Subject: Looking for a Python mentor In-Reply-To: <1129167866.253155.157850@g43g2000cwa.googlegroups.com> References: <1129167866.253155.157850@g43g2000cwa.googlegroups.com> Message-ID: <1129190254.745763.59460@g47g2000cwa.googlegroups.com> I'll gladly give you a hand. I should point out - I'm no expert. I think I've reached a point a bit beyond yours; I learnt OO programming principles with java and have spent this last Summer learning python. I have a good grasp of it. If you want to get in touch, email rob_cowie AT mac DOT com From rune.strand at gmail.com Wed Oct 12 03:43:27 2005 From: rune.strand at gmail.com (Rune Strand) Date: 12 Oct 2005 00:43:27 -0700 Subject: Adding a __filename__ predefined attribute to 2.5? References: <1129098667.336115.303060@g47g2000cwa.googlegroups.com> Message-ID: <1129103007.870187.101790@g44g2000cwa.googlegroups.com> I Steve, I know it's several ways to isolate the filename. I just want to avoid the overhead of importing sys or os to achieve it. Currently I have this in my scripts: __filename__ = __file__.replace('\\', '/').rsplit('/', 1)[-1] From bignose+hates-spam at benfinney.id.au Mon Oct 31 02:32:34 2005 From: bignose+hates-spam at benfinney.id.au (Ben Finney) Date: Mon, 31 Oct 2005 18:32:34 +1100 (EST) Subject: Rich __repr__ References: Message-ID: Ben Finney wrote: > If I want to implement a __repr__ that's reasonably "nice" to the > programmer, what's the Right Way? Are there recipes I should look > at? As a (carefully selected) example from the code I'm writing: >>> import lib.attribute >>> m = lib.attribute.Human_Sex("male") >>> m Human_Sex(name='male') >>> isinstance(m, basestring) True >>> print m male Thus, a Human_Sex instance is a string, and that's how it prints (because of the __str__ attribute of the 'str' type). But since there are potentially other things to know about a Human_Sex instance, the __repr__ is overridden to give an idealised constructor call for the instance. class Human_Sex(str): def __repr__(self): repr_str = "%s(name=%s)" % ( self.__class__.__name__, str.__repr__(self) ) return repr_str def __init__(self, name): str.__init__(name) # [... other initialisation for this class ...] I've simplified somewhat; Human_Sex is actually just one possible attribute being implemented, and the above methods actually come from a superclass. I'm looking for how to do this in general, and this is a simple enough example of what I want. Is this __repr__ implementation too complex? Too simple? Limited in some way? Confusingly non-standard? -- \ "Laurie got offended that I used the word 'puke.' But to me, | `\ that's what her dinner tasted like." -- Jack Handey | _o__) | Ben Finney From steve at holdenweb.com Sun Oct 16 05:34:26 2005 From: steve at holdenweb.com (Steve Holden) Date: Sun, 16 Oct 2005 10:34:26 +0100 Subject: UI toolkits for Python In-Reply-To: <3ras6oFit2djU1@individual.net> References: <7xslv56ud1.fsf@ruckus.brouhaha.com> <3ras6oFit2djU1@individual.net> Message-ID: Claudio Grondi wrote: > "Kenneth McDonald" wrote in > news:mailman.2032.1129236372.509.python-list at python.org... > >>Thanks for reminding me of Gtk. OK, add that to the list. >> >>The Web Browser interface is good for simple things, and will get better >>with CSS2's adoption, but they still don't have a good way for important >>things like interactive styled text, key bindings, etc. Good for >>simple things >>(for which I use them), not for more complex stuff. > > > I don't fully understand your attitude here. The Web Browser interface has > all I can imagine is required for a GUI, so what is missing when you > consider, that you can generate custom images on the fly on the server and > let the user shape the page without requesting CPU power from the server > using JavaScript. In this case then, I'm afraid the failure is in your imagination :-) > I don't even name here the not really beeing itegral part of Internet > Browsers JavaApplets and any other kind of plugin stuff. > The only issue I can see with this approach is the speed of responding to > user interactions, but for really optimize this one needs a compiled > language anyway. > What is that complex, that it can't be solved using an Internet Browser as a > GUI? > Do I miss here something? > While you are correct in saying (I paraphrase) that HTML interfaces nowadays can offer a rich graphical interface, it can be quite difficult to manage state maintenance between the two components (web server, web client) in the system. A "proper" GUI runs all functionality inside a single process, and allows much easier control over complex interactions, creation of dynamic dialogues, and so on. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From vyzasatya at gmail.com Fri Oct 7 09:08:51 2005 From: vyzasatya at gmail.com (vyzasatya at gmail.com) Date: 7 Oct 2005 06:08:51 -0700 Subject: How to run python scripts with IDLE Message-ID: <1128690531.661166.102690@g14g2000cwa.googlegroups.com> Hi all, My problem is # I have to run a script which takes a command line parameter which is unicode text # I cant use Windows console as it doesnt support /display unicode # I dont seems to find a way to pass command line arguments to scripts in IDLE. Please suggest me what I can do. Thanks in Advance Ravi From bosteen at maysubdivide.org Thu Oct 27 10:48:53 2005 From: bosteen at maysubdivide.org (Ben O'Steen) Date: Thu, 27 Oct 2005 15:48:53 +0100 (BST) Subject: Help: Quick way to test if value lies within a list of lists of ranges? Message-ID: <40824.213.235.52.66.1130424533.squirrel@www.maysubdivide.org> Scenario: ========= Using PyGame in particular, I am trying to write an application that will run a scripted timeline of events, eg at 5.5 seconds, play xxx.mp3 and put the image of a ball on screen, at 7.8 seconds move the ball up and down. At this point, I hear you say 'Oh, like Flash'. Yes, well... Like Flash, but I don't want to take this app in the same direction as Macromedia took Flash, nor do I (ever) want the two to be compatible. One particular need is for the timeline to be quickly traversable. If I want to go to time=239.4 seconds, I'd like it to go there pretty much painlessly and hopefully with one call. (Same with play, reverse and pause really) I also want it to play for a long duration, with lots of different items (images, audio, etc.) Let me be a little more specific: sprite(a) -> (onscreen during) 2 - 10 secs, 20 - 50 secs sprite(b) -> (onscreen during) 15 - 30 secs sprite(c) -> (onscreen during) 42 - 50 secs .... I need a quick way to rattle off a list of sprites that should be on screen at a given time. Needless to say the number of sprites will be variable, and might even change unpredictably in game. E.G. onscreen(time = 8.8 secs): return [sprite(a)] onscreen(time = 44.134 secs): return [sprite(a), sprite(c)] onscreen(time = 28 secs): return [sprite(a), sprite(b)] (NB Anything from 10 -> 200 sprites would be normal intended usage, each set -up with a list of start,stop times.) Any suggestions on a clever way to do this? I don't like the idea of looping through 100+ sprites and test them each an arbitary number of times every update. Is this just something unavoidable which should be written in C for speed and included with SWIG or something similar? Ben (Anti-Zealotry ward) :0: * ^Subject:.*Re: Microsoft Hatred FAQ | gzip >> junk-archive.gz IMO, We all have our personal experience or beliefs as to how MS operates. Petitioning MEP's/Senators will accomplish more than arguing on a Python mailing list. From alevinci at cheapnet.it Fri Oct 14 09:40:14 2005 From: alevinci at cheapnet.it (Vinci) Date: 14 Oct 2005 06:40:14 -0700 Subject: Node Subtree Message-ID: <1129297214.916954.306340@g49g2000cwa.googlegroups.com> Hi, I'm using Python to work on Xml documents importing the minidom module: in particular I need to get the whole subtree rooted at a given node "n". Does anyone know whether there is a way to find it with a function /class or by importing another module? Thank you! -- Alevi From flupke at nonexistingdomain.com Thu Oct 27 10:36:30 2005 From: flupke at nonexistingdomain.com (flupke) Date: Thu, 27 Oct 2005 14:36:30 GMT Subject: time conversion Message-ID: Is there an easy to convert following hour notation hh:mm to decimals? For instance 2 hours and 30 minutes as 2:30 to 2,50 I don't really know where to search for this kind of conversion. Thanks, Benedict From sidanko at scientist.com Wed Oct 26 12:50:55 2005 From: sidanko at scientist.com (sidanko) Date: 26 Oct 2005 09:50:55 -0700 Subject: WinXP vs. Win98 In-Reply-To: References: <1130331088.292656.213430@g47g2000cwa.googlegroups.com> Message-ID: <1130345455.653853.256940@z14g2000cwz.googlegroups.com> Thanks a lot! I have set the environment variable and now it runs just fine! From http Mon Oct 10 10:46:27 2005 From: http (Paul Rubin) Date: 10 Oct 2005 07:46:27 -0700 Subject: socketServer questions References: <1128699247.9040.15.camel@athop1.ath.vt.edu> <7xll15paha.fsf@ruckus.brouhaha.com> <1128718708.7800.2.camel@athop1.ath.vt.edu> <7xoe61yoa2.fsf@ruckus.brouhaha.com> <1128774994.14078.2.camel@athop1.ath.vt.edu> <7xu0frogwj.fsf@ruckus.brouhaha.com> <1128948284.15030.7.camel@athop1.ath.vt.edu> <7x4q7po7l2.fsf@ruckus.brouhaha.com> <1128953995.15590.19.camel@athop1.ath.vt.edu> Message-ID: <7xzmph77lo.fsf@ruckus.brouhaha.com> rbt writes: > > Instead, for client #i, let that client's key be something like > > hmac(your_big_secret, str(i)).digest() > > and the client would send #i as part of the string. > > How is this different from sending a pre-defined string from the client > that the server knows the md5 hash of? The clients know the string, the > server knows the hash of that string. I'm confused, I don't understand what that md5 whatever would do for you. I'm assuming the server is secure and the clients are less secure. > Also, could this not be done both ways? So that, if an attacker figures > out the string he's supposed to send from a client to the server (which > he could easily do). He could not easily figure out the string the > server should send back as all he would have is the hash of that string. I'm still confused, are you now trying to prevent the client from accepting bogus stuff from the server? You can do that with a digital signature and not need client-side secrets. But I still don't see much gain from that. > So, before the actual data is sent from the client to the server. The > client would send it's secret string that the server would verify and > then if that worked, the server would send its own secret string that > the client must verify. We'd have two secret strings instead of one. If the client is insecure, an attacker who gets control of it will get all the secrets in it, so it doesn't matter if there's one or several. > Nothing important. It just logs network data. It's an anti-theft program > for laptops that phones home data like this: public and private IP(s), Yeah, if a laptop is stolen and the thief is sophisticated enough to go finding the authentication keys inside some binary, s/he also won't be dumb enough to leave the program active. Those programs are just for dumb thieves (of whom there are a lot) or their customers, who simply plug in the laptop and start using it, without concern about what software is on it. If they have any sense they'll do a total reinstall. But anyway, yeah, people who enroll in the system should get a customer number. Then you can derive an auth key from the customer number as described earlier. From sathyaish at gmail.com Sat Oct 1 22:08:42 2005 From: sathyaish at gmail.com (Sathyaish) Date: 1 Oct 2005 19:08:42 -0700 Subject: How is wxWindows related to Python? In-Reply-To: References: <1128216966.664758.179160@f14g2000cwb.googlegroups.com> Message-ID: <1128218922.138631.171880@g14g2000cwa.googlegroups.com> Thanks, guys. From lsumnler at uniqueinsuranceco.com Wed Oct 12 17:28:36 2005 From: lsumnler at uniqueinsuranceco.com (LenS) Date: 12 Oct 2005 14:28:36 -0700 Subject: Advice on this code Message-ID: <1129152516.432512.80460@g43g2000cwa.googlegroups.com> If this is the wrong place to post this, please advise better place. Otherwise, I have created the following python program and it works. Running on XP. I think I am now at that stage of learning python where I'm not quit a newbie and I am not really knowlegable. I know just enough to be dangerous and can really screw things up. Any suggestion on improving would be greatly appreciated. However my real question is I would like to run this program under a GUI interface and have the GUI have a start button to start this process running and the messages in the program placed in a multiline text field which when the stop button is pressed the text field would be copied to a logfile and the program exited. Below this program is the skeleton of the python gui program using wxPython (the gui program also works). I have a metal block on merging the two programs. I think part of the problem is the first is not really using object except for the database access and the gui is all object. Second, I'am getting all wrapped up with variable, object, etc scope issues. ** FIRST PROGRAM ** """This program is an attempt to modularize the lmsface program. I also will try to document the logic of the program""" import os import glob import time import re import shutil from win32com.client import Dispatch from ADOConstants import * def cvtfiles(): """ cvtfiles is the driving routine for converting and/or changing the V1sta quote flat file being sent by QuotePro to Unique. The function gets a list of the files in the FTP directory path and opens each file one at a time and copies the data (with any necessary changes or additions to the output directory where V1sta's interface program picks it up and converts it into the V1sta's SQL quote files. Individual functions are called to process different segments of the flat file record.""" global novehflag novehflag = False global ofile list1 = glob.glob('*.dat') for f1 in list1: if f1.lower().startswith("unq"): if f1.lower().rfind("void") < 0: print f1 + " is being processed now." input1 = open(cfdir + f1, 'r') output = open(ctdir + f1, 'w+') ifile = input1.readline() output.write(wrkpol(ifile)) output.write(wrkdrv(ifile,1406,6)) output.write(wrkveh(ifile,1784,6)) if novehflag == True: input1.close() output.close() shutil.copy2(cfdir + f1,cfdir + 'voided\\' + f1) os.remove(cfdir + f1) os.remove(ctdir + f1) novehflag = False else: output.write(wrkmisc(ifile,2582)) output.write(wrkviol(ifile,2774,16)) output.write(wrkaccid(ifile,3270,16)) output.write(wrkmisc2(ifile,3638)) output.write(wrkcov(ifile,3666,6)) output.write(wrklp(ifile,4314,7)) output.write(wrkai(ifile,4909,6)) output.write(wrkmisc3(ifile,5707)) output.close() input1.close() shutil.copy2(cfdir + f1,cfdir + 'processed\\' + f1) os.remove(cfdir + f1) print f1 + " has been processed." else: shutil.copy2(cfdir + f1,cfdir + 'voided\\' + f1) os.remove(cfdir + f1) print f1 + " is a VOIDED Quote from QuotePro." else: pass def wrkpol(ifile): """ wrkpol functions converts the policy information segment. Currently the only changes made to the policy segment is to change Current-Carrier-Type to 0 if it contains a 0 or 1 or change Current-Carrier-Type to 1 if it contains a 2""" polwrk = '' polwrk = polwrk + ifile[0:577] polwrk = polwrk + ' ' polwrk = polwrk + ifile[588:653] if ifile[653:654] in ['0','1']: polwrk = polwrk + '0' else: polwrk = polwrk + '1' polwrk = polwrk + ifile[654:974] maxcnt = 6 cnt = 0 strstart = 974 while cnt < maxcnt: if ifile[strstart + 41:strstart + 52] == ' ': polwrk = polwrk + ifile[strstart:strstart + 72] else: polwrk = polwrk + ifile[strstart:strstart + 41] polwrk = polwrk + ' ' polwrk = polwrk + ifile[strstart + 52:strstart + 72] strstart += 72 cnt += 1 return polwrk def wrkdrv(ifile,strstart,maxcnt): """ wrkdrv function at this point just moves the data as is. The driver segment is an occurs 6""" cnt = 0 drvwrk = '' while cnt < maxcnt: if ifile[strstart + 23:strstart + 31] <> ' ': drvwrk = drvwrk + ifile[strstart:strstart + 63] else: drvwrk = drvwrk + ifile[strstart:strstart + 63] strstart += 63 cnt += 1 return drvwrk def wrkveh(ifile,strstart,maxcnt): """ wrkveh function does an SQL record lookup to try an select the correct vehicle in the V1sta make and model files. If the correct model is found I move V1sta's make model and body descriptions to the flat file. Currently, I hard code a 1 for vehicle use. The drive segment is an occurs 6""" global novehflag cnt = 0 vehwrk = '' while cnt < maxcnt: if ifile[strstart:strstart + 10] == ' ': if cnt == 0: print 'No vehicle on quote' novehflag = True vehwrk = vehwrk + ifile[strstart:strstart + 133] else: vehwrk = vehwrk + ifile[strstart:strstart + 133] else: vmake = ifile[strstart:strstart + 10] vyear = ifile[strstart + 98:strstart + 102] vvin4_8 = ifile[strstart +53:strstart + 58] vmodel = '' vbody = '' oParmYear.Value = vyear oParmMake.Value = vmake (oRS, result) = oCmd.Execute() while not oRS.EOF: wvin = oRS.Fields.Item("VO_VIN_NO").Value.replace('*','.') wvin.replace('*','.') wvin = wvin[0:5] r1 = re.compile(wvin) if r1.match(vvin4_8): vmake = oRS.Fields.Item("VA_MK_DESCRIP").Value vmodel = oRS.Fields.Item("VO_MODEL").Value vbody = oRS.Fields.Item("VO_DESCRIPTION").Value vmodelid = oRS.Fields.Item("VO_MODEL_ID").Value print 'DRC model ' + vmake + ' ' + vyear + ' ' + vmodel + \ ' ' + vmodelid vehwrk = vehwrk + vmake + vmodel + vbody break else: oRS.MoveNext() else: vehwrk = vehwrk + ifile[strstart:strstart + 50] print 'DRC model NOT FOUND' vehwrk = vehwrk + ifile[strstart + 50:strstart + 107] vehwrk = vehwrk + '1' vehwrk = vehwrk + ifile[strstart + 108:strstart + 133] strstart += 133 cnt += 1 return vehwrk def wrkmisc(ifile,strstart): """ wrkmisc function was a simplistic way to take care of misc vehicle data which was not formated correctly in the flate file to begin with.""" return ifile[2582:2774] def wrkviol(ifile,strstart,maxcnt): """ wrkviol function is an occurs 6 and is a straight move of the data""" cnt = 0 violwrk = '' while cnt < maxcnt: if ifile[strstart:strstart + 1] <> ' ': violwrk = violwrk + ifile[strstart:strstart + 31] else: violwrk = violwrk + ifile[strstart:strstart + 31] strstart += 31 cnt += 1 return violwrk def wrkaccid(ifile,strstart,maxcnt): """ wrkaccid function is an occurs 6 and is a straight move of the data""" cnt = 0 accdwrk = '' while cnt < maxcnt: if ifile[strstart:strstart + 7] <> ' ': accdwrk = accdwrk + ifile[strstart:strstart + 23] else: accdwrk = accdwrk + ifile[strstart:strstart + 23] strstart += 23 cnt += 1 return accdwrk def wrkmisc2(ifile,strstart): """ wrkmisc2 function is again code to pickup data that probably should have been placed somewhere else but just got tacked on here""" return ifile[3638:3666] def wrkcov(ifile,strstart,maxcnt): """ wrkcov function moves the coverage data on any coverage segment which has towing or rental premium it files in the coverage fields for towing and rental coverage. This is also an occurs 6 field""" cnt = 0 covwrk = '' while cnt < maxcnt: if ifile[strstart + 17:strstart + 19] <> ' ': covwrk = covwrk + ifile[strstart:strstart + 8] if ifile[strstart + 92:strstart + 100] == '0 ': covwrk = covwrk + ifile[strstart + 8:strstart + 12] else: covwrk = covwrk + '50 ' if ifile[strstart + 100:strstart + 108] == '0 ': covwrk = covwrk + ifile[strstart + 12:strstart + 16] else: covwrk = covwrk + '20 ' covwrk = covwrk + ifile[strstart + 16:strstart + 108] else: covwrk = covwrk + ifile[strstart:strstart + 108] strstart += 108 cnt += 1 return covwrk def wrklp(ifile,strstart,maxcnt): """ wrklp function moves the loss payee data with no changes. It is an occurs 7. I am not sure if QuotePro messed up on the occurs which should be a 6 and V1sta just went with the flow or what. In addition there are 3 other field that SHOULD have gone in this segment but are in the Additional Insured segment which are LP-ZIP-CODE-1, LP-ZIP-CODE-2, AND LP-CANCEL-DATE.""" cnt = 0 lpwrk = '' while cnt < maxcnt: if ifile[strstart:strstart] <> ' ': lpwrk = lpwrk + ifile[strstart:strstart + 85] else: lpwrk = lpwrk + ifile[strstart:strstart + 85] strstart += 85 cnt += 1 return lpwrk def wrkai(ifile,strstart,maxcnt): """ wrkai function moves the additional insured information as well as the three loss payee fields mentioned in the wrklp function, go figure. This is an occurs 6""" cnt = 0 aiwrk = '' while cnt < maxcnt: if ifile[strstart:strstart] <> ' ': aiwrk = aiwrk + ifile[strstart:strstart + 133] else: aiwrk = aiwrk + ifile[strstart:strstart + 133] strstart += 133 cnt += 1 return aiwrk def wrkmisc3(ifile,strstart): """ wrkmisc3 just moves the remaining part of the file unchanged""" return ifile[5707:6435] # The following code creates a connection object, # assigns the connection string, opens the # connection object, and then verifies a good # connection. oConn = Dispatch('ADODB.Connection') oConn.ConnectionString = "Provider=SQLOLEDB.1;" +\ "Data Source=uicesv05;" +\ "uid=aiis;" +\ "pwd=aiis;" +\ "database=auto_mo_001" oConn.Open() if oConn.State == adStateOpen: print "Database connection SUCCEEDED" else: print "Database connection FAILED" # The following code creates a command object, # assigns the command to the connection object, # sets the query, creates the parameters objects to # be passed to the command object and requests the # query to be prepared (compiled by the SQL system). oCmd = Dispatch('ADODB.Command') oCmd.ActiveConnection = oConn oCmd.CommandType = adCmdText oCmd.CommandText = """\ SELECT VA_MK_YEAR,VA_MK_DESCRIP,VO_VIN_NO,VO_MODEL,VO_BODY, VO_DESCRIPTION,VO_MODEL_ID FROM D014800 INNER JOIN D014900 ON VA_MK_NUMBER_VER = VO_MAKE_NO AND VA_MK_YEAR = VO_YEAR WHERE VA_MK_YEAR = ? AND VA_MK_DESCRIP = ? """ vyear = '' vmake = '' oParmYear = oCmd.CreateParameter(vyear,adChar,adParamInput) oParmYear.Size = 4 oParmMake = oCmd.CreateParameter(vmake,adChar,adParamInput) oParmMake.Size = 10 oCmd.Parameters.Append(oParmYear) oCmd.Parameters.Append(oParmMake) oCmd.Prepared = True # The following code saves the current working directory # and creates a copy from directory variable and a copy # to directory variable. We then change the working dir. # to the copy from dir. # # The copy from dir. is the FTP library that the raters # send the files to. The copy to dir. is where program # send the changed file to where it is then picked up by # DRC's interface program and entered into the V1sta # system. currdir = os.getcwd() cfdir = currdir + '\\quotepro\\' ctdir = currdir + '\\unique\\' os.chdir(cfdir) # Next comes what is an infinite loop YES on purpose for # right now. I intend to eventually replace this code with # a gui window (as soon as I figure out how). Basicly, the # way the loop wooks is that it will continue looping # through the copy from dir (cfdir) looking for files. # As long as it finds files it will process the files # and then move them to the copy to dir. (ctdir). If no # files are found the program goes into sleep mode for a # short time (currently 15 sec) and then looks in the dir # again. while True: cvtfiles() # If no files are found in the FTP directory the program goes # to sleep for 15 seconds time.sleep(15) # Closes the SQL record set object oRS.Close() oRS = None # Closes the SQL connection if oConn.State == adStateOpen: oConn.Close() oConn = None ** GUI PROGRAM ** """This program is an attempt to modularize the lmsface program. I also will try to document the logic of the program""" import wx import os ID_ABOUT = 101 ID_OPEN = 102 ID_BUTTON1 = 110 ID_BUTTON2 = 120 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() 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, 'E&xit', 'Terminate the program') menuBar = wx.MenuBar() menuBar.Append(filemenu, '&File') self.SetMenuBar(menuBar) wx.EVT_MENU(self, ID_ABOUT, self.OnAbout) wx.EVT_MENU(self, ID_EXIT, self.OnExit) wx.EVT_MENU(self, ID_OPEN, self.OnOpen) self.button1 = wx.Button(self, ID_BUTTON1, '&Start') self.button2 = wx.Button(self, ID_BUTTON2, '&Stop') wx.EVT_BUTTON(self, ID_BUTTON1, self.OnStart) wx.EVT_BUTTON(self, ID_BUTTON2, self.OnStop) self.sizer2 = wx.BoxSizer(wx.HORIZONTAL) self.sizer2.Add(self.button1, 1, wx.EXPAND) self.sizer2.Add(self.button2, 1, wx.EXPAND) self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.control, 1, wx.EXPAND) self.sizer.Add(self.sizer2, 0, wx.EXPAND) 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) d.ShowModal() d.Destroy() def OnExit(self, e): self.Close(True) def OnOpen(self,e): """ Open a file """ self.dirname = '' 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 def OnStart(self, e): self.control.AppendText('Start Button Pressed\n') def OnStop(self, e): self.control.AppendText('Stop Button Pressed\n') class myApp(wx.App): def OnInit(self): frame = MainWindow(None, -1, "QuotePro/V1sta Interface") frame.Show(True) self.SetTopWindow(frame) return True app = myApp() app.MainLoop() From g.franzkowiak at onlinehome.de Sun Oct 2 16:08:17 2005 From: g.franzkowiak at onlinehome.de (g.franzkowiak) Date: Sun, 02 Oct 2005 22:08:17 +0200 Subject: struct.unpack Message-ID: Hello Everybody, I've read a pipe and store it in a object. My next step was the separation from 4 bytes with obj = string.join(list(dataObject)[:4] ==> '\x16 \x00 \x00 \x00' and the converting by value = struct.unpack('I', obj) generated the error "unpack str size does not match format" Unfortunately is len(obj) 7, but integer lengt 4. Why 7 ? Any ideas ? gf From bokr at oz.net Tue Oct 25 16:55:52 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 25 Oct 2005 20:55:52 GMT Subject: namespace dictionaries ok? References: <9Xs7f.4060$Zd.3377@tornado.tampabay.rr.com> Message-ID: <435e998e.950534346@news.oz.net> On Tue, 25 Oct 2005 16:20:21 GMT, Ron Adam wrote: >Duncan Booth wrote: >> Ron Adam wrote: >> >>>James Stroud wrote: >>> >>>>Here it goes with a little less overhead: >>>> >>>> >> >> >> >>>But it's not a dictionary anymore so you can't use it in the same places >>>you would use a dictionary. >>> >>> foo(**n) >>> >>>Would raise an error. >>> >>>So I couldn't do: >>> >>> def foo(**kwds): >>> kwds = namespace(kwds) >>> kwds.bob = 3 >>> kwds.alice = 5 >>> ... >>> bar(**kwds) #<--- do something with changed items >>> >> >> I agree with Steven D'Aprano's reply, but if you are set on it you could >> try this: >> >> >>>>>class namespace(dict): >> >> def __init__(self, *args, **kw): >> dict.__init__(self, *args, **kw) >> self.__dict__ = self >> >> >> >>>>>n = namespace({'bob':1, 'carol':2, 'ted':3, 'alice':4}) >>>>>n.bob >> >> 1 >> >>>>>n.bob = 3 >>>>>n['bob'] >> >> 3 >> >> The big problem of course with this sort of approach is that you cannot >> then safely use any of the methods of the underlying dict as they could be >> masked by values. >> >> P.S. James, *please* could you avoid top-quoting. > >Or worse, the dictionary would become not functional depending on what >methods were masked. > > >And this approach reverses that, The dict values will be masked by the >methods, so the values can't effect the dictionary methods. But those >specific values are only retrievable with the standard dictionary notation. > > class namespace(dict): > __getattr__ = dict.__getitem__ > __setattr__ = dict.__setitem__ > __delattr__ = dict.__delitem__ > > n = namespace() > n.__getattr__ = 'yes' # doesn't mask __getattr__ method. > > print n['__getattr__'] -> 'yes' > >The value is there and __getattr__() still works. But n.__getattr__ >returns the method not the value. > >So is there a way to keep the functionality without loosing the methods? > > >BTW, I agree with Steven concerning data structures. This really isn't >a substitute for a data structure. Many keys will not work with this. > > n.my name = 'Ron' > n.(1,2) = 25 > n.John's = [ ... ] > >The use case I'm thinking of is not as a shortcut for data structures, >but instead, as a way to keep names as names, and maintaining those >names in a group. Thus the namespace association. > > def foo(**kwds): > kwds = namespace(kwds) > print kwds.name > print kwds.value > ... > > name = 'ron' > value = 25 > foo( name=name, position=position ) > Just had the thought that if you want to add bindings on the fly modifying the original object, you could use the __call__ method, e.g., >>> class NameSpace(dict): ... __getattr__ = dict.__getitem__ ... __setattr__ = dict.__setitem__ ... __delattr__ = dict.__delitem__ ... def __call__(self, **upd): ... self.update(upd) ... return self ... >>> def show(x): print '-- showing %r'%x; return x ... >>> ns = NameSpace(initial=1) >>> show(ns) -- showing {'initial': 1} {'initial': 1} And updating with a second keyword on the fly: >>> show(show(ns)(second=2)) -- showing {'initial': 1} -- showing {'second': 2, 'initial': 1} {'second': 2, 'initial': 1} FWIW ;-) Regards, Bengt Richter From ccdetail at gmail.com Wed Oct 26 10:17:12 2005 From: ccdetail at gmail.com (Curt Finch) Date: 26 Oct 2005 07:17:12 -0700 Subject: online story about python In-Reply-To: References: Message-ID: <1130336232.081023.249570@g43g2000cwa.googlegroups.com> http://software.itmanagersjournal.com/software/05/10/25/1631220.shtml?tid=12 has a good article that talks about why python rocks From gmilas at gmail.com Mon Oct 31 19:58:53 2005 From: gmilas at gmail.com (gmilas at gmail.com) Date: 31 Oct 2005 16:58:53 -0800 Subject: Expanding Python as a macro language In-Reply-To: <1130592935.839750.322930@g14g2000cwa.googlegroups.com> References: <1130545600.925061.287390@g49g2000cwa.googlegroups.com> <1130592935.839750.322930@g14g2000cwa.googlegroups.com> Message-ID: <1130806733.803499.250350@g43g2000cwa.googlegroups.com> qwweeeit at yahoo.it wrote: > Imagine you want to access a big database from a html server which > only allows you to access such data in chunks pressing a "next" > button on an ASP file. It will take several hours to click the button > and then save the new data supplied by the server! > That is a typical task of AutoIt, very easily programmable, This may be of some use for you: - http://www.idyll.org/~t/www-tools/twill.html a python tool with a language to script "web commands" - http://maxq.tigris.org/ a java tool with python as macro-language to script "web commands" I would guess, probably any tool designed for testing be it web or gui should have some of the functionality you are looking after? From michaelschneider at fuse.net Fri Oct 14 12:43:43 2005 From: michaelschneider at fuse.net (Michael Schneider) Date: Fri, 14 Oct 2005 12:43:43 -0400 Subject: Problems with properties In-Reply-To: References: Message-ID: <434FE03F.1090507@fuse.net> Thanks to all, I added the object as a subclass (should this be required for 2.4.1 ???) I also switched to the decorator with the @property syntax Thank you very much for the help for adding @property to the language. what a great language :-) Mike Michael Schneider wrote: > Hello All, > > I have been working on learning how to use python properties. > > The get property access is working, but the the set > property is not working. > > Rather then dispatching the property assignment to setNothing, the > property object is being replaced with a string. > > I must be doing something very stupid here. > > Could someone please point out my error, I have dents in my forehead > for this one. > > Thanks, > Mike > > > > ------------------------------------------------------------------ > > from unittest import TestCase > import unittest > > > class Task: > def __init__(self,command): > self._command = command > > def setNothing(self, value): > raise AttributeError > > def getCommand(self): > return self._command > > command=property(getCommand, setNothing) > > > class taskTest(TestCase): > > def testTask(self): > t = Task("dir c:") > c = t.command > self.assertEquals("dir c:", c) > > # should fail, but doesn't > t.command = "foo Bar" > > self.assertEquals("dir c:", t.command) > > > > if __name__ == "__main__": > unittest.main() -- The greatest performance improvement occurs on the transition of from the non-working state to the working state. From gordonb.pru8x at burditt.org Sun Oct 9 19:04:49 2005 From: gordonb.pru8x at burditt.org (Gordon Burditt) Date: Sun, 09 Oct 2005 23:04:49 -0000 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> Message-ID: <11kj8ghonmialfc@corp.supernews.com> >>And how do you fix the problem of unsolicited USENET articles? >>(*ALL* of them are unsolicited to someone). Or unsolicited >>email? > >Read my essay. >http://mindprod.com/projects.html/mailreadernewsreader.html > >I talk around those problems. > >It requires a fresh start. This URL does not work. However, from some of the other replies, it seems that your suggestion involved identification of the sender with digital signatures. I think one necessary function of email and USENET is that it should allow you to SAFELY communicate with strangers or, worse, people you know but do not trust at all, and who are known to be malicious, if you wish to do so, especially since meeting in person might invoke the use of weapons of mass destruction (like, for example, me and my hypothetical ex-wife). For example, George W. Bush ought to be able to exchange email with Osama Bin Laden without risking revealing nuclear launch codes. Hitler and Winston Churchill should have been able to exchange email (had it been available during World War II) without revealing state secrets accidentally. I ought to be able to exchange email with my boss without his being able to track if/when I read it. I ought to be able to communicate with the Direct Marketing Association to get them to take my name off a mailing list without risking spyware installation or revealing my credit card numbers. Union leaders and management should be able to negotiate by email without unwittingly leaking information. HTML is *mostly* dangerous. (links. Javascript. references to other files on the user's computer. Forms.) It's a lot more than text formatting. I suggest that if you want a text formatting language, start with *TROFF* and take out the parts that refer to other files. As far as I know, troff doesn't have any networking references in it. Lots of people probably hate troff, but it's a better start than HTML. Gordon L. Burditt From ggrp1.20.martineau at dfgh.net Thu Oct 6 12:23:44 2005 From: ggrp1.20.martineau at dfgh.net (Martin Miller) Date: 6 Oct 2005 09:23:44 -0700 Subject: replacments for stdio? References: <1127477278.036977.189230@g44g2000cwa.googlegroups.com> <1127670588.872596.117560@o13g2000cwo.googlegroups.com> <1128079278.563621.8310@g47g2000cwa.googlegroups.com> <1128548582.759883.326290@g47g2000cwa.googlegroups.com> <1128597932.529665.51810@g14g2000cwa.googlegroups.com> Message-ID: <1128615824.381261.47200@g14g2000cwa.googlegroups.com> In what way would you like to get "stdin to work"? In Bryan's post in the Application(Frame).__init__() he binds some lambda functions to key strokes which allow control-C copying of text in the window. Seems like additonal application-specific things might be possible, but then the code would no longer be generic. Interaction with the main application would likely be tricky because each output window is lanuched as a separate process when output is first sent to it. As far a redistribution goes, I would think anything posted to the public comp.lang.python usenet newgroup is unencumbered unless the author indicates otherwise -- or at most covered by the same open source license as Python. -Martin Ido.Yehieli at gmail.com wrote: > yes, > I've tried it aswell - nice work indeed! > > now, maybe also get stdin to work from this TK window... ;-) From http Fri Oct 14 17:21:25 2005 From: http (Paul Rubin) Date: 14 Oct 2005 14:21:25 -0700 Subject: Function to execute only once References: <1129317118.937439.159550@g43g2000cwa.googlegroups.com> <1129322058.901077.90680@o13g2000cwo.googlegroups.com> <1129324139.891942.3710@g47g2000cwa.googlegroups.com> Message-ID: <7xzmpbpzfu.fsf@ruckus.brouhaha.com> "snoe" writes: > Also why is it if I set tmp as a global and don't pass it as a > paremeter to the various functions as per the OP that I get an > "UnboundLocalError: local variable 'tmp' referenced before assignment"? If you don't declare it as a global, and if you try to assign a value to it, then Python thinks it's a local. If you only refer to it and never assign it, Python decides it's global. Python is weird that way. One consequence is that if it's local to some outer scope, then it's neither global nor local to your function, so there's no way to assign to it. I think Pythonic style is to not do complex things with closures, but to use class instances instead. From kenneth.m.mcdonald at sbcglobal.net Wed Oct 5 21:18:31 2005 From: kenneth.m.mcdonald at sbcglobal.net (Kenneth McDonald) Date: Wed, 5 Oct 2005 20:18:31 -0500 Subject: What documentation "standard" to use In-Reply-To: <0001HW.BF6A03AA00B1AD5CF0284550@news.individual.de> References: <0001HW.BF6A03AA00B1AD5CF0284550@news.individual.de> Message-ID: This is, as far as I'm concerned, one of the great weaknesses of Python. (One of a relatively few, to be honest--I'm still an enthusiast after all!) There are numerous docstring-oriented tools; in my opinion, none of them are satisfactory, because docstrings only apply to certain entities, and there are many other entities one might wish to document. Fred Lundh pointed out just a day or two ago a program of his called PythonDoc where documentation is put into comments, and from the brief look I had at it, I may start using it, it looks pretty nice. ReStructuredText (now called ReST, I believe) looks like it's finally become a quite good text markup language, and if there were a non-docstring system that used it, I think that also would be good. But what I'd really like is for Guido et al to declare a standard documentation system and include in the standard Python distro. That way we would have _some_ standard, and people could concentrate their energy on improving it, rather than on continually coming up with their own, non-interoperable, solutions. Cheers, Ken On 5-Oct-05, at 3:26 PM, Kalle Anke wrote: > I'm confused of how I should document my code, I've always liked > being able > to document my code directly in my source file and then to use some > tool to > extract the documentation to some other format. > > My problem with Python is that there are so many tools and > formats ... I > don't know which one I should use. I've tried to figure out if > there is one > that is the "de-facto standard" but ... > > Could someone advice me on what format/tool I should use? > > -- > http://mail.python.org/mailman/listinfo/python-list > From grante at visi.com Wed Oct 5 10:52:47 2005 From: grante at visi.com (Grant Edwards) Date: Wed, 05 Oct 2005 14:52:47 -0000 Subject: Call C functions from Python References: <1128454231.381256.297280@g47g2000cwa.googlegroups.com> <1128514161.835258.138730@g44g2000cwa.googlegroups.com> <1128522414.964010.65970@g14g2000cwa.googlegroups.com> Message-ID: On 2005-10-05, Java and Swing wrote: > i tried... > >>> from ctypes import * >>> myapp = cdll.LoadLibrary("c:\\myapp.dll") >>> dumpbin /exports myapp.pyd > > i get, SyntaxError: invalid syntax with it pointing at the first "p" in > myapp.pyd. Um, just a guess, but I don't think that was python code. Try it at a command prompt. -- Grant Edwards grante Yow! The entire CHINESE at WOMEN'S VOLLEYBALL TEAM all visi.com share ONE personality -- and have since BIRTH!! From davids at webmaster.com Thu Oct 27 08:40:39 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 05:40:39 -0700 Subject: Microsoft Hatred FAQ References: <5am333-iia.ln1@news.it.uc3m.es> <4ua533-60t.ln1@news.it.uc3m.es> Message-ID: Roedy Green wrote: > On Thu, 27 Oct 2005 04:06:16 -0700, "David Schwartz" > wrote, quoted or indirectly quoted someone who > said : >> Right, they send gun-wielding thugs to use force against people. >> That's a lot like refusing to do business with people who won't >> uphold their contractual obligations. > You stupid fuck! How many times do I have to tell you. > There was NO contract. Just a THREAT to make me do what they wanted, > to go along with their extortion racket. Getting information from you is like pulling teeth. This threat was to do what they wanted or else .. WHAT? DS From pranab_bajpai at yahoo.com Wed Oct 19 15:51:02 2005 From: pranab_bajpai at yahoo.com (pranab_bajpai at yahoo.com) Date: 19 Oct 2005 12:51:02 -0700 Subject: Python variables are bound to types when used? Message-ID: <1129751462.061785.124830@g49g2000cwa.googlegroups.com> So I want to define a method that takes a "boolean" in a module, eg. def getDBName(l2): ... Now, in Python variables are bound to types when used, right? Eg. x = 10 # makes it an INT whereas x = "hello" # makes it a string I take it, the parameters to a function (in the above example "l2") are bound in the definition, rather than as invoked. So, if I use "l2" thus: if (l2): # only then does it make it a boolean? and if I did, if (l2 = "hello"): # would it become string? and what if I never used it in the definition body? Elucidate please. From richard at nospam.com Sun Oct 9 08:03:26 2005 From: richard at nospam.com (Richard Townsend) Date: Sun, 9 Oct 2005 13:03:26 +0100 Subject: Creating internet shortcuts Message-ID: <1p9jp8i0al14h$.1xmuz4fyfs4m5.dlg@40tude.net> I've seen the python.faqts page: http://www.faqts.com/knowledge_base/view.phtml/aid/4475/fid/538 on how to create windows shortcuts using Python. Does anyone know if this be adapted to create internet shortcuts on windows? (as used for Favorites). Thank you, -- Richard From nil at dev.nul Sun Oct 16 14:00:23 2005 From: nil at dev.nul (Christian Stapfer) Date: Sun, 16 Oct 2005 20:00:23 +0200 Subject: Comparing lists References: <1128930699.799657.146210@g47g2000cwa.googlegroups.com> <1128952417.0544cc73190bbbd4e683448c137969c8@teranews> <434ba977@nntp0.pdx.net> <1129216693.445956.155490@g47g2000cwa.googlegroups.com> Message-ID: "Ron Adam" wrote in message news:jYv4f.152052$xl6.59875 at tornado.tampabay.rr.com... > Christian Stapfer wrote: >> "Ron Adam" wrote in message >> news:cTp4f.16180$ae.11317 at tornado.tampabay.rr.com... >> >>>Christian Stapfer wrote: >>> >>> >>>>This discussion begins to sound like the recurring >>>>arguments one hears between theoretical and >>>>experimental physicists. Experimentalists tend >>>>to overrate the importance of experimental data >>>>(setting up a useful experiment, how to interpret >>>>the experimental data one then gathers, and whether >>>>one stands any chance of detecting systematic errors >>>>of measurement, all depend on having a good *theory* >>>>in the first place). Theoreticians, on the other hand, >>>>tend to overrate the importance of the coherence of >>>>theories. In truth, *both* are needed: good theories >>>>*and* carefully collected experimental data. >>>> >>>>Regards, >>>>Christian >>> >>>An interesting parallel can be made concerning management of production >>>vs >>>management of creativity. >>> >>>In general, production needs checks and feedback to insure quality, but >>>will often come to a stand still if incomplete resources are available. >>> >>>Where as creativity needs checks to insure production, but in many cases >>>can still be productive even with incomplete or questionable resources. >>>The quality may very quite a bit in both directions, but in creative >>>tasks, that is to be expected. >>> >>>In many ways programmers are a mixture of these two. I think I and >>>Steven >>>use a style that is closer to the creative approach. I get the feeling >>>your background may be closer to the production style. >> >> >> This diagnosis reminds me of C.G. Jung, the psychologist, >> who, after having introduced the concepts of extra- and >> introversion, came to the conclusion that Freud was >> an extravert whereas Adler an introvert. The point is >> that he got it exactly wrong... >> >> As to the value of complexity theory for creativity >> in programming (even though you seem to believe that >> a theoretical bent of mind can only serve to stifle >> creativity), the story of the discovery of an efficient >> string searching algorithm by D.E.Knuth provides an >> interesting case in point. Knuth based himself on >> seemingly quite "uncreatively theoretical work" (from >> *your* point of view) that gave a *better* value for >> the computational complexity of string searching >> than any of the then known algorithms could provide. >> >> Regards, >> Christian > > >> (even though you seem to believe that >>> a theoretical bent of mind can only serve to stifle >>> creativity) > > No, that is not at all what I believe. What I believe is, "The insistence > of strict conditions can limit creative outcomes." That's agreed. But going off *blindly*experimenting* without trying to relate the outcome of that experimenting back to ones theoretical grasp of the work one is doing is *not* a good idea. Certainly not in the long run. In fact, muddling-trough and avoiding the question of suitable theoretical support for one's work is perhaps more typical of production environments. > The lack of those limits does not prevent one from using any resources > (including theoretical ones) if they are available. > > You seem to be rejecting experimental results in your views. Not at all. You must have mis-read (or simply not-read) my posts in this thread and are simply projecting wildly, as psychoanalysts would call it, that is all. > And the level of insistence you keep in that view, A view that I do not really have: you are really projecting indeed. > leads me to believe you favor a more productive environment > rather than a more creative one. You are mistaken. Although I have some "practical background" (originally working as a "self-taught" programmer - although, ironically, for a "development and research department"), I went on to study mathematics at the Federal Institute of Technology here in Switzerland. Do you want to say that having been trained as a mathematician makes one uncreative? - But it is true that mathematicians are socialized in such a way that they tend to take over rather high standards of precision and theoretical grounding of their work. > Both are good, and I may entirely wrong about you, .. you are at least *somewhat* wrong about me, that I am quite sure of... > as many people are capable of wearing different hats depending on the > situation. > > I think the gist of this thread may come down to... > > In cases where it is not clear on what direction to go because the choices > are similar enough to make the choosing difficult. It is almost always > better to just pick one and see what happens than to do nothing. As it appears, not even my most recent post has had *any* recognizable effect on your thoroughly misapprehending my position. Regards, Christian From hancock at anansispaceworks.com Fri Oct 7 17:43:11 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Fri, 7 Oct 2005 16:43:11 -0500 Subject: When someone from Britain speaks, Americans hear a "British accent"... In-Reply-To: References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <200510071528.25305.hancock@anansispaceworks.com> Message-ID: <200510071643.11162.hancock@anansispaceworks.com> On Friday 07 October 2005 03:44 pm, Steve Holden wrote: > Precisely because there *is* such a thing as a saving. If I buy a $100 > gumball for $80 I have achieved a saving of 20%. Nope, that's incorrect American. ;-) You can say "I bought a $100 gumball for $80, saving 20%," or "If I buy a $100 gumball for $80, I have achieved a savings of 20%." (Although, you lose points for style with "achieved", and those are awfully expensive gumballs). ;-) -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From deets at nospam.web.de Thu Oct 13 20:26:22 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 14 Oct 2005 02:26:22 +0200 Subject: Setdefault bypasses __setitem__ In-Reply-To: References: <3r6hsnFi3qb8U1@uni-berlin.de> Message-ID: <3r8c9qFhsj84U1@uni-berlin.de> Duncan Booth wrote: > Diez B. Roggisch wrote: > > >>So if setdefault >>was implemented as >> >>def setdefault(self, v): >> self["SOME_DEFAULT_KEY_NAME"] = v > > > if setdefault was implemented that way then all current uses of setdefault > would throw an exception. > > setdefault takes *three* parameters: self, key, value. Once you include the > key parameter your entire argument implodes. Yup. It does implode, leaving me thunderstruck because of my dumbness. I rarely find things in python strange or named incorrectly, but this is IMHO such a case - setdefault led me to think that using it would set a default value to return for _future_ lookups of non-existant keys. That semantics is known in e.g. ruby or java. I think a better name would be getdefault, or even get_setdefault - in oppposition to the get(key, d) form. But now that this became clear to me... I guess I can live with the name :) Diez From tim.golden at viacom-outdoor.co.uk Wed Oct 26 08:22:52 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Wed, 26 Oct 2005 13:22:52 +0100 Subject: Windows vs Linux [was: p2exe using wine/cxoffice] Message-ID: <9A28C052FF32734DACB0A288A3533991044D22A2@vogbs009.gb.vo.local> Tim Golden wrote: > As it happens, (and I suspect I'll have to don my flameproof suit here), > I prefer the Windows command line to bash/readline for day-to-day use, > including in Python. Why? Because it does what I can't for the life of > me get readline to do: you can type the first few letters of a > previously-entered command and press F8. This brings up (going backwards > > with further presses) the last command which starts like that. And > *then* > you can just down-arrow to retrieve the commands which followed it. > If someone can tell me how to do this with bash/readline I will be > indebted to them and it will increase my chances of switching to Linux > a bit! (Although not at work where I have no choice!) [bonono at gmail.com] > But command line in Windows is in no way in the same > league as *nix shell. Use for command completion and up/down > arrow or to search for history. [darren kirby] > Try ctrl-r in bash, then type your first few letters... Thanks to both of you. But that much I already knew. It's not that I have *no* knowledge about readline: I did at least read the manuals when I got stuck! But as far as I can tell from my experience and from the docs -- and I'm not near a Linux box at the mo -- having used ctrl-r to recall line x in the history, you can't just down-arrow to recall x+1, x+2 etc. Or can you? (Sorry guys; I realise this is more stuff for comp.os.linux or comp.commandlineshells.bash or whatever it's called. But if someone *did* know the answer, I'd be really happy!) 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 steve at holdenweb.com Sat Oct 8 05:42:10 2005 From: steve at holdenweb.com (Steve Holden) Date: Sat, 08 Oct 2005 10:42:10 +0100 Subject: When someone from Britain speaks, Americans hear a "Britishaccent"... In-Reply-To: <4346c5a8.0@entanet> References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kbgj7421kd560@corp.supernews.com> <4h5ck1hkqq0ls83pq0lodkb51tsda4053k@4ax.com> <4346c5a8.0@entanet> Message-ID: Duncan Smith wrote: > Rocco Moretti wrote: [...] > > So English is spoken only in the South East of England, except London? > I think you should also disbar the queen (unless she's already > classified as a Londoner), due to her apparent confusion between the 1st > person singular and 1st person plural :-). > There are special rules for the monarchs, who are expected to refer to themselves in the first person plural. Oscar Wilde understood this. When he boasted that he could speak extempore for a minute on any subject of a challenger's choosing someone shouted "The Queen", to which he replied "The Queen, sir, is not a subject". regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From oliver.andrich at gmail.com Sun Oct 23 11:25:11 2005 From: oliver.andrich at gmail.com (Oliver Andrich) Date: Sun, 23 Oct 2005 17:25:11 +0200 Subject: How to separate directory list and file list? In-Reply-To: <0e9nl1tvvgqlhkahkmrrfc810b3ed1unb6@4ax.com> References: <0e9nl1tvvgqlhkahkmrrfc810b3ed1unb6@4ax.com> Message-ID: <6f7b52d0510230825w4b0ae363t@mail.gmail.com> Hi, 2005/10/23, Gonnasi : > With > >glob.glob("*") > > or > >os.listdir(cwd) > > I can get a combined file list with directory list, but I just wanna a > bare file list, no directory list. How to get it? don't know if it is the best solution, but it looks nice. :) path = "/home/test" files = [fn for fn in os.listdir(path) if os.path.isfile(os.path.join(path, fn))] This gives you just the list of files in a given directory. Best regards, Oliver -- Oliver Andrich --- http://roughbook.de/ From lycka at carmen.se Wed Oct 5 03:34:55 2005 From: lycka at carmen.se (Magnus Lycka) Date: Wed, 05 Oct 2005 09:34:55 +0200 Subject: "no variable or argument declarations are necessary." In-Reply-To: References: <434084 3b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99 f9f10238681bf68f@teranews> Message-ID: en.karpachov at ospaz.ru wrote: > Some people just don't get the simple fact that declarations are > essentially kind of unit test you get for free (almost), and the compiler > is a testing framework for them. It seems you've missed the entire point of using a dynamically typed language. It's not just about saving typing time and making your methods take up fewer lines of code. It's about writing generic code. Just look at C++ with all that mess with complex templates, silly casting and dangerous void pointers etc that are needed to achieve a fraction of the genericity that Python provides with no effort from the programmer. With properly written tests, you can be reasonably that the program does what you want. Type declarations are extremely limited in this aspect, and they often give programmers a false sense of security. From mlh at selje.idi.ntnu.no Mon Oct 3 18:08:16 2005 From: mlh at selje.idi.ntnu.no (Magnus Lie Hetland) Date: Mon, 3 Oct 2005 22:08:16 +0000 (UTC) Subject: PEP 350: Codetags References: <20050926223521.GE10940@kitchen.client.attbi.com> Message-ID: In article , Terry Hancock wrote: [snip] >The <> terminator is evil. People will hate that. If there are no fields, >you should just be able to leave it off. This will have an additional >advantage in that many will already have compliant codetags if you leave >off this requirement. I heartily agree. I use codetags like these all the time -- *except* that I don't add the "<>" at the end. >You worry over the need to detect the end of the block, but wouldn't '\n\n' >be a much more natural delimiter? I.e.: That would make perfect sense, and is in no way restrictive. ># TODO: This is a multi-line todo tag. ># You see how I've gone to the next line. > ># This, on the other hand is an unrelated comment. You can tell it's not ># related, because there is an intervening blank line. I think people ># do this naturally when writing comments (I know I do -- I'm fairly ># certain I've seen other people do it). ># ># Whereas, as you can see, a mere paragraph break can be represented by ># a blank comment line. Indeed. ># Whitespace formatting, after all, is VERY PYTHONIC. ;-) ># Delimiters on the other hand -- well, we prefer not to mention ># the sort of languages that use those, right? ;-) IMO, the syntax could be really simple: One comment (one or more contiguous comment lines) that start with # FOO: (with FOO being any of the tags) is grouped along with the tag. One can dhen optionally add the <...> stuff at the end. (Not sure if that would be my preferred syntax for it, but I won't complain as much about that as about the empty '<>' thing :) -- Magnus Lie Hetland "The early bird may get the worm but the second http://hetland.org mouse gets the cheese." -- Willie Nelson From vinay_sajip at yahoo.co.uk Fri Oct 7 16:00:36 2005 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: 7 Oct 2005 13:00:36 -0700 Subject: multiple logger References: <1128713230.539865.202980@g49g2000cwa.googlegroups.com> Message-ID: <1128715236.856509.266020@o13g2000cwo.googlegroups.com> Just replace logging.basicConfig(level=logging.DEBUG) with logging.getLogger().setLevel(logging.DEBUG) and you will no longer get messages written to the console. The basicConfig() method is meant for really basic use of logging - it allows one call to set level, and to add either a console handler a simple (non-rotating) file handler to the root logger. See the documentation for more information. Vinay Sajip From dietmar at schwertberger.de Sun Oct 16 12:11:48 2005 From: dietmar at schwertberger.de (Dietmar Schwertberger) Date: Sun, 16 Oct 2005 18:11:48 +0200 Subject: Length of read in in python-gpib References: <4351a665$0$41142$14726298@news.sunsite.dk> Message-ID: In article <4351a665$0$41142$14726298 at news.sunsite.dk>, Madhusudan Singh wrote: > python-gpib provides Gpib.py (see end of post) for Linux. > > I am trying to use the method called read. I usually use it without > arguments (the default length being 512). However, I am trying to read in a > string with some 16,000 comma separated floating point numbers. I've never used python-gpib, but I'm using National Instrument GPIB cards with a wrapper that loads the driver DLL using ctypes. Usually for such long data you have to perform multiple read operations and check the card/bus status whether the read operation is finished (Code "END" - "END or EOS detected"). So with the National Instrument drivers I'm checking whether ibsta is something like 0x2000, i.e. 1<<13. The following code is a snippet from my sources. Hope this helps. From your post I can see that python-gpib also provides an ibsta method. I'd expect that END is also 1<<13. Regards, Dietmar import ctypes gpib = ctypes.windll.LoadLibrary("gpib-32") # read buffer _bufsize = 1024 _buffer = ctypes.c_buffer(_bufsize) _readstatus = 0x2000 _errorstatus = 0x8000 def get_ibcntl(): return ctypes.c_int.in_dll(gpib, "user_ibcntl").value def ibrd(handle): ret = [] ibsta=0 global _buffer while not (ibsta & _readstatus): ibsta = gpib.ibrd(handle, _buffer, _bufsize) new = _buffer.raw[:get_ibcntl()] ret.append( new ) if ibsta & _errorstatus: _raise(GPIBIOError, "ibrd(handle=%d): Could not read data."%handle, ibsta ) ret = "".join(ret) if '\012' in ret: ret = ret[0:string.find(ret, '\012')] if '\015' in ret: ret = ret[0:string.find(ret, '\015')] return ret From rich.teer at rite-group.com Mon Oct 10 13:28:02 2005 From: rich.teer at rite-group.com (Rich Teer) Date: Mon, 10 Oct 2005 17:28:02 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <41hhk195gcipfarnqu85ggs606aqi89ea1@4ax.com> Message-ID: On Mon, 10 Oct 2005, Steven D'Aprano wrote: > But there is always an alternative. You can always send me a Word > document, a PDF, an Powerpoint presentation showing the steps one per > page, why the possibilities are endless. Why saddle you with a proprietory format (M$ Office), when StarOffice and OpenOffice do the job just as well, for much cheaper (and are cross platform too)?! > You could even send me a URL to a webpage. Indeed! -- Rich Teer, SCNA, SCSA, OpenSolaris CAB member President, Rite Online Inc. Voice: +1 (250) 979-1638 URL: http://www.rite-group.com/rich From Ido.Yehieli at gmail.com Mon Oct 10 06:10:13 2005 From: Ido.Yehieli at gmail.com (Ido Yehieli) Date: 10 Oct 2005 03:10:13 -0700 Subject: searching a project to contribute to Message-ID: <1128939012.964789.23840@g43g2000cwa.googlegroups.com> Thank you all for your advice, I currently have several offers that I'm really tempted about - I will take a closer look at both of them (as well as continue searching) and will make an educated decision within the next few days. I've also decided to get rid of the sily pseudonym... From thakadu at gmail.com Thu Oct 6 10:31:30 2005 From: thakadu at gmail.com (thakadu) Date: 6 Oct 2005 07:31:30 -0700 Subject: Simple prototype text editor in python In-Reply-To: References: <1128530997.895468.164240@g49g2000cwa.googlegroups.com> Message-ID: <1128609090.858119.28110@g43g2000cwa.googlegroups.com> Hi Viktor At the moment I dont have any web site where I can upload it. Do you or anyone have any suggestions or know of any web sites where one can post python code? If not please email me and I will send you the code by email. Regarding the license I have not yet decided what type of license (if any, since its very few lines of code) but probably will be GPL or BSD style. I have no former experience in licensing code so any suggestions will be welcome there as well. (For one, do you know if simply stating somewhere in the code "This is licensed under blah blah" is sufficient to consider the code licensed?) From gh at ghaering.de Fri Oct 21 14:19:58 2005 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Fri, 21 Oct 2005 20:19:58 +0200 Subject: Psycopg2 date problems: "Can't adapt" In-Reply-To: <4358F620.7040107@holdenweb.com> References: <4358F620.7040107@holdenweb.com> Message-ID: <4359314E.70906@ghaering.de> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Steve Holden wrote: > I'm trying to copy data from an Access database to PostgreSQL, as the > latter now appears to work well in the Windows environment. However I'm > having trouble with date columns. [...] > Here's the problem in a nutshell: > > >>> d > > >>> ocurs.execute("DELETE FROM Lines") This repr looks like a mxDateTime object. psycopg does include adapters for mxDateTime, but in order for them to be built, the mxDateTime sources and headers must be made available at psycopg build time (because it interfaces mxDateTime at the C extension level, unlike most if not all other Python DB-API adapters). A quick look at its setup.py reveals a have_mxdatetime variable and a check that decides wether to build with mxDateTime support or not. So, if it does not find mxDateTime, it builds without support for it. Which is apparently what you're experiencing. HTH, - -- Gerhard -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDWTFOdIO4ozGCH14RAgMyAJkB7gV88qhsmLmiMTCKXEDCbmjclACdEiW0 S56KM6ArQRUqP+jel2dC14M= =cExi -----END PGP SIGNATURE----- From onurb at xiludom.gro Mon Oct 31 09:23:05 2005 From: onurb at xiludom.gro (bruno at modulix) Date: Mon, 31 Oct 2005 15:23:05 +0100 Subject: 'super' to only be used for diamond inheritance problems? In-Reply-To: References: Message-ID: <436628cb$0$13718$636a15ce@news.free.fr> Alex Hunsley wrote: > I've seen a few discussion about the use of 'super' in Python, including > the opinion that 'super' should only be used to solve inheritance > diamond problem. (And that a constructor that wants to call the > superclass methods should just call them by name and forget about super.) > What is people's opinion on this? Does it make any sense? Since you'll never know how your class will be used, better to stick with super... super(MyClass, self).dothis() is no more difficult to use than MySuperClass.dothis(self), and does not require much more typing, so I don't see any reason not to use it. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From news at NOwillmcguganSPAM.com Thu Oct 13 14:00:44 2005 From: news at NOwillmcguganSPAM.com (Will McGugan) Date: Thu, 13 Oct 2005 19:00:44 +0100 Subject: 1-liner to iterate over infinite sequence of integers? In-Reply-To: <434e9d4b$0$32652$da0feed9@news.zen.co.uk> References: <434e9d4b$0$32652$da0feed9@news.zen.co.uk> Message-ID: <434ea0cd$0$318$da0feed9@news.zen.co.uk> Will McGugan wrote: > Neal Becker wrote: > >> I can do this with a generator: >> >> def integers(): >> x = 1 >> while (True): >> yield x >> x += 1 >> >> for i in integers(): >> Is there a more elegant/concise way? >> > > import itertools > for i in itertools.count(): > print i > Actualy itertools.count(1) to start at 1.. Will McGugan -- http://www.willmcgugan.com "".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in "jvyy*jvyyzpthtna^pbz") From aleaxit at yahoo.com Sun Oct 23 13:08:45 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Sun, 23 Oct 2005 10:08:45 -0700 Subject: Syntax across languages References: <1130052687.396109.145420@o13g2000cwo.googlegroups.com> <1130072403.157932.147930@z14g2000cwz.googlegroups.com> <1130072891.260350.179950@g43g2000cwa.googlegroups.com> Message-ID: <1h4vqhb.miuwq9cq3lbbN%aleaxit@yahoo.com> bonono at gmail.com wrote: > just curious, how can this identity function be used ? In haskell, > because all functions are curried, I can sort of visualize/understand > how id is used. Not quite understand how it can be used in python. There was a very recent example posted to this group (by Robin Becker, I believe, looking for ways to "override property"), something like: def __init__(self, validate=None): if not validate: validate = lambda x: x self.validate = validate and later on, self.validate is always unconditionally called to extract a valid value from an input argument to another method -- a nicer style, arguably, than assigning self.validate unconditionally and then having to test each and every time in the other method. Such subcases of the well-known "Null Object" design pattern, where you don't want to store None to mean "no such object" but, to avoid repeated testing, rather want to store an object which "reliably does nothing", are reasonably common. In an abstract way, they're somewhat akin to having the 'pass' statement in the language itself;-). Alex From ryanlists at gmail.com Thu Oct 6 11:44:11 2005 From: ryanlists at gmail.com (Ryan Krauss) Date: Thu, 6 Oct 2005 11:44:11 -0400 Subject: shelve object back to dictionary Message-ID: Is there an easy way to convert a shelved object back to a dictionary? When I save a dictionary using shelve and then load it in a later session, I have an object whose property names are the keys of the dictionary used as an input to shelve. For example, instead of user['name'] I have user.name. I would prefer to have the scripts I write to analyze the saved data have a similar syntax to the ones I used to create it, so I would rather deal with a dictionary after I load the shelved data. Ryan From bokr at oz.net Tue Oct 4 13:49:01 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 04 Oct 2005 17:49:01 GMT Subject: Controlling who can run an executable References: <1128395422.904212.318930@g44g2000cwa.googlegroups.com> <7x3bnhlx1m.fsf@ruckus.brouhaha.com> <1128422990.741343.292310@o13g2000cwo.googlegroups.com> Message-ID: <4342bf7b.3192487554@news.oz.net> On 4 Oct 2005 03:49:50 -0700, "Cigar" wrote: >Paul Rubin wrote: >> "Cigar" writes: >> > Now that I'm three months into the development of this program, my >> > client tells me she would like to protect her investment by preventing >> > her employees from doing the same to her. (Going to the competition >> > and using her program.) >> >> Exactly what is the threat here? > >I think the BIGGEST threat here is a feeling of vulnerablity. She now >realizes that she is in a position that her competition was many years >ago when she came into possesion of program the 'other side' was using >and that she is now vulnerable. She wants to feel safe in the >knowledge that she didn't reach into her pocket and pay thousands of >dollars for a program that now could now be used by her competition. >Nobody wants to pay money to level the playing field for all in a >business environment. So the biggest threat would seem to be her competition posting requirements here and having some showoff post a complete solution ;-) Regards, Bengt Richter From apardon at forel.vub.ac.be Thu Oct 6 02:44:41 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 6 Oct 2005 06:44:41 GMT Subject: "no variable or argument declarations are necessary." References: <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <86slvijt8s.fsf@bhuda.mired.org> <434245F5.6060500@REMOVEMEcyber.com.au> <7xr7b14lk0.fsf@ruckus.brouhaha.com> <7xu0fx9l7y.fsf@ruckus.brouhaha.com> <4344b80d.3321657210@news.oz.net> Message-ID: Op 2005-10-06, Bengt Richter schreef : > On 5 Oct 2005 09:27:04 GMT, Duncan Booth wrote: > >>Antoon Pardon wrote: >> >>> It also is one possibility to implement writable closures. >>> >>> One could for instace have a 'declare' have the effect that >>> if on a more inner scope such a declared variable is (re)bound it >>> will rebind the declared variable instead of binding a local name. >> >>That is one possibility, but I think that it would be better to use a >>keyword at the point of the assigment to indicate assignment to an outer >>scope. This fits with the way 'global' works: you declare at (or near) the >>assignment that it is going to a global variable, not in some far away part >>of the code, so the global nature of the assignment is clearly visible. The >>'global' keyword itself would be much improved if it appeared on the same >>line as the assignment rather than as a separate declaration. >> >>e.g. something like: >> >>var1 = 0 >> >>def f(): >> var2 = 0 >> >> def g(): >> outer var2 = 1 # Assign to outer variable >> global var1 = 1 # Assign to global > > IMO you don't really need all that cruft most of the time. E.g., what if ':=' > meant 'assign to variable wherever it is (and it must exist), searching according > to normal variable resolution order (fresh coinage, vro for short ;-), starting with > local, then lexically enclosing and so forth out to module global (but not to builtins).' Just some ideas about this 1) Would it be usefull to make ':=' an expression instead if a statement? I think the most important reason that the assignment is a statement and not an expression would apply less here because '==' is less easy to turn into ':=' by mistake than into = Even if people though that kind of bug was still too easy 2) What if we reversed the operation. Instead of var := expression, we write expression =: var. IMO this would make it almost impossible to write an assignment by mistake in a conditional when you meant to test for equality. -- Antoon Pardon From stanbar at si.rr.com Sat Oct 15 09:15:01 2005 From: stanbar at si.rr.com (Stan Krajewski) Date: Sat, 15 Oct 2005 09:15:01 -0400 Subject: New to Python: my impression v. Perl/Ruby Message-ID: <000901c5d18a$74bdb950$2d32a818@stan8gnbwsgaio> Very interesting. I too am deciding between the three languages. I find Python to be the easiest to use. By far. I find the forced indentation in Python a blessing in disguise. It seems Python is making in-roads into the progarmming community. With Ruby, its back to idiosyncratic and abstract syntax. Why? Is it necessary to be cryptic? Whoever can figure out the puzzle is the smartest one? "Everything should be made as simple as possible, but no simpler." Albert Einstein Thanks for sharing your thoughts! Stan -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Wed Oct 19 23:01:28 2005 From: roy at panix.com (Roy Smith) Date: Wed, 19 Oct 2005 23:01:28 -0400 Subject: Python vs Ruby References: <1129776956.254389.188040@z14g2000cwz.googlegroups.com> Message-ID: In article <1129776956.254389.188040 at z14g2000cwz.googlegroups.com>, "jean-marc" wrote: > I'd believe that would be Lua, but then again what is common to one > might not be to another ;-) Dang, you're right! Lua's got Ruby beat two-fold! From elicriffield at gmail.com Tue Oct 18 16:09:19 2005 From: elicriffield at gmail.com (Eli Criffield) Date: 18 Oct 2005 13:09:19 -0700 Subject: nested escape chars in a shell command Message-ID: <1129666159.791998.134880@g49g2000cwa.googlegroups.com> I'm try run an ssh command in pexpect and I'm having trouble getting everything escaped to do what i want. Here's a striped down script showing what i want to do. -- #!/usr/bin/env python import pexpect import sys if len(sys.argv) < 3: print "ssh.py host command" sys.exit(1) host = sys.argv[1] command = sys.argv[2] child = pexpect.spawn('''sh -x -c "stty -echo ; ssh -t -o 'StrictHostKeyChecking no' %s '%s' |awk '{print \"%s:\"$0}' " '''%(host,command,host), timeout=30) child.setlog(sys.stdout) child.expect(pexpect.EOF) -- The problem in the pexpect.spawn line, It doesn't like the \"%s:\" part of the awk command. This is necessary so i can see what server the command is running on, In the full script the command will be running on about 100 servers at a time. It parses out into: + stty -echo + ssh -t -o 'StrictHostKeyChecking no' testserver date + awk '{print testserver:$0}' It totally strips out the " The stty -echo is required because part of what the program does is it tries to remember any passwords that are asked for, So you can run a command like "su -c id" and it will remember roots password for the next server and try that. -echo keeps the root password from being echoed to the screen. The second problem with the command is while "su -c id" works (taking out the awk part) running any command with more then one word after the -c in su fails, It strips out the ' like so: ./sshexpect testserver "su -c 'ls -l /root'" + stty -echo + ssh -t -o 'StrictHostKeyChecking no' testserver 'su -c ls' -l /root su: user /root does not exist I have tried every combination of escaping i can think of can i can't get either problem solved. Any ideas? Eli From michele.simionato at gmail.com Tue Oct 11 03:19:28 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 11 Oct 2005 00:19:28 -0700 Subject: Batteries Included? In-Reply-To: <86achgzgjo.fsf@bhuda.mired.org> References: <1129010199.291968.142720@g47g2000cwa.googlegroups.com> <86achgzgjo.fsf@bhuda.mired.org> Message-ID: <1129015167.969228.256110@z14g2000cwz.googlegroups.com> Mike Meyer: > After you create a setup.py file for you program, doing > > "python setup.py bdist --formats=wininst" > > should do the trick. > > Of course, I don't own a Windows box, so I can't check it, but when I > ask a setup file for help on formats, it tells me the wininst format > is a windows installer. I can confirm that it works (for pure Python applications), since I did it. Michele Simionato From fredrik at pythonware.com Sat Oct 15 14:18:11 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 15 Oct 2005 20:18:11 +0200 Subject: Perl-Python-a-Day: Sorting References: <1128937897.500935.254770@o13g2000cwo.googlegroups.com><87oe5xfyng.fsf@qrnik.zagroda> <7xpsqdtwv4.fsf@ruckus.brouhaha.com><877jch9wwn.fsf@qrnik.zagroda> Message-ID: Tim Roberts wrote: > >This entry is obsolete: it should mention the 'key' option of the > >standard sort method. > > It should mention it, but not necessarily recommend it. > > I haven't run the numbers in Python, but in Perl, the undecorated sort is > so well-optimized that the Schwartzian transform is almost always faster > than passing a custom comparator to the sort function. the "key" option is used for decoration. from the documentation: key specifies a function of one argument that is used to extract a comparison key from each list element: "key=str.lower" In general, the key and reverse conversion processes are much faster than specifying an equivalent cmp function. This is because cmp is called multiple times for each list element while key and reverse touch each element only once. From nszabolcs at gmail.com Fri Oct 28 11:08:27 2005 From: nszabolcs at gmail.com (Szabolcs Nagy) Date: 28 Oct 2005 08:08:27 -0700 Subject: How to translate python into C In-Reply-To: <1130493811.719479.160450@z14g2000cwz.googlegroups.com> References: <1130491053.787273.201650@g44g2000cwa.googlegroups.com> <1130493304.961498.226200@g47g2000cwa.googlegroups.com> <1130493811.719479.160450@z14g2000cwz.googlegroups.com> Message-ID: <1130512107.873940.291700@g14g2000cwa.googlegroups.com> python script crashed and you want to debug it? if no trace back provided with the line number where the exception raised, then the crash caused by an extension module (most likely written in C), i don't know howto debug it, but at least you can find the place where the crash occures by adding lots of print statements with debug information. i don't think compiling to c would make it easier. there are python debuggers but i've never used one (these can only debug python scripts not the binary extension modules). pdb builtin module: http://docs.python.org/lib/module-pdb.html nice debugger with gui: http://www.digitalpeers.com/pythondebugger/ From tokidokix at gmail.com Wed Oct 19 08:47:36 2005 From: tokidokix at gmail.com (toki doki) Date: Wed, 19 Oct 2005 14:47:36 +0200 Subject: How to organize Python files in a (relatively) big project Message-ID: Hello again, Actually, I found a (pretty ugly) workaround to my problem: In every __init__.py of the subdirectories I created, I add the following lines: import os.path,sys for directory,sub_dir,files in os.walk(os.path.normpath(os.path.join( os.path.dirname(__file__),".."))): sys.path.append(directory) That add all of the sub-directories of the parent directory to the sys.path. I can then move my files in the directories I want without having to change a single line in them. it may not be very elegant, but for the moment, it will do. Actually, after thinking about it, I think that my problem is more a problem with the os than with python. subdirectories are the only method most OS provide for file organization. If there was a method for, for example, add labels to files and then browse files according to the labels, I wouldn't have this problem. (ok, I could arrange that with the names of the files, but it doesn't feel the same for me). Jason> Actually, unless I am wrong, you don't need to add the path of the package with a .pth . It should be done automatically when you import it. Giovanni> >The usual way is to do "import pkgN" and then dereference What do you call 'dereference'? do you mean something like 'import spam.foofoo= spam.foo' ? >My preferred way is to have __init__.py just do "from submodules import *", and then each submodule defines __all__ to specify which are its public symbols. Your solution soud interesting (although it doesn't exactly do what I want in the present case). I would consider it when I have to do hierarchical packages. However, I think I read somewhere that "from module import *" statements could cause (probably small) performance issue. Do you think this can be the case here? Anyway, thank you all for your very interesting replies. (and sorry for the double-post) TokiDoki -------------- next part -------------- An HTML attachment was scrubbed... URL: From david at jotax.com Tue Oct 25 01:14:34 2005 From: david at jotax.com (David Poundall) Date: 24 Oct 2005 22:14:34 -0700 Subject: Importing at runtime References: <1130215994.502926.99190@g43g2000cwa.googlegroups.com> Message-ID: <1130217274.386750.96420@g49g2000cwa.googlegroups.com> Thanks James, just after I posted I stumbled across the execfile command. Looks like with 'exec' and 'execfile' I should be able to do what I want. What an elegant language. From olivier.dormond at hispeed.ch Wed Oct 26 10:53:59 2005 From: olivier.dormond at hispeed.ch (Olivier Dormond) Date: Wed, 26 Oct 2005 16:53:59 +0200 Subject: Pickle to source code In-Reply-To: <1130332534.999358.152530@g49g2000cwa.googlegroups.com> References: <1130315056.793178.232760@g14g2000cwa.googlegroups.com> <1130332534.999358.152530@g49g2000cwa.googlegroups.com> Message-ID: Gabriel Genellina wrote: > Or perhaps: > > xxx = new.instance(MyClass, {'a':1,'b':2,'done':1}) > > In other words, I need a *string* which, being sent to eval(), would > return the original object state saved in the pickle. > As has been pointed, repr() would do that for simple types. But I need > a more general solution. Doesn't pickle.loads just do what you need ? e.g.: >>> pickled = file('test.dat', 'rb').read() >>> obj = eval('pickle.loads(%r)'%pickled) >>> obj <__main__.MyClass instance at 0xb7bfb76c> >>> obj.a, obj.b, obj.done (1, 2, 1) >>> As I've never used the persistent_id mechanism of pickle I don't know if that would do the trick. Cheers, Olivier From kenneth.m.mcdonald at sbcglobal.net Thu Oct 13 16:30:58 2005 From: kenneth.m.mcdonald at sbcglobal.net (Kenneth McDonald) Date: Thu, 13 Oct 2005 15:30:58 -0500 Subject: Yes, this is a python question, and a serious one at that (moving to Win XP) Message-ID: For unfortunate reasons, I'm considering switching back to Win XP (from OS X) as my "main" system. Windows has so many annoyances that I can only compare it to driving in the Bay Area at rush hour (OS X is like driving in Portland at rush hour--not as bad, but getting there), but there are really only a couple of things that are really, absolutely preventing me from making the switch. Number one is the lack of a decent command line and command-line environment, and I'm wondering (hoping) if perhaps someone has written a "Python shell"-- something that will look like a regular shell, let users type in commands, maybe have some of the nice features of bash etc. like tab completion, etc, and will then execute an underlying python script when the command is entered. I'm not thinking of IDLE, but something that is really aimed more at being a system terminal, not a Python- specific terminal. Yes, I know that Cygwin is out there, but last I looked, they still went through the Win command-line window, which imposes a lot of restrictions. More generally, has anyone written any python programs to administer various Win settings for which one must otherwise delve deep into mazes of twisty little dialogs, all alike? Or to help out with other annoyances? I know there are a lot of general utilities, but if they're in Python, I can also use them as a starting base for my own needs. Finally, a significant incentive in doing this is that I could avoid a lot of installation hassle, since virtually everything has at least a decent installation package for Win. (I'd hoped this would happen for OS X, but it never has). Can anyone think of important python- related packages (release level, not cutting edge alphas) for which this might not be the case? Many thanks, Ken From nbg at nbg.invalid Tue Oct 25 14:13:03 2005 From: nbg at nbg.invalid (Not Bill Gates) Date: Tue, 25 Oct 2005 18:13:03 GMT Subject: Microsoft Hatred FAQ References: <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <5l1rl1dt2vj6lanvbfue4pglv1kkgl1qn9@4ax.com> Message-ID: steve at REMOVETHIScyber.com.au wrote... > On Tue, 25 Oct 2005 15:35:47 +0000, Not Bill Gates wrote: > > > Heck, I dunno. Like you, I don't even really care all that much. > > You don't care that innovation in desktop software has been crippled by > the actions of the monopoly player Microsoft? You need to first prove innovation in desktop software has been crippled, don't you? From http Sat Oct 1 04:16:40 2005 From: http (Paul Rubin) Date: 01 Oct 2005 01:16:40 -0700 Subject: Will python never intend to support private, protected and public? References: <311b5ce105092800102da32267@mail.gmail.com> <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <7x64skzvas.fsf@ruckus.brouhaha.com> <7xd5mstqab.fsf@ruckus.brouhaha.com> <7xzmpwuxd0.fsf@ruckus.brouhaha.com> <20050930075313.67b9b676.jk@ospaz.ru> <7xbr2a6dlz.fsf@ruckus.brouhaha.com> <7xk6gyoibc.fsf@ruckus.brouhaha.com> Message-ID: <7xwtkx3b4n.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > A cautionary tale of what happens when religious wars enter programming > debates. For all I know, Paul Rubin is intelligent, gentle, kind to > animals and small children, generous, charitable and modest. Don't bet on it. > But touch his religious belief in the necessity of "truly" private > variables, and boy oh boy does he lose the plot. I haven't claimed necessity (except in some specific types of applications). I've said it's a useful feature in a certain type of development process. So I think you're the one losing the plot and acting like a religious whacko. If there's a feature you don't want to use, nobody is making you use it. You're going off the deep end saying nobody else should be allowed to use it either. > Paul misses the point: in a language like Python that allows the dynamic > modification of public methods (as well as private ones) you can't be > sure with absolute 100% mathematical certainty that your public interface > is the same at runtime as it was when you did your last code audit. Obviously any privacy-enforcement mechanism has to cope with that. Think of the situation with Bastion, back when it existed and was believed to sort-of work. > If your development team uses test-driven development, you will catch this > breakage immediately you check the code in. If you don't, you've got > lots more bugs that you don't know about, so one more is no big deal. Methinks you have too much faith in testing. It only shows that your program handles the test cases that you give it. To show that the program handles all the other cases, you need actual logic. > > Why on earth would you want to unnecessarily introduce random bugs > > into a word processor or anything else? > > Paul puts words into my mouth: I never suggested that it was good to > introduce bugs, unnecessarily or otherwise. What I said was that aiming > for 100% mathematical certainty that there are no bugs in a word processor > is pointless. No lives are at stake. The fate of nations doesn't rest on > your ability to make sure that PyWord is 100% bug free. Relax dude, the > world won't end if there is a bug or two in your code. See: http://vowe.net/archives/005838.html (found with about 5 seconds of Google searching). People could very well have died over disclosures like that, whether caused by software bugs or (as in this instance) by unlucky interaction of intentional features. These things happen over and over. If you look at the NSA's initial release of the Skipjack algorithm spec, it was a PDF file containing a bitmap that was obviously a scan of a fax of a document that had come out of a word processing program. People chuckled that a mighty operation like the NSA could be so technologically backward that they couldn't just put the word processor file directly online. Later they realized that maybe the NSA was simply being careful, that the document had been prepared in a classified environment and they didn't trust their word procssing software to not leak classified info into the file, so they stuck to a policy of only moving data like that around on paper and not in computer files. Information leakage from word processors is a serious problem. > Of course, if Paul had been paying attention, he would have realised that > 100% certainty is not possible in general no matter what style of > development you use. Perhaps folks have heard of the halting problem? You don't know what you're talking about. That is a red herring. > You can reduce the probability of bugs by using best practices, but never > reduce it to zero. How small do you need? Is it really shocking to suggest > that while a one in a billion billion chance of a bug might be > needed for a nuclear reactor, we might be satisfied with just one in a > million for a word processor? In some ways, word processors are harder to write safely than nuclear reactor code. Nuclear reactors usually run in carefully controlled environments and the field is mature enough that you can have some reasonable confidence that the data going into the program (e.g. from sensors) will be similar to the data that you tested the program with. What you're left with is Murphy's Law: something unexpected could happen by accident and you can make some reasonable assumptions about the distribution of inputs to make sure the probability is low. Ross Anderson calls this "programming Murphy's computer". A word processor, on the other hand, has to deal with malicious input, that can be fiendishly crafted in ways that the implementer never dreamed of. It's the difference between worrying about being hit by a meteor at random, and worrying about being hit by a meteor because someone in the asteroid belt is steering them towards you on purpose. Anderson calls this "programming Satan's computer". > Should we decide that C is not suitable for critical applications? Yes, absolutely. C (by which term I include C++) is unsuitable for critical applications including word processors. C is woefully underspecified, it has no type safety, yada yada. It's even worse than Python. People write those applications in C today anyway only because they are irresponsible and/or insane. Look at all the buffer overflow exploits in Microsoft Office that keep appearing every day of the week. If Office had not been written in C, those bugs wouldn't have anything like such bad consequences. > In any case, there is a difference between mission-critical applications > (such as, perhaps, a word processor) and what are generally called "real > time" critical systems such as those controlling nuclear power stations > and the like. I doubt that Python runs on any real-time operating > systems suitable for such critical systems, but perhaps I'm wrong. I don't see any point to that. Critical is critical whether it's real-time or not. If you write an inventory management program and someone uses it to route medical supplies into a disaster area, it can kill people. From amichail at gmail.com Tue Oct 4 08:09:38 2005 From: amichail at gmail.com (Amir Michail) Date: 4 Oct 2005 05:09:38 -0700 Subject: cgi relay for python cgi script References: <1128411305.541560.90790@g44g2000cwa.googlegroups.com> Message-ID: <1128427778.421720.205370@g43g2000cwa.googlegroups.com> Fredrik Lundh wrote: > Amir Michail wrote: > > > Is there an easy way to execute a python cgi script on a different > > machine from the cgi server? > > http://www.google.com/search?q=reverse+proxy > > Is there an easy way to do this without modifying the configuration of the cgi server and without running a cgi server on the other machine where the script will actually run? Perhaps someone wrote a simple server that provides the required environment for the cgi script to run? I'm looking for something simple that does not require root access. Amir From martin at v.loewis.de Sun Oct 9 12:36:02 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 09 Oct 2005 18:36:02 +0200 Subject: [regex] case-splitting strings in unicode In-Reply-To: References: Message-ID: <434946f2$0$15668$9b622d9e@news.freenet.de> John Perks and Sarah Mount wrote: > I have to split some identifiers that are casedLikeThis into their > component words. In this instance I can safely use [A-Z] to represent > uppercase, but what pattern should I use if I wanted it to work more > generally? I can envisage walking the string testing the > unicodedata.category of each char, but is there a regex'y way to denote > "uppercase"? In this form, it is currently not implemented, although it should be (written as [[:upper:]], I believe); contributions are welcome (make sure you read the Unicode consortium's guidelines on regular expressions before attempting to implement it). Until then, the "best" way is to use a regular character class, precomputed or computed at runtime. uni_upper = [unichr(i) for i in range(sys.maxunicode) if unichr(i).isupper()] uni_re = u"["+u"".join(uni_upper)+u"]" On my machine, this takes approximately one second to compute, which may or may not be too much as a startup cost. To speed this up, you could dump the resulting uni_re into a Python source file. Regards, Martin From rrr at ronadam.com Wed Oct 26 17:43:57 2005 From: rrr at ronadam.com (Ron Adam) Date: Wed, 26 Oct 2005 21:43:57 GMT Subject: How best to reference parameters. In-Reply-To: <1130342595.533405.191920@g43g2000cwa.googlegroups.com> References: <1130274796.584531.229340@g43g2000cwa.googlegroups.com> <4SM7f.4313$Zd.1145@tornado.tampabay.rr.com> <1130342595.533405.191920@g43g2000cwa.googlegroups.com> Message-ID: David Poundall wrote: > Sadly Ron, c_y can only see index and showall in your example. Well, don't give up! The approach is sound and I did say it was untested. Here's a tested version with a few corrections. :-) Cheers, Ron class Pump(object): def __init__(self, name, ptype, number): self.status = 0 self.name = name self.ptype = ptype self.number = number class C_Y(object): def __init__(self, plist): index = [] for p in plist: self.__dict__[p[0]] = Pump(*p) index.append(p[0]) self.index = index def showall(self): out = [] for item in self.index: out.append( "%s: %r, %r, %r\n" % ( self.__dict__[item].name, self.__dict__[item].status, self.__dict__[item].ptype, self.__dict__[item].number ) ) return ''.join(out) pumplist = [ ('p1', 'ob1', 0), ('p2', 'ob1', 1), ('p3', 'ob1', 2) ] c_y = C_Y(pumplist) print c_y.p1.name print c_y.p1.status print c_y.p1.ptype print c_y.p1.number print c_y.p1.status = 1 print c_y.p1.status print print c_y.showall() From fredrik at pythonware.com Sun Oct 9 03:02:30 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 9 Oct 2005 09:02:30 +0200 Subject: What about letting x.( ... ? ... ) be equivalent to ( ... x ... ) References: Message-ID: ddelay at club-internet.fr wrote: > These 3 intermediate variables used to improve readability > can introduce bugs : you have to check that b, c and d are > not used anywhere else in the code. if you have a fear of introducing new local variables, you have problems that cannot be solved by syntax. From ms at cerenity.org Sat Oct 8 08:23:23 2005 From: ms at cerenity.org (Michael) Date: Sat, 08 Oct 2005 13:23:23 +0100 Subject: When someone from Britain speaks, Americans hear a "British accent"... References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kdpnd1vuc2oce@corp.supernews.com> Message-ID: <4347b9ff$0$15081$ed2619ec@ptn-nntp-reader02.plus.net> Terry Hancock wrote: > > Well, yeah, although the correct pronunciation is apparently > "te-tra-HEE-dra-GON". > As opposed to a "te-tra-SHE-dra-GON" ? ;-) Michael. From twic at urchin.earth.li Fri Oct 21 07:29:03 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Fri, 21 Oct 2005 12:29:03 +0100 Subject: Python vs Ruby In-Reply-To: <86wtk7ty71.fsf@bhuda.mired.org> References: <02efl19c4n4994vtlt2ubrs7ulg4mcm8ug@4ax.com> <1129853715.441205.322480@g49g2000cwa.googlegroups.com> <86wtk7ty71.fsf@bhuda.mired.org> Message-ID: On Thu, 20 Oct 2005, Mike Meyer wrote: > "bonono at gmail.com" writes: > >> other than haskell and SQL, the others are more or less the same to me >> so getting familiar with them is not too difficult. > > There are actually lots of good "train your brain" type languages. > Members of the LISP family, for instance, to learn what you can do with > lists, and also for how cool a real macro facility can be. I happen to > like Scheme, but that's just me. I haven't actually done anything much in any LISP, but Scheme definitely looks like a winner to me - single namespace, generally cleaned-up language and library, etc. tom -- For one thing at least is almost certain about the future, namely, that very much of it will be such as we should call incredible. -- Olaf Stapledon From chemag at gmail.com Thu Oct 20 15:15:48 2005 From: chemag at gmail.com (chemag at gmail.com) Date: 20 Oct 2005 12:15:48 -0700 Subject: Question on re.IGNORECASE In-Reply-To: <4357e9a6$1_3@newspeer2.tds.net> References: <1129834544.533189.301780@g14g2000cwa.googlegroups.com> <4357e9a6$1_3@newspeer2.tds.net> Message-ID: <1129835748.938216.266780@z14g2000cwz.googlegroups.com> Thanks for your help. -myself From kenneth.pronovici at cedar-solutions.com Wed Oct 5 16:21:16 2005 From: kenneth.pronovici at cedar-solutions.com (Kenneth Pronovici) Date: Wed, 5 Oct 2005 15:21:16 -0500 Subject: epydoc, variables and encoding Message-ID: <20051005202116.GH643@cedar-solutions.com> > I found a "problem" on epydoc. If I specify an encoding, epydoc not find > my global variables, and if I remove it, it work well. > > code.py: > > #!/usr/bin/env python > # -*- coding: utf-8 -*- > > MY_VAR = None > > class foo(object): > def __init__(self, foo): > """ > Some text > @param foo: Pass me what you want > @type foo: A type > @return: The object > """ > return foo > > This not work (MY_VAR is silently skipped), but if I remove: > # -*- coding: utf-8 -*- > > it see MY_VAR and put it to my html file. > > Is it normal? No, it's not normal, and I'm fairly sure it's a bug. The problem is that the extra encoding statement at the top of the file changes the AST parse tree that epydoc uses, which confuses epydoc. There seem to be two solutions. The first is easy. Just add a @var entry to the module docstring, listing MY_VAR. Epydoc seems to notice the variable if you do that. #!/usr/bin/env python # -*- coding: utf-8 -*- """ @var MY_VAR: Is a variable """ Otherwise, you can try applying the following patch: Index: objdoc.py =================================================================== RCS file: /cvsroot/epydoc/epydoc/src/epydoc/objdoc.py,v retrieving revision 1.93 diff -u -r1.93 objdoc.py --- objdoc.py 12 Jan 2005 16:11:02 -0000 1.93 +++ objdoc.py 5 Oct 2005 19:56:00 -0000 @@ -1345,9 +1345,15 @@ # Construct a list of defined variables. To do this, we search # the parse tree for statements of the form "a=b" or "a=b=c" or - # "a,b=c" or "(a,b)=c" or "[a,b]=c". + # "a,b=c" or "(a,b)=c" or "[a,b]=c". We have to make sure to + # strip any encoding statement off the front first, though. defined_variables = {} - for stmt in ast.totuple()[1:]: + stmts = ast.totuple() + if symbol.sym_name[stmts[0]] == "encoding_decl": + stmts = stmts[1:][0][1:] + else: + stmts = stmts[1:] + for stmt in stmts: dict = {} if _ast_match(self._EXPR_STMT_PATTERN, stmt, dict)[0]: expr_stmt = dict['expr_stmt'] Maybe Edward won't like this patch, but since he seems to be unreachable for the last six months , you'll have to settle for my less-than-educated guess at a fix. :) KEN -- Kenneth J. Pronovici http://www.cedar-solutions.com/ From zen19725 at zen.co.uk Sun Oct 9 08:50:47 2005 From: zen19725 at zen.co.uk (phil hunt) Date: Sun, 9 Oct 2005 13:50:47 +0100 Subject: [Info] PEP 308 accepted - new conditional expressions References: <3q4ro9Fd770nU3@individual.net> Message-ID: On Fri, 7 Oct 2005 01:05:12 -0500, Terry Hancock wrote: > >GvR's syntax has the advantage of making grammatical sense in English (i.e. >reading it as written pretty much makes sense). I know, let's re-write Python to make it more like COBOL! That's bound to be a winner! -- Email: zen19725 at zen dot co dot uk From qwweeeit at yahoo.it Sat Oct 29 20:25:58 2005 From: qwweeeit at yahoo.it (qwweeeit at yahoo.it) Date: 29 Oct 2005 17:25:58 -0700 Subject: Expanding Python as a macro language In-Reply-To: <1130545600.925061.287390@g49g2000cwa.googlegroups.com> References: <1130545600.925061.287390@g49g2000cwa.googlegroups.com> Message-ID: <1130631958.683127.215300@g14g2000cwa.googlegroups.com> At first you must forgive my double posting (4 & 5 in terms of date and 4 & 7 in terms of answers). I must then thank the new comers: Michael, Alex Martelli and Mike Meyer. Michel wrote: >> qwwee... at yahoo.it wrote: >> But then I changed idea... Also if it is already one year that I try >> to find a solution in Linux (mainly with Python or DCOP and KDE), > This doesn't express the question you have anywhere clearly enough. My English is so poor that I don't understand... > Linux can run perfectly happily without any form of windowing > environment. I know, but nowadays almost any relevant application has a GUI. > Do you want to replay against qt applications? KDE? wx? GTK? > Or send raw X11 events? The answers to these questions aren't > linux specific either... I have nothing against GUI and in fact I chose Qt also if I made only limited tests using Qt Designer. However I should prefer not to program at low level (sending raw X11 events...). Being a newbye I was confident that someone had already developed a macro language for Linux... I hoped to have found it in Python, but I was wrong. Alex Martelli wrote: > Actually, if the app is running under X11 you may try to fake out a > keystroke event (with low level calls, but ctypes might let you use > it from Python). Of course, the app WILL be told that the keystroke > is fake, through a special flag if it cares to check for it, > for security reasons; but if the app doesn't specifically defend > itself in this way. > See, for example, http://xmacro.sourceforge.net/ -- I guess that > xmacroplay could pretty easily be adapted, or maybe even used as is > with an os.popen. My answer is the same as that given to Michael about low level programming. But I must thank anyway Alex for giving informations to such a level (I didn't know that under Linux there was such a level of sophistication with the possibility for an application to discover fake keystrokes...). If this fake keystroke is used to fire an event (like pressing a button), the fake flag is propagated to the action taken by the button? For the other Alex observations (about Mac OsX and my examples of automation centered on web automation) I have a PC, and the fact that Python is very good at dealing with the web, doesn't help too much in this case... In any case a macro language like AutoIt is a general purpose application. At last I must thank Mike Meyer for his suggestion to use python-xlib to avoid low level programming... Bye. From vvoipio at kosh.hut.fi Mon Oct 10 07:18:28 2005 From: vvoipio at kosh.hut.fi (Ville Voipio) Date: Mon, 10 Oct 2005 14:18:28 +0300 (EEST) Subject: Python reliability References: <434A2F31.6010507@REMOVEMEcyber.com.au> Message-ID: In article <434A2F31.6010507 at REMOVEMEcyber.com.au>, Steven D'Aprano wrote: > If you have enough hardware grunt, you could think > about having three independent processes working in > parallel. They vote on their output, and best out of > three gets reported back to the user. In other words, > only if all three results are different does the device > throw its hands up in the air and say "I don't know!" Ok, I will give you a bit more information, so that the situation is a bit clearer. (Sorry, I cannot tell you the exact application.) The system is a safety system which supervises several independent measurements (two or more). The measurements are carried out by independent measurement instruments which have their independent power supplies, etc. The application communicates with the independent measurement instruments thrgough the network. Each instrument is queried its measurement results and status information regularly. If the results given by different instruments differ more than a given amount, then an alarm is set (relay contacts opened). Naturally, in case of equipment malfunction, the alarm is set. This covers a wide range of problems from errors reported by the instrument to physical failures or program bugs. The system has several weak spots. However, the basic principle is simple: if anything goes wrong, start yelling. A false alarm is costly, but not giving the alarm when required is downright impossible. I am not building a redundant system with independent instruments voting. At this point I am trying to minimize the false alarms. This is why I want to know if Python is reliable enough to be used in this application. By the postings I have seen in this thread it seems that the answer is positive. At least if I do not try apply any adventorous programming techniques. - Ville -- Ville Voipio, Dr.Tech., M.Sc. (EE) From mde at micah.elliott.name Fri Oct 21 12:34:30 2005 From: mde at micah.elliott.name (Micah Elliott) Date: Fri, 21 Oct 2005 09:34:30 -0700 Subject: Execute C code through Python In-Reply-To: <11li3b2hsa3lhb5@corp.supernews.com> References: <1129844737.586396.61080@g47g2000cwa.googlegroups.com> <1129861083.010702.6770@g49g2000cwa.googlegroups.com> <1129906892.696582.288010@g43g2000cwa.googlegroups.com> <11li3b2hsa3lhb5@corp.supernews.com> Message-ID: <20051021163430.GD27602@kitchen.client.attbi.com> On Oct 21, Grant Edwards wrote: > I'm guessing you're using Windows based on the question. +1 QOTW. -- _ _ ___ |V|icah |- lliott http://micah.elliott.name mde at micah.elliott.name " " """ From fredrik at pythonware.com Thu Oct 6 15:08:00 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 6 Oct 2005 21:08:00 +0200 Subject: date reformatting References: <2387F0EED10A4545A840B231BBAAC722607F18@slcimail1.slcgov.com> Message-ID: "Bell, Kevin" wrote: > Anyone aware of existing code to turn a date string "8-15-05" into the > number 20050815? date = "8-15-05" import re m, d, y = map(int, re.match("(\d+)-(\d+)-(\d+)$", date).groups()) number = 20000000 + y*10000 + m*100 + d print number From robert.kern at gmail.com Fri Oct 7 23:50:50 2005 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 07 Oct 2005 20:50:50 -0700 Subject: GUI on Macintosh In-Reply-To: <1128717512.502956.45170@g49g2000cwa.googlegroups.com> References: <1128717512.502956.45170@g49g2000cwa.googlegroups.com> Message-ID: Joshua.R.English at gmail.com wrote: > I am using Python 2.3.3 on an Mac OS9 system. I am looking for a build > of Python 2.3.3+ with a built in GUI, since Tk is missing. One day I > hope to upgrade to a new Mac with OSX on it, so a GUI that is available > on OS9 and OSX is preferable. I don't want to write my GUI code from > scratch if I ever manage to upgrade. > > Any suggestions? Try as hard as you can to get Tkinter running. But if that fails, look at what the IDE is using. I believe the waste module is still distributed with some versions of MacPython for OS X (none of them recent). I don't think there's a whole lot of documentation, but if Tkinter won't work, that's your only bet. -- 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 tim at tt1lock.org Wed Oct 12 17:46:12 2005 From: tim at tt1lock.org (Tim Tyler) Date: Wed, 12 Oct 2005 21:46:12 GMT Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <11kh8196f3vm481@corp.supernews.com> <868xx3m2ve.fsf@bhuda.mired.org> <86irw6l1mc.fsf@bhuda.mired.org> Message-ID: In comp.lang.java.programmer Mike Meyer wrote or quoted: > Tim Tyler writes: > > In comp.lang.java.programmer Mike Meyer wrote or quoted: > >> Roedy Green writes: > >> > Read my essay. > >> > http://mindprod.com/projects.html/mailreadernewsreader.html > >> > > >> > I talk around those problems. > >> > >> Virus writers will love the ability to change peoples address books > >> remotely. > > > > Since - in Roedy's essay - messages are digitally signed, authority > > to advise about any email address updates would presumably be confined > > to those people with access to the sender's private key. > > It's not confined to just people - software can do this as well. In > particular, you should expect that the users mail agent will have to > have access to the key, so it can automatically send out the change of > address notice when the user changes their address (it actually needs > it to send any mail). Viruses regularly make users mail agents do > thing. "Change my address" becomes much more entertaining when that > triggers sending out change of addresses notices to everyone in the > address book. More likely, though, there'll be an API for getting the > key so that users can change mail agents without invalidating the > public key that everyone they correspond with has for them, and the > virus will just use that API. Viruses can mail out change of address messages to everyone in the compromised machine's address book today. Of course, viruses don't bother doing that - since it's stupid and pointless. If you've compromised someone's machine there are typically lots more rewarding things to do with it than spoof change-of-address notices. Top of the cracker's list seems to be: * Attack organisations; * Relay spam; * Attempt to compromise other machines; -- __________ |im |yler http://timtyler.org/ tim at tt1lock.org Remove lock to reply. From johnnyandfiona at hotmail.com Tue Oct 18 04:42:32 2005 From: johnnyandfiona at hotmail.com (Johnny Lee) Date: 18 Oct 2005 01:42:32 -0700 Subject: Question on class member in python In-Reply-To: References: <1129537638.714752.120290@g49g2000cwa.googlegroups.com> Message-ID: <1129624952.836150.159520@g44g2000cwa.googlegroups.com> But I still wonder what's the difference between the A().getMember and A().member besides the style From enas_khalil at yahoo.com Tue Oct 11 08:28:00 2005 From: enas_khalil at yahoo.com (enas khalil) Date: Tue, 11 Oct 2005 05:28:00 -0700 (PDT) Subject: Where is the error Message-ID: <20051011122801.686.qmail@web30511.mail.mud.yahoo.com> hello, when i run the following code to Read and tokenize data from a tagged text as follows : from nltk.corpus import brown from nltk.tagger import TaggedTokenizer from nltk.tokenizer import * tagged_txt_str=open('corpus.txt' ).read() tagged_txt_token=Token(TEXT=tagged_txt_str) TaggedTokenizer.tokenize(tagged_txt_token) print tagged_txt_token i got the following error : Traceback (most recent call last): File "C:\My Documents\TAGGING.PY", line 3, in -toplevel- from nltk.tagger import TaggedTokenizer ImportError: cannot import name TaggedTokenizer could anyone help me thanks in advance enas --------------------------------- Yahoo! Music Unlimited - Access over 1 million songs. Try it free. -------------- next part -------------- An HTML attachment was scrubbed... URL: From pydecker at gmail.com Mon Oct 3 12:50:19 2005 From: pydecker at gmail.com (Peter Decker) Date: Mon, 3 Oct 2005 12:50:19 -0400 Subject: Reply-To header In-Reply-To: <7rc0f.11261$Un.585792@phobos.telenet-ops.be> References: <2ECA6FE9-3C8F-4C60-9E89-70CC078B14EF@gmail.com> <7rc0f.11261$Un.585792@phobos.telenet-ops.be> Message-ID: On 10/3/05, Roel Schroeven wrote: > The default of this list is not to make conversations private; in fact > the list doesn't have any default. It's you who chooses to send replies > to the original author, to the list, or both, by choosing which button > to press in your mail client. Interesting: which button do I press to reply only to the list? I'm using Gmail, and it only has 'Reply' and 'Reply to all' as options. One sends a private reply; the other sends 2 replies. I checked all my other mail clients, and they work the same way. Setting the default Reply-To: to the list means that 'Reply' sends just to the list (the desired behavior most of the time), and 'Reply to all' sends 2 copies. I'm on several other lists, some of which default replies to the list, and others which default to the sender. I've *never* seen threads like this on the former, while such threads appear like clockwork on the latter. Draw your own conclusion. > Not that it matters that much to me, since I read practically all > mailing lists via gmane.org. That turns the lists into newsgroups, where > the reply button (follow-up, more accurately) does send the reply to the > newsgroup. So the answer is to not use the email interface, since the newsgroup interface actually gets it right! :) -- # p.d. From gregpinero at gmail.com Wed Oct 12 12:19:37 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Wed, 12 Oct 2005 12:19:37 -0400 Subject: Windows memory pointers in Python? In-Reply-To: <312cfe2b0510120904v6bb0d008ub32a00659efd6699@mail.gmail.com> References: <312cfe2b0510120904v6bb0d008ub32a00659efd6699@mail.gmail.com> Message-ID: <312cfe2b0510120919w370fc423w4ae050e4e9d5b4da@mail.gmail.com> Well, I think I've got it after a bit of research: c_char_p(address) seems to do the trick. Thus it would be: ctypes.c_char_p(address) Of course still let me know if this is somehow WRONG, or if there is a better way, but this seems good. Thanks again ctypes! http://starship.python.net/crew/theller/ctypes/ -Greg On 10/12/05, Gregory Pi?ero wrote: > > Hi guys, > > I'm really lost of on this one. How can I turn this (VB?) code into > Python? Basically I call a function exposed from a dll and it returns me > what I believe is a pointer to a location in memory? Now I need to read that > area to get the string I need. This link has the solution but it is written > in VB: > > http://www.contactreview.com/mb/showflat.php/Cat/0/Number/15670/an/0/page/14(it's the third post down) > > I have to think Python would have something similiar. > > Below is my relevant source code just in case you need that too. > > I really appriciate any help anyone might have. > > -- > Gregory Pi?ero > Chief Innovation Officer > Blended Technologies > (www.blendedtechnologies.com ) > > #---My code: (testing the GOLDMINE API) > from ctypes import * > windll.LoadLibrary('GM6S32.dll') > windll.GM6S32.GMW_LoadBDE > ('J:\\','J:\\GMBase\\',r'J:\\Common\\','user','pw') > windll.GM6S32.GMW_NV_SetValue(container,"AccountNo", "(310)555-1212") > #finally, I call a function to see what I stored: > windll.GM6S32.GMW_NV_GetValue(container, "AccountNo", "'(none)'") > #it returns 16236360 > #Now I need to access the string related to this somewhere ... > > > > -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com ) -------------- next part -------------- An HTML attachment was scrubbed... URL: From eric.nieuwland at xs4all.nl Tue Oct 11 02:01:45 2005 From: eric.nieuwland at xs4all.nl (Eric Nieuwland) Date: Tue, 11 Oct 2005 08:01:45 +0200 Subject: [Info] PEP 308 accepted - new conditional expressions In-Reply-To: <1128986126.7aab88bc9d9a2f56ea6d61ec086380ec@teranews> References: <3q4ro9Fd770nU3@individual.net> <1128986126.7aab88bc9d9a2f56ea6d61ec086380ec@teranews> Message-ID: <6c1c850ec2c9f05c6884f4c33399c776@xs4all.nl> Dave Hansen wrote: > And Basic, and Fortran, and Lisp, and just about any programming > language you care to name, including python (if Condition: Affirmative > else: Negative). > > Not to mention that the sequence is identical to execution order. > It's just plain goofy to have to scan to the middle of an expression > to find out what happens first, then depending on the result of that, > skipping back over what you just skipped. 1 word: Perl > FWIW, in over 20 years of C programming, I use it pretty rarely too, > though I never had to look it up after I first saw it in K&R. It only > very rarely holds any advantage over a simple if/else statement, > especially in modern compilers. It's most useful in macros, which > python doesn't even have. same time span and I used it zillions of times ==eric From stewart.midwinter at gmail.com Thu Oct 13 22:10:20 2005 From: stewart.midwinter at gmail.com (stewart.midwinter at gmail.com) Date: 13 Oct 2005 19:10:20 -0700 Subject: Bad magic no. in python zipfile In-Reply-To: <1OudnVsv95XVVdDeRVn-rw@powergate.ca> References: <1129168338.457437.276820@z14g2000cwz.googlegroups.com> <1OudnVsv95XVVdDeRVn-rw@powergate.ca> Message-ID: <1129255820.418348.24070@o13g2000cwo.googlegroups.com> okay, I've figured out the problem - the zip file was being mangled by a file transfer. I was fetching a remote python-generated zip file in 8k chunks, and then writing those chunks to a file. At first I was using an array to store the data in, and had the 'bad magic number' problem. This may have been due to writing the chunks out to a local file as strings, which would definitely have corrupted the file; I also noticed that the local copy was several kb larger, probably due to the line endings being added. When I took care to write the file as a binary file, all was well. case closed. BTW, regarding using zipfile under Python 1.5.2... I found zipfile.py in Python 1.6, but it wouldn't run. You need to build Python 1.5 with the binascii.c and zlibmodule.c from Python 1.6, since a CRC32 method has been added to those modules. This was more trouble than it was worth, in the end. S From lsumnler at uniqueinsuranceco.com Wed Oct 12 21:47:23 2005 From: lsumnler at uniqueinsuranceco.com (LenS) Date: 12 Oct 2005 18:47:23 -0700 Subject: Python adodb In-Reply-To: <434db297$1_1@newspeer2.tds.net> References: <1129158246.494302.140670@g47g2000cwa.googlegroups.com> <434db297$1_1@newspeer2.tds.net> Message-ID: <1129168043.315586.138040@g14g2000cwa.googlegroups.com> You also might want to take a look at; http://www.mayukhbose.com/python/ado/index.php I found it very helpful LenS From hancock at anansispaceworks.com Fri Oct 7 17:18:57 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Fri, 7 Oct 2005 16:18:57 -0500 Subject: When someone from Britain speaks, Americans hear a "British accent"... In-Reply-To: <1128709915.677e761b4ee3431140a6964c46a02b82@teranews> References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kd19ajdtkoi6f@corp.supernews.com> <1128709915.677e761b4ee3431140a6964c46a02b82@teranews> Message-ID: <200510071618.57431.hancock@anansispaceworks.com> On Friday 07 October 2005 01:31 pm, Dave Hansen wrote: > >Don't get me started on _that_ one. I found it particularly > >horrifying that Jimmy Carter pronounced it "nucular" -- he had > >studied nuclear engineering at the naval acadamy, and should at > >least be able pronounce the word. Well, there's your problem. He learned from engineers. Engineers can't speak English. I was instructed in my "Engineering Statics" class that a three-dimensional structure connecting non-coplanar points in space was called a "tetrahedragon". I am not kidding. This actually happened. Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From joerg.schuster at gmail.com Wed Oct 26 04:06:37 2005 From: joerg.schuster at gmail.com (Joerg Schuster) Date: 26 Oct 2005 01:06:37 -0700 Subject: more than 100 capturing groups in a regex In-Reply-To: References: <1130160675.270886.208420@z14g2000cwz.googlegroups.com> <1130312136.411976.118780@o13g2000cwo.googlegroups.com> Message-ID: <1130313997.136536.299570@g47g2000cwa.googlegroups.com> So what? From stijndesaeger at gmail.com Sun Oct 23 21:47:26 2005 From: stijndesaeger at gmail.com (vdrab) Date: 23 Oct 2005 18:47:26 -0700 Subject: High Order Messages in Python References: <1130015536.273136.295800@g43g2000cwa.googlegroups.com> <435bb315$0$15040$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <1130118446.643842.178950@g47g2000cwa.googlegroups.com> On a (somewhat) related note, I've always wondered whether it is possible to emulate ruby blocks using a python generator '+ alpha'. In my limited understanding of the ruby block, the generator can inject values into a block, I suppose, but what is the block itself? can it be a function? a class instance? what would it look like? I am sure someone must have played around with this. any pointers? cheers, v. From lasse at vkarlsen.no Mon Oct 31 03:41:02 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Mon, 31 Oct 2005 09:41:02 +0100 Subject: Scanning a file In-Reply-To: <4363fdd4$0$2107$edfadb0f@dtext02.news.tele.dk> References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <4363fdd4$0$2107$edfadb0f@dtext02.news.tele.dk> Message-ID: David Rasmussen wrote: > If you must know, the above one-liner actually counts the number of > frames in an MPEG2 file. I want to know this number for a number of > files for various reasons. I don't want it to take forever. Don't you risk getting more "frames" than the file actually have? What if the encoded data happens to have the magic byte values for something else? -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From riplin at Azonic.co.nz Sun Oct 9 16:12:43 2005 From: riplin at Azonic.co.nz (riplin at Azonic.co.nz) Date: 9 Oct 2005 13:12:43 -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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <41hhk195gcipfarnqu85ggs606aqi89ea1@4ax.com> Message-ID: <1128888762.964727.17750@g14g2000cwa.googlegroups.com> > My grandma doesn't put captions in her photo album, > and she doesn't need captions on her photos in email. She doesn't need captions in the album because she will explain the pictures, at length, every single one of them, to anyone who comes within grabbing distance. > "Here's Johnny with the dog. Here is Johnny with the > dog again. This one is Johnny on his own. Here is the > dog. Oh look, it is Johnny with the dog again -- ... If your photos are so banal then only people who would recognise the people would care about them. Captions are for people who won't recognise the subject of the photo. When you send a photo of a house to Granma is she supposed to just _know_ that it your new house, or the one across the road, or the one that burnt down last week ? From hancock at anansispaceworks.com Fri Oct 7 17:54:48 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Fri, 7 Oct 2005 16:54:48 -0500 Subject: When someone from Britain speaks, Americans hear a "British accent"... In-Reply-To: <11kdpnd1vuc2oce@corp.supernews.com> References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <11kdpnd1vuc2oce@corp.supernews.com> Message-ID: <200510071654.48040.hancock@anansispaceworks.com> On Friday 07 October 2005 04:21 pm, Grant Edwards wrote: > On 2005-10-07, Terry Hancock wrote: > > > Well, there's your problem. He learned from engineers. Engineers > > can't speak English. I was instructed in my "Engineering Statics" > > class that a three-dimensional structure connecting non-coplanar > > points in space was called a "tetrahedragon". [typo: the word "four" is missing above in the definition] > Watch out for the fire-breathing kind. They're especially > dangerous since they have multiple faces, so there's no > "behind" from which to sneak up upon them from... of... to..... Well, yeah, although the correct pronunciation is apparently "te-tra-HEE-dra-GON". (Wishing I had figured out how to type IPA symbols so you could fully appreciate that ;-) ). It was very distracting, though, subvocalizing "tetrahedron" constantly during this guy's lectures. I suppose that might've contributed to my poor grade in this class (I left engineering altogether very shortly thereafter). -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From noway at sorry.com Mon Oct 31 19:28:12 2005 From: noway at sorry.com (Giovanni Bajo) Date: Tue, 01 Nov 2005 00:28:12 GMT Subject: 'super' to only be used for diamond inheritance problems? References: Message-ID: Alex Hunsley wrote: > I've seen a few discussion about the use of 'super' in Python, > including the opinion that 'super' should only be used to solve > inheritance diamond problem. (And that a constructor that wants to > call the superclass methods should just call them by name and forget > about super.) What is people's opinion on this? Does it make any > sense? I personally consider super a half-failure in Python. Some of my reasons are cited here: http://fuhm.org/super-harmful/ -- Giovanni Bajo From mde at micah.elliott.name Mon Oct 31 17:08:41 2005 From: mde at micah.elliott.name (Micah Elliott) Date: Mon, 31 Oct 2005 14:08:41 -0800 Subject: Rename files with numbers In-Reply-To: <1130789205.862429.10090@g43g2000cwa.googlegroups.com> References: <1130776390.085587.116270@g43g2000cwa.googlegroups.com> <1130784747.373637.108040@g14g2000cwa.googlegroups.com> <1130789205.862429.10090@g43g2000cwa.googlegroups.com> Message-ID: <20051031220841.GF2575@kitchen.client.attbi.com> On Oct 31, dudufigueiredo at gmail.com wrote: > but my focus is to learn how to acess a folder and rename all files in > this folder. This is a little more flexible than my last post, and it does the whole job:: #! /usr/bin/env python import glob, os, string def fix_ugly_song_names(songdir, band, spacerepl='_'): """Rename an ugly MP3 file name to a beautified shell-correct name. Only works for files named like "03 song name.mp3". Use `spacerepl` to alter space replacement character. WARNING: no error-handling! """ # Begin working in specified `songdir`. os.chdir(songdir) # Shell-unfriendly characters made into a string. badchars = ''.join( set(string.punctuation) - set('-_+.~') ) # Identity table for later translation (removal of `badchars`). tbl = string.maketrans('', '') # MP3 files in `songdir` having ugly characters. uglies = glob.glob("*.mp3") # Make some step-by-step changes to build `pretties` list. pretties = [] for ugly in uglies: song, ext = os.path.splitext(ugly) song = song.translate(tbl, badchars) song = song.replace(" ", spacerepl) song = song.title() song = band+spacerepl+"-"+spacerepl+song[3:] songext = song + ext pretties.append(songext) # Rename each file from ugly to pretty. for ugly, pretty in zip(uglies, pretties): if __debug__: print ugly, '-->', pretty else: os.rename(ugly, pretty) So for you to use spaces, just call with something like this:: fix_ugly_song_names('/var/mp3/pop/The_Beatles/Rubber_Soul', 'The Beatles', spacerepl=' ') I used the __debug__ gate to allow you to just see what it will do:: $ ls -1 01 drive my car.mp3 02 norwegian wood.mp3 03 you won't see me.mp3 04 nowhere man.mp3 mvmp3.py $ python ./mvmp3.py 01 drive my car.mp3 --> The Beatles - Drive My Car.mp3 02 norwegian wood.mp3 --> The Beatles - Norwegian Wood.mp3 03 you won't see me.mp3 --> The Beatles - You Wont See Me.mp3 04 nowhere man.mp3 --> The Beatles - Nowhere Man.mp3 And then to actually do it with the non-__debug__ path:: $ python -O ./mvmp3.py $ ls -1 mvmp3.py The Beatles - Drive My Car.mp3 The Beatles - Norwegian Wood.mp3 The Beatles - Nowhere Man.mp3 The Beatles - You Wont See Me.mp3 If you want to keep the `badchars` in the file names, then you will have to do *more* work since `song.title()` won't be able to do the work for you. Now I need to go beautify my collection. :-) -- _ _ ___ |V|icah |- lliott http://micah.elliott.name mde at micah.elliott.name " " """ From qrczak at knm.org.pl Thu Oct 13 12:58:16 2005 From: qrczak at knm.org.pl (Marcin 'Qrczak' Kowalczyk) Date: Thu, 13 Oct 2005 18:58:16 +0200 Subject: Perl-Python-a-Day: Sorting References: <1128937897.500935.254770@o13g2000cwo.googlegroups.com> <87oe5xfyng.fsf@qrnik.zagroda> <7xpsqdtwv4.fsf@ruckus.brouhaha.com> Message-ID: <877jch9wwn.fsf@qrnik.zagroda> Abdulaziz Ghuloum writes: > Python FAQs contain an entry to the schwartzian transform. > > http://www.python.org/doc/faq/programming.html#i-want-to-do-a-complicated-sort-can-you-do-a-schwartzian-transform-in-python This entry is obsolete: it should mention the 'key' option of the standard sort method. -- __("< Marcin Kowalczyk \__/ qrczak at knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/ From sjmaster at gmail.com Wed Oct 5 14:25:56 2005 From: sjmaster at gmail.com (Steve M) Date: 5 Oct 2005 11:25:56 -0700 Subject: MS Word mail merge automation References: <1128115390.643636.281610@z14g2000cwz.googlegroups.com> Message-ID: <1128536756.871668.289410@o13g2000cwo.googlegroups.com> I was finally able to get things working right, so I thought I'd stick an example here for posterity. """An example of a MS Word mail merge using the COM interface. In order for this script to work you must first run the COM Makepy utility and select "Microsoft Word 10.0 Object Library (8.2)" or whatever your version of Word is. The template must also be set up with merge fields corresponding to the data source. """ import os, win32com.client doc_template_name = os.path.abspath('template.doc') data_source_name = os.path.abspath('record23.csv') doc_final_name = os.path.abspath('record23.doc') app = win32com.client.Dispatch("Word.Application") doc_template = app.Documents.Open(doc_template_name) mm = doc_template.MailMerge #attach data source to template mm.OpenDataSource(data_source_name) #merge just one record - this step may be redundant mm.DataSource.FirstRecord = 1 mm.DataSource.LastRecord = 1 #send the merge result to a new document mm.Destination = win32com.client.constants.wdSendToNewDocument #merge mm.Execute() #apparently app.Documents is like a stack doc_final = app.Documents[0] #save our new document doc_final.SaveAs(doc_final_name) #cleanup doc_final.Close() doc_template.Close() app.Quit() From lycka at carmen.se Tue Oct 11 12:05:23 2005 From: lycka at carmen.se (Magnus Lycka) Date: Tue, 11 Oct 2005 18:05:23 +0200 Subject: Python's Performance In-Reply-To: <1128888628.643764@yasure> References: <20051008040614.47429.qmail@web30607.mail.mud.yahoo.com><43495259$0$29124$626a14ce@news.free.fr> <178B879D-FDB6-458C-BE00-A03820D98703@advfn.com> <1128888628.643764@yasure> Message-ID: Donn Cave wrote: > Quoth "Fredrik Lundh" : > | Alex Stapleton wrote > | > | > Except it is interpreted. > | > | except that it isn't. Python source code is compiled to byte code, which > | is then executed by a virtual machine. if the byte code for a module is up > | to date, the Python runtime doesn't even look at the source code. > > Fair to say that byte code is interpreted? Seems to require an > application we commonly call an interpreter. It's fair to say that Python works just the same as Java in this regard. The myth seems to be that Python is interpreted in the same way as a unix shell script, while Java does some- thing much better. From http://www.osnews.com/story.php?news_id=5602 """Both Java and the .NET languages are "semi-compiled" (or, looking at the flip side of the coin, "semi-interpreted"). By this I mean that source code is compiled into intermediate-level code and then run by a combination interpreter/just-in-time compiler. With Java, the intermediate language is called bytecode and the interpreter/compiler is called a Java Virtual Machine (JVM). Source code in the .NET world is compiled into the Microsoft Intermediate Language (MSIL) and is run on the .NET Common Language Runtime (CLR) engine.""" ... """I wanted to find out how semi-compiled languages compare to fully interpreted languages like Python, Perl or PHP.""" The big difference between Java and Python in regards to this benchmark is that Python uses dynamic typing, which means that code such as "a = a + i" must be capable to handle any concievable value of a and i. In a naive benchmark like this, dynamic typing is just a disadvantage. In real software development, it's often a big advantage, mainly in terms of programmer productivity and program size. From andreas.zwinkau at googlemail.com Wed Oct 5 07:42:05 2005 From: andreas.zwinkau at googlemail.com (beza1e1) Date: 5 Oct 2005 04:42:05 -0700 Subject: bug or feature? In-Reply-To: <4343b0d5$1@news.home.net.pl> References: <1128508770.727391.313300@f14g2000cwb.googlegroups.com> <4343b0d5$1@news.home.net.pl> Message-ID: <1128512525.894377.275340@z14g2000cwz.googlegroups.com> Thanks for you answer! This copy trick is the most elegant solution i think. From gordonb.8utmv at burditt.org Wed Oct 12 21:42:49 2005 From: gordonb.8utmv at burditt.org (Gordon Burditt) Date: Thu, 13 Oct 2005 01:42:49 -0000 Subject: Jargons of Info Tech industry References: <1123809822.696399.317570@g44g2000cwa.googlegroups.com> Message-ID: <11kresp8j9hl9aa@corp.supernews.com> >I would say by extrapolating the problem of spam and snooping that the >next level of email software needs to concentrate on the following: > >1. routine and transparent encryption. OK, but the Feds are really going to hate that. >2. making spam no longer economic. Blocking all spam is, even in >theory, impossible. I sometimes read a message and am ambivalent >myself about whether I wanted to read or receive it. The key is to >provide efficient, transparent spam solutions. They can be layered to >filter higher and higher percentages of mail depending on how big your >spam problem is. One way of making spam non-economic would be making it difficult to use throw-away identities. If I block by someone's identity, it stays blocked. >3. prevent phishing. When PayPal sends you an email, you want to know >for sure it really is from PayPal. This means corporate users at >least will all have digital ids, and all emails will be digitally >signed. I'm assuming that email is supposed to be useful and usable for *SAFELY* conducting a conversation (or negotiations) with someone out to kill you or steal from you. (Consider union vs. management, any husband vs. his ex-wife, the IRS vs. everyone, whistleblower vs. employer, etc.) >4. status tracking. Unless blocked by the receiver, the sender knows >if his message has been receiveived/read. I consider this an unacceptable risk to the receiver, unless the acknowledgement is manually initiated. It also risks a lot of confusion regarding what constitutes "read", especially if the user saved it into a file without displaying it. I'm assuming here that there are some people (e.g. George W. Bush) who will attempt to try to turn an IP address into a geographic location and launch missiles at it when he finds out Osama Bin Laden read his email. At least when Osama *sends* email, he can click the send button and run like hell. >5. making it impossible for any incoming email to mount any sort of >attack. the only parts the email software processes are the data >parts. Any enclosed programs must be explicitly installed. The email >software would warn if any code were not digitally signed with proper >certificate to identify the author. In HTML, that means NO links, NO Javascript, NO forms, and NO references to other files. Reading your email should not generate hits on anything specified by the sender. Gordon L. Burditt From uval at rz.uni-karlsruhe.de Thu Oct 27 13:37:38 2005 From: uval at rz.uni-karlsruhe.de (=?ISO-8859-1?Q?Daniel_Sch=FCle?=) Date: Thu, 27 Oct 2005 19:37:38 +0200 Subject: how do i run another script from my python script In-Reply-To: <1130431172.443751.230730@o13g2000cwo.googlegroups.com> References: <1130431172.443751.230730@o13g2000cwo.googlegroups.com> Message-ID: Steve already answeared to your question, regaring PHP script if this would be python script, you could run it by import'ing it #a.py print "in a" ------------ #b.py import a # prints "in a" print "in b" ------------ and of course other solutions import os if os.fork()==0: os.execv("/bin/cmd_here", ["-blabla"]) else: # parent here or maybe using threading >>> class FileWatcher(th.Thread): ... def __init__(self, filename): ... th.Thread.__init__(self) ... self.filename = filename ... def run(self): ... import time ... from os.path import exists ... while not exists(self.filename): ... time.sleep(0.5) ... print "not there" ... >>> f = FileWatcher("/pool/xyz") >>> f.start() >>> not there not there not there not there not there not there not there not there not there not there not there not there >>> hth, Daniel From sam at email-scan.com Wed Oct 5 19:02:57 2005 From: sam at email-scan.com (Sam) Date: Wed, 05 Oct 2005 18:02:57 -0500 Subject: Python eats gator. Message-ID: http://www.wnbc.com/family/5060215/detail.html I know there's an on-topic joke in here somewhere, but I'm having some problem finding it, at the moment. You may take a crack at it, if you'd like? -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From lasse at vkarlsen.no Sat Oct 29 08:51:11 2005 From: lasse at vkarlsen.no (=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=) Date: Sat, 29 Oct 2005 14:51:11 +0200 Subject: how to associate files with application In-Reply-To: References: <1130439184.801178.280190@g14g2000cwa.googlegroups.com> Message-ID: Dennis Lee Bieber wrote: > On Fri, 28 Oct 2005 09:48:27 -0400, "Colin J. Williams" > declaimed the following in comp.lang.python: > > > >>I'm no Windows expert but I think that, using Windows Explorer, one can, >>with a right mouse click, select "Open With". There are several ways to do this using Windows Explorer. I was under the assumption the OP wanted to know how he could automate it since that is what you typically want to do with applications you write. -- Lasse V?gs?ther Karlsen http://usinglvkblog.blogspot.com/ mailto:lasse at vkarlsen.no PGP KeyID: 0x2A42A1C2 From raims at dot.com Sun Oct 30 05:02:27 2005 From: raims at dot.com (Lawrence Oluyede) Date: Sun, 30 Oct 2005 11:02:27 +0100 Subject: query a port References: <1130642480.233982.197760@g49g2000cwa.googlegroups.com> Message-ID: Il 2005-10-30, eight02645999 at yahoo.com ha scritto: > hi > in python, how do one query a port to see whether it's up or not? > thanks > Have a look at this: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286240 -- Lawrence http://www.oluyede.org/blog From bobrien18 at yahoo.com Wed Oct 19 22:53:36 2005 From: bobrien18 at yahoo.com (KraftDiner) Date: 19 Oct 2005 19:53:36 -0700 Subject: destroy your self???? Message-ID: <1129776816.148308.210460@g44g2000cwa.googlegroups.com> if I create an object like... obj = None ... obj = anObject() can obj set itself to none in some method of the class? From derek.perriero at gmail.com Fri Oct 7 15:06:46 2005 From: derek.perriero at gmail.com (Derek Perriero) Date: Fri, 7 Oct 2005 15:06:46 -0400 Subject: SMB Authentication Module Message-ID: <17fc20160510071206n55c3784awd6eb986eb723be36@mail.gmail.com> This may be a simple question to answer, but is there any module that will let you authenticate against a SMB server? An equivalent package in perl would be the Authen::SMB. That is the realms of what I am looking for, but in Python. -Derek Perriero -- Perriero, Derek derek.perriero at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jim.eggleston at gmail.com Sat Oct 29 09:05:20 2005 From: jim.eggleston at gmail.com (jim.eggleston at gmail.com) Date: 29 Oct 2005 06:05:20 -0700 Subject: Debugging with SciTE In-Reply-To: <1130567282.404337.61950@g47g2000cwa.googlegroups.com> References: <1130567282.404337.61950@g47g2000cwa.googlegroups.com> Message-ID: <1130591120.133458.52040@z14g2000cwz.googlegroups.com> Based on information from Jarek Zgoda in another thread on the Windows USERPROFILE environment variable, debug.py should be: import sys from pdb import pm, set_trace from inspect import getmembers if sys.platform == 'win32': import os os.environ['HOME'] = os.environ['USERPROFILE'] del sys.argv[0] execfile(sys.argv[0]) From skip at pobox.com Wed Oct 26 15:23:49 2005 From: skip at pobox.com (skip at pobox.com) Date: Wed, 26 Oct 2005 14:23:49 -0500 Subject: Python 2.3.4, Berkeley db 1.85, db file format not recognized In-Reply-To: References: Message-ID: <17247.55237.444550.291681@montanaro.dyndns.org> Dan> import bsddb Dan> bsddb.hashopen("access.db") Dan> but I get: Dan> bsddb._db.DBInvalidArgError: (22, 'Invalid argument -- access.db: unexpected file type or format') Dan> .... Any suggestions on how to read this file? See if the bsddb185 module is available: % python Python 2.5a0 (#94, Oct 8 2005, 06:49:04) [GCC 3.3 20030304 (Apple Computer, Inc. build 1671)] on darwin Type "help", "copyright", "credits" or "license" for more information. impo>>> import bsddb >>> import bsddb185 >>> dir(bsddb185) ['__doc__', '__file__', '__name__', 'btopen', 'error', 'hashopen', 'open', 'rnopen'] >>> dir(bsddb) ['UserDict', '_DBWithCursor', '__builtins__', '__doc__', '__file__', '__name__', '__path__', '__version__', '_bsddb', '_checkflag', '_db', '_iter_mixin', '_openDBEnv', 'btopen', 'db', 'error', 'hashopen', 'os', 'ref', 'rnopen', 'sys'] If the old libdb.a stuff is available, the bsddb185 module should have been built automagically. Skip From davids at webmaster.com Sun Oct 16 01:25:48 2005 From: davids at webmaster.com (David Schwartz) Date: Sat, 15 Oct 2005 22:25:48 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: "John Bokma" wrote in message news:Xns96F0C9445F383castleamber at 130.133.1.4... > Ok, let me spell it out for you: If all your applications are web based, > and the OS shouldn't matter, why do Linux distributions matter? It > doesn't matter which one you use to run, for example, OpenOffice. Yet > people pick a certain distribution. Why? Well, one reason is that people > like to belong to a group. So even if it really doesn't matter which OS > you are going to use to access a web application, or even which browser, > people will pick a certain browser, and a certain OS, just because. You don't get it. The point is, you can pick any Linux distribution and still use the same applications. This is exactly what Microsoft *doesn't* want. They want applications to be locked to Microsoft OSes. For then to do this, applications have to be as tied to the OS as possible. The browser as a target platform threatened this Microsoft vision, so Microsoft reacted by trying to corner the browser market and balkanize Java. You can agree or disagree with the rationale and by sympathetic with or antagonistic to Microsoft's motive. But these are historical facts. DS From davids at webmaster.com Thu Oct 27 13:43:23 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 10:43:23 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <66u633-etj.ln1@news.it.uc3m.es> <7xbr1aewtq.fsf@ruckus.brouhaha.com> <86acgulv5z.fsf@localhost.localdomain> Message-ID: Espen Myrland wrote: > "David Schwartz" writes: >> What is an "illegal monopoly"? > The opposite of a "legal monopoly". For example, in Norway we have > "Vinmonopolet", a monopoly which are the only one allowed to sell > wine and spirits to the public. Seriously, I have no idea what you he means by "illegal monopoly". I understand that one can be granted a monopoly by law, however not being granted a monopoly by law does not make the monopoly illegal. Is he claiming the monopoly itself violated some law? For example, I know what "illegal monopoly maintenance" is. It's illegally maintaining a monopoly. But it's not maintaining an illegal monopoly. As the appeals court put it, "the monopoly in this case was not found to have been illegally acquired, but only to have been illegally maintained." Both the district and appellate courts characterized Microsoft's monopoly as "lawfully-acquired". Sorry to be pedantic, but I think it's an important point that no court ever found that Microsoft illegally acquired a monopoly. So to characterize the monopoly itself as "illegal" is simply erroneous. DS From steve at REMOVETHIScyber.com.au Sun Oct 9 18:58:42 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Mon, 10 Oct 2005 08:58:42 +1000 Subject: Jargons of Info Tech industry References: <1124804082_1011@spool6-east.superfeed.net> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <41hhk195gcipfarnqu85ggs606aqi89ea1@4ax.com> <2dadnfArEfWwvdTeRVnzvA@telenor.com> <0trik1ldrtvuhsdvoai4a7h34q7la1pehl@4ax.com> Message-ID: On Sun, 09 Oct 2005 19:40:30 +0000, Roedy Green wrote: > Imagine a main sending emailed floor tile samples to his wife on a > business trip for her final veto and not being allowed to caption > them. I don't have to imagine it, I've done it, more or less something like this: "Dear wifey, here are five pictures of the tiles I like. My favourite is tile02.jpg. They are all in the price range we can afford. You pick the one you think suits best, then call Freddy at TileMart on blah blah blah and order them. We'll need X square metres." Sheesh Roedy, to listen to you go anyone would think that human communication was impossible before HTML email was invented. -- Steven. From grante at visi.com Sat Oct 29 16:36:20 2005 From: grante at visi.com (Grant Edwards) Date: Sat, 29 Oct 2005 20:36:20 -0000 Subject: popen2 References: <1130524659.070912.256550@o13g2000cwo.googlegroups.com> <11m6tj5q9rskma1@corp.supernews.com> Message-ID: <11m7na4je921j89@corp.supernews.com> On 2005-10-29, Piet van Oostrum wrote: >>GE> That would require that the application know about the named >>GE> pipe and open it. I don't think there is any way to swap a >>GE> pipe in for stdin/stdout once a process is running. > > Sure. 'myprogram' should be designed to communicate through a > named pipe, or be called with named pipe(s) as stdin/stdout. That's all well and good, but it's got nothing to do with the OP's problem: he's got a program that's already running and he wants to write a Python program that can "attach" pipes to that already running program's stdin/stdout. I know there's no way to do that under Unix. IIRC, the OP is running Win32, and I'm not quite as confident that it can't be dont under Win32, but I don't think it can. -- Grant Edwards grante Yow! With YOU, I can be at MYSELF... We don't NEED visi.com Dan Rather... From usgog at yahoo.com Tue Oct 25 12:37:09 2005 From: usgog at yahoo.com (usgog at yahoo.com) Date: 25 Oct 2005 09:37:09 -0700 Subject: Newbie question: string replace Message-ID: <1130258229.662596.228630@g49g2000cwa.googlegroups.com> I have a config file with the following contents: service A = { params { dir = "c:\test", username = "test", password = "test" } } I want to find username and replace the value with another value. I don't know what the username value in advance though. How to do it in python? From john at castleamber.com Sun Oct 16 01:26:51 2005 From: john at castleamber.com (John Bokma) Date: 16 Oct 2005 05:26:51 GMT Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <11l16dst501kjdd@corp.supernews.com> Message-ID: Steven D'Aprano wrote: > On Sun, 16 Oct 2005 00:47:09 +0000, John Bokma wrote: > >> Ok, let me spell it out for you: If all your applications are web >> based, and the OS shouldn't matter, why do Linux distributions >> matter? It doesn't matter which one you use to run, for example, >> OpenOffice. Yet people pick a certain distribution. Why? Well, one >> reason is that people like to belong to a group. So even if it really >> doesn't matter which OS you are going to use to access a web >> application, or even which browser, people will pick a certain >> browser, and a certain OS, just because. > > Dude, do you think that Microsoft gives a rat's tail[1] for what a > handful of computer enthusiasts and geek programmers pick? So you missed the point again. > They want > to control the business world, and believe me, corporations don't pick > the OS of their computer because they want to join a community, they > pick the OS that lets them run the applications that their business > needs to run. So basically you're saying that even if web based applications become the shit, everybody keeps running Microsoft? So I am right :-) > Operating-system independent browser-based applications threaten the > ability of Microsoft to tie that choice to Windows. Ah, sure, you really think that a business is going to run office applications on a web server? Are they already moving to Linux with OpenOffice (free as in speech?). > That is why MS > decided to bundle IE with Windows and (try to) kill off Netscape as a > competitor. So and when exactly do we see the web based office? -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From mwm at mired.org Wed Oct 5 00:38:08 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 05 Oct 2005 00:38:08 -0400 Subject: Newbie Text Processing Question References: <1128481479.661502.14020@g14g2000cwa.googlegroups.com> Message-ID: <867jcsinnz.fsf@bhuda.mired.org> gshepherd281 at earthlink.net writes: > I'm a total newbie to Python so any and all advice is greatly > appreciated. Well, I've got some for you. > I'm trying to use regular expressions to process text in an SGML file > but only in one section. This is generally a bad idea. SGML family languages aren't easy to parse - even the ones that were designed to be easy to parse - and generally require very complex regular expessions to get right. It may be that your SGML data can be parsed by the re you use, but there are almost certainly valid SGML documents that your parser will not properly parse. In general, it's better to use a parser for the language in question. > So the input would look like this: > > RESEARCH GUIDE > <sec-main no="1.01"><title>content > <para>content > > <sec-main no="2.01"><title>content > <para>content > > > <ch-part no="II"><title>FORMS > <sec-main no="3.01"><title>content > > <sec-sub1 no="1"><title>content > <para>content > > <sec-sub2 no="1"><title>content > <para>content This is funny-looking SGML. Are the the end tags really optional for all the tag types? > But no matter what I try I end up changing the entire file rather than > just one part. Other have explained why you can't do that, so I'll skip it. > Here's what I've come up with so far but I can't think of anything > else. > > *** > > import os, re > setpath = raw_input("Enter the path where the program should run: ") > print > > for root, dirs, files in os.walk(setpath): > fname = files > for fname in files: > inputFile = file(os.path.join(root,fname), 'r') > line = inputFile.read() > inputFile.close() > > > chpart_pattern = re.compile(r'<ch-part > no=\"[A-Z]{1,4}\"><title>(RESEARCH)', re.IGNORECASE) This makes a number of assumptions that are invalid about SGML in general, but may be valid for your sample text - how attributes are quoted, the lack of line breaks, which can be added without changing the content, and the format of the "no" attribute. > while 1: > if chpart_pattern.search(line): > line = re.sub(r"<sec-main > no=(\"[0-9]*.[0-9]*\")><title>(.*)", r"<sec-main > no=\1><title>\2\n<biblio>", line) Ditto. Heren's an sgmllib solution that gets does what you do above, except it writes it to standard out: #!/usr/bin/env python import sys from sgmllib import SGMLParser datain = """ <ch-part no="I"><title>RESEARCH GUIDE <sec-main no="1.01"><title>content <para>content <sec-main no="2.01"><title>content <para>content <ch-part no="II"><title>FORMS <sec-main no="3.01"><title>content <sec-sub1 no="1"><title>content <para>content <sec-sub2 no="1"><title>content <para>content """ class Parser(SGMLParser): def __init__(self): # install the handlers with funny names setattr(self, "start_ch-part", self.handle_ch_part) # And start with chapter 0 self.ch_num = 0 SGMLParser.__init__(self) def format_attributes(self, attributes): return ['%s="%s"' % pair for pair in attributes] def unknown_starttag(self, tag, attributes): taglist = self.format_attributes(attributes) taglist.insert(0, tag) sys.stdout.write('<%s>' % ' '.join(taglist)) def handle_data(self, data): sys.stdout.write(data) def handle_ch_part(self, attributes): """This should be called start_ch-part, but, well, you know.""" self.unknown_starttag('ch-part', attributes) for name, value in attributes: if name == 'no': self.ch_num = value def start_para(self, attributes): if self.ch_num == 'I': sys.stdout.write('<biblio>\n') self.unknown_starttag('para', attributes) parser = Parser() parser.feed(datain) parser.close() sgmllib isn't a very good SGML parser - it was written to support htmllib, and really only handles that subset of sgml well. In particular, it doesn't really understand DTDs, so can't handle the missing end tags in your example. You may be able to work around that. If you can coerce this to XML, then the xml tools in the standard library will work well. For HTML, I like BeautifulSoup, but that's mostly because it deals with all the crud on the net that is passed off as HTML. For SGML - well, I don't have a good answer. Last time I had to deal with real SGML, I used a C parser that spat out a parse tree that could be parsed properly. <mike -- Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From robert.kern at gmail.com Tue Oct 18 01:37:31 2005 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 17 Oct 2005 22:37:31 -0700 Subject: Hygenic Macros In-Reply-To: <J6CdnbTuYc84G8neRVn-qA@lmi.net> References: <J6CdnbTuYc84G8neRVn-qA@lmi.net> Message-ID: <dj21mr$tem$1@sea.gmane.org> David Pokorny wrote: > Hi, > > Just wondering if anyone has considered macros for Python. I have one > good use case. In "R", the statistical programming language, you can > multiply matrices with A %*% B (A*B corresponds to pointwise > multiplication). In Python, I have to type > > import Numeric > matrixmultiply(A,B) > > which makes my code almost unreadable. Well, dot(A, B) is better. But if you must: 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 opengeometry at yahoo.ca Tue Oct 11 23:39:54 2005 From: opengeometry at yahoo.ca (William Park) Date: Tue, 11 Oct 2005 23:39:54 -0400 Subject: [Info] PEP 308 accepted - new conditional expressions References: <3q4ro9Fd770nU3@individual.net> <cone.1128120829.960449.32420.500@commodore.email-scan.com> <mailman.1305.1128121518.509.python-list@python.org> <cone.1128139058.808314.32420.500@commodore.email-scan.com> <3q6oo1Fddg7eU3@individual.net> <7xr7b5zq31.fsf@ruckus.brouhaha.com> Message-ID: <aee42$434c858a$d8fea4f8$7404@PRIMUS.CA> Paul Rubin <http://phr.cx at nospam.invalid> wrote: > Reinhold Birkenfeld <reinhold-birkenfeld-nospam at wolke7.net> writes: > > For a conditional, syntax must be found, and the tradition of Python > > design is not to use punctuation for something that can be solved > > with keywords. > > Yeah, "if C then A else B" is a ancient tradition stretching from > Algol-60 to OCAML, and who knows what all else in between. I'm not > sure what Guido saw in the "A if C else B" syntax but it's not a big > deal. Perhaps, he's preparing Python for the eventual absorption into Perl7. -- 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 apardon at forel.vub.ac.be Thu Oct 27 04:12:15 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 27 Oct 2005 08:12:15 GMT Subject: Would there be support for a more general cmp/__cmp__ References: <slrndlegvb.1lo.apardon@rcpc42.vub.ac.be> <mailman.2303.1129805834.509.python-list@python.org> <slrndleuuo.1lo.apardon@rcpc42.vub.ac.be> <mailman.2306.1129808035.509.python-list@python.org> <slrndlh430.1lo.apardon@rcpc42.vub.ac.be> <djbaur$ruj$1@rumours.uwaterloo.ca> <slrndlpa1e.hdl.apardon@rcpc42.vub.ac.be> <pan.2005.10.24.12.07.23.897761@REMOVETHIScyber.com.au> <slrndlpnic.hdl.apardon@rcpc42.vub.ac.be> <djleav$86k$1@rumours.uwaterloo.ca> <pan.2005.10.25.14.50.12.136272@REMOVETHIScyber.com.au> <slrndlug2l.hdl.apardon@rcpc42.vub.ac.be> <xkL7f.213784$p_1.11962@tornado.tampabay.rr.com> Message-ID: <slrndm12uv.hdl.apardon@rcpc42.vub.ac.be> Op 2005-10-26, Ron Adam schreef <rrr at ronadam.com>: > > > Antoon Pardon wrote: > >> Op 2005-10-25, Steven D'Aprano schreef <steve at REMOVETHIScyber.com.au>: > >>>Can somebody remind me, what is the problem Antoon is trying to solve here? >> >> >> Well there are two issues. One about correct behaviour and one about >> practicallity. >> >> The first problem is cmp. This is what the documentation states: >> >> cmp(x, y) >> Compare the two objects x and y and return an integer according to >> the outcome. The return value is negative if x < y, zero if x == y >> and strictly positive if x > y. >> >> The problem is, that if someone implements a partial ordered class, >> with the rich comparisons, cmp doesn't behave correct. It can't >> behave correct because it will always give an number as a result >> and such a number implies one of three relations between two >> elements, but with partial ordered classes, it is possible none >> of these relations exist between those two elements. So IMO cmp >> should be changed to reflect this. This can be done either by cmp >> returning None or UnequalValues. or by cmp raising UnequalValues >> in such a case. > > Instead of changing cmp, why not just have several common versions to > choose from instead of trying to make one tool do it all? That would be an option. Lets call such an alternative comp. Would that mean also have a __comp__ method for customization. >> The second part is one of practicallity. Once you have accepted cmp, >> should reflect this possibility, it makes sense that the __cmp__ >> method should get the same possibilities, so that where it is more >> pratical to do so, the programmer can implement his partial order >> through one __cmp__ method instead of having to write six. >> >> >> In my opinion such a change would break no existing code. This >> is because there are two possibilities. > > >> 1) The user is using cmp on objects that form a total order. >> In such circumstances the behaviour of cmp doesn't change. >> >> 2) The user is using cmp on objects that don't form a total >> order. In such circumstances cmp doesn't give consistent >> results, so the code is already broken. > > Adding complexity to cmp may not break code, but it could probably slow > down sorting in general. The evidence suggests that cmp is not used in sorting. If you have a list of sets, sort will happily try to sort it, while calling cmp with a set as an argument throws an exception. I have a feeling that adding comp (and its brother __comp__) would have a detrimental effect on sorting, because using '<' would then mean one extra method to look for that could be used in determining if a < b or not. > So I would think what ever improvements or > alternatives needs to be careful not to slow down existing sorting cases. I have done some tests and have come to the conclusion that other factors will have a greater influence on sorting times. I have written the following program to estimate effects: from random import shuffle from time import time class UnequalValues(Exception): pass class cla: def __init__(self, i): self.value = int(i) def __cmp__(self, other): return self.value - other.value class clb: def __init__(self, i): self.value = int(i) def __lt__(self, other): return self.value < other.value class clc: def __init__(self, i): self.value = int(i) def __comp__(self, other): return self.value - other.value def __lt__(self, other): try: return self.__comp__(other) < 0 except UnequalValues: return False def test(lng, rep): for cl in cla, clb, clc: total = 0.0 for _ in xrange(rep): lst = [cl(i) for i in xrange(lng)] shuffle(lst) start = time() lst.sort() stop = time() total += stop - start print "%s: %d repeats, %d long, %9.6f secs" % (cl, rep, lng, total) test(1000,1000) This is the result I get: __main__.cla: 1000 repeats, 1000 long, 31.986618 secs __main__.clb: 1000 repeats, 1000 long, 8.963896 secs __main__.clc: 1000 repeats, 1000 long, 16.893321 secs I find it very odd that clc sorts about twice as fast as cla. That means that every class that has a __cmp__ method can be speeded up with sorting by writing a similar __lt__ method as in clc. I do wonder what is causing this. -- Antoon Pardon From mwm at mired.org Thu Oct 6 22:46:51 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 06 Oct 2005 22:46:51 -0400 Subject: When someone from Britain speaks, Americans hear a "British accent"... References: <1119983260.720573.255200@z14g2000cwz.googlegroups.com> <mailman.1019.1119995572.10512.python-list@python.org> <djcbk1llj080upi7j8hu28c82u6rdlh9gh@4ax.com> <11kbgj7421kd560@corp.supernews.com> Message-ID: <867jcqoxgk.fsf@bhuda.mired.org> Grant Edwards <grante at visi.com> writes: > On 2005-10-06, DaveM <asma61 at dsl.pipex.com> wrote: >>>Frankly, I can't watch Shakespeare or movies like "the full >>>monty" or "trainspotting" because I can't understand a damn >>>word they say. British talk sounds like gibberish to me for the >>>most part. >> Not just you. It always amuses me in trips to the US that >> British voices (outside of the movies) are often subtitled, >> while first-generation Americans whose English is. um, >> limited, are not. > What?!? I've never seen a British voice (inside or outside of > the movies) subtitled -- with the exception of one of a > nightclub scenes in one movie (I think it was Trainspotting) > where the dialog was inaudible because of the music. Maybe they were dubbed? I know America International dubbed the first version of "Mad Max" that they imported into the US. Then again, American International is well-know for their quality. <mike -- Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From hrvoje at despammed.com Wed Oct 5 02:57:26 2005 From: hrvoje at despammed.com (Hrvoje Blazevic) Date: Wed, 05 Oct 2005 08:57:26 +0200 Subject: Idle In-Reply-To: <1128472457.920615.52980@g43g2000cwa.googlegroups.com> References: <dhuo72$8lo$1@ss405.t-com.hr> <08C0f.517$ht7.198@newssvr21.news.prodigy.com> <dhurjr$fsg$1@ss405.t-com.hr> <1128472457.920615.52980@g43g2000cwa.googlegroups.com> Message-ID: <dhvtcd$qt9$1@ss405.t-com.hr> petercable at gmail.com wrote: > If you are compiling python and you want to build idle/tkinter, you > need to have the development packages for tcl and tk. The python build > scripts will only build tkinter should they find the libraries > (libtk8.4.so and libtcl8.4.so) and the header files (tk.h and tcl.h). > If you don't have the development packages installed, you most likely > do not have the header files. > > If you install the development packages and recompile, test by > importing _tkinter. If that is successful, idle should run just fine. > Thanks. After installing new versions of Tcl/Tk, python compilation did work. What is surprising is that although Python is bundled with most (all?) Linux distros, Idle does not work on most??? -- Hrvoje From steve at REMOVETHIScyber.com.au Sun Oct 9 08:15:13 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 09 Oct 2005 22:15:13 +1000 Subject: Here I am again, same old arguments References: <wg32f.411657$x96.212964@attbi_s72> Message-ID: <pan.2005.10.09.12.15.12.523844@REMOVETHIScyber.com.au> On Sun, 09 Oct 2005 07:02:52 +0000, CJ wrote: > Okay, same program, different issue. Thanks to the help that I was > given I was able to complete my program to find variables in a list that > were repeated, and display them once, and how many times they appeared in > the list. And it worked great! > > But, being the perfectionist that I am, I wanted to make the proggie > allow any size of list, and not have to be recoded every time. So step > one was to not make the program reliant on the list itself being of X > length all the time. First off -- don't use a for loop with an index as you are doing. > #setup variables > grub=[3,25,3,5,3,"a","a","BOB",3,3,45,36,26,25,"a",3,3,3,"bob","BOB",67] > grubrpt=grub > cntro=0 > cntrt=0 > rpt=0 > skipped=0 You are doing too much manual work! Let Python do the lion's share of the work for you! > #set up for variable length of grub > ttllen=len(grub)-1 Why are you subtracting one from the length of the list? > print "The heck is this for loop doing?" > for point in range(0,ttllen,1): Using point as a loop index is generally a bad idea. The result coming from range is not a point, it is an integer, so why call it a point? You are also over-specifying the input arguments to range. If the step size is one, you don't need to specify it -- that's the default. You just make it harder to read, for no reason. Likewise the initial starting value of zero. Just use range(ttllen). This, by the way, will return a list [0, 1, 2, ... , length of list - TWO] because you already subtracted one from the length. > print "Here's Grub=",grub > print "And grubrpt=",grubrpt > grubrpt[point]="blk" As others have pointed out, grub and grubrpt are both names for the same list. Changing one changes the other. > #Makes sure that there are not multiple prints. > def alrdy_dn(grub,grubrpt): > if grub[cntro] in grubrpt: Ew!!! Global variables!!! Bad programmer! No biscuit!!! *wink* Global variables are almost always a BAD idea. > return grubrpt > else: > print grub[cntro],"appears in list",rpt,"times." > grubrpt[grubrpt.index("blk")]=grub[cntro] return grubrpt This is a strange function. What exactly is it meant to do? It combines user interface (printing the number of times each item appears) and functionality (counting the number of times each item appears) and side effects (changing the list), before returning one of the input arguments again. At least two of those things (counting the items, and printing the results) should be separated into different functions for ease of comprehension. I'm going to skip the rest of your code, because I don't understand it and am too lazy, er, I mean busy, to spend the time trying to decipher it. Especially since the function you are trying to duplicate manually is so easy to do if you work with Python instead of against it. def count_item(L, item): """Count the number of times item appears in list L.""" return L.count(item) Or wait... that's too easy :-) If you want to roll your own, then do it like this: def count_item(L, item): """Count the number of times item appears in list L by reinventing the wheel.""" n = 0 for obj in L: if obj == item: n += 1 return n Notice that we don't change the list at any time. Why change it? That just adds complexity to our program and adds extra places to make bugs. Of which you have many :-) Now you use it like this: grub=[3,25,3,5,3,"a","a","BOB",3,3,45,36,26,25,"a",3,3,3,"bob","BOB",67] for item in grub: n = count_item(grub, item) print item, "appears in list", n, "times." And you are done. No, not quite -- my code has a bug in it. You want to print the count for each *unique* item. Mine prints the count for each item, regardless of whether it is unique or not. So what we need to keep track of which items have been counted before. Here is one way of doing it: grub=[3,25,3,5,3,"a","a","BOB",3,3,45,36,26,25,"a",3,3,3,"bob","BOB",67] already_seen = [] for item in grub: if item not in already_seen: n = count_item(grub, item) print item, "appears in list", n, "times." already_seen.append(item) Notice that rather than *deleting* from a copy of the original list, we *add* to a new list that started off empty. Here is another way: grub=[3,25,3,5,3,"a","a","BOB",3,3,45,36,26,25,"a",3,3,3,"bob","BOB",67] unique_counts = {} # use a dictionary, not a list for item in grub: n = count_item(grub, item) unique_counts[item] = n for item, n in unique_counts.items(): print item, "appears in list", n, "times." The second version has a disadvantage that the objects in your list can't be lists themselves, because lists can't be keys of dictionaries. It also has what appears to be a disadvantage that it stores the item count in the dictionary, even if that count has already been stored. Wasted work! But wait... it might not be wasted. It takes work to test if your item has already been seen. That work might be more than it would take to just blindly store the result even if it is there. Think of this real world equivalent. You tried to send a fax to somebody, but you aren't sure if it went through correctly. What's the cheapest way to make sure? You could call them up on the phone and ask, but that costs money and time. It could be cheaper and quicker to just re-fax the document. > Also, I do realize that there is an easier way to do this, I just > created a little project for myself to learn the basics of the language. This is good, but keep in mind that "the basics" of Python include tools to do things you are trying to do by hand. For instance, if you find yourself writing a loop like this: counter = 0 while counter < some_value: do_something_with(counter) counter = counter + 1 you almost always want to change that to: for counter in range(some_value): do_something_with(counter) If you find a loop like this: for indx in range(len(some_list)): obj = some_list[indx] do_something_with(obj) you almost always want to write it like this: for obj in some_list: do_something_with(obj) Don't fight the language -- you aren't programming in C or Java now, this is Python and there is usually an easier way to do something. *wink* Hope this is of use to you, -- Steven. From guillermo_s at hotmail.com Tue Oct 4 21:34:03 2005 From: guillermo_s at hotmail.com (Ville) Date: 4 Oct 2005 18:34:03 -0700 Subject: Turn $6 into $6.000 Message-ID: <1128476043.147955.40620@f14g2000cwb.googlegroups.com> HOW TO TURN 6 BUCKS INTO 6 THOUSAND! (WORLD WIDE) WARNING: READING THIS WILL CHANGE YOUR LIFE! I found this on a Bulletin board and decided to try it. A little while back, I was browsing through newsgroups, just like you are now, and came across an article similar to this that said you could make thousands of dollars within weeks with only an initial investment of $6.00! So I thought, "Yeah right, this must be a scam", but like most of us, I was curious, so I kept reading.Anyway, it said that you send $1.00 to each of the 6 names and addresses stated in the article. You then place your own name and address in the bottom of the list at #6, and post the article in at least 200 newsgroups. (There are thousands) No catch, that was it. So after thinking it over, and talking to a few people first, I thought about trying it. I figured: "what have I got to lose except 6 stamps and $6.00, right?" Then I invested the measly $6.00. Well GUESS WHAT!! Within 7 days, I started getting money in the mail! I was shocked! I figured it would end soon, but the money just kept coming in. In my first week, I made about $25.00. By the end of the second week I had made a total of over $1,000.00! In the third week I had over $10,000.00 and it's still growing. This is now my fourth week and I have made a total of just over $42,000.00 and it's still coming in rapidly. It's certainly worth $6.00, and 6 stamps, I have spent more than that on the lottery!! Let me tell you how this works and most importantly, why it works. Also, make sure you print a copy of this article NOW, so you can get the information off of it, as you need it. I promise you that if you follow the directions exactly, that you will start making more money than you thought possible by doing something so easy! Suggestion: Read this entire message carefully! (Print it out or download it.) Follow the simple directions and watch the money come in! It's easy. It's legal, and your investment is only $6.00 (Plus postage) IMPORTANT: This is not a rip-off; it is not indecent; it is not illegal; and it is virtually no risk because it really works!!!If all of the following instructions are adhered to exactly, you will receive extraordinary dividends. PLEASE NOTE: Please follow these directions EXACTLY, and $50,000 or more can be yours in 20 to 60 days. This program remains successful because of the honesty and integrity of the participants. Please continue its success by carefully adhering to the instructions. You will now become part of the Mail Order business. In this business your product is not solid and tangible, it's a service. You are in the business of developing Mailing Lists. Many large corporations are happy to pay big bucks for quality lists. However, the money made from the mailing lists is secondary to the income which is made from people like you and me asking to be included in that list. Here are the 4 easy steps to success: STEP 1: Get 6 separate pieces of paper and write the following on each piece of paper "PLEASE PUT ME ON YOUR MAILING LIST!" Now get 6 US $1.00 bills and place ONE inside EACH of the 6 pieces of paper so the bill will not be seen through the envelope (to prevent thievery). Next, place one paper in each of the 6 envelopes and seal them. You should now have 6 sealed envelopes, each with a piece of paper stating the above phrase, your name and address, and a $1.00 bill. What you are doing is creating a service. THIS IS ABSOLUTELY LEGAL! You are requesting a legitimate service and you are paying for it! Like most of us I was a little skeptical and a little worried about the legal aspects of it all. So I checked it out with the U.S. Post Office (1-800-725-2161) and they confirmed that it is indeed legal. Mail the 6 envelopes to the following addresses: Note: Make sure you put the correct amount of postage stamps on your envelopes.Other countries my need more stamps so be correct on how many you put.And remember your business will be running Throughout the world so when you start posting messages or emails to people this will bring in thousands of dollars from all over the world. So now, you have money flowing \ in from countries!That's how I became so successful in this business. Mail the 6 envelopes to the following addresses: #1) Tom Zimmerman IV 193 Yard St Nesquehoning, PA. 18240 #2) B. Pratt 5535 E 100 N Knox, IN 46534 #3) Michele Tyska PO Box 765 Northport, NY 11768 #4) David Weir PO Box 144 Schooleys Mt., NJ 07870 #5) S. Nagirnyak 14139 Pine Forest Drive #208 North Royalton, OH 44133 #6) Guillermo Oscar Sanchez Mallea Madero 225 Vicente Lopez CP:1638 Buenos Aires - Argentina STEP 2:Now take the #1 name off the list that you see above, move the other names up (6 becomes 5, 5 becomes 4, etc...) and add YOUR NAME as number 6 on the list.STEP 3: Change anything you need to, but try to keep this article as close to original as possible. Now, post your amended article to at least 200 newsgroups. (I think there are close to 24,000 groups) All you need is 200, but remember, the more that you post, the more money you make! This is perfectly legal! If you have any doubts, refer to Title 18 Sec. 1302 & 1341 of the Postal lottery laws. Keep a copy of these steps for yourself and, whenever you need money, you can use it again, and again. PLEASE REMEMBER that this program remains successful because of the honesty and integrity of the participants and by their carefully adhering to the directions. Look at it this way, if you are a person of integrity, the program will continue and the money that so many others have received will come your way. NOTE: You may want to retain every name and address sent to you, either on a computer or hard copy and keep the notes people send you. This VERIFIES that you are truly providing a service. (Also, it might be a good idea to wrap the $1 bill in dark paper to reduce the risk of mail theft.) So, as each post is downloaded and the directions carefully followed, six members will be reimbursed for their participation as a List Developer with one dollar each. Your name will move up the list geometrically so that when your name reaches the #1 position you will be receiving thousands of dollars in CASH!!! What an opportunity for only $6.00 ($1.00 for each of the first six people listed above) Send it now, add your own name to the list and you're in business!!! DIRECTIONS FOR HOW TO POST TO NEWSGROUPS: STEP 1: You do not need to re-type this entire letter to do your own posting. Simply put your cursor at the beginning of this letter and drag your cursor to the bottom of this document, and select ''copy'' from the edit menu. This will copy the entire letter into the computer''s memory. STEP 2: Open a blank ''notepad'' file and place your cursor at the top of the blank page. From the ''edit'' menu select ''paste''. This will paste a copy of the letter into notepad so that you can add your name to the list. STEP 3: Save your new notepad file as a text file. If you want to do your postings in different settings, you''ll always have this file to go back to. STEP 4: Use Netscape or Internet explorer and try searching for various newsgroups (on-line forums, message boards, chat sites, discussions.) STEP 5: Visit these message boards and post this article as a new message by highlighting the text of this letter and selecting paste from the edit menu. Fill in the Subject, this will be the header that everyone sees as they scroll through the list of postings in a particular group, click the post message button. You''re done with your first one! Congratulations...THAT''S IT! All you have to do is jump to different newsgroups and post away, after you get the hang of it, it will take about 30 seconds for each newsgroup! **REMEMBER, THE MORE NEWSGROUPS YOU POST IN, THE MORE MONEY YOU WILL MAKE!! BUT YOU HAVE TO POST A MINIMUM OF 200** that''s it! You will begin receiving money from around the World within days! You may eventually want to rent a P.O. Box Due to the large amounts coming to you!P.S. It's only 6 bucks what u got to lose? So check it out! From steve at REMOVETHIScyber.com.au Sun Oct 9 05:56:02 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 09 Oct 2005 19:56:02 +1000 Subject: Function decorator that caches function results References: <TdCdnVSTs-A-Wtre4p2dnA@telenor.com> Message-ID: <pan.2005.10.09.09.56.02.95699@REMOVETHIScyber.com.au> On Sat, 08 Oct 2005 15:20:12 +0200, Lasse V?gs?ther Karlsen wrote: > Ok, so I thought, how about creating a decorator that caches the > function results and retrieves them from cache if possible, otherwise it > calls the function and store the value in the cache for the next invokation. > > This is what I came up with so far: > > def cache_function(fn): > cache = {} > def cached_result(*args, **kwargs): > if args in cache: > return cache[args] > result = fn(*args, **kwargs) > cache[args] = result > return result > return cached_result I'm curious... where does cache live after you use cache_function to memoize some function? It doesn't appear to be an attribute of the newly memoized function, nor does it look like a global variable. > The solution would have to consider fibonacci(50) and fibonacci(idx = > 50) as the same call and thus retrieve the second one from the cache. In general, you probably can't do that without lots and lots of really clever code searching through the function argument lists. If you know that your function will always have the same keyword, then you can do something like this: if args in cache: return cache[args] elif kwargs.keys() == "idx": return cache[kwargs["idx"]] but that's a special case and you really don't want to do it *wink* Otherwise, just accept that you may be caching multiple copies of the same data, and do something like this: if args in cache: return cache[args] elif kwargs.items() in cache: return cache[kwargs.items()] with the appropriate changes to the rest of the code. You may also find that you could get a slight performance increase by using the idiom try: return cache[args] except: # calculate the result and store it in the cache. instead of testing for membership. As always, timing some test functions is your friend... -- Steven. From mwm at mired.org Mon Oct 31 17:54:10 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 31 Oct 2005 17:54:10 -0500 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <djqie5$5vf$1@nntp.webmaster.com> <7xbr1aewtq.fsf@ruckus.brouhaha.com> <djr2no$bto$1@nntp.webmaster.com> <86acgulv5z.fsf@localhost.localdomain> <djr3jo$c4m$1@nntp.webmaster.com> <7xvezi8ypy.fsf@ruckus.brouhaha.com> <86y84ehd3j.fsf@bhuda.mired.org> <djrkc9$i9u$1@nntp.webmaster.com> <86hdb2h750.fsf@bhuda.mired.org> <djrvhu$mb4$1@nntp.webmaster.com> <86zmoufiww.fsf@bhuda.mired.org> <djtvt0$dhl$1@nntp.webmaster.com> <86oe59e57v.fsf@bhuda.mired.org> <djuiii$k49$1@nntp.webmaster.com> <868xwcevke.fsf@bhuda.mired.org> <dk5r3p$ab5$1@nntp.webmaster.com> <86br1530w7.fsf@bhuda.mired.org> <dk5v7p$bqp$1@nntp.webmaster.com> <867jbt2xyb.fsf@bhuda.mired.org> <dk64nk$dp0$1@nntp.webmaster.com> Message-ID: <863bmh2t7x.fsf@bhuda.mired.org> "David Schwartz" <davids at webmaster.com> writes: >> I'm trying to find out why you regularly ignore that difference for >> everyone but MS. > To substantiate that claim, you'd have to point to some cases where I > talk about something other than MS. You do that *every time* someone compares MS with other criminals - you immediately refer to "criminals with guns" and refuse to discuss the issue further. And yes, you've already claimed that you only do that when the other reference is to "actual use of force", and I've already disproved that. > But if you do a little research, you'll find I'm completely > consistent and have said similar things about numerour other > entities. Not in this thread, you haven't. The only consistency here has been trying to treat MS's crimes as somehow different from other peoples crimes. I'm still waiting for you to quit trying to lie (or, as you would say, "argue") your way out of it, and come up with a reason for this behavior other than doing so at MS's orders. <mike -- Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From usenet at marduk.letterboxes.org Wed Oct 5 16:08:46 2005 From: usenet at marduk.letterboxes.org (marduk) Date: Wed, 05 Oct 2005 20:08:46 GMT Subject: how to keep collection of existing instances and return one on instantiation In-Reply-To: <di1275$66b$02$1@news.t-online.com> References: <1128529206.4560.13.camel@blackwidow> <mailman.1554.1128531386.509.python-list@python.org> <1128532725.4560.25.camel@blackwidow> <di1275$66b$02$1@news.t-online.com> Message-ID: <1128542925.4560.37.camel@blackwidow> On Wed, 2005-10-05 at 19:24 +0200, Peter Otten wrote: > Use a weakref.WeakValueDictionary as the cache instead of a normal > dict. > > Peter Thanks for the reference to the weakref module. Until now I've never had a use for it, but it sounds like what I'm looking for. -m From xushanjun1212 at yahoo.com-dot-cn.no-spam.invalid Mon Oct 3 08:46:18 2005 From: xushanjun1212 at yahoo.com-dot-cn.no-spam.invalid (shanjunxu) Date: 03 Oct 2005 12:46:18 GMT Subject: about pyopengl Message-ID: <4341281a$1$98071$892e7fe2@authen.white.readfreenews.net> I am a chinese boy,my english is not good,so i don not know how to tell you about my question,i hope you can understand what i say. I like python, and now i using pyopengl to draw three-dimensional. but how can i use mouse to control objects?such as selecting object.I know a function( glSelectBuffer() ) can be used,In C language the format is glSelectBuffer(size, buffer), but in python the format is glSelectBuffer(size), how can i get the "buffer" pointer? The following is one section function of my codes: def ProcessSelection(x,y): viewport=range(4) glSelectBuffer(64) viewport=glGetIntegerv(GL_VIEWPORT) glMatrixMode(GL_PROJECTION) glPushMatrix() glRenderMode(GL_SELECT) glLoadIdentity() gluPickMatrix(x, viewport[3]-y, 2, 2, viewport) gluPerspective(45.0, aspect, 0.1, 200.0) DrawButton() hits=glRenderMode(GL_RENDER) glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) If you know how to do ,can you mail to me?thank you! my e-mail is xushanjun1212 at yahoo.com.cn From rvtol+news at isolution.nl Sun Oct 9 05:19:26 2005 From: rvtol+news at isolution.nl (Dr.Ruud) Date: Sun, 9 Oct 2005 11:19:26 +0200 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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <pan.2005.10.04.23.38.40.465171@REMOVETHIScyber.com.au> <csbgk199k2jkvcdl6v0s2jd6q6s6k9d1to@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> <PK-dnZZdetOs39Xe4p2dnA@telenor.com> <7xvf07a1ro.fsf@ruckus.brouhaha.com> <86ll13mlpn.fsf@bhuda.mired.org> Message-ID: <diauqc.g8.1@news.isolution.nl> Mike Meyer: > Paul Rubin: >> I read mail over an ssh connection to a Unix shell. I have no easy >> way to read html email with a graphics browser. > > You don't need a grahics browser - you just need a browser. I read > mail in emacs, and use emacs-w3m to view html in the mailer. Works for > most things, and doesn't have the nasty side effect of letting the > sender know I read it by fetching images from their web site. > >> I occasionally get html email that I want to read. I save it in a >> file and read it with lynx, which so far works perfectly well. I >> find html email to be a PITA and as someone else said, html in email >> is an almost sure sign that it's a message that I want to trash >> without reading it. > > Unfortunately, I've found that HTML email comes in two flavors: That > which sets content-type to text/html in the headers, and that which > sets it to some form of multipart in the headers. I used to bounce all > mail of either form. Then I discovered that the AOL client - used by > my relatives - could *not* be set to not send HTML email. At least it > sends text/plain as well. On investigation, most legit email does > sends multipart/mixed, so I only reject mail whose sole content is > text/html. Let procmail make all those decisions and transformations for you. I have a maildir called 'raw' where I keep a copy of all non-spammish mail. Copies of the same messages also get delivered in the right mailboxes, by procmail. A message that contains only html, is piped though lynx -dump -stdin. A message containing both HTML and a plain/text-part, is de-mime-d, leaving only the plain/text-part (unless that part contains only a silly remark). Footers and long signatures are limited or even deleted. Etc., etc. (I like my mail cooked.) One of the reasons that I started with Perl, is that I want to rewrite procmail in Perl. -- Affijn, Ruud <http://www.pandora.com/?sc=sh770781&cmd=tunermini> "Gewoon is een tijger." From csubich.spam.block at spam.subich.block.com Fri Oct 7 14:10:33 2005 From: csubich.spam.block at spam.subich.block.com (Christopher Subich) Date: Fri, 07 Oct 2005 14:10:33 -0400 Subject: socketServer questions In-Reply-To: <7xll15paha.fsf@ruckus.brouhaha.com> References: <1128699247.9040.15.camel@athop1.ath.vt.edu> <7xll15paha.fsf@ruckus.brouhaha.com> Message-ID: <di6dmt$r46$1@rumours.uwaterloo.ca> Paul Rubin wrote: > rbt <rbt at athop1.ath.vt.edu> writes: > >>1. Do I need to use threads to handle requests, if so, how would I >>incorporate them? The clients are light and fast never sending more >>than 270 bytes of data and never connecting for more than 10 seconds >>at a time. There are currently 500 clients and potentially there >>could be a few thousand... how high does the current version scale? > > open for very long. If you want to have longer-running connections > open simultaneously, you need some type of concurrency such as threads. > But then you have to write the code differently, to serialize the > log recording. > > You probably should get a copy of "Python Cookbook" which explains the > basics of multi-threaded programming, if you have to ask a question Or take a look at non-threaded ways of doing non-blocking IO; I've personally used the Twisted libraries and they work decently without manual thread overhead [indeed, the default reactor uses select, and there's a version for 'nix systems that uses poll]. Either way will work, it just depends on how deeply you want to integrate the network functionality into the code. As someone else said (paraphrased, an apologies for stealing the quote; a Google search isn't bringing it up), "You don't use Twisted, you provide Twisted callbacks to use you." From mwm at mired.org Mon Oct 3 00:20:18 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 03 Oct 2005 00:20:18 -0400 Subject: Will python never intend to support private, protected and public? References: <7xbr2dxqqq.fsf@ruckus.brouhaha.com> <dhed0c$uk4$1@newsreader1.utanet.at> <7xk6h0zxnm.fsf@ruckus.brouhaha.com> <dhf3id$b7n$1@newsreader1.utanet.at> <7x64skzvas.fsf@ruckus.brouhaha.com> <pan.2005.09.28.23.33.50.934919@REMOVETHIScyber.com.au> <7xll1gvk7w.fsf@ruckus.brouhaha.com> <1128001308.905398.321670@g44g2000cwa.googlegroups.com> <311b5ce105092908332c12164c@mail.gmail.com> <mailman.1163.1128009314.509.python-list@python.org> <7xbr2btv84.fsf@ruckus.brouhaha.com> <bvkpj1hcg9gjj9js072d18k44p8pr35b24@4ax.com> <7xy85fvxny.fsf@ruckus.brouhaha.com> <86vf0inlt3.fsf@bhuda.mired.org> <7xd5mq9ir9.fsf@ruckus.brouhaha.com> <86wtkym33t.fsf@bhuda.mired.org> <7xll1d7l2c.fsf@ruckus.brouhaha.com> <86slvlmdnv.fsf@bhuda.mired.org> <7xr7b3spri.fsf@ruckus.brouhaha.com> <86br27mztp.fsf@bhuda.mired.org> <7x8xxbidtp.fsf@ruckus.brouhaha.com> Message-ID: <86ll1bkz99.fsf@bhuda.mired.org> Paul Rubin <http://phr.cx at NOSPAM.invalid> writes: > Mike Meyer <mwm at mired.org> writes: >> > What convention? It just makes it possible to write code with some >> > specific invariants if there's a need to do so. >> That you don't pass private variables to a function unless it's a builtin. > No, I don't see that as "convention", it's just something that you do > if you want to make sure that all the references are local or > builtins. Semantics... > It's like saying that if you if you want to be sure that x > is always positive, then don't execute statements like "x = -3". I > wouldn't call something like that a "convention". Right - that's not a convention. That behavior would be a convention if you did somehing like prefixing the variable name with a "p" to indicate that you don't do that. > maybe I'd like to be sure that x never yields negative numbers. > CPython happens to have some features that stop me from guaranteeing > that invariant. I'd say CPython was missing the features that you need to guarantee that. Missing quite a *lot* of features, in fact. But Python has never been about keeping people from writing bad code - it's about helping people write good code. >> It wouldn't catch overriding things in __builtins__ or >> overriding builtins in a module, or things poking at the variable >> through __dict__, or - well, there are probably lots of things that >> need to be dealt with. > Yes, but I see all of those as implementation artifacts, not anything > fundamental. Right - those aren't fundamental. It's things like Python allowing programmers to use whatever style is appropriate to the problem at hand, rather than insisting on an OO style. Once you get outside the OO style, "private" attributes becomes problematic. >> Preventing accidents is all "private" does - without fundamental >> changes to the implementation of the language. You have to catch every >> mechanism that can be used to find a reference to an attribute, like >> references to __dict__ and to the class variable. > > The Python stdlib for a long time had a module called Bastion that > attempted to do exactly that, so you can't say that the desire is > un-Pythonic. Of course I can say it's unpythonic. I might even be right: just because the standard library does something doesn't mean that something is automatically pythonic. But I haven't said that "private" is unpythonic. I will say that the things you need to program effectively with private variables - like having to inherit all your utility functions - is unpythonic. > Bastion was only removed because implementation issues > kept it from working properly. Those issues probably can't bbe > resolved in the 2.x series but as the language evolves, maybe > something can be done to bring it back. Pretty much every attempt to restrict what other programmers do in Python has failed - for "implementation issues". I think that's a good sign that this kind of thing isn't going to work without some serious work on the interpreter. <mike -- Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From grunar at gmail.com Thu Oct 20 00:55:30 2005 From: grunar at gmail.com (grunar at gmail.com) Date: 19 Oct 2005 21:55:30 -0700 Subject: sqlstring -- a library to build a SELECT statement In-Reply-To: <mailman.2288.1129777943.509.python-list@python.org> References: <1129774730.887128.314960@z14g2000cwz.googlegroups.com> <mailman.2288.1129777943.509.python-list@python.org> Message-ID: <1129784130.596225.174860@z14g2000cwz.googlegroups.com> Jason Stitt wrote: > > I think some operator overloading, especially the obvious cases like > ==, is cleaner than using only functions because it lets you order > things normally. But some of the operator choices are non-intuitive. > Personally, I would make something like 'alias' a function or class, > rather than overloading XOR. Not sure about ** for where. My strategy is to do both. Have a "where" method that could be called instead of ** (ie. person.where(person.last_name=="smith"), but also allow for the ** syntax. After using it for a while, I'm finding the ** and ^ for alias very clear. Alias function brings up the issue of name-space (since table.alias could be a column if not a special method.) I'm assuming people don't use where, select, or other SQL key words as column names, and if they do, they have a table["column"] syntax to fall back on. But I digress. A method makes sense, though. > > Using // for 'in' looks really weird, too. It's too bad you can't > overload Python's 'in' operator. (Can you? It seems to be hard-coded > to iterate through an iterable and look for the value, rather than > calling a private method like some other builtins do.) // was a bit of a stretch. I'd initially thought it for the "where" clause, becuase it's lower precedence than ** (I think), and really late at night // kind of looks like a W. I decided against it because it looks to close to a comment in some other languages. Python "in" clause doesn't seem exploitable in any way--probably a good thing. I did add a "in_" method (name is arguable), which does the same thing, also a not_in. > Have you ever used Pyparsing? Its use of a combination of classes and > operator overloading works pretty well. I took a look at it. Seems like a happy balance there--with the overloading. <a href="http://www.aminus.org/blogs/index.php/fumanchu/2005/08/11/where_dejavu_fits_in_the_orm_cosmos">Dejavu</a> is another cool solution--using Lambda expressions. But it goes into scary bytecode stuff (though it's well contained). > > For SQL function calls, don't you also want to support stored > procedures? In that case, you don't want pre-set magic functions so > much as a function that takes a string parameter for a function name > and then a list of function parameters. This is what I had in mind (echo.py in the distribution). The only issue becomes knowing when to quote the parameters (is a string always a string?). I 've ended up quoting everything, and forcing the user to supply table.column notation if they don't want it quoted. > > >>>> print person_smith("party_id", "first_name") \ > >>>> > > < < model.address ** (\ > > model.address.party_id == model.person.party_id) > > SELECT > > party_id party_id, > > first_name first_name, > > address.* > > FROM > > [person] person > > LEFT OUTER JOIN [address] address ON > > address.party_id = person.party_id > > WHERE person.first_name = 'Smith' > > See, this is where I'm not sure about operator precedence. If << > binds tighter than **, it works, because the << operator would make a > 'join' object and then the ** could be interpreted as an 'on' clause. > But if ** binds tighter you get an extra 'where' clause on the > address table, and then a join... > There's a little dark magic going on with the precedence here. The ** is higher precedence, so it happens first, and is applied to the address table object, which is then joined into person (with the << operator), and pulling in the existing where on address. This sounds bad, but it allows for where clauses to trickle up through the python expression, which is how I get a + b >> c to behave as expected. Thanks for the positive feedback! Runar From bokr at oz.net Sat Oct 29 14:12:40 2005 From: bokr at oz.net (Bengt Richter) Date: Sat, 29 Oct 2005 18:12:40 GMT Subject: Scanning a file References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com> <7xek65nal0.fsf@ruckus.brouhaha.com> <1130505731.850947.68690@o13g2000cwo.googlegroups.com> <slrndm4bme.igb.a_mccarthy@hotmail.com> <867jbxfpvb.fsf@bhuda.mired.org> <1h55ri3.1hzntdk1dtxpa7N%aleaxit@yahoo.com> <43632812.1249162210@news.oz.net> <djvc4q$sai$04$1@news.t-online.com> Message-ID: <4363b997.1286415918@news.oz.net> On Sat, 29 Oct 2005 10:34:24 +0200, Peter Otten <__peter__ at web.de> wrote: >Bengt Richter wrote: > >> On Fri, 28 Oct 2005 20:03:17 -0700, aleaxit at yahoo.com (Alex Martelli) >> wrote: >> >>>Mike Meyer <mwm at mired.org> wrote: >>> ... >>>> Except if you can't read the file into memory because it's to large, >>>> there's a pretty good chance you won't be able to mmap it either. To >>>> deal with huge files, the only option is to read the file in in >>>> chunks, count the occurences in each chunk, and then do some fiddling >>>> to deal with the pattern landing on a boundary. >>> >>>That's the kind of things generators are for...: >>> >>>def byblocks(f, blocksize, overlap): >>> block = f.read(blocksize) >>> yield block >>> while block: >>> block = block[-overlap:] + f.read(blocksize-overlap) >>> if block: yield block >>> >>>Now, to look for a substring of length N in an open binary file f: >>> >>>f = open(whatever, 'b') >>>count = 0 >>>for block in byblocks(f, 1024*1024, len(subst)-1): >>> count += block.count(subst) >>>f.close() >>> >>>not much "fiddling" needed, as you can see, and what little "fiddling" >>>is needed is entirely encompassed by the generator... >>> >> Do I get a job at google if I find something wrong with the above? ;-) > >Try it with a subst of length 1. Seems like you missed an opportunity :-) > I was thinking this was an example a la Alex's previous discussion of interviewee code challenges ;-) What struck me was >>> gen = byblocks(StringIO.StringIO('no'),1024,len('end?')-1) >>> [gen.next() for i in xrange(10)] ['no', 'no', 'no', 'no', 'no', 'no', 'no', 'no', 'no', 'no'] Regards, Bengt Richter From akameswaran at gmail.com Mon Oct 24 10:02:34 2005 From: akameswaran at gmail.com (akameswaran at gmail.com) Date: 24 Oct 2005 07:02:34 -0700 Subject: newbie question about SocketServer In-Reply-To: <djbfms$4ea$1@news.freedom2surf.net> References: <1129842796.819897.309040@g49g2000cwa.googlegroups.com> <djbfms$4ea$1@news.freedom2surf.net> Message-ID: <1130162554.056436.111790@g43g2000cwa.googlegroups.com> After further playing - it seems that the server_close() just takes time to execute. I have found that if I wait a while (1-3 seconds) the second connection will fail as well. Locking is already built into my handler class - so I'll just use it to prevent further connections until server_close() completes. From pwatson at redlinepy.com Sun Oct 30 20:53:17 2005 From: pwatson at redlinepy.com (Paul Watson) Date: Sun, 30 Oct 2005 19:53:17 -0600 Subject: Scanning a file In-Reply-To: <mailman.2707.1130659042.509.python-list@python.org> References: <1130497567.764104.125110@g44g2000cwa.googlegroups.com><3sf070Fo0klqU1@individual.net> <3sg8hiFmvbo7U1@individual.net><864q70evci.fsf@bhuda.mired.org> <3si036Fofks2U1@individual.net> <mailman.2707.1130659042.509.python-list@python.org> Message-ID: <4365790D.3010009@redlinepy.com> Fredrik Lundh wrote: > Paul Watson wrote: > >>This is Cyngwin on Windows XP. > > using cygwin to analyze performance characteristics of portable API:s > is a really lousy idea. Ok. So, I agree. That is just what I had at hand. Here are some other numbers to which due diligence has also not been applied. Source code is at the bottom for both file and mmap process. I would be willing for someone to tell me what I could improve. $ python -V Python 2.4.1 $ uname -a Linux ruth 2.6.13-1.1532_FC4 #1 Thu Oct 20 01:30:08 EDT 2005 i686 $ cat /proc/meminfo|head -2 MemTotal: 514232 kB MemFree: 47080 kB $ time ./scanfile.py 16384 real 0m0.06s user 0m0.03s sys 0m0.01s $ time ./scanfilemmap.py 16384 real 0m0.10s user 0m0.06s sys 0m0.00s Using a ~ 250 MB file, not even half of physical memory. $ time ./scanfile.py 16777216 real 0m11.19s user 0m10.98s sys 0m0.17s $ time ./scanfilemmap.py 16777216 real 0m55.09s user 0m43.12s sys 0m11.92s ============================== $ cat scanfile.py #!/usr/bin/env python import sys fn = 't.dat' ss = '\x00\x00\x01\x00' ss = 'time' be = len(ss) - 1 # length of overlap to check blocksize = 64 * 1024 # need to ensure that blocksize > overlap fp = open(fn, 'rb') b = fp.read(blocksize) count = 0 while len(b) > be: count += b.count(ss) b = b[-be:] + fp.read(blocksize) fp.close() print count sys.exit(0) =================================== $ cat scanfilemmap.py #!/usr/bin/env python import sys import os import mmap fn = 't.dat' ss = '\x00\x00\x01\x00' ss='time' fp = open(fn, 'rb') b = mmap.mmap(fp.fileno(), os.stat(fp.name).st_size, access=mmap.ACCESS_READ) count = 0 foundpoint = b.find(ss, 0) while foundpoint != -1 and (foundpoint + 1) < b.size(): #print foundpoint count = count + 1 foundpoint = b.find(ss, foundpoint + 1) b.close() print count fp.close() sys.exit(0) From ron at vnetworx.net Fri Oct 14 14:34:49 2005 From: ron at vnetworx.net (Ron Guerin) Date: Fri, 14 Oct 2005 14:34:49 -0400 Subject: NYLUG meeting: The Python Object Model with Alex Martelli & Google(open bar and food!) In-Reply-To: <312cfe2b0510141103i162034a1x8009b9123d041717@mail.gmail.com> References: <mailman.2077.1129308291.509.python-list@python.org> <1129312792.c8c0370da34fd63e5cace1fe6133aff9@teranews> <312cfe2b0510141103i162034a1x8009b9123d041717@mail.gmail.com> Message-ID: <434FFA49.1040001@vnetworx.net> Gregory Pi?ero wrote: > A reasonable question ... Sure is. ;) October 26, 2005 6:00pm - 10:00pm - Ron From theller at python.net Wed Oct 5 08:18:58 2005 From: theller at python.net (Thomas Heller) Date: Wed, 05 Oct 2005 14:18:58 +0200 Subject: How to prevent logging warning? Message-ID: <psqkp365.fsf@python.net> I'm about to add some logging calls to a library I have. How can I prevent that the script that uses the library prints 'No handlers could be found for logger "comtypes.client"' when the script runs? I would like to setup the logging so that there is no logging when nothing is configured, and no warning messages are printed. Thomas From larry.bates at websafe.com Wed Oct 12 15:07:27 2005 From: larry.bates at websafe.com (Larry Bates) Date: Wed, 12 Oct 2005 14:07:27 -0500 Subject: Converting C++ array into Python In-Reply-To: <slrndkqd54.2ss.jgrahn-nntq@frailea.sa.invalid> References: <mailman.1957.1129122735.509.python-list@python.org> <eZCdnVD6O_XQq9DeRVn-ig@comcast.com> <slrndkqd54.2ss.jgrahn-nntq@frailea.sa.invalid> Message-ID: <m6CdnR_HYNyJwtDeRVn-ig@comcast.com> Yes, I'm normally calling .DLL function with a defined API and memory layout. May not be optimal, when you don't have the C code available and the data structure is part of the API it works just fine. -Larry Bates Jorgen Grahn wrote: > On Wed, 12 Oct 2005 11:13:52 -0500, Larry Bates <larry.bates at websafe.com> wrote: > >>Like others, without more information on what you have tried we are >>just guessing. Many times I've used the struct.unpack() module to >>unpack C "arrays" into python objects. > > > In that case, it sounds like you make yourself depend on the memory layout > of those C arrays -- generally a very bad thing to do. > > >>Don't know if this will help, >>but thought I'd pass it along. Post some code and we can help more. > > > Yes. Or at least tell us what the /type/ of that array is. > > I assume it's 'Foo thearray[]', in which case you usually would return it as > a Python list of whatever Python data structure you encode a Foo into -- > might be a tuple, or an integer, or a full-blown class of some kind, or ... > > /Jorgen > From lard at tardis.ed.ac.molar.uk Mon Oct 31 07:47:16 2005 From: lard at tardis.ed.ac.molar.uk (Alex Hunsley) Date: Mon, 31 Oct 2005 12:47:16 GMT Subject: mixin helper class for unknown attribute access? In-Reply-To: <pan.2005.10.31.12.40.23.812468@REMOVETHIScyber.com.au> References: <Mvm9f.25313$m%6.18781@fe3.news.blueyonder.co.uk> <pan.2005.10.31.12.40.23.812468@REMOVETHIScyber.com.au> Message-ID: <ono9f.25939$m%6.21522@fe3.news.blueyonder.co.uk> Steven D'Aprano wrote: > On Mon, 31 Oct 2005 10:39:40 +0000, Alex Hunsley wrote: > > >>I know that I can catch access to unknown attributes with code something >>like the following: >> >>class example: >> def __getattr__(self, name): >> if name == 'age': >> return __age >> else: >> raise AttributeError >> >> >>but is there an existing mixin helper class in Python (or one someone >>has written) already that will assist with this? (Just not wanting to >>reinvent the wheel....) > > > Too late. > > py> class Example: > ... age = 0 > ... > py> Example.age > 0 > py> Example.aeg > Traceback (most recent call last): > File "<stdin>", line 1, in ? > AttributeError: class Example has no attribute 'aeg' > > It works for instances too: > > py> Example().aeg > Traceback (most recent call last): > File "<stdin>", line 1, in ? > AttributeError: Example instance has no attribute 'aeg' > > > Your __getattr__ code is completely unnecessary. Sorry, as I noted in another reply not long ago, I was having a 'braino' and not saying what I actually meant! What I was talking about was the accidental _setting_ of the wrong attribute. And the mixin class I'm looking for is one that could be told what were valid attributes for the class, and would then catch the situation where you mis-spelt an attribute name when setting an attrib. thanks! alex > > > From aleaxit at yahoo.com Fri Oct 28 23:28:18 2005 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 28 Oct 2005 20:28:18 -0700 Subject: suggestions between these two books References: <RQL7f.1244$No6.28617@news.tufts.edu> <mailman.2607.1130339640.509.python-list@python.org> Message-ID: <1h55sjs.15zg7oz1rhbwyzN%aleaxit@yahoo.com> Micah Elliott <mde at micah.elliott.name> wrote: > On Oct 26, John Salerno wrote: > > Hi all. I'm fairly new to programming and I thought I'd like to try > > Python. I'm trying to decide between these two books: > > > > Learning Python (O'Reilly) > > Beginning Python: From Novice to Professional (APress) > > Consider first reading the tutorial. If you prefer to read from paper > there is a PDF version > <http://www.python.org/doc/2.4.2/download.html>. ...but both of the quoted books have added value. Well, I don't actually KNOW that about the APress one, since my good friend Magnus Hetland didn't think of sending me a review copy (hint, hint, Magnus, if you want any more recommendations;-), but its predecessor "Pratical Python" was good indeed. > There is also the "Python in a Nutshell" book which only covers Python > 2.2 but has a very concise language intro, and will become an > invaluable reference. I wish I had started with this book; then I > wouldn't have needed to buy some of the others. Why, thanks! I'm working on a new edition to cover 2.3 and 2.4 (and perhaps 2.5 by the time I'll be done, as progress is being quite slow -- as uber technical lead at Google, I'm pretty busy these days!-), but I do agree that the current edition is still quite useful. Alex From gsakkis at rutgers.edu Thu Oct 13 10:15:43 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: Thu, 13 Oct 2005 10:15:43 -0400 Subject: how to make this code faster References: <1129183717.183243.100540@g49g2000cwa.googlegroups.com> <mailman.1987.1129185081.509.python-list@python.org> <1129192669.716031.269340@g44g2000cwa.googlegroups.com> Message-ID: <1129212949.b229b833824fd3d22639fba1064865eb@teranews> <ajikoe at gmail.com> wrote: > hello, > > I found that scipy only works with python 2.3 or? You can use Numeric instead of scipy if you need/want to: from Numeric import arange,reshape,sin def computeMatrix(n): xcoor = arange(0,1,1/float(n)) ycoor = reshape(xcoor, (n,1)) return sin(xcoor*ycoor) + 8*xcoor Note that arange() does not include the endpoint, i.e. arange(0,1,0.25).tolist() ==[0.0, 0.25, 0.5, 0.75]. > I don't know if the logic is correct: > 1. loop inside loop uses a lot of resources > 2. Numeric or Numpy can make program faster > 3. It use kind of Array/Matrix analysis style > 4. We have to change our algorithms so that Numeric or Numpy can help > us, Matrix style That's correct more or less. George From davids at webmaster.com Fri Oct 28 16:01:50 2005 From: davids at webmaster.com (David Schwartz) Date: Fri, 28 Oct 2005 13:01:50 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <neq0l153mbhu758inptt5sc7jfsf5bqkaq@4ax.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <dis0ve$m65$1@nntp.webmaster.com> <yw1x4q7il3gu.fsf@ford.inprovide.com> <diso3l$uf4$1@nntp.webmaster.com> <kvv4l15d1ish33n9pm3fnu04tjdj8nph5r@4ax.com> <qpb1m1p0q89e0rn685rfbaserrn2c4uo32@4ax.com> <djqcrv$423$1@nntp.webmaster.com> <1130417205.892409.230580@g14g2000cwa.googlegroups.com> <djqik8$5vg$1@nntp.webmaster.com> <djqjic$qb7$1@sadr.dfn.de> <djqjrt$6dh$1@nntp.webmaster.com> <djqkc0$qk2$1@sadr.dfn.de> <djqmjq$7ff$1@nntp.webmaster.com> <djsmvh$jk$1@sadr.dfn.de> Message-ID: <dju03e$dhq$1@nntp.webmaster.com> "Lasse V?gs?ther Karlsen" <lasse at vkarlsen.no> wrote in message news:djsmvh$jk$1 at sadr.dfn.de... > Ok, let me just make my opinion very clear on this and then I'll just > leave this thread altogether. > > I think you are comparing apples and oranges so whatever conclusion you > manage to draw from that is in my eyes invalid. It doesn't matter, in my > opinion, if you managed to conclude that Microsoft was the saints > themselves because, in my opinion, your reasoning is not valid. I'm not > saying one way or the other, I'm just picking at your reasoning. > > To me it sounds like concluding that the prices of RAM will drop because > the swallows are flying high this fall. > > But enough, I'll just leave it. There is no value whatsoever in simply saying "I don't agree with you" and including no argument or reasoning. Were you afraid someone might erroneously think you did agree with me and that this would harm your reputation? If you want to participate in discussion, you have to make claims and defend them. MS imposed a restriction that was logically lesser than saying "if you want to buy Windows wholesale, you cannot sell products that compete with PCs with Windows pre-loaded on them". (Logically lesser because they allowed you sell them but charged a fee. You could avoid the fee by simply not selling them.) This is a perfectly ordinary type of franchise sales arrangement engaged in by companies of all kinds. For someone who does not already have a monopoly, it is even perfectly legal. DS From brusstoc at gmail.com Sat Oct 1 01:04:34 2005 From: brusstoc at gmail.com (brusstoc at gmail.com) Date: 30 Sep 2005 22:04:34 -0700 Subject: A Moronicity of Guido van Rossum In-Reply-To: <1128003857.930444.47650@g14g2000cwa.googlegroups.com> References: <1128003857.930444.47650@g14g2000cwa.googlegroups.com> Message-ID: <1128143074.088232.189710@o13g2000cwo.googlegroups.com> I have an excellent idea. Create your own programming language and do whatever you want with it. Until then, I'm thinking that Guido can do whatever he wants with his. But I'm guessing that your programming skills will be in the same place as your greatness - in your own head. From aleax at mail.comcast.net Sat Oct 8 00:56:12 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Fri, 7 Oct 2005 21:56:12 -0700 Subject: "no variable or argument declarations are necessary." References: <jsh0k1hqc2kb7lq83jmcr9ieqkb29i6n7h@4ax.com> <R1Y%e.618$2F2.116453@news20.bellglobal.com> <ubu0k15824nn743c09vqdd347d7v4ccq5c@4ax.com> <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <slrndk1lln.6o3.apardon@rcpc42.vub.ac.be> <Xns96E45EC3E6CB2duncanbooth@127.0.0.1> <slrndk20pn.6o3.apardon@rcpc42.vub.ac.be> Message-ID: <1h42zdb.1hqmbvr101wlsoN%aleax@mail.comcast.net> Antoon Pardon <apardon at forel.vub.ac.be> wrote: ... > >> egold = 0: > >> while egold < 10: > >> if test(): > >> ego1d = egold + 1 > >> > > > > Oh come on. That is a completely contrived example, > > No it is not. You may not have had any use for this > kind of code, but unfamiliary with certain types > of problems, doesn't make something contrived. It's so contrived it will raise a SyntaxError due to the spurious extra colon on the first line;-). Or, consider, once the stray extra colon is fixed: Helen:/tmp alex$ cat ap.py def ap(): egold = 0 while egold < 10: if test(): ego1d = egold + 1 Helen:/tmp alex$ pychecker ap.py Processing ap... Warnings... ap.py:4: No global (test) found ap.py:5: Local variable (ego1d) not used Helen:/tmp alex$ If you're so typo-prone and averse to unittests that you consider this kind of issue to be a serious problem, just use pychecker and get informed about any such typo, just as above. Incessant whining about the non-existent advantages of declarations, rather than the simple use of tools that can diagnose such spelling mistakes without any need for declarations, would qualify you as a troll even if you didn't have a long history of trolling this group... > Names do get misspelled and sometimes that misspelling is hard to spot. It's totally trivial, of course, as shown above, and there is no need to pervert and distort the language for the purpose, as you, troll, have kept whining about for years. I'm partial to pychecker -- that's what we use at Google, and we also, incidentally, recently had the good fortune to hire Neal Norwitz, pychecker's author; but there are several other free tools that perform similar tasks, albeit with very different philosophy, such as Logilab's pylint...: Helen:/tmp alex$ pylint ap.py No config file found, using default configuration ************* Module ap W: 2: Bad indentation. Found 3 spaces, expected 4 W: 3: Bad indentation. Found 3 spaces, expected 4 W: 4: Bad indentation. Found 5 spaces, expected 8 W: 5: Bad indentation. Found 7 spaces, expected 12 C: 0: Too short name "ap" W: 0: Missing docstring W: 0: Missing required attribute "__revision__" C: 1:ap: Too short name "ap" W: 1:ap: Missing docstring E: 4:ap: Undefined variable 'test' W: 5:ap: Unused variable 'ego1d' [rest of long critique of ap.py snipped] Again, unused variables (typos...) get easily diagnosed without any need for declarations. (Similar tools, of course, apply to languages requiring declaration, to diagnose a variable that's declared but unused, which is a very bad code smell typical of such languages). Of course, pylint is about enforcing all sort of code rules, such as, by default, indentation by multiples of 4 spaces, name length, docstrings, and so on; while pychecker is much simpler and more narrowly aimed at diagnosing likely mistakes and serious code smells. But, with either tool or any of many others, there is no need at all for declarations in order to catch typos (of course, unittests are still a VERY good idea -- catching all typos and even coding rules violations is NO guarantee that your code is any good, testing is A MUST). > > It would give the > > programmer a false sense of security since they 'know' all their > > misspellings are caught by the compiler. It would not be a substitute for > > run-time testing. > > I don't think anyone with a little bit of experience will be so naive. Heh, right. After all, _I_, for example, cannot have even "a little bit of experience" -- after all, I've been programming for just 30 years (starting with my freshman year in university), and anyway all I have to show for that is a couple of best-selling books, and a stellar career culminating (so far) with my present job as Uber Technical Lead for Google, Inc, right here in Silicon Valley... no doubt Google's reaching over the Atlantic to come hire me from Italy, and the US government's decision to grant me a visa under the O-1 category (for "Aliens with Outstanding Skills"), were mere oversights on their part that, obviously, I cannot have even "a little bit of experience", given that I (like great authors such as Bruce Eckel and Robert Martin) entirely agree with the opinion you deem "so naive"... that any automatic catching of misspellings can never be a substitute for unit-testing! Ah well -- my good old iBook's settings had killfiles for newsreaders, with not many entries, but yours, Antoon, quite prominent and permanent; unfortunately, that beautiful little iBook was stolen (http://www.papd.org/press_releases/8_17_05_fix_macs_211.html), so I got myself a brand new one (I would deem it incorrect to use for personal purposes the nice 15" Powerbook that Google assigned me), and it takes some time to reconstruct all the settings. But, I gotta get started sometime -- so, welcome, o troll, as the very first entry in my brand-new killfile. In other words: *PLONK*, troll!-) Alex From svenn.are at bjerkem.de Mon Oct 31 16:50:52 2005 From: svenn.are at bjerkem.de (svenn.are at bjerkem.de) Date: 31 Oct 2005 13:50:52 -0800 Subject: Using graphviz to visualize trace.py output, anybody? In-Reply-To: <slrndmcm7k.1ud.dek@bosshog.lbl.gov> References: <1130710534.618559.40680@g43g2000cwa.googlegroups.com> <slrndmcm7k.1ud.dek@bosshog.lbl.gov> Message-ID: <1130795452.074883.250760@g43g2000cwa.googlegroups.com> I am referring to the trace.py which comes with python2.3 which is installed on Panther by default. (I found it with 'locate trace.py' after reading about its existence here) I was thinking in the direction of your suggestion 2) but before I reinvent the wheel, I would like to know if someone has already invented it. As it doesn't seem like anybody has, I will have to go do it myself. If somebody happen to finish before me I would be happy to get a notice. -- Svenn From ccdetail at gmail.com Wed Oct 26 17:05:31 2005 From: ccdetail at gmail.com (ccdetail at gmail.com) Date: 26 Oct 2005 14:05:31 -0700 Subject: python in the news Message-ID: <1130360731.133242.244980@g47g2000cwa.googlegroups.com> http://software.itmanagersjournal.com/software/05/10/25/1631220.shtml... From nowayjose at noway.com Mon Oct 10 01:03:40 2005 From: nowayjose at noway.com (el chupacabra) Date: Mon, 10 Oct 2005 05:03:40 GMT Subject: python and MySQL - 3 questions Message-ID: <MCm2f.2227$B%6.1580@tornado.socal.rr.com> I'm using mysqldb module and python 2.4. I'm a newbie. Thanks in advance. 1. Output desired: "hello" "world" I know that MySQL takes \n and \t and what not. But my python script, it takes that \n as literal. Meaning, when I retrieve the records, they show up like "hello \n world". How can keep formatting when inserting data to table? This is what I have: cursor.execute('insert into table values (%s, %s, %s, %s)', (newId, insertEntryName, insertLastName, insertSSN) 2. How can make my python show *** (stars) when entering user passwords? 3. Is it possible to make Python/MySQL transactions secure, encrypted? Can you point me to readings or something? --------------= Posted using GrabIt =---------------- ------= Binary Usenet downloading made easy =--------- -= Get GrabIt for free from http://www.shemes.com/ =- From deets at nospam.web.de Sun Oct 9 06:21:39 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 09 Oct 2005 12:21:39 +0200 Subject: Function decorator that caches function results In-Reply-To: <pan.2005.10.09.09.56.02.95699@REMOVETHIScyber.com.au> References: <TdCdnVSTs-A-Wtre4p2dnA@telenor.com> <pan.2005.10.09.09.56.02.95699@REMOVETHIScyber.com.au> Message-ID: <3qs99kFg3fcoU1@uni-berlin.de> >>def cache_function(fn): >> cache = {} >> def cached_result(*args, **kwargs): >> if args in cache: >> return cache[args] >> result = fn(*args, **kwargs) >> cache[args] = result >> return result >> return cached_result > > > I'm curious... where does cache live after you use cache_function to > memoize some function? It doesn't appear to be an attribute of the newly > memoized function, nor does it look like a global variable. It's part of the closure - as well as fn, btw. So it is per-decorated-function. Diez From lycka at carmen.se Tue Oct 11 09:36:31 2005 From: lycka at carmen.se (Magnus Lycka) Date: Tue, 11 Oct 2005 15:36:31 +0200 Subject: date reformatting In-Reply-To: <mailman.1627.1128622152.509.python-list@python.org> References: <mailman.1627.1128622152.509.python-list@python.org> Message-ID: <digf4v$93t$1@wake.carmen.se> Bell, Kevin wrote: > Anyone aware of existing code to turn a date string "8-15-05" into the > number 20050815? >>> import datetime >>> s = "8-15-05" >>> month,day,year = map(int, s.split('-')) >>> date = datetime.date(2000+year,month,day) >>> date.strftime('%Y%m%d') '20050815' Of course, if you really want the *number* 20050815 you'd have to do >>> int(date.strftime('%Y%m%d')) Using a datetime.date object means that you have good support for a lot of arithmetic on and formatting of dates without writing a lot of new code. If you really mean that you want the number 20050815, I assume this is because some legacy system beyond you control need to have dates in that format. It's not a particularly good format for dates. If you just want a numeric storage of dates, I'd suggest using datetime.date.toordinal/fromordinal. Those numbers aren't as easy to decipher manually, but at least they work right if you subtract dates or add or subtract days from a date. From deets at nospam.web.de Fri Oct 7 04:53:54 2005 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 07 Oct 2005 10:53:54 +0200 Subject: "no variable or argument declarations are necessary." In-Reply-To: <slrndkc6lo.h7o.apardon@rcpc42.vub.ac.be> References: <jsh0k1hqc2kb7lq83jmcr9ieqkb29i6n7h@4ax.com> <R1Y%e.618$2F2.116453@news20.bellglobal.com> <ubu0k15824nn743c09vqdd347d7v4ccq5c@4ax.com> <4340843b$0$73585$ed2619ec@ptn-nntp-reader03.plus.net> <1128306351.13c600edac4bfa99f9f10238681bf68f@teranews> <slrndk1lln.6o3.apardon@rcpc42.vub.ac.be> <Xns96E45EC3E6CB2duncanbooth@127.0.0.1> <slrndk20pn.6o3.apardon@rcpc42.vub.ac.be> <Xns96E482833CD9Fduncanbooth@127.0.0.1> <slrndk2e89.6o3.apardon@rcpc42.vub.ac.be> <pan.2005.10.03.16.48.30.411255@REMOVETHIScyber.com.au> <slrndk4bo2.6o3.apardon@rcpc42.vub.ac.be> <3qi8erFf252rU1@uni-berlin.de> <slrndk9muo.h7o.apardon@rcpc42.vub.ac.be> <3qkdbrFfgga9U1@uni-berlin.de> <slrndka20j.h7o.apardon@rcpc42.vub.ac.be> <3qkn7qFffkl6U1@uni-berlin.de> <slrndkabe7.h7o.apardon@rcpc42.vub.ac.be> <3qkr1hFfgj5uU1@uni-berlin.de> <slrndkc6lo.h7o.apardon@rcpc42.vub.ac.be> Message-ID: <3qmrd2Ffocu8U1@uni-berlin.de> > Why do you call this a JAVA Object or C void*? Why don't you call > it a PYTHON object. It is this kind of reaction that IMO tells most > opponents can't think outside the typesystems they have already > seen and project the problems with those type systems on what > would happen with python should it acquire a type system. Well, because maybe I wanted you to give you an example of languages that are statically typed and have such an any construct - that, by the way, is not a piece of inguine imagination of yours, but has been thought of before, e.g. CORBA (and called there any, too)? It makes no sense putting python into that context - as it is _not_ statically typed. Which you should know, after discussing this very subject way too long. >>>Would my suggestion be classified as a statically typed world? >> >>See above. > > > Your answer tells more about you then about my suggestion. Your answer tells us something too: Just because you don't know anything about typechecking does not mean that you are in the position to make assumptions on "how things could work if the people who know stuff wouldn't be so stupid". That's like saying "cars can't fly because the stupid engineers lack my sense of imagination." Just blathering about the possibility of some super-duper-typechecker and countering criticism or being told about problems in that domain by making bold statements that this sure could work - provide us with an implementation. Or maybe - just maybe - you could sit back and think about the fact that lots of people who are way cleverer than you and me have been working on this subject, and so far haven't found a way. Which doesn't necessarily mean that there is no way - but certainly its hard, theory-laden work and won't emerge in a NG discussion by some snide remarks of either you or anybody else. Diez From scott.daniels at acm.org Fri Oct 14 16:37:03 2005 From: scott.daniels at acm.org (Scott David Daniels) Date: Fri, 14 Oct 2005 13:37:03 -0700 Subject: [PIL]: Question On Changing Colour In-Reply-To: <434eb32d$0$29544$4fafbaef@reader1.news.tin.it> References: <00fe01c5cf7c$410750e0$69820257@Gavana> <mailman.1927.1129080609.509.python-list@python.org> <434eb32d$0$29544$4fafbaef@reader1.news.tin.it> Message-ID: <43501678$1@nntp0.pdx.net> <Confusion about applying hue to a grey value> Try this: >>> import colorsys as cs >>> grey = (.7, .7, .7) >>> blue = (0., 0., 1.) >>> hsv_grey = cs.rgb_to_hsv(*grey) >>> hsv_blue = cs.rgb_to_hsv(*blue) >>> hsv_grey (0.0, 0.0, 0.69999999999999996) >>> hsv_blue (0.66666666666666663, 1.0, 1.0) The problem is that the saturation of the grey is 0. There is no Hue to anything between black and white. Maybe you want something like: def apply_hue(color, rgb): hue, _saturation, _value = cs.rgb_to_hsv(*color) _hue, saturation, value = cs.rgb_to_hsv(*rgb) return cs.hsv_to_rgb(hue, max(.1, saturation), value) Or: def apply_hs(color, rgb): hue, saturation, value = cs.rgb_to_hsv(*color) _hue, _saturation, value = cs.rgb_to_hsv(*rgb) return cs.hsv_to_rgb(hue, saturation, value) --Scott David Daniels scott.daniels at acm.org From codecraig at gmail.com Fri Oct 28 12:08:22 2005 From: codecraig at gmail.com (py) Date: 28 Oct 2005 09:08:22 -0700 Subject: SNMP Message-ID: <1130515702.436348.190240@g43g2000cwa.googlegroups.com> >From what I have seen Python does not come with an snmp module built in, can anyone suggest some other SNMP module (preferably one you have used/experienced)..I have googled and seen yapsnmp and pysnmp (which seem to be the two most active SNMP modules). Thanks From apardon at forel.vub.ac.be Wed Oct 5 05:20:06 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 5 Oct 2005 09:20:06 GMT Subject: dictionary interface References: <slrndk4uud.6o3.apardon@rcpc42.vub.ac.be> <mailman.1437.1128433183.509.python-list@python.org> <Pine.LNX.4.62.0510050023290.13409@urchin.earth.li> <slrndk73cp.6o3.apardon@rcpc42.vub.ac.be> <7xll18gxhx.fsf@ruckus.brouhaha.com> Message-ID: <slrndk76m6.h7o.apardon@rcpc42.vub.ac.be> Op 2005-10-05, Paul Rubin schreef <http>: > Antoon Pardon <apardon at forel.vub.ac.be> writes: >> But that is contradicted by the unittest. If you have a unittest for >> comparing dictionaries, that means comparing dictionaries has a >> testable characteristic and thus is further defined. > > No, I don't think so. The unittest makes sure that a particular > implementation works as intended. That doesn't mean that every part > of the of how that particular implementation works is required by the > language definition. As far as I understand, unittest test for functionality clients should be able to rely on. They shouldn't be used to test a specific implementation feature. The idea is that if you change the implementation, you can quickly test the functionality is unharmed. But you can't do that if also specific implementation details are tested for. > It can have some non-required (but > non-forbidden) characteristics and those could still get tested. That doesn't seem to make sense. If it is not required it shouldn't be tested for, at least not in a unittest, because otherwise a new implementation that doesn't have the non-required characteristics will be rejected. My tree class is almost finished, but one unittest still fails, is this a failing of my class (as a replacement for a dictionary) or is this a non-required characteristic of dictionaries? -- Antoon Pardon From twic at urchin.earth.li Sun Oct 23 19:30:20 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Mon, 24 Oct 2005 00:30:20 +0100 Subject: Syntax across languages In-Reply-To: <mailman.2431.1130054053.509.python-list@python.org> References: <1130052687.396109.145420@o13g2000cwo.googlegroups.com> <mailman.2431.1130054053.509.python-list@python.org> Message-ID: <Pine.LNX.4.62.0510232346320.24000@urchin.earth.li> On Sun, 23 Oct 2005, Fredrik Lundh wrote: > bearophileHUGS at lycos.com wrote: > >> - ~== for approximate FP equality > > str(a) == str(b) This is taken from the AIEEEEEEEE 754 standard, i take it? :) Seriously, that's horrible. Fredrik, you are a bad man, and run a bad railway. However, looking at the page the OP cites, the only mention of that operator i can find is in Dylan, and in Dylan, it's nothing to do with approximate FP equality - it means 'not identical', which we can spell "is not". What would approximate FP equality even mean? How approximate? >> - Exception retrying: after catching an exception, tell the snippet to >> be re-run "retry" as in Ruby > >>>> x = 0 >>>> while 1: > ... try: > ... x += 1 > ... if x <= 5: > ... raise ValueError > ... except ValueError: > ... print "retry" > ... continue > ... else: > ... break > ... > retry > retry > retry > retry > retry >>>> That works well for trivial cases, and not at all for anything complex. If you have this sort of structure: def reverse_the_polarity_of_the_neutron_flow(): five_hundred_lines_of_code() and_dozens_of_layers_of_nesting_and_indirection() interrossitor.activate() # can raise InterrossitorError do_what_we_came_here_to_do() try: reverse_the_polarity_of_the_neutron_flow() except InterrossitorError: degausser.degauss(interrossitor) interrossitor.activate() RETRY # how do you implement this? You're in trouble. I realise that this snippet is not a hugely compelling example, but the point is that there could be some corrective action that you can take in an exception handler which, for some reason, you can't write close enough to the source of the exception that control can carry on flowing in the right direction. What you can do - and this is fairly high-grade evil of a different sort - is package the exception-handling specifics in a function, and pass that in, to be applied at the appropriate point: def reverse_the_polarity_of_the_neutron_flow(ie_hdlr): five_hundred_lines_of_code() and_dozens_of_layers_of_nesting_and_indirection() try: interrossitor.activate() # can raise InterrossitorError except InterrossitorError, e: ie_hdlr(e) do_what_we_came_here_to_do() def handle_interrossitor_error(e): degausser.degauss(interrossitor) interrossitor.activate() reverse_the_polarity_of_the_neutron_flow(handle_interrossitor_error) You can even do extra bonus higher-order-functioning: def reverse_the_polarity_of_the_neutron_flow(ie_hdlr): five_hundred_lines_of_code() and_dozens_of_layers_of_nesting_and_indirection() ie_hdlr(interrossitor.activate) do_what_we_came_here_to_do() def handle_interrossitor_error(fn): try: fn() except InterrossitorError, e: degausser.degauss(interrossitor) interrossitor.activate() reverse_the_polarity_of_the_neutron_flow(handle_interrossitor_error) Although i can't see any reason why you'd want to. >> - recursive "flatten" as in Ruby (useful) > > if you can define the semantics, it's a few lines of code. if you're > not sure about the semantics, a built-in won't help you... While we're on the subject, we had a big recursive flatten bake-off round here a few months back: look for a thread called "flatten(), [was Re: map/filter/reduce/lambda opinions andbackground unscientific mini-survey]", and filter out the posts with code from the posts with rants. There are all sorts of solutions, coming at the problem from different angles, but the end of it is more or less here: http://groups.google.co.uk/group/comp.lang.python/msg/0832db53bd2700db Looking at the code now, i can see a couple of points where i could tweak my flatten even more, but i think the few microseconds it might save aren't really worth it! tom -- It is a laborious madness, and an impoverishing one, the madness of composing vast books. -- Jorge Luis Borges From daniel.neilson at gmail.com Thu Oct 13 21:11:12 2005 From: daniel.neilson at gmail.com (daniel.neilson at gmail.com) Date: 13 Oct 2005 18:11:12 -0700 Subject: matching elements of numeric arrays In-Reply-To: <mailman.2038.1129247582.509.python-list@python.org> References: <1129239096.340248.222440@g49g2000cwa.googlegroups.com> <mailman.2038.1129247582.509.python-list@python.org> Message-ID: <1129252272.226343.161440@o13g2000cwo.googlegroups.com> Thanks a lot. It was this equal.outer idea that I was missing. From pdirezze at rogers.com Mon Oct 10 12:50:18 2005 From: pdirezze at rogers.com (Paul DiRezze) Date: Mon, 10 Oct 2005 12:50:18 -0400 Subject: Learning Python Message-ID: <7e6dnQAA36FTBtfeRVn-rg@rogers.com> I'm spending the next two weeks off and I'm looking to take a crack at learning how to program in Python. Here's a list of the places I've bookmarked: http://www.python.org/doc/ and more specifically http://wiki.python.org/moin/ http://wiki.python.org/moin/BeginnersGuide http://www.python.org/doc/Intros.html http://www.python.org/topics/ I'm looking for additional resources (links, names of books, whatever...) that you think may help me out. I'm a hobby programmer using mostly BASIC(s) and some Java. I know procedural programming and I know what encapsulation, inheritance and polymorphism are but I have very little experience in using them as I've written just a few Java programs (i.e., I guess I could use a primer in OO programming). Any ideas? paul From peter at engcorp.com Wed Oct 12 22:36:36 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 12 Oct 2005 22:36:36 -0400 Subject: Bad magic no. in python zipfile In-Reply-To: <1129168338.457437.276820@z14g2000cwz.googlegroups.com> References: <1129168338.457437.276820@z14g2000cwz.googlegroups.com> Message-ID: <1OudnVsv95XVVdDeRVn-rw@powergate.ca> stewart.midwinter at gmail.com wrote: \> I'm able to create a new zipfile with the module's ZipFile class and > add files to it. After closing the file, I'm able to view the contents > of it with WinZip. I can also confirm that it is a python zip file by > using the is_zipfile() method. All good so far. However, under some > circumstances, I am unable to later read the file and extract its > contents. As soon as a I attempt to instantiate a new ZipFile > instance, I receive an error regarding Bad Magic number. In the past, > I've seen that when trying to use a .pyc module, created with one > Python version, using another Python version. But in this case, I > created the zip file under Python 2.4.2 and tried to open it under > Python 2.4.2 as well. Any ideas on what to do? Maybe try posting the full traceback so we can see the "Bad Magic Number" error you are getting... -Peter From zhu_dave at yahoo.com Sat Oct 8 13:28:25 2005 From: zhu_dave at yahoo.com (Dave) Date: Sat, 8 Oct 2005 10:28:25 -0700 (PDT) Subject: Python's Performance In-Reply-To: <434779F1.9080508@designaproduct.biz> Message-ID: <20051008172825.77615.qmail@web30612.mail.mud.yahoo.com> Yes, I would like to know how many internal string operations are done inside the Python interpreter. Thanks. Laszlo Zsolt Nagy <gandalf at designaproduct.biz> wrote: Dave wrote: > Hello All, > > I would like to gather some information on Python's runtime > performance. As far as I understand, it deals with a lot of string > objects. Does it require a lot string processing during program > execution? How does it handle such time-consuming operations? Is there > a way to find out how many string operations (perhaps in the > underlying system) ) it does during program execution? Do you want to know how many internal string operations are done inside the Python interpreter? I believe it is not a useful information. There are benchmarks testing the *real performance* of Python. For example: http://www.osnews.com/story.php?news_id=5602 Les --------------------------------- Yahoo! Music Unlimited - Access over 1 million songs. Try it free. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-list/attachments/20051008/2bf8cb66/attachment.html> From dakman at gmail.com Mon Oct 31 14:03:49 2005 From: dakman at gmail.com (dakman at gmail.com) Date: 31 Oct 2005 11:03:49 -0800 Subject: Arguments for button command via Tkinter? In-Reply-To: <pan.2005.10.31.15.58.47.813776@virgilio.it> References: <1130768146.414955.106780@g47g2000cwa.googlegroups.com> <1130768592.010756.97890@g49g2000cwa.googlegroups.com> <pan.2005.10.31.15.58.47.813776@virgilio.it> Message-ID: <1130785429.572610.86240@z14g2000cwz.googlegroups.com> Yah, thats how i learned how to do it, thanks. From claudio.grondi at freenet.de Mon Oct 10 19:28:45 2005 From: claudio.grondi at freenet.de (Claudio Grondi) Date: Mon, 10 Oct 2005 23:28:45 -0000 Subject: Wanted: Python module allowing direct access to raw sectors of harddrives (MFT, boot sector, etc.) in MS Windows Message-ID: <3r04p5Fh4lshU1@individual.net> Googling for keywords like "direct access sector harddrive Python module Windows" seems to give no useful results. Any hints(best if cross-platform)? Claudio From ms at cerenity.org Sun Oct 9 07:29:31 2005 From: ms at cerenity.org (Michael) Date: Sun, 09 Oct 2005 12:29:31 +0100 Subject: What is executed when in a generator References: <dhtq5k$62c$1@elingue.unicaen.fr> Message-ID: <4348fede$0$49800$ed2e19e4@ptn-nntp-reader04.plus.net> [ I've got no idea of your skill level, but since you say you feel a bit lost I'll take baby steps here. Apologies if it's too low or high :-) I'm also taking baby steps because less people understand generators than they might. After all, most new programmers often want something like generators when they start programming, but life gets in their way. ] Jerzy Karczmarczuk wrote: > Could you tell me please where can I read something in depth about the > semantics of generators? I feel a bit lost. Watch what happens if you take your example (I'm not convinced it's the best example for this, but it is your example :-) on the python shell: >>> gl=0 >>> def gen(x): ... global gl ... gl=x ... yield x ... >>> s=gen(1) Clearly this has done something. What you haven't understood by the looks of things is what and why. Let's take this session a bit further. Let's find out the value of s: >>> s <generator object at 0x40397a8c> OK, so the call to the generator function returned a generator. That should make sense to you. This will hopefully make more sense if we make a few more calls to 'gen' and look at their values. >>> t=gen(2) >>> t <generator object at 0x40397bec> As you'd expect the next call *also* creates a generator object. You'll note that it has a different location ( "at 0x....." ) meaning they're different objects. Do that a few more times and we see the same: >>> u=gen(3) >>> u <generator object at 0x403979ec> >>> v=gen(4) >>> v <generator object at 0x40397c0c> What this is doing is creating a generator object which can then be asked repeatedly to run, and yield values. A more accurate term might be iterating over the generator object. However the /idea/ is that you create the object wrapping a context of/for running that can suspend its own control and return intemediate values. Clearly the generator also needs a way of telling us its finished iterating. Let's make that more concrete. You call the .next() method of the object, and when it's done it raises a StopIteration exception. The way we do this with your code is as follows: >>> s.next() 1 Yay! That's the "1" that you were expecting to see. In your function you also updated a global "gl". This is probably not a wise idea, but hey, let's look at what happened to that value: >>> gl 1 Again, this is what you should have expected - since it's what you were after. Again, looking at your function, "yield x" was the last statement, so you should be wondering what happens next: >>> s.next() Traceback (most recent call last): File "<stdin>", line 1, in ? StopIteration As you can see we get told that it's dropped off the end. If we try calling again: >>> s.next() Traceback (most recent call last): File "<stdin>", line 1, in ? StopIteration If we retry with the generator objects created above, we can see: >>> t=gen(2) >>> u=gen(3) >>> v=gen(4) >>> t.next() 2 >>> gl 2 >>> v.next() 4 >>> gl 4 >>> u.next() 3 >>> gl 3 Hopefully that's a clearer explanation of what's actually going on with your code. A more complex example is based on the example in the PEP: def configurable_fib(base1=1, base2=1): a, b = base1, base2 while 1: yield a a,b = b, a+b >>> def configurable_fib(base1=1, base2=1): ... a, b = base1, base2 ... while 1: ... yield a ... a,b = b, a+b >>> normal_fib = configurable_fib(1,1) >>> normal_fib.next() 1 >>> normal_fib.next() 1 >>> normal_fib.next() 2 >>> normal_fib.next() 3 We can then create another one and ask that for values: >>> normal_fib2 = configurable_fib(1,1) >>> normal_fib.next(), normal_fib2.next() (5, 1) >>> normal_fib.next(), normal_fib2.next() (8, 1) >>> normal_fib.next(), normal_fib2.next() (13, 2) Or we can create a few, with unusual bases for the fibonacci sequence and find their first few values. Let's take the bases of 1 to 10. >>> fibs = [ configurable_fib(x,x) for x in range(1,11) ] >>> print [ x.next() for x in fibs ] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> print [ x.next() for x in fibs ] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> print [ x.next() for x in fibs ] [2, 4, 6, 8, 10, 12, 14, 16, 18, 20] >>> print [ x.next() for x in fibs ] [3, 6, 9, 12, 15, 18, 21, 24, 27, 30] >>> print [ x.next() for x in fibs ] [5, 10, 15, 20, 25, 30, 35, 40, 45, 50] This shows that returning a generator *object* rather than just a value when you call the generator function is a useful behaviour, even if initially when learning generators it's slightly counter intuitive. One way to really understand them though is to try building something with a whole load of generators. For those purposes, I wrote a tutorial for our project which is based very much around having lots of generators. The tutorial is made up of a set of learning exercises: * http://kamaelia.sourceforge.net/MiniAxon/ We've tested this tutorial on a couple of novices at work (they learn python one week and get this tutorial the next), and they've found it relatively simple. The first hadn't done any programming before, except a small amount of VB - he was a pre-university trainee. The second was a university vacation trainee who'd done 2 years, but had no experience of the ideas in the tutorial or python before joining us. It's specifically targeted at novices and might be of use when seeing the possibilities of what you can actually use generators for. { Incidentally if anyone reading this, not just yourself, decides to give it a go, I'd really appreciate hearing back from you what you thought of it, easy/difficult, clear/unclear, what level of experience you have, etc. People don't have to really, I'm posting this because I've noticed a couple of people have tried this so far as a means to trying to understand generators :-) } Best Regards and hope the above is useful, Michael. From jzgoda at o2.usun.pl Sat Oct 29 05:46:14 2005 From: jzgoda at o2.usun.pl (Jarek Zgoda) Date: Sat, 29 Oct 2005 11:46:14 +0200 Subject: Automatically creating a HOME environ variable on Windows? In-Reply-To: <1130549236.679806.297670@g43g2000cwa.googlegroups.com> References: <1130549236.679806.297670@g43g2000cwa.googlegroups.com> Message-ID: <djvgei$5t7$1@nemesis.news.tpi.pl> jim.eggleston at gmail.com napisa?(a): > Windows doesn't have a HOME environment variable, but it does have > HOMEDRIVE and HOMEPATH. Could Windows versions of Python automatically > populate os.environ with HOME, where HOME = > os.path.join(os.environ['HOMEDRIVE'], os.environ['HOMEPATH'])? MS recommends using %USERPROFILE%, as the above in many cases returns "C:\", which is wrong. -- Jarek Zgoda http://jpa.berlios.de/ From pmartin at snakecard.com Fri Oct 21 19:39:31 2005 From: pmartin at snakecard.com (Philippe C. Martin) Date: Fri, 21 Oct 2005 23:39:31 GMT Subject: how to modify text in html form from python References: <0Ra6f.5050$q%.616@newssvr12.news.prodigy.com> <kab6f.5052$q%.1841@newssvr12.news.prodigy.com> <86d5lyu0j8.fsf@bhuda.mired.org> <%Tb6f.5062$q%.3600@newssvr12.news.prodigy.com> <864q7atxcv.fsf@bhuda.mired.org> <8je6f.5358$q%.1645@newssvr12.news.prodigy.com> <86mzl2sbpl.fsf@bhuda.mired.org> Message-ID: <T_e6f.6359$7h7.6341@newssvr21.news.prodigy.com> Mike Meyer wrote: > "Philippe C. Martin" <pmartin at snakecard.com> writes: > >> I feel fairly stupid ... but to my defense in the past 17 years of >> coding, i've only spent 3 days looking at web stuff: >> >> I now can understand how "writing" to an existing form field from a cgi >> script might not work: how would the browser know ?: unless there is a >> very sophisticated scheme there (as those used in image transfer), I >> assume the complete page would have to be sent back: so might as well >> regenerate/rewrite everything. >> >> Yes ? >> >> I so, I'm back to finding a way for a browser plugin and a server based >> cgi script to exchange information. >> >> Any idea welcome... I know I don't want to open another socket/port but >> stick to http:80 > > Then you're out of luck. You can't even depend on their being an open > http connection available to use when the plugin runs. The browser may > well do: Load all data. Close connections. Render page as far as we > can. Launch code objects that we loaded. > > <mike But the plugin "opened" the connection: var l_w = window.open(l_url,""); Philippe From davids at webmaster.com Thu Oct 27 09:08:22 2005 From: davids at webmaster.com (David Schwartz) Date: Thu, 27 Oct 2005 06:08:22 -0700 Subject: Microsoft Hatred FAQ References: <djmc1d$lh2$1@nntp.webmaster.com> <5am333-iia.ln1@news.it.uc3m.es> <djoi5p$ell$1@nntp.webmaster.com> <b94533-nu5.ln1@news.it.uc3m.es> <djoqkb$hsm$1@nntp.webmaster.com> <4ua533-60t.ln1@news.it.uc3m.es> <djp4t3$lgu$1@nntp.webmaster.com> <pj60m194h7023ro20chuirldl8o29n31ca@4ax.com> <djpf90$pbm$1@nntp.webmaster.com> <ssr0m1tq3n5uksv0ltaf4edl5sttj47h7g@4ax.com> <djq0q8$vnh$1@nntp.webmaster.com> <ac51m11gbvthdc5rrb3ojmr41bc27ptuc2@4ax.com> <djqcb9$3r6$1@nntp.webmaster.com> <9bj1m11k5l9h5pq2dt4evpp5a2qbsqgfsn@4ax.com> Message-ID: <djqjg7$6db$1@nntp.webmaster.com> Roedy Green wrote: > 1. it was a threat to destroy a business -- e.g vandalise tens of > thousands of dollars of property. For all practical purpose they > threatened to steal my business. It would be roughly the same dollar > value as threatening to burn down a large house. No, it was a threat to stop providing you with a business by allowing you to resell their products. > 2. it was a threat to force me to commit a criminal act -- namely > extract money from people and hand it to Microsoft and give those > people nothing of value in return. That in principle is no different > from demanding I go out an night and rob people and give MS the > proceeds. The selected victims were those who expressed a contempt > for MS products by refusing to buy or even have any need for them. If you didn't think Windows was worth paying for, don't sell it. An wholesale agreement that prohibits you from selling competing products is not at all unusual. > 3. What MS did was theft, namely taking money from people and giving > them nothing of value in return against their will. Then don't agree to it. All you had to do was say no. All you would have lost was the ability to do business *with* *Microsoft*. > What if MS had simply made the threat without being specific about how > they were going to carry it off? Would you consider MS so innocent > then? If it could have been in any way taken as a threat to use force, lie to others about your company, file a lawsuit knowing it had no merit, or anything of the like, then I would not consider MS innocent at all. To my mind, that is where the line is drawn. But in this case, all it seems that Microsoft threatened to do was to prohibit you from doing business with them. And all they wanted in exchange was more of what being able to sell their products was actually worth to you. The point here is that Microsoft was offering you something of tremendous value to you. And they, in return, asked for a lot of money from you. It's really this simple -- is the money they want from you more or less than the value? If yes, you have no right to complain. If no, why ever did you agree? DS From python_it at hotmail.com Thu Oct 13 10:53:45 2005 From: python_it at hotmail.com (Python_it) Date: 13 Oct 2005 07:53:45 -0700 Subject: cgi python Message-ID: <1129215225.778017.20340@g47g2000cwa.googlegroups.com> I going to use the cgi-handler (mod_python): http://www.modpython.org/live/mod_python-3.2.2b/doc-html/hand-cgi.html If I test a simply py script it works code: =========== print "Content-type: text/html\n" print """ <html> <body> <h1>TEST</h1> </body> </html> """ ============ But if I test a py script with cgi comments (import cgi): Part of the code ============ import cgi #get HTTP query parameters query = cgi.FieldStorage() #Get the selected year and month selectedYear = int(query["year"].value) selectedMonth = int(query["x"].value) + 1 #Get the monthly revenue monthlyRevenue = float(query["value"].value) ============ I get the following error: errormessage: ========================== Mod_python error: "PythonHandler mod_python.cgihandler" Traceback (most recent call last): File "C:\Program Files\Python24\Lib\site-packages\mod_python\apache.py", line 299, in HandlerDispatch result = object(req) File "C:\Program Files\Python24\Lib\site-packages\mod_python\cgihandler.py", line 96, in handler imp.load_module(module_name, fd, path, desc) File "C:/Program Files/Apache Group/Apache2/htdocs/clue/modules/templates\clickpie.py", line 9, in ? selectedYear = int(query["year"].value) File "C:\Program Files\Python24\Lib\cgi.py", line 559, in __getitem__ raise KeyError, key KeyError: 'year' Who can help me? From andrewm at object-craft.com.au Thu Oct 13 23:11:35 2005 From: andrewm at object-craft.com.au (Andrew McNamara) Date: Fri, 14 Oct 2005 13:11:35 +1000 Subject: CSV module and Mac excel format problem In-Reply-To: <372F951A-3C5E-11DA-9C8A-000A27B3B070@eastlink.ca> References: <372F951A-3C5E-11DA-9C8A-000A27B3B070@eastlink.ca> Message-ID: <20051014031135.D4B987940DD@longblack.object-craft.com.au> >Hi. I have had good success with CSV module but recently came across >problem with reading excel from Mac Office. The trouble is with line >endings. Instead of \r\n you have just \r and the file as a whole >appears as a single line. CSV coughs and provides this exception: > >_csv.Error: newline inside string > >Saving as Windows (text) in Mac Office solves this but I don't >necessarily want to force users to save this way just to avoid >modifying my code. There is a lineterminator in the package. Adding >parameter lineterminator='\r' did not correct the problem. Open the file in universal-newline mode - for example: sample = open(filename, 'rU') "lineterminator" is only used for output - we use the supplied iterator (and whatever conventions it imposes) for input. -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ From aisaac0 at verizon.net Tue Oct 25 17:07:58 2005 From: aisaac0 at verizon.net (David Isaac) Date: Tue, 25 Oct 2005 21:07:58 GMT Subject: grep References: <Nvk7f.14699$gF4.11900@trnddc07><1130223409.28336.2.camel@blackwidow> <mailman.2511.1130226871.509.python-list@python.org> Message-ID: <O8x7f.1829$I65.860@trnddc01> "Fredrik Lundh" <fredrik at pythonware.com> wrote:: def grep(pattern, *files): search = re.compile(pattern).search for file in files: for index, line in enumerate(open(file)): if search(line): print ":".join((file, str(index+1), line[:-1])) grep("grep", *glob.glob("*.py")) I was afraid the re module was the answer. ;-) Use of enumerate is a nice idea. Thanks. Alan From mde at micah.elliott.name Thu Oct 6 12:31:50 2005 From: mde at micah.elliott.name (Micah Elliott) Date: Thu, 6 Oct 2005 09:31:50 -0700 Subject: Compile as static In-Reply-To: <1128591773.4344f19d7b429@webmail.sussex.ac.uk> References: <1128591773.4344f19d7b429@webmail.sussex.ac.uk> Message-ID: <20051006163150.GG32363@kitchen.client.attbi.com> On Oct 06, tjue1 at sussex.ac.uk wrote: > Has anyone had any luck with this? Im trying to compile python 2.4.2 on > Slackware 10.1 into one large executable. One which contains everything > required to run python (as static). So python doesn't look for > dynamically shared objects like libpthread.so.0. > > I have tried ./configure --disable-dynamic > --enable-dynamic=NO > --enable-static > > However the executable size is always the same :/ Please assist. ldd is your friend for seeing the dependencies. I see what you mean, though. I'm no autoconf expert, but AFAICT this was not an intended feature. My attempted grok of the Makefile also supports this theory. And I don't see any of the options you specified as being valid. Using "--disable-shared" also doesn't affect "python", but does appear to make libpython static, but I think it is regardless. You can force the issue with: $ ../configure ... $ make LDFLAGS=-static $ ls -l ./python -rwxr-xr-x 1 mdelliot support 2888818 Oct 6 08:06 ./python $ ldd ./python not a dynamic executable But this gives some import warnings, and running has some problems... Then I found these, indicating that it is easy ;-) http://groups.google.com/group/comp.lang.python/browse_frm/thread/9407982ad24b62ec/5018f9abebaa285a?lnk=st&q=build+python+static&rnum=3&hl=en#5018f9abebaa285a http://groups.google.com/group/comp.lang.python/browse_frm/thread/1ac371489ed4040b/076580464204cd79?lnk=st&q=build+python+static&rnum=5&hl=en#076580464204cd79 http://groups.google.com/group/comp.lang.python/browse_frm/thread/c532cc6469e29488/c6fcc1afbd7c41b0?lnk=st&q=build+python+static&rnum=17&hl=en#c6fcc1afbd7c41b0 It might be nice to have an autoconf option to make this more obvious for guys like us. Maybe this is just a rare need. -- Micah Elliott <mde at micah.elliott.name> From darkpaladin79 at hotmail.com Sat Oct 8 11:59:01 2005 From: darkpaladin79 at hotmail.com (Ivan Shevanski) Date: Sat, 08 Oct 2005 11:59:01 -0400 Subject: noob question Letters in words? In-Reply-To: <pan.2005.10.08.03.26.14.393951@REMOVETHIScyber.com.au> Message-ID: <BAY103-F5F1869B46FFE4E900D339A2870@phx.gbl> Thanks everyone for helping once again, lots of good ideas there Thanks, -Ivan _________________________________________________________________ FREE pop-up blocking with the new MSN Toolbar ? get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/ From fredrik at pythonware.com Tue Oct 25 04:51:17 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 25 Oct 2005 10:51:17 +0200 Subject: how to use new AST goodies References: <1130200430.365124.211950@g49g2000cwa.googlegroups.com> Message-ID: <djkrma$486$1@sea.gmane.org> Simon Burton wrote: > I'd like to experiment with this, does anyone know where to start ? with the "once there is" parts, probably (see below). > It seems that the parser module still produces the same junk as before. > So where do we find these nice high level AST objects ? here's a nice summary: http://www.amk.ca/diary/2005/10/the_ast_branch_lands_1 which ends with: "The primary benefit is that it should now be easier to write optimization passes and tools such as PyChecker or refactoring browsers, particularly once there's a Python interface to the AST and once everything is documented." </F> From pydecker at gmail.com Mon Oct 3 11:30:59 2005 From: pydecker at gmail.com (Peter Decker) Date: Mon, 3 Oct 2005 11:30:59 -0400 Subject: Reply-To header In-Reply-To: <laa0f.11129$SS1.481410@phobos.telenet-ops.be> References: <2ECA6FE9-3C8F-4C60-9E89-70CC078B14EF@gmail.com> <mailman.1370.1128343310.509.python-list@python.org> <laa0f.11129$SS1.481410@phobos.telenet-ops.be> Message-ID: <ca55a9900510030830scc7bf21y5b542ff4545a88af@mail.gmail.com> On 10/3/05, Roel Schroeven <rschroev_nospam_ml at fastmail.fm> wrote: > Indeed, and that's by design: http://www.unicom.com/pw/reply-to-harmful.html Of course, that's only one side of the argument: http://www.blackgate.net/consulting/reply-to_munging_useful.html On lists like this, where everyone benefits by sharing information, it seems pretty lame to hide behind purist arguments about Reply-To: headers. The default behavior should be the one most useful to the list. Think for a moment how many useful bits of information you've missed because the default for this list it to make conversations private. -- # p.d. From mwm at mired.org Sat Oct 22 19:55:45 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 22 Oct 2005 19:55:45 -0400 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <neq0l153mbhu758inptt5sc7jfsf5bqkaq@4ax.com> <11l16dst501kjdd@corp.supernews.com> <86ll0vs1sw.fsf@bhuda.mired.org> <dis0ve$m65$1@nntp.webmaster.com> <yw1x4q7il3gu.fsf@ford.inprovide.com> <diso3l$uf4$1@nntp.webmaster.com> <b15923-vj4.ln1@news.it.uc3m.es> <dj7dkr$rra$1@nntp.webmaster.com> <33sj23-6om.ln1@news.it.uc3m.es> <dj7rfg$108$1@nntp.webmaster.com> <t1bk23-age.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <pan.2005.10.22.03.58.40.332401@REMOVETHIScyber.com.au> <djcg8s$1qf$1@nntp.webmaster.com> <pan.2005.10.22.09.12.53.825745@REMOVETHIScyber.com.au> <djeha1$ouh$1@nntp.webmaster.com> Message-ID: <86k6g59ke6.fsf@bhuda.mired.org> "David Schwartz" <davids at webmaster.com> writes: > "Steven D'Aprano" <steve at REMOVETHIScyber.com.au> wrote in message > news:pan.2005.10.22.09.12.53.825745 at REMOVETHIScyber.com.au... >> On Fri, 21 Oct 2005 21:47:27 -0700, David Schwartz wrote: >>>> That's basic economics. Something which can be allowed or ignored or >>>> even >>>> encouraged when done by small businesses in a competitive market can >>>> easily become harmful and bad for the economy when done by a monopolist >>>> or >>>> duopolist in an uncompetitive market. >>> Microsoft goal is and should be their own success, not the success of >>> the economy or the market in general. >> Neither I, nor you, nor the government of any nation, should care a >> monkey's toss specifically for Microsoft's success. Microsoft is one >> special interest, out of a potentially unbounded number of possible >> players in the economy of a country and the world. > No, not at all. It is the gravest act of self-contradiction to maintain > that one should be allowed to pursue one's own interest while denying that > same right to others. Not at all. No one is denying anyones right to purssue their own interest. What's being denied is the right to use illegal means to do so. If MS restricted themselves to legal means, no one would have a problem with them. >> Unless you or I are specifically shareholders in Microsoft, we should not >> care about their specific success; and the government should be entirely >> agnostic about who are the winners and losers in an economy. > We should certainly care that Microsoft be allowed to pursue their own > success. The government should be agnostic about who the winners and losers > are, but must respect each entity's right to attempt to be that winner. Nice thought. Unfortunately, the government doesn't work that way. They believe that a practical monopoly is a bad thing, and limit the things such a company can do, and have been known to disassemble companies they believe are harming the economy in general. >> The >> government's role should be to ensure a level playing field, and minimum >> levels of health, safety and environmental standards. There is no place >> for government giving special-interests like Microsoft favours. > The problem is, people complain when the playing field is in fact level. > For example, Microsoft's "exclusionary" Windows agreements didn't ask for > more than Windows was worth (or nobody would have agreed to them). Yet they > are considered examples of the playing field not being level. No, they didn't ask for more than Windows were worth. They tilted the playing field against MS competitors by causing consumers to pay MS money for products they didn't receive. In most countries, taking money from unwilling victims without giving them anything in exchange is called "theft". >> Microsoft's behaviour over-all has been just as anti-social, >> anti-competitive and harmful to the over-all running of the economy as a >> hypothetical Walmart or Safeway that regularly parked their trucks in the >> middle of the main road for a few hours while they unloaded. > The problem is, the government does not own the economy. So it does not > get to manage it the way it gets to manage the roads it in fact owns. Sorry, but you're wrong. The government *does* own the econnomy. Who do you think originally created all the money that is flowing through it? The government charges you for the privilege of participating in their economy - it's called "income tax". 2000 years ago Christ knew who owned the economy, and said "Render unto Ceaser that which is Ceasers." >> Maybe, just maybe, if Mom & Pop's Corner Store tried it once or twice, we >> could afford to turn a blind eye, especially if the disruption caused by >> towing their delivery van was greater than the disruption caused by their >> double-parking. Thousands of people break the law by double-parking for a >> few minutes, and society doesn't collapse. But something that we can >> afford to ignore when done by M&P's Corner Store becomes a serious problem >> if done by somebody with the economic power of Walmart, with their >> thousands of deliveries by 18-wheelers every day across the country. > Again, the analogy fails. You are comparing the government's right to > manage its own property with the government's "right" to interfere with > other people's right to manage their property. Sorry, but nobody but the government actually owns property. In most places, you can't make non-trivial changes to "your" property without permission from the government. They even charge you rent on "your" property, only they call it "property tax". >>> Microsoft's status of a "monopolist" >>> is only meaningful if you define the market as "desktop operating systems >>> for 32-bit x86 computers". >> That is *precisely* the market we're talking about. Not "any item that >> runs off electricity", not "orange juice", not "pork bellies", not "all >> computing devices", but desktop PCs. What did you think the Justice >> Department's investigation was about? Motor vehicles? > I thought it was about operating systems, actually. And I thought that > both OSX and Linux competed with it. I guess it hasn't sunk in yet that the existence of competition doesn't keep a company from being a monopoly. But it does. Companies that owned less of their market than MS owns of it's market have been broken up. A classic monopoly behavior is to want the competition to survive "just barely", because that gives them leverage in court. Which is why MS has helped out Apple in the past. >>> There is no way Microsoft could have expected the >>> market to be defined in this way and no way to argue that Microsoft had >>> any >>> reason to believe their conduct was illegal. >> Microsoft have lawyers. Microsoft destroyed emails and at least one senior >> manager perjured himself in court. Microsoft created a fake video >> demonstration which they then gave as evidence. Do you really believe that >> Microsoft's executives are so incompetent that they don't get legal advice >> before writing up contracts? Or that nobody in authority at Microsoft >> realised that destroying evidence and lying to a judge are crimes? > When a criminal willing to use force points a gun at your head, you lie > to him. You sound like an anarchist to me. This wasn't a criminal, this was the government. Lieing to random individuals isn't a crime. Lieing to the government is. >> In any case, even if you are right that Microsoft had no ideas... so what? >> Ignorance of the law never has been an excuse for criminal behaviour. It >> has always been every individual's responsibility to make sure that they >> do not act illegally, and that goes for companies as well. > I am not saying Microsoft did not know the law. I am saying that no > rational person could have expected the law to be applied to Microsoft that > way it was. The law *must* put a person on notice of precisely what conduct > it prohibits. However, in this case, the law's applicability was conditioned > on an abritrary and irrational choice of what the relevant market was. MS has a long history of dancing with the DOJ, and has been repeatedly warned about the legality - or lack thereof - of their behavior. No rational person who knew of that history could expect the law to be applied to MS in any way other than the way it was. <mike -- Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From davids at webmaster.com Mon Oct 24 18:26:22 2005 From: davids at webmaster.com (David Schwartz) Date: Mon, 24 Oct 2005 15:26:22 -0700 Subject: Microsoft Hatred FAQ References: <yw1x4q7il3gu.fsf@ford.inprovide.com> <diso3l$uf4$1@nntp.webmaster.com> <b15923-vj4.ln1@news.it.uc3m.es> <dj7dkr$rra$1@nntp.webmaster.com> <33sj23-6om.ln1@news.it.uc3m.es> <dj7rfg$108$1@nntp.webmaster.com> <t1bk23-age.ln1@news.it.uc3m.es> <1129826863.422951.146970@g49g2000cwa.googlegroups.com> <pan.2005.10.22.03.58.40.332401@REMOVETHIScyber.com.au> <djcg8s$1qf$1@nntp.webmaster.com> <70njl1t0gu91o2redeptktvsjp8lprao02@4ax.com> <djegt1$onl$1@nntp.webmaster.com> <s3oll1tbve3t5h4c8eghbqihsuuusj72nc@4ax.com> <djenjt$r2o$1@nntp.webmaster.com> <slrndlpdig.hdl.apardon@rcpc42.vub.ac.be> <djjef5$jqk$1@nntp.webmaster.com> <m3irvma9w3.fsf@invalid.address> Message-ID: <djjn2f$n2f$1@nntp.webmaster.com> <joe at invalid.address> wrote in message news:m3irvma9w3.fsf at invalid.address... > "David Schwartz" <davids at webmaster.com> writes: >> I think you need to look up "extortion" in a dictionary. I can >> walk up to you and say "if you want me to mow your lawn, you must >> pay me $1 every time you smoke a cigarette". So long as you can say >> "no" and all that happens is that I don't mow your lawn (which I >> have no obligation to do anyway), it isn't extortion. > Extortion isn't the right word, of course. Nevertheless, being unable > to pay for a computer without also having to pay for an operating > system I don't want seems wrong to me. Then don't do it. > Yes, I have alternatives, I generally buy components and put them > together myself. But why should I have to do that simply to avoid > paying for an OS I'm not going to use? When you are not in the majority, you are going to face inconveniences. You'd face the same inconvenience if you wanted to buy a new car without seats. Most people wants cars with seats, so that's the way they're packaged. > The way this seems to work in practice strikes me as questionable at > best. Perhaps not illegal (IANAL so I don't know that) but certainly > one-sided. For one example, see > > http://www.netcraft.com.au/geoffrey/toshiba.html This, I think, is unacceptable. DS From toufeeqh at gmail.com Wed Oct 5 06:10:40 2005 From: toufeeqh at gmail.com (Toufeeq Hussain) Date: Wed, 5 Oct 2005 15:40:40 +0530 Subject: Help needed in OOP-Python In-Reply-To: <c293dd340510050044t35e86d09h5d7a3a3c344d00f3@mail.gmail.com> References: <c293dd340510042234s74a4db47x85bdd5658a1ad803@mail.gmail.com> <dhvpto$o0q$1@sea.gmane.org> <c293dd340510042323o14db7dcdn43b7f21c376b2e48@mail.gmail.com> <dhvvd0$5dh$1@sea.gmane.org> <c293dd340510050044t35e86d09h5d7a3a3c344d00f3@mail.gmail.com> Message-ID: <c293dd340510050310s376eb5ebw3088cfa48bc28bc7@mail.gmail.com> Thanks Fredrik. Went through the code to make sure "self" was used properly and one of the parent classes was missing a "self".It's fixed now. /me kicks self -toufeeq On 10/5/05, Toufeeq Hussain <toufeeqh at gmail.com> wrote: > > Fredrik, > > sigh! > I see the problem you mention and I agree. > Should have posted the orginal code without edits. :( > Anyway I'll try to fill in whereever required. > > On 10/5/05, Fredrik Lundh <fredrik at pythonware.com> wrote: > > > > > > $ python test.py > > condition satisfied > > Traceback (most recent call last): > > File "test.py", line 4, in ? > > Test_Case.Option1_constraint() > > File "module3.py", line 11, in Option1_constraint > > self.FOO_warning.Fire() > > AttributeError: Option1_Rule1 instance has no attribute 'FOO_warning' > > > > FOO_warning? there's no FOO_warning anywhere in the code. > > > FOO_warning is "Option1_warning" from Module3. > > And, in Module1 comment out the line: > "common_subs.write_to_out_file( 'FOO_OUT',self.Warn_text)" > > ::: > > > > so, after four attempts, I've found four problems, three of which was > > present > > in your posted code, but I still haven't seen the problem you reported: > > > > Traceback (most recent call last): > > File "test_case.py", line 7, in ? > > TH = constraint.Option1_Rule1() > > File " constraint.py", line 13, in __init__ > > declaration.Option1.__init__(self) > > TypeError: __init__() takes no arguments (1 given) > > > But the script when given as individual commands works fine in IDLE. > While executing the script it throws that error. :( > > which, in itself, looks like you've forgotten the self argument in some > > init > > method somewhere (but the code you posted doesn't have that problem). > > > Yes,I've doubled checked this. > > if you want to post code, 1) try to reduce the problem to as little code > > as you > > possibly can, and 2) make sure that the code you post really has the > > problem > > you're seeing... (i.e. run it at least once before you post it) > > > All points noted and will follow the same. > Thanks and my sincere apologies. > > -toufeeq > -- > Get Firefox:http://www.mozilla.org/products/firefox/ > The fastest, safest and best Browser !! > -- Get Firefox:http://www.mozilla.org/products/firefox/ The fastest, safest and best Browser !! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-list/attachments/20051005/1e66a41b/attachment.html> From sjuranic at gmail.com Tue Oct 4 11:11:15 2005 From: sjuranic at gmail.com (Steve Juranich) Date: Tue, 4 Oct 2005 08:11:15 -0700 Subject: Swig and Python In-Reply-To: <1128429987.357140.111280@f14g2000cwb.googlegroups.com> References: <1128429987.357140.111280@f14g2000cwb.googlegroups.com> Message-ID: <56190b6c0510040811x7195ab95t649c9ee2c77000de@mail.gmail.com> On 4 Oct 2005 05:46:27 -0700, Java and Swing <codecraig at gmail.com> wrote: > ...Ok, so I have a couple questions. > 1) How would I call MakeDigits from python? In the C code I would > normally have something like... > MY_DIGIT tmp[10]; > MakeDigits(tmp); How I usually do this is to write a typemap so that MY_DIGIT arrays are automagically converted to/from regular python lists. See the SWIG docs on writing typemaps. When that is done, you can call it just like this: MakeDigits(range(10)) MakeDigits([1, 3, 5, 7, 9]) # etc. > 2) How would I call GetString? Again, in C I would have... > char *ptr; > char msg[100] = "Hello World"; > MY_DIGIT x = 98; > ptr = GetString(msg, x); This should happen for you fairly automatically: GetString('Hello World', 98) > 3) Did I define MY_DIGIT correctly in my SWIG interface file? I can't really say. I don't use typedefs all that much. You can always look at the generated C/C++ code to see if it looks right. Read the docs on the Python/C API if you haven't already. > 4) If I try the following Python code... > x = new_digit_array() > print x > then Python.exe dies...any idea? Smells like a segfault from here. Might have to put some printfs in the generated code to find out exactly what's happening. > thanks for the help. I am trying to find my answers int he SWIG > docs...either i haven't found it or I didn't understand when I came > across it. The SWIG user community also has a very helpful list. Check out http://www.swig.org/mail.html for more info. You might find that your SWIG related issues get addressed more quickly when posting to the SWIG list. There are lots of Python hackers on the list, too. So don't be afraid to ask fairly Python-centric questions either. -- Steve Juranich Tucson, AZ USA From dinamo99 at lycos.com Sun Oct 23 02:52:26 2005 From: dinamo99 at lycos.com (Joe) Date: Sun, 23 Oct 2005 06:52:26 GMT Subject: downloading web images Message-ID: <KqG6f.269292$1i.195859@pd7tw2no> I'm just wandering if I'm doing this correct way I'm trying to download an image and store it into a file this does the job, but created file does not apear to be an image, it works fine and I can open image, I'm just wandering if there is a better way of doing this. htmlSource=urllib.urlopen("http://www.godandscience.org/images/nebula.jpg") # Read from the object, storing the page's contents in 's'. s = htmlSource.read() htmlSource.close() myfile = open("myfile.jpg", "w") myfile.write(s) myfile.close Thanks From jeremy at emperorlinux.com Wed Oct 5 23:25:11 2005 From: jeremy at emperorlinux.com (Jeremy Moles) Date: Wed, 05 Oct 2005 23:25:11 -0400 Subject: Absolultely confused... In-Reply-To: <di3dft$g99$1@news.sap-ag.de> References: <mailman.1610.1128607227.509.python-list@python.org> <di3dft$g99$1@news.sap-ag.de> Message-ID: <1128569111.3513.22.camel@localhost.localdomain> Well, there's certainly no doubting that all of you are right. I guess now I need to track down how this is happening and either fix it or understand it so that I can explain why I'm having to work around it. :) Many, many thanks. :) On Thu, 2005-10-06 at 16:48 +0200, Daniel Dittmar wrote: > Jeremy Moles wrote: > > So, here is my relevant code: > > > > PyArg_ParseTuple(args, "O!", &PyType_vector3d, &arg1) > > > > And here ismy error message: > > > > argument 1 must be pylf.core.vector3d, not pylf.core.vector3d > > > > It looks as if two PyType_vector3d exist in your system > - the one that created the object passed to your routine > - the one in your extension code > > As PyType_vector3d probably comes from a shared object/DLL > - does your code accesses really the same shared object that is also > loaded by the Python interpreter? It could be that you linked with a > specific file, but Python loads something different from $PYTHONPATH > - on Windows, you couldn't simply import a variable from a DLL, you had > to call a special routine to get the pointer > > One possible portable solution: in your module initialization > - import pylf.core > - create an object of type vector3d > - use your knowledge about the inner structure of Python objects and get > the pointer to the PyType from the object > - store it in a module static variable TypeVector3D > - pass that variable to PyArg_ParseTuple > > Browse the Python Extension API, maybe partts or all of this are already > available. > > There's still a problem left when pylf.core gets reloaded (rare, but > possible). I assume the shared object also gets reloaded, which means > that the type objects gets loaded to a new address and PyArg_ParseTuple > will complain again. I'm not sure if there is a solution to this, > because there still could be objects create from the old module. > > Maybe you should just check the type yourself by comparing the class > names buried in the PyType. You could cache one or two type pointers to > speed this up. > > Daniel From stefan.behnel-n05pAM at web.de Mon Oct 17 05:30:40 2005 From: stefan.behnel-n05pAM at web.de (Stefan Behnel) Date: Mon, 17 Oct 2005 11:30:40 +0200 Subject: ANN: MathDOM 0.5.2 - MathML in Python - now featuring lxml API! Message-ID: <divr12$54a$1@lnx107.hrz.tu-darmstadt.de> Hi everyone, MathDOM 0.5.2 is ready for download from SourceForge. http://mathdom.sourceforge.net/ MathDOM is a set of Python modules (using pyparsing and either PyXML or lxml) that import mathematical terms as a Content MathML DOM. It currently parses MathML and literal infix terms into a DOM and writes out MathML and literal infix, prefix, postfix or Python terms. The DOM elements are enhanced by domain specific methods that make using the DOM a little easier. You can call it the shortest way between different term representations and an enhanced Content MathML DOM. Ever noticed the annoying differences between terms in different programming languages? Build your application around the DOM and stop caring about the term representation that users prefer or that your machine can execute. If you need a different representation, add a converter, but don't change the model. Literal terms are connected through an intermediate AST step that makes writing converters for Python/SQL/yourfavorite easier. ** New in 0.5.2 ** This release features the original 4DOM based API as well as a completely new API based on a patched version of lxml. lxml is an ElementTree like API on top of libxml2, which combines fast XPath, XSLT, XInclude, etc. computation with the ease of a pythonesque API. Try it, it's worth making the change. Have fun, Stefan From gandalf at designaproduct.biz Thu Oct 6 06:53:15 2005 From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy) Date: Thu, 06 Oct 2005 12:53:15 +0200 Subject: Help-log in to a web page In-Reply-To: <6x61f.11$nq6.8@news.oracle.com> References: <aM51f.8$nq6.116@news.oracle.com> <mailman.1594.1128589260.509.python-list@python.org> <zf61f.10$nq6.24@news.oracle.com> <6x61f.11$nq6.8@news.oracle.com> Message-ID: <4345021B.1020406@designaproduct.biz> >> >> I tried to view the source,it has, >> .... >> .... >> src="/em/cabo/images /t.gif" height="80"></td><td><table >> align="center" border="0" cellspacing="2" cellpadding="0"><tr >> id="username >> __xc_"><td align="right" nowrap><span class="x8"><span >> title="Required" class="xc">*</span> *User Name</s >> pan></td><td width="12"><img src="/em/cabo/images/t.gif" >> width="12"></td><td valign="top" nowrap><input >> id="username" class="x4" onkeypress="return >> _submitOnEnter(event, 'User');" name="j_username" size="30" >> type="text" value="myadmin"></td></tr><tr><td align="right" >> nowrap><span class="x8"><span title="Required" >> class="xc">*</span> Password</span></td><td >> width="12"><img src="/em/cabo/images/t.gif" width="12"></td >> ><td valign="top" nowrap><input id="M__Id" class="x4" >> name="j_password" size="30*" autocomplete="off" type="p >> ... >> ... > Either it is a javascript or a form. Most likely this will be a normal form, like: <form method="POST" action="login.php"> <input name="login" type="text"> <input name="pwd" type="text"> </form> This is another authentication method that is used frequently. You need to POST the login/password and other parameters to the URL specified by the "action" attribute of the "form" tag. Say, if you download the above HTML page from http://here.net/there then you should POST your login data to http://here.net/there/login.php The response may contain cookies - you need to use them to keep yourself logged in. Please read documentation about these: - HTML forms - HTTP cookies and then read the docs of the urllib module here: http://www.python.org/doc/current/lib/module-urllib.html It has parts where you can learn how to POST or GET data. If you need to handle cookies as well (probably, this is true in your case), you might want to change to urllib2 http://www.python.org/doc/current/lib/module-urllib2.html because it has support for cookies. Don't do anything until you understand what cookies and HTML forms are. (And don't ask about them here - it is not about Python programming...) Best, Les From scott.daniels at acm.org Tue Oct 18 14:40:25 2005 From: scott.daniels at acm.org (Scott David Daniels) Date: Tue, 18 Oct 2005 11:40:25 -0700 Subject: Why asci-only symbols? In-Reply-To: <43545340.277176128@news.oz.net> References: <86vf04zx0k.fsf@bhuda.mired.org> <434ccfcd$0$28021$9b622d9e@news.freenet.de> <4351cef6.112238340@news.oz.net> <4352289a$0$15038$9b622d9e@news.freenet.de> <4353085a.192466642@news.oz.net> <435434f1$0$5767$9b622d9e@news.freenet.de> <43545340.277176128@news.oz.net> Message-ID: <43554106@nntp0.pdx.net> Bengt Richter wrote: > <on tracking the encodings of literal generated astrings> The big problem you'll hit is figuring out how to use these strings. Which string ops preserve the encoding? Even the following is problematic: #-*- coding: utf-8 -*- name = 'Martin L?wis' brokenpart = name[: 9] Because brokenpart is not a correct utf-8 encoding of anything. The problem is that there is no good way to propagate the encoding without understanding the purpose of the operations themselves. --Scott David Daniels scott.daniels at acm.org From my_email_is_posted_on_my_website at munged.invalid Sun Oct 9 03:27:04 2005 From: my_email_is_posted_on_my_website at munged.invalid (Roedy Green) Date: Sun, 09 Oct 2005 07:27: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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <pan.2005.10.04.23.38.40.465171@REMOVETHIScyber.com.au> <csbgk199k2jkvcdl6v0s2jd6q6s6k9d1to@4ax.com> <863bnbofe5.fsf@bhuda.mired.org> <PK-dnZZdetOs39Xe4p2dnA@telenor.com> <p1igk1lrkf54of1apt1vdssqnjb6qdtpj1@4ax.com> <86psqfmukd.fsf@bhuda.mired.org> Message-ID: <sghhk1hcom1adf7ic99j253bks1j54iqs4@4ax.com> On Sat, 08 Oct 2005 19:56:50 -0400, Mike Meyer <mwm at mired.org> wrote or quoted : >Show us *examples*! Do you create a style sheet for every site you >visit that overrides there classes? What? Why don't you download a copy of Opera, see http://mindprod.com/jgloss/opera.html Then try out the feature. Click View | style | user -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. From john at castleamber.com Mon Oct 10 00:28:18 2005 From: john at castleamber.com (John Bokma) Date: 10 Oct 2005 04:28: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> <3nd5k1dhv77j1bs88qjdl66cc0jnattvka@4ax.com> <11k5gjpqkt7878b@corp.supernews.com> <1pbgk1pbcu3u27vblor052ass03epq5vqr@4ax.com> <Pine.SOL.4.58.0510081632220.21577@excalibur> <Xns96E9BDC924CC0castleamber@130.133.1.4> <85hhk1d9ife3gvk6co97ra03u4hah7o8i8@4ax.com> Message-ID: <Xns96EAEEC1B9C8Bcastleamber@130.133.1.4> Roedy Green <my_email_is_posted_on_my_website at munged.invalid> wrote: > On 8 Oct 2005 23:39:27 GMT, John Bokma <john at castleamber.com> wrote or > quoted : > >>Yeah, yeah, and 640K is enough for everybody. Same song, different tune. > > For how long. Surely attachments are a stop gap. Can you imagine > people sharing images that way 100 years from now? No, but I agree with you :-) I am not using HTML myself in email, but I will when it makes things easier. > Why should we wait for the future? The problems blocking easy to use > photo sharing are not technological but social. Yup, agreed. Like I already wrote, if I route all HTML email to /dev/null I'll lose some customers, and some friends :-) -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ I ploink googlegroups.com :-) From apardon at forel.vub.ac.be Tue Oct 11 03:36:41 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 11 Oct 2005 07:36:41 GMT Subject: [Info] PEP 308 accepted - new conditional expressions References: <3q4ro9Fd770nU3@individual.net> <mailman.1655.1128664871.509.python-list@python.org> <slrndki4h7.55g.zen19725@cabalamat.somewhere> <mailman.1860.1128980285.509.python-list@python.org> Message-ID: <slrndkmqs9.32p.apardon@rcpc42.vub.ac.be> Op 2005-10-10, Terry Hancock schreef <hancock at anansispaceworks.com>: > On Sunday 09 October 2005 07:50 am, phil hunt wrote: >> On Fri, 7 Oct 2005 01:05:12 -0500, Terry Hancock <hancock at anansispaceworks.com> wrote: >> >GvR's syntax has the advantage of making grammatical sense in English (i.e. >> >reading it as written pretty much makes sense). >> >> I know, let's re-write Python to make it more like COBOL! That's >> bound to be a winner! > > Whereas the "natural order" of "condition affirmative negative" is natural > for what reason? That it is so in C? > > I don't find that so compelling either, frankly. Why should it really > matter in the end? I've always found C's order (and punctuation) confusing, > I have to look it up practically everytime I use it or have to read it > (which correlates to it being used very rarely, with causality in both > directions). > > Given that situation, choosing a form which is easy to read is surely > an advantage, and, since it is the way that Python has handled logic > in the past, it makes sense to continue doing so. Personnaly I would think some consistency between conditional expressions and conditional statements would have been a good thing. I haven't seen a discussion where the following kind of if statement was discussed. do: return a[0] if a[0] < a[1] else: return a[1[ > No doubt, ANY choice of ternary operator for Python will be > criticized, and no doubt, ANY choice would nevertheless be > usable. Agreed, I think having it is more important than what form it comes in. My preference has more to do with consistency with the statement. > OTOH, I think this choice is consistent with the rest of Python's > design. The general choice to use keyword operators for LOGIC > and symbolic operators for MATH is retained, and so long as we're > describing the logic in words, it makes sense for the wording > to sound natural. > > Consistency certainly does make it easier for me to remember. I think that a consistency within the language would have made more sense than consistency with someone's mother tongue. When I program I program in python or some other programming language. Not in english, dutch, french or some other natural language. But for me this is just style talk. I don't care that much for style, I'm more concerned with functionality and I'm glad this functionality will become available. -- Antoon Pardon From jjl at pobox.com Thu Oct 13 15:01:13 2005 From: jjl at pobox.com (John J. Lee) Date: 13 Oct 2005 20:01:13 +0100 Subject: Well written open source Python apps References: <1129214592.342917.100090@g43g2000cwa.googlegroups.com> Message-ID: <7jchw8au.fsf@pobox.com> "Ben" <bwsanders at gmail.com> writes: > Could anyone suggest an open source project that has particularly well > written Python? I am especially looking for code that people would > describe as "very Python-ic". (Not trying to start any kind of war - > just wanted some good examples of a well written Python app to read.) [...] At the time I looked at it I thought this was nice, though that was some time ago (it was still 'sketch' then) so I wonder if I'd still have the same opinion if I looked now (due to me changing my view of "good code", not the skencil source code changing!): http://www.nongnu.org/skencil/ John From davecook at nowhere.net Sat Oct 29 14:42:21 2005 From: davecook at nowhere.net (Dave Cook) Date: Sat, 29 Oct 2005 18:42:21 GMT Subject: Any Pythonic GTK Undo library? References: <*firstname*nlsnews-62BA42.13375929102005@news.verizon.net> Message-ID: <slrndm7gku.e68.davecook@localhost.localdomain> On 2005-10-29, Tony Nelson <*firstname*nlsnews at georgea*lastname*.com> wrote: > I'm looking for a "pythonic" GTK Undo library/class. It would have a You might ask the authors of Kiwi if they plan to add undo/redo. Or help them add it if you can. http://www.async.com.br/projects/kiwi/ It would be great to have this feature in the Gtk C API, though. I do see some relevant bugzilla entries: http://bugzilla.gnome.org/show_bug.cgi?id=316551 You might want to make a new request for a general undo/redo interface. Dave Cook From davids at webmaster.com Sat Oct 15 19:57:17 2005 From: davids at webmaster.com (David Schwartz) Date: Sat, 15 Oct 2005 16:57:17 -0700 Subject: Microsoft Hatred FAQ References: <1129341702.532198.224880@g14g2000cwa.googlegroups.com> <neq0l153mbhu758inptt5sc7jfsf5bqkaq@4ax.com> <11l16dst501kjdd@corp.supernews.com> <a103l1tkejrc99s0385qjqqhm96d46dpc4@4ax.com> <dis138$m68$1@nntp.webmaster.com> <Xns96F0B7AE1A639castleamber@130.133.1.4> Message-ID: <dis512$nlp$1@nntp.webmaster.com> "John Bokma" <john at castleamber.com> wrote in message news:Xns96F0B7AE1A639castleamber at 130.133.1.4... > "David Schwartz" <davids at webmaster.com> wrote: >> "Tim Roberts" <timr at probo.com> wrote in message >> news:a103l1tkejrc99s0385qjqqhm96d46dpc4 at 4ax.com... >>> Part of their behavior really escape me. The whole thing about >>> browser wars confuses me. Web browsers represent a zero billion >>> dollar a year market. Why would you risk anything to own it? >> It really isn't that hard to understand that web-based >> applications that >> work in any browser on any OS threaten to make it irrelevent what OS >> you're running. > And it's even easier to understand that your statement is nonsense. To you, if you don't understand it. > It doesn't matter which Linux distribution you pick, all use the Linux > kernel. On all I can run OpenOffice, and get the same results. Yet people > seem to prefer one distribution over one other. Right, and that's what Microsoft wants to avoid. They wants to make sure people *have* to choose a Microsoft operating system to get their applications to work. He doesn't want most applications to work the same on all operating systems. MS was afraid the browser would replace the operating system in the sense that it would be the target platform for applications. >> MS has a strong interest in making sure it's important >> to be running on one of their OSes. > Maybe *they* do have a point :-). Well, they have their vision of the future of computing, and you can bet all things made by Microsoft are at the center of it. DS From stephen at theboulets.net Fri Oct 7 16:04:46 2005 From: stephen at theboulets.net (stephen at theboulets.net) Date: 7 Oct 2005 13:04:46 -0700 Subject: Saving an image to file from windows clipboard In-Reply-To: <mailman.1719.1128714861.509.python-list@python.org> References: <1128713363.664540.84030@f14g2000cwb.googlegroups.com> <mailman.1719.1128714861.509.python-list@python.org> Message-ID: <1128715486.858009.112460@z14g2000cwz.googlegroups.com> Thanks -- works as advertised. Stephen From __peter__ at web.de Sun Oct 2 18:31:44 2005 From: __peter__ at web.de (Peter Otten) Date: Mon, 03 Oct 2005 00:31:44 +0200 Subject: struct.unpack References: <dhpem5$nne$1@online.de> <mailman.1354.1128285272.509.python-list@python.org> <dhpk5m$lcu$1@online.de> Message-ID: <dhpn42$q9o$00$1@news.t-online.com> g.franzkowiak wrote: > tmpList = list(dataObject)[:4]) > obj = tmpList[0]+tmpList[1]+tmpList[2]+tmpList[3]. Have you tried just obj = dataObject[:4] without the intermediate list? If that failed, can you tell us the type of the dataObject? E. g. >>> print type(dataObject) <class '__main__.NeitherListNorString'> Peter From salvatore.didio at wanadoo.fr Sun Oct 2 08:10:17 2005 From: salvatore.didio at wanadoo.fr (salvatore.didio at wanadoo.fr) Date: 2 Oct 2005 05:10:17 -0700 Subject: Nufox : Xul + Python In-Reply-To: <mailman.1343.1128252067.509.python-list@python.org> References: <1128163366.631178.74800@o13g2000cwo.googlegroups.com> <1128182754.232912.9980@z14g2000cwz.googlegroups.com> <mailman.1320.1128183336.509.python-list@python.org> <433f051f$0$49786$ed2e19e4@ptn-nntp-reader04.plus.net> <1128249650.166566.81790@g44g2000cwa.googlegroups.com> <mailman.1343.1128252067.509.python-list@python.org> Message-ID: <1128255017.708134.49380@g14g2000cwa.googlegroups.com> You are perfectly right ;-) And I've been a network technician !!! I've modified the address, thank you for testing Regards Salvatore From sina.818 at gmail.com Mon Oct 3 10:01:01 2005 From: sina.818 at gmail.com (sina.818 at gmail.com) Date: 3 Oct 2005 07:01:01 -0700 Subject: You Can FIND any thing u want Message-ID: <1128345269.878419.33230@g44g2000cwa.googlegroups.com> Hi This website can help you to find any links you want: http://www.lxlinks.cjb.net Enjoy From xiaoning_zhang at hotmail.com Mon Oct 31 23:46:10 2005 From: xiaoning_zhang at hotmail.com (zhang xiaoning) Date: Tue, 01 Nov 2005 12:46:10 +0800 Subject: how to import extension module from embedding application on aix5 Message-ID: <BAY113-F3753BB8E5F4D7FA6B3590FB6F0@phx.gbl> Hi, I download and extract python-2.4.2 source code for unix, and then, build and install it on aix5, the configure option I used is: ./configure --enable-shared --disable-ipv6 --prefix=/usr/python then, I run: make and make install because I want to embed python in other language, so I continue run: make libpython2.4.so then,run make install again. after works above, I start python, try: >import time >print time.localtime() every thing is okay. and then, I try a simple example: import.c #include <Python.h> int main(int argc, char *argv[]) { Py_Initialize(); PyRun_SimpleString("import time\n" "print time.localtime()\n"); Py_Finalize(); return 0; } the Makefile is like: cc_r -c -I. -o ./import.o import.c $(PYINC). cc_r -o ./importApp ./import.o -brtl $(LIBPATH) -lpython2.4 where PYINC and LIBPATH are correct. I got the importApp, I try to run it: ./importApp I got an error message: ImportError: Exec format error I test most of extension module which is in <python_home>/lib/python2.4/lib-dynload, such as math, parser, I got the same error. It seems due to try to import extension module from embedding application. Any thing wrong I did when I configure and make install python? Thank you! Xiaoning From lycka at carmen.se Tue Oct 4 08:18:33 2005 From: lycka at carmen.se (Magnus Lycka) Date: Tue, 04 Oct 2005 14:18:33 +0200 Subject: what does 0 mean in MyApp(0) In-Reply-To: <1128102240.452942.180890@g44g2000cwa.googlegroups.com> References: <1128089733.684329.101320@o13g2000cwo.googlegroups.com> <dhjiih$kvc$1@news1.zwoll1.ov.home.nl> <1128102240.452942.180890@g44g2000cwa.googlegroups.com> Message-ID: <dhtrup$rag$1@wake.carmen.se> Alex wrote: > Alterbnative 2 is simple and useful, so that's why everybody use that > alternative. Everybody doesn't... Particularly in Windows, it's common that people make a .pyw-file, and then you don't see any console, or otherwise they double-click on a .py-file, and if the app dies with an error, they'll never get a chance to read the traceback (unless they have a horribly slow computer). Even worse, it they use command.com as their shell (default on MS DOS derivates such as Windows ME) copying text from the shell doesn't work very well, even if the shell didn't close. Getting all printouts, tracebacks etc into a file is very convenient during development. In a decent development environment, you're likely to have a window open where you do "tail -f" on the file. Even in production, it's a good thing if it's at least possible to enable output to a debug file. I've had that as a command line switch, and asked users to turn that on and mail me the resulting log file as they reproduced a buggy behaviour. From eurleif at ecritters.biz Mon Oct 17 13:28:47 2005 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Mon, 17 Oct 2005 17:28:47 GMT Subject: newbie regex In-Reply-To: <RWQ4f.280$A21.55151@newshog.newsread.com> References: <1129565047.255804.266190@z14g2000cwz.googlegroups.com> <RWQ4f.280$A21.55151@newshog.newsread.com> Message-ID: <jbR4f.281$A21.55299@newshog.newsread.com> Leif K-Brooks wrote: > csselo at gmail.com wrote: > >>I want to filter some strings,but i don t know how to use compile >>method. > > Why not? Sorry: I misread that as not _wanting_ to use the compile method. From ms at cerenity.org Sat Oct 8 09:08:40 2005 From: ms at cerenity.org (Michael) Date: Sat, 08 Oct 2005 14:08:40 +0100 Subject: Continuous system simulation in Python References: <20051007011222.1aeab426@linuxcestcomplique.fr> Message-ID: <4347c49d$0$15036$ed2619ec@ptn-nntp-reader02.plus.net> Nicolas Pernetty wrote: > I'm looking for any work/paper/ressource about continuous system > simulation using Python or any similar object oriented languages (or > even UML theory !). > > I'm aware of SimPy for discrete event simulation, but I haven't found > any work about continuous system. > I would like to develop a generic continous system simulator, and so > would be eager to join any open source effort on the subject. There was going to be a talk on continuous system simulation (*) at EuroPython this year, but for some reason it didn't appear to happen (It was one of the talks I was hoping to see). I've no real idea of the content of the talk or the work involved though for obvious reasons. Maybe that can provide a lead? (*) http://www.python-in-business.org/ep2005/alisttrack.chtml?track=646 "Implementing Continuous Time Simulation Systems in Python, Paul J Nolan" Another lead //might// actually be to ask on the pygame list (MAYBE). It's not directly the same thing, but essentially lots of games are in many respects a form of continuous systems simulation, and someone on that list might be able to point you in a good direction. One book I bought a while back (looked interesting) which might be relevant for you is O'Reilly's "physics for game developers", and and another is "AI for games programmer"(*) since they both touch on these areas. If you have a Safari account already that could be an easy way of checking to see whether the book covers the sorts of answers you're after. (They don't use python as their example language, but that's a minor problem really IMO) (*) This is less obviously relevant, but deals with things deciding to move themselves around continuous spaces and visualised at indeterminate frame or display rates. Best Regards, Michael. From google at shawndyer.com Mon Oct 17 12:43:24 2005 From: google at shawndyer.com (shawn) Date: 17 Oct 2005 09:43:24 -0700 Subject: subtyping a builtin type in a C extension In-Reply-To: <mailman.2149.1129538147.509.python-list@python.org> References: <1129522775.678995.80090@z14g2000cwz.googlegroups.com> <mailman.2149.1129538147.509.python-list@python.org> Message-ID: <1129567404.421734.223940@g49g2000cwa.googlegroups.com> Thank you. I should have looked for this sort of example. That was exactly what I needed. I don't ask for help here very often, but when I have, I have ALWAYS gotten faster results than with any commercial support option I have used. We have a good developer community :-) From steve at holdenweb.com Fri Oct 21 03:21:05 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 21 Oct 2005 08:21:05 +0100 Subject: classmethods, class variables and subclassing In-Reply-To: <43588b5c$0$6536$ed2619ec@ptn-nntp-reader01.plus.net> References: <4357EE59.1000005@bakerjaffe.plus.com> <mailman.2326.1129843278.509.python-list@python.org> <43588b5c$0$6536$ed2619ec@ptn-nntp-reader01.plus.net> Message-ID: <dja4ss$m2i$2@sea.gmane.org> Andrew Jaffe wrote: >>Andrew Jaffe wrote: [...] > > The problem is that I actually do want to call these methods on the > class itself, before I've made any instances. > Except you could use staticmethods with an explicit class argument ... regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/