From bobx at linuxmail.org Sun Feb 17 10:02:20 2002 From: bobx at linuxmail.org (Bob) Date: 17 Feb 2002 07:02:20 -0800 Subject: ActiveState version of 2.2??? Message-ID: <1001ff04.0202170702.6ebaaf55@posting.google.com> When? From pinard at iro.umontreal.ca Mon Feb 18 12:31:17 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 18 Feb 2002 12:31:17 -0500 Subject: comp.lang.python in English? (was Re: Why Python is like BASIC) In-Reply-To: References: Message-ID: [Aahz Maruch] > In article , > Fernando =?ISO-8859-1?Q?P=E9rez?= wrote: > > > >Would you folks mind sticking to English in public discussions? Use private > >email for other languages, please. > I think the occasional non-English post simply reflects the international > nature of Python. Exactement. Bravo! Bien dit! :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From gcordova at hebmex.com Mon Feb 11 16:15:25 2002 From: gcordova at hebmex.com (Gustavo Cordova) Date: Mon, 11 Feb 2002 15:15:25 -0600 Subject: Best python way to do 'object messaging' Message-ID: <19650FF08A99D511B19E00B0D0F06323060A27@SRM201002> Have to taken a look at some of the available MUDs? I believe some of them are scriptable as you say, you define an object class, which can be anything in the game; you define lotsa properties and methods which control the way it interacts with the environment. The objects you create can be weapons, plants, scrolls, monsters, seemingly anything. Good luck on your quest :-) -- Gustavo C?rdova Avila * gcordova at sismex.com * 8351-3861 | 8351-3862 From sholden at holdenweb.com Fri Feb 1 16:46:27 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 1 Feb 2002 16:46:27 -0500 Subject: reading sendmail alaises References: Message-ID: "David Bear" wrote in message news:m34rl2jh7m.fsf at moroni.pp.asu.edu... > I would like a quick way to resolve sendmail aliases. I've thought > about reading and parsing /etc/aliases myself but thats too much > work. Is there some module/interface to sendmail that would allow > something like > > realaddress = sendmail.resolve-alias(name) > > Even though I could build a dictionary from aliases, the file may > actually be in db format -- so I'm looking for a 'sendmail' way of > grabbing them. > [root at headrat tmp]# /usr/lib/sendmail -bv testalias sholden... deliverable: mailer local, user sholden root... deliverable: mailer local, user root so: #! /usr/bin/python import os, sys, string f = os.popen("/usr/lib/sendmail -bv %s" % string.join(sys.argv[1:], " ")) names = [] while 1: line = f.readline() if not line: break name = string.split(line)[0] names.append(name[:-3]) print names Sorry about the 1.5isms - nothing more recent to hand :-) regards Steve -- Consulting, training, speaking: http://www.holdenweb.com/ Python Web Programming: http://pydish.holdenweb.com/pwp/ From philh at comuno.freeserve.co.uk Fri Feb 22 09:58:05 2002 From: philh at comuno.freeserve.co.uk (phil hunt) Date: Fri, 22 Feb 2002 14:58:05 +0000 Subject: Python Gotcha with Octal Numbers References: Message-ID: On 22 Feb 2002 04:06:42 -0800, Clive Page wrote: >Philip Swartzleonard wrote in message news:... >> >> Steve has mentioned that UNIX people are used to it... i think it's a >> little deeper than that, b'cause as far as i know, _every_ programming >> language that has ever supported octal does it this way... > >Not quite all of them. Fortran (at least since Fortran90) allows the >forms O"01234" or O'1234' i.e. an upper-case O and a quoted string of >digits (but they are only allowed in data statements, unfortunately). > >Prior to Fortran90 there was no _standard_ way of expressing octal >constants, but lots of vendors had their own extensions. But I don't >recall ever coming across anything as error-prone as the C notation >with a leading zero. Fortran is a much safer language than C; I >recommend it as the nearest thing to a compiled form of Python. :-) I like the way Smalltalk does it: BrN Where B is a base, 2 to 36, and N is a number in that base, e.g: 2r11110000, 8r377, 16rFF, etc. -- ===== Philip Hunt ===== philh at comuno.freeserve.co.uk ===== Herbivore, a zero-effort email encryption system. Details at: From threeseas at earthlink.net Sun Feb 17 12:57:51 2002 From: threeseas at earthlink.net (Timothy Rue) Date: Sun, 17 Feb 2002 17:57:51 GMT Subject: Apology References: <3C68274C.F6F702F5@ccvcorp.com> <2320.811T442T11913096threeseas@earthlink.net> Message-ID: <12393.813T2860T7905870threeseas@earthlink.net> On 16-Feb-02 13:13:54 phil hunt wrote: >On Sat, 16 Feb 2002 01:45:42 GMT, Timothy Rue >wrote: >>On 12-Feb-02 10:46:49 phil hunt wrote: >>>On Mon, 11 Feb 2002 18:37:51 -0600, Chris Gonnerman >>> wrote: >>>> >>>>Indeed. He uses a nonstandard definition of "language" and applies >>>>"physics" >>>>to programming. He can't program, you know; ten years on this project and >>>>nothing to show for it. If I had tried to develop something like this for >>>>ten years and had nothing to show for it but a website, I'd give up. >> >>>At least his code is all neatly lined up! >> >>Chris's comprehension level is greatly lacking and you've shown your >>superiority attitude. >> >>Ten years???? it was Feburary 1988 when I identified the nine commands. >14 years then. You do realise, that makes you look even worse. >>I never claimed to be a programmer >14 years is plenty of time to lesarn, if you want to. >>and never wanted to make the VIC but >>rather someone to use it. >This implies you'd rather someone else coded it... >>But I also don't, and never will want to be >>abused by any programmer wanting to take credit and property rights to the >>VIC. >...but if they do, you want to take the credit and copyright for their >code. >>The computer industry has alot of ethical problems in this area of taking >>everything the can from the users, from their ideas, to their debugging >>efforts (feedback), to their money in payment for what came from them, and >>now rental....and always it is never quite right but lacking always... for >>upgrading recycling of consumer entrapment abuse. >If you refer to Microsoft, I agree. But free software / open source *isn't* >like that, in fact it is deliberately in opposition to that sort of thing. >>It's good to know that such practice is going to soon come to an end. >Because of VIC? Or because of something else? You have made it perfectly clear that you do not like me or this project and that you will even commit acts of deception in your taking out of context things I have said and in the wrongful insinuations you make. It's an open project Phil, under the GPL (and I reserve the right to change that to a more secure license should there be found a weakness in the GPL - Lawrence Lessig seems to be now going in a direction in consideration of what I've said regarding a fundamental change in intellectual property laws, and this includes Copyrights, in the "Creative Commons" http://www.sfgate.com/cgi-bin/article.cgi?file=/gate/archive/2002/11/creatcom.DTL soooo there will be plenty of choices.) And if that ain'tr enough: http://www.eetimes.com/story/OEG20020208S0079 I have already stated that I believe in giving credit where it is deserved and more so than as it is explained in: http://tuxedo.org/~esr/writtings/cathedral-bazaar where the lead of a project gets more credit than they actually do, but from my stand in that by using usenet and the unbiased date time stamped public accessable archives it is possible to insure credit is given to where it belongs, to those who openly help. In the movie "The Matrix" (wonderful collection of metaphors) Neo goes after Morpheus. Into a FEDERAL BUILDING... It's never been done before.... that's why it is going to work.... Usenet is that Federal Building Phil. Unbiased Date Time Stamped Public Recorder enabler built by the federal government. You want to contribute to this project and be assured you'll get credit for it? Simple, post you work! International copyright law states that the moment a work is published (Usenet counts) copyright law applies. The 14 years you mentioned Phil, it doesn't make me look bad Phil, it makes the computer industry look bad. How is it that such a collection and integrated configuration of common functionality not have been recognized and already done, unless the computer industry has gotten so detached from genuine science? (most everyone knows it got very detached) And what was it that cause it to become detached? Easy Money, all you have to do is be dishonest, as Bill Gates said, "make people need you". And you do that by not giving people the tools to allow them to do things for themselves, but rather have them rely on, or need, you to do it for them (for a price, as you have expressed here yourself.) I took electronics in High School (early 70's when ICs began to really filter into the market - But tube technology was still being taught) and I aced it. Late 70's I took a "Minicomputer and Microprocessor technology" course thru Capitol Radio Engineering Institute, where I aced thru as much of the course [2/3] as I completed in a summer (before this world wide top electronics corespondance school went belly up.) In 1990 I went back to school [Dekalb Tech] to learn C programming, mainly for this project. While working full time in a job that had nothing to do with computers or programming. I made Deans List twice and it would have been 3 times only that last term simply didn't have enough credit to qualify. I have a 4.0 in all computer electronic and programming courses I have ever taken. But there seems to always be something missing from the needed resources for me to do this project. Then it was the fact that I began to do it in Minix but really wanted to do it on the Amiga, where the Amiga already had a growing application, device, library list of things that had the third user interface built in, as standard (The Application side door port - or as I'm now calling it, the Automation Port Interface (API).) OK so I learned C on a PC with all it single tasking junk. But wanted to do the project on the multi-tasking Amiga, only that's a different beast to write for and there ain't no school classes, only hard to use RKMs (ROM Kernel Manuals) which I tried to use. I even tried to get a job in programming, figuring it would help me to get and keep my mind geared in the programmer mindset, only at that period of time we were dealing with a recession and jobs were far fewer and employers where far more selective knowing they could get greater experience and education for less money. Certainly I made nobodies potential employees list, even in consideration of grade and willingness to continue school. So I continued on working as cabinet maker and due to lack of work got back involved in the Tradeshow business of building booths. Not something that is supportive of the programmers mindset. At some point in time while working as a cabinet maker I set out to do some programming that would help the company generate drawings and cut list, etc.. In the process I found a freely available C library that could help me do this. In pursuing this library I found it had been sold and some of it was being converted to assembly while the rest of it was being rewritten and greatly improved and enhanced. I had the opportunity to buy it before it was released at good discount, so I did. The time went by and it wasn't released, more time and still not released.... two years later I had to insist the company send me a copy of the finally release version of what I had paid for, even though I could not use it due to the system requirement to run the library having changed to system upgrade I could not afford. Not to mention that the project died a year earlier due to failure to deliver by the company by set date. There are alot of people in this world Phil, Not everyone can be a programmer, or we'd all starve. But that doesn't mean that programmers have a right to abuse the rest of us, treat us like coppertops, in not doing their job to automate the things we need automated and most certainly can be, in order to allow us to do alot more. And that includes programming. Programmers and in some cases even robotics (controlled by programming) have taken jobs away from people. Sooooo What, people who lost their jobs found other ones. And in the software industry, programmers changing jobs is not uncommon. Sooooo What! that auto-coding would cause the elimination of jobs. In fact another kind of "autocoding" is going on by programmers that is resulting in the loss of jobs in the field of medicine. Medical Transcription is being replaced by autocoding that is created by programmers. It's time for psuedo Programmrs to get in line for losing their jobs. I'm not heartless, they will find other jobs (perhaps as automaters). Heartless is promising something that will help and empower others to do things for themselves but never really delivering. There is no obscene enough language to describe some of the deceptitive actions that go on in the computer industry, and we all know it's level of dishonesty is high, thanks to cases like MS vs. DOJ. There even exist public record of such statement as "sure we are greedy" by well known people in the computer industry. There is public recoder of a great deal of dishoinesty and deception in the computer industry. It's really long past the time for this childish sandbox greed to stop. There is more to this project than just the tool. The tool is really very small and simple to all that is possible to convert, build and create for and thru this tool. Consider a compiler, what good is it without all the support libraries, such as even .net and C# are small in themselves but limited without all the support stuff. But the difference here with the VIC is that it opens the door up, takes them off their hinges (blows the doors off the coders exclusive elitist elevator), and allows alot more people to become involved, like typical users even, or should I say the ones who need to and have a right to know and do for themselves. Phil, you think 14 years makes me look bad? But the truth is that you have a really messed up bad attitude and intent (even regardless of how much proof you have supplied to show that). What you should be seeing is that I've given the computer industry 14 years to correct their crap. You really should see and understand the last thing Neo Said in the Movie "The Matrix". . What good is it to the users/consumers if the industry holds control over what the users/consumers can and can't do for themselves? The VIC is a small tool, smaller than many shells. To have it put together out in the openness of the automatic credit giving machinery of Usenet, under the GPL side of the spectrum, with the help of those in the industry... Like I said before, there will never be enough programmers to do all the things the users of computers want to and need to have done. But there is the exact number of users of computers to do all the things the users of computers want to and need to have done. And to knock that psuedo pedistal out from under you Phil, you too, are a user of computers. You are NOT Excluded! How will I know that sandbox greed of the industry has come to it's end? How do you suppose I can help it come to an end? I've been telling people what you and those like you and follower of such, do not want the people to hear, and after a decade there is some good evidence I'm clearly being heard and even that people, the masses, are ready for the greedy of the computer industry to be looking for another job. So stop being manipulatingly greedy, Phil. There is plenty for everyone to do. 14 years ago I would have prefered to have been using the VIC to do the things I wanted to do and to have been doing so all these years. But that's just not the job I've been given in this matter, due to the greed of the computer software industry. If you want to be greedy Phil, to take that job away from me, then give me the tool under the conditions of which I want it. I am of the alpha and the omega, the great consumer, the first to consider, the last to receive. And as the Consumer, I am always right in having the right to become a producer. The Tool Phil, hand it over, all of it, including the genuine "we all are in this together" heart felt support. --- *3 S.E.A.S - Virtual Interaction Configuration (VIC) - VISION OF VISIONS!* *~ ~ ~ Advancing How we Perceive and Use the Tool of Computers!* Timothy Rue What's *DONE* in all we do? *AI PK OI IP OP SF IQ ID KE* Email @ mailto:timrue at mindspring.com >INPUT->(Processing)->OUTPUT>v Web @ http://www.mindspring.com/~timrue/ ^<--------<----9----<--------< From tdelaney at avaya.com Sun Feb 17 18:43:38 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Mon, 18 Feb 2002 10:43:38 +1100 Subject: Have to try Message-ID: From: Rick Hamilton [mailto:rhamilt at pacbell.net] > OK - I know I am going to get fried here but - > I am out of options. I'm a programmer (Java, > VB and C++) and am taking a class on Operating > systems. The nut teaching this course is asking > us to do a ton on programming in Python. OK - > So I am trying to do a (what should be) simple > thing. I have a string stored in a variable. I > want to search that string for the occurrence of > a sub string. I have tried > > Find(s,sub) > Rfind > MyString.find(sub) > > Nothing - I have not yet figured out the appropriate > way to treat a string and am heading for a very weak > book that we have as a reference. Anyone will to toss > a fellow programmer a helping had I'm willing to get > flamed to get this over with. Python Documentation http://www.python.org/doc/ and in particular, The Python Tutorial http://www.python.org/doc/current/tut/tut.html Tim Delaney From l0819m0v0smfm001 at sneakemail.com Sat Feb 9 20:42:33 2002 From: l0819m0v0smfm001 at sneakemail.com (Joshua Macy) Date: Sun, 10 Feb 2002 01:42:33 GMT Subject: Perhaps I am just dumb References: <8852d33c.0202090222.34be7da2@posting.google.com> <3C64F51A.2070208@sneakemail.com> <8852d33c.0202091432.452ad6f9@posting.google.com> Message-ID: <3C6596B6.20008@sneakemail.com> wooks wrote: >>One of the basic philosophies of Python design is that it is wrong for >>the language to guess when presented with something that's ambiguous. >> > > Which seems to be the opposite of the Perl philosophy - we will try to > do the right thing. > > >>That something is "automagical" is usually a swear word in Python. This >>can make Python seem hairier than other languages which cheerfully take >>a stab at what the designers think you may have wanted, but the Python >>belief is that those languages are leading you down the garden path, and >>sooner rather than later you'll be bitten by the subtlety that the other >>language tried to gloss over. >> >> > > Hmmm. The good thing about the Perl approch is that (if you read the > right resource) you get an explanation of the process via it tries to > do the right thing, which is very effective at getting the conceptual > message across. > Yeah, I came to Python from Perl, too, and I used to think that all that context sensitivity was the cat's pyjamas--but after the second two-day debugging session caused by Perl guessing wrong (or my guessing wrong about what Perl would guess), I wasn't so thrilled. I actually tried Python because I bought the O'Reilly book on Advanced Perl Programming, and in the author's intro he said really nice things about Python. I went out and looked at Python online, then bought Programming Python, and never looked back. The Perl book is still sitting unread on my shelf.... > > I was very specific. Is there a forum for the dumber less demanding > Python user? I got answers that I consider helpful. Thanks to you and > Sheila. > Well, glad to be of help. Joshua From core.lists.python at core-sdi.com Mon Feb 11 13:43:04 2002 From: core.lists.python at core-sdi.com (Mariano Corsunsky) Date: Mon, 11 Feb 2002 15:43:04 -0300 Subject: IPX Message-ID: <019701c1b32b$f0b676e0$8642a8c0@corelabs.coresdi.com> Hi there! Could anybody send me an example of a client/server pair of python scripts to do (client side) send "potato" (server side) You've said "potato" send "poteito" (server side) You've said "poteito" ...... but using IPX. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From mcherm at destiny.com Thu Feb 14 13:55:13 2002 From: mcherm at destiny.com (Michael Chermside) Date: Thu, 14 Feb 2002 13:55:13 -0500 Subject: preference tree like in jdk 1.4 Message-ID: <3C6C0811.2010900@destiny.com> > i was thinking of an empty function: > > def empty(): pass > > and then use it to build complex tree of preferences: > > pref = empty > pref.personalData = empty > pref.personalData.firstName = 'John' > pref.personalData.lastName = 'Cleese' > pref.windowSettings = empty > pref.windowSettings.windowA = empty > pref.windowSettings.windowA.x = 200 > # and so on... > > > to store or load this pref object, just use the pickle mechanism. > > my question is, is there a simpler, more beautiful, elegant way? Yes. Instead of using an empty function, use something designed specifically for holding fields: a class! >>> class Empty: pass >>> pref = Empty() >>> pref.personalData = Empty() >>> pref.personalData.firstName = 'John' >>> pref.personalData.lastName = 'Cleese' >>> pref.windowSettings = Empty() >>> pref.windowSettings.windowA = Empty() >>> pref.windowSettings.windowA.x = 200 -- Michael Chermside (Note: there may be fundamentally better solutions too; I just wanted to get away from mis-using functions.) From thomas at weholt.org Wed Feb 20 18:01:18 2002 From: thomas at weholt.org (Thomas Weholt) Date: Wed, 20 Feb 2002 23:01:18 GMT Subject: XML-RPC over HTTPS/SSL References: <8rKc8.4$5vh.135400448@news.telia.no> Message-ID: <2VVc8.7284$%m1.150721@news4.ulv.nextra.no> Ok, after a few hours of "hard" work I finally got it working, even supports gzipped xmlrpc-responses and basic user authentication. The code is available at http://home.online.no/~t-weh/releases/xmlrpcauth.py and is no more than a modified version of the post I found using google ( address below ). I didn't see the replies until now so I haven't had time to check those out yet. Probably learned something while hacking at the code so it wasn't a total waste of time ( hopefully ). Anyway, thanks for your replies. Best regards, Thomas Weholt "Thomas Weholt" wrote in message news:8rKc8.4$5vh.135400448 at news.telia.no... > I got a xmlrpc-server running using M2Crypto, making it encrypted with SSL. > I cannot get any xmlrpc-client to connect though, no matter what. > > Looked at resources found searching google, for instance > http://lists.zope.org/pipermail/zope/2001-May/089457.html. but with no luck. > Does anybody have any code showing how to connect a client to a > xml-rpc-server using SSL/HTTPS , preferrably with user authentication also? > ( to make it perfect, it would accept gzip-encoding to speed up transfers > :-) ) > > I'm using xmlrpclib from pythonware.com. > > I keep seeing stuff about SSL/HTTPS-support in standard python, but ... ?? > Do you compile the interpreter with OpenSSL etc ?? My clients and servers > will most probably run 60% on Linux and 40% windows, and re-compilation > isn't always feasable for windows-users. > > Any clues or hints appreciated > > Best regards, > Thomas Weholt > > From fperez528 at yahoo.com Fri Feb 22 15:11:43 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Fri, 22 Feb 2002 20:11:43 +0000 Subject: Request for comments: Search and replace script References: Message-ID: VanL wrote: > > >?please?try?to?keep?a?line?down?to?78?chars > > Fixed, at least for most of the code.??I?don't?know?how?to?deal?with > long strings, tho: > For example, self.writeLog('This is a very long line that has this %s > substitution and will go longer than 78 chars") > use self.writeLog('This is a very long line that has this %s' ' substitution and will go longer than 78 chars") contiguous strings are concatenated. or for really long stuff, use self.writeLog( """This is a very long line that has this %s This is a very long line that has this %sThis is a very long line that has this %sThis is a very long line that has this %sThis is a very long line that has this %sThis is a very long line that has this %sThis is a very long line that has this %s ' substitution and will go longer than 78 chars""" ) cheers, f From tim at vegeta.ath.cx Fri Feb 15 04:56:49 2002 From: tim at vegeta.ath.cx (Tim Hammerquist) Date: Fri, 15 Feb 2002 09:56:49 GMT Subject: Pythonistas? <- Re: OT: Perl programmers? References: Message-ID: Gustavo Cordova graced us by uttering: >> No es importante. Es importante que Ud. continue aprender. Puede >> aprender Espa?ol, Ingles, Japon?s, Perl, Python, o Ruby. > > "Es importante que continue APRENDIENDO." Lo siento. English's flexibility comes at the cost of simplicity. I intended "continue to learn", but I guess it's not an option. ;) > Have a nice Feb/14 :-) Thx. > Japon?s es muy interesante, me encant? la caligraf?a. La gram?tica de japon?s es muy interesante, tambi?n. Es muy f?cil, pero muy espresivo. La dif?cil es la escritura... > Espa?ol, ciertamente, es pr?cticamente predecible en cuanto a su > pronunciaci?n, eso lo hace agradable. Si. > Por otro lado, tiene chorromil reglas para su uso correcto, porque > Espa?ol correcto es una modalidad de escritura que pocos aprenden. Que me des unos ejemplos? Gracias, Tim Hammerquist -- It is better to give than to lend, and it costs about the same. From Norbert.Klamann at klamann-software.de Tue Feb 26 01:53:47 2002 From: Norbert.Klamann at klamann-software.de (Norbert Klamann) Date: 25 Feb 2002 22:53:47 -0800 Subject: Making breakpoints functional in IDLE on Windows References: <3C7AAA43.82FEC0D0@tds.net> Message-ID: <65c27c6b.0202252253.35174fe8@posting.google.com> "Edward K. Ream" wrote in message news:<3C7AAA43.82FEC0D0 at tds.net>... [description of history and fix snipped] > This works for me on Windows XP and Python 2.1. I'll let you know if > any > problems come up. > Thank you for the good work ! Works fine under Win NT 4 SP 6 too (not really surprising). Best regards Norbert Klamann From jwbaxter at spamcop.net Fri Feb 1 18:11:00 2002 From: jwbaxter at spamcop.net (John W. Baxter) Date: Fri, 01 Feb 2002 15:11:00 -0800 Subject: What is a "bus error"? References: <3C56448B.58833301@engcorp.com> Message-ID: <010220021511005074%jwbaxter@spamcop.net> In article , Kenny wrote: > However, some of these programs now give a "bus error" message - > what does this mean? cf: "What happens if Guido is hit by a bus?" (From early Python history.) --John (who only did this because you've gotten real answers already) From tismer at tismer.com Fri Feb 22 18:43:58 2002 From: tismer at tismer.com (Christian Tismer) Date: Sat, 23 Feb 2002 00:43:58 +0100 Subject: Stackless Platform Independence? References: Message-ID: <3C76D7BE.8080500@tismer.com> Grant Edwards wrote: > In article , Christopher Browne wrote: > >>Centuries ago, Nostradamus foresaw when Christian Tismer would write: >> >>>Dear Stackless Python Community, >>> >>>As you might have noticed, Stackless has changed quite >>>much: >>>- Platform independence is gone. >>> >>I hope not... I would hope to hear that "platform indepedence has >>_ARRIVED_" >> > > TANSTAAFL. IIUC, platform independance has been sacrificed to make the > other gains that were listed in the post. Feeling like being understood is sometimes much cheaper than taking a therapy because of not being understood. Currently, I' feeling very good, although taking the latter, anyway (last but not least since it's free). BTW., you're right, absolutely. There is no free lunch! sincerely - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Kaunstr. 26 : *Starship* http://starship.python.net/ 14163 Berlin : PGP key -> http://wwwkeys.pgp.net/ PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF where do you want to jump today? http://www.stackless.com/ From robin at jessikat.fsnet.co.uk Wed Feb 27 10:24:31 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Wed, 27 Feb 2002 15:24:31 +0000 Subject: PIL vs eps Message-ID: <6LZfFKAvoPf8EwHo@jessikat.fsnet.co.uk> I think this is a pure ghostscript problem, but PIL fails to convert eps to other formats and in fact it seems that gs won't create any output without a showpage at least somewhere. Can anyone confirm that my hunch is correct and what if anything is the best way to detect/correct this problem? -- Robin Becker From ramb at synopsys.com Mon Feb 25 13:16:13 2002 From: ramb at synopsys.com (Ram Bhamidipaty) Date: Mon, 25 Feb 2002 18:16:13 GMT Subject: Need Help: Can only set gdb breakpoints in python module the first time Message-ID: Python is embedded into my application. I have a custom module that is part of the application - it is not loaded as a shared library - rather the object files are incorporated into the final binary at link time. The problem I am having is that I can set breakpoints in my module only when gdb is first started. Once my app exits I am no longer able to set breakpoints on functions in my module. I suspect that python is somehow changing the mapping of the text segment, but that just a guess. My question: What is python doing that prevents gdb from setting breakpoints after the program exits the first time? How can I prevent this? Thanks for any info. -Ram From maxm at mxm.dk Mon Feb 25 16:40:01 2002 From: maxm at mxm.dk (Max M) Date: Mon, 25 Feb 2002 21:40:01 +0000 Subject: help: Problem with cgi form References: Message-ID: <3C7AAF31.8040201@mxm.dk> netvegetable wrote: > I have a hidden input on a cgi form... > > print '' > > I need the VALUE to be the variable "last_byte_pos", but unfortunately > when I run the script for the first time the script crashes because it's > undeclared. > > What subroutine do I use to check if last_byte_pos is undeclared, and > assign it a default value if it is? Somehow I have the feeling that you are asking in east and I am answering in west, but here goes :-) last_byte_pos = locals().get('last_byte_pos', 'defaultValue') But this is a stupid and redundant way to do it! Usually you just declare it in your program like: last_byte_pos = 'defaultValue' And then print it to the form like: print '' % last_byte_pos Btw. If you are trying to keep state (keeping the variables value via a form) it is a good idea to call it the same thing in the form as in your script. It is a lot easier to remember :-) like: print '' % last_byte_pos Then you can get the also get the variable again from the form via: import cgi form = cgi.FieldStorage() if form.has_key('last_byte_pos'): last_byte_pos = form['last_byte_pos'].value else: last_byte_pos = 'defaultValue' And this last snippet is probably what you meant all along. regards Max M From emile at fenx.com Thu Feb 28 10:19:51 2002 From: emile at fenx.com (Emile van Sebille) Date: Thu, 28 Feb 2002 07:19:51 -0800 Subject: writing efficiently a numpy array References: Message-ID: "Stephan" wrote in message news:fc905aec.0202280020.738f55db at posting.google.com... > > In what area are you looking to be more efficient? Memory, time, or > > something else? Do you need it in ascii form for another program, or > > are you saving it to be read back in? > > in Time !!! > > I need it in ascii file because this file will be the input file of > another program. The numpy arrays store fields of velocity, pressure, > saturation... The fields are computed on a mesh with about 300000 > nodes. Then another program read the fields and compute the migration > of several species. Take advantage of Numeric's output formatting, using: for ii in range(0,len(a),N): file.write(str(a[ii:ii+N])[1:-1]+"\n") HTH, -- Emile van Sebille emile at fenx.com --------- From Bill.Scherer at VerizonWireless.com Wed Feb 27 09:02:54 2002 From: Bill.Scherer at VerizonWireless.com (Scherer, Bill) Date: Wed, 27 Feb 2002 09:02:54 -0500 (EST) Subject: Rotor in Jython? Message-ID: Hello - I've a need to perform rotor decryption in Jython. A quick search didn't reveal anything to help. I've begun coding it in Python from rotormodule.c. My C knowledge is not strong, so there are spots that are surely not right. What I have now creates a 'rotor' object and performs a decryption without error, but the results are incorrect. I can make the code available. Any help is appreciated. Thanks! -- Bill.Scherer at Verizon Wireless RHCE 807101044903581 From mdk at mdk.com Wed Feb 6 09:23:32 2002 From: mdk at mdk.com (MDK) Date: Wed, 6 Feb 2002 09:23:32 -0500 Subject: Is there a Python module that already does this? References: Message-ID: "Chris Gonnerman" wrote in message news:mailman.1013003651.8981.python-list at python.org... > ----- Original Message ----- > From: "MDK" > > > > I need to convert a list into a list of characters. > > > > For example: > > > > ("cat",5,['dog',[3,3,1]],"zoo") > > That's not a "list", it's a tuple containing strings, ints, and lists; > further, you have nested lists. Ouch. > > > Would become: > > > > ('c','a','t',5,'d','o','g',3,3,1,'z','o','o') > > > > Any information would be appreciated. > > This is doable, but there is no Python builtin I am aware of that can > do it. Why do you need to do this? If we understand what you are trying > to do, we may be able to steer you away from this mess. > > P.S Sorry, I used the wrong symbols. I meant ["cat",5,['dog',[3,3,1]],"zoo"]. From rdsteph at earthlink.net Sun Feb 10 16:44:38 2002 From: rdsteph at earthlink.net (Ron Stephens) Date: Sun, 10 Feb 2002 21:44:38 GMT Subject: Linux and Python scripts, help needed References: <3C665762.550F7605@earthlink.net> <3C668B73.9E6F5BF8@earthlink.net> Message-ID: <3C66EAA6.23F9BA36@earthlink.net> Thanks i will try this ;-))) Chris Gonnerman wrote: > > ----- Original Message ----- > From: "Ron Stephens" > > > Hmmm, thanks for your comments. I just noticed that in my syslogs > > there was an attempt to open /etc/news/inn.conf that failed. So I > > just went in and chown 'ed that file to be owned by me rather than > > root. > > That's not the right solution; /etc/news/inn.conf should not be > writable by "world". You need to find out why/what tried to open it. > > > I don't know if that is part of the problem. But in general, I > > am finding that almost nothing I try to do with respect to running > > Python scripts using crontab works at first, simply because of all > > the permission stuff. So I change ownership and rights a lot. > > Bad sign. Your crontab runs with your user credentials, so anything > you can do, it can do. The problem here is usually environment > variables which are set differently. > > > But I didn't even know that /etc/news/inn.conf was needed, and maybe > > it isn't! > > Shouldn't be, if you aren't calling inn as an external program. > > > I wonder what else is needed but not owned or allowed by my > > user? How does one ever get any real work done when unknown > > permission and file ownership problems lurk under every hidden log > > ;-)))) > > In general anything that works at your command line can be made to > work in your crontab. Implement the logging as described in my > previous post and see what happens. From pricerbumanto at hotmail.com Tue Feb 12 17:36:00 2002 From: pricerbumanto at hotmail.com (George Partlow) Date: 12 Feb 2002 14:36:00 -0800 Subject: Pythonistas? <- Re: OT: Perl programmers? References: Message-ID: "Afonso Fernandez Nogueira" wrote in message news:... > Esperantists always use the -ist- suffix ("Esperantistoj") to refer to > themselves though. I've seen several webpages about Python written in > Esperanto, so I'm sure there has to be an established way to call > Pythonistas in this beautiful language. How established it is I don't know, but I did find (using Google) an occurence of "pitonisto" at . > > Cheers, > Fonso Korajn salutojn, Georgo From mark at codesourcery.com Sun Feb 17 21:18:23 2002 From: mark at codesourcery.com (Mark Mitchell) Date: Sun, 17 Feb 2002 18:18:23 -0800 Subject: Synchronous signals vs. robust code Message-ID: <28870000.1013998703@warlock.codesourcery.com> Python provides synchronous signals, even though signals are asynchronous events at the operating system level. In many ways, this is a Good Thing. For example, in C you can't do much of anything from within a signal handler since you don't know much about the current state of the application, but in Python you can do just about anything. In particular, you can throw an exception from a Python signal handler, which makes handling signals simple. In C, you generally have to set a flag from within the signal handler, and then poll the flag elsewhere; in Python you simply have the signal handler thrown an exception and then provide an appropriate exception handler. But, I'm having a hard time figuring out how to write signal-safe code in the presence of synchronous signals. Consider, for example, the following: pipe = os.pipe() try: # Do stuff with the pipe. finally: # Close the ends of the pipe. os.close(pipe[0]) os.close(pipe[1]) This code is supposed to make sure that the file descriptors are not leaked; when we exit this scope, the descriptors will be closed, even if an exception occurs. [Note that I am assuming that os.close will never thrown an exception when given a valid file descriptor. That's not strictly speaking true on some operating systems, but let's pretend that it is true. For the purposes of this discussion, the particular functions involved don't matter.] This code, however, is not signal-safe. For example, if a signal occurs between the two calls to os.close, we will end up not closing the second descriptor. The equivalent C++ code *would* be signal safe; an exception cannot be thrown from the signal-handler, so if the program is still executing we can be sure that both calls to os.close will occur. One solution, of course, is to make sure that the signal-handlers do not throw exceptions. But that's not a reasonable solution in library code; the library can't go around deciding what signal handlers should be doing. Another solution is to install an alternate signal handler around the entire try-block. This alternate signal handler would remember the signal; we could then regenerate it at the end of the try-block. This, however, is not very robust; what about multiple signals occurring? And if the signal that occurs is important, we're ignoring it until the end of the try-block, which isn't polite. Another solution would be to provide a module that provides access to sigprocmask. Then, one could explicitly block signals during parts of the code where these problems could occur. For example: pipe = os.pipe() try: # Do stuff with the pipe. finally: # Block signals. sigprocmask(...) # Close the ends of the pipe. os.close(pipe[0]) os.close(pipe[1]) # Unblock signals. sigprocmask(...) This does not work either; there are still at least two race conditions. A signal that arrives after we have entered the finally clause, but before we have called sigprocmask, would still result in a failure to close the descriptors. Similarly, a signal that occurs after the call to os.pipe, but before the try-block is entered would result in us skipping the finally clause. (And moving the try earlier is not valid; we can't clean up the descriptors unless we know that the pipe has been created.) Here is another try: # Block signals. sigprocmask(...) try: pipe = os.pipe() try: # Do stuff with the pipe. finally: # Close the ends of the pipe. os.close(pipe[0]) os.close(pipe[1]) finally: # Unblock signals. sigprocmask(...) This variant is robust; we are now guaranteed that if the pipe is created, the descriptors will be closed. However, it is still unsatisfactory in that it results in the signal being delayed for an arbitrary amount of time; if a time-critical signal happens during the try-block, we will not process it until much later. Another solution is to require that the code be run in a thread other than the main thread; since only the main thread receives signals, the signal-safety problem does not occur. However, it seems excessive to require threads simply to write signal-safe code! And if you have code that depends on, say, getting SIGPIPE, then you have to have some way of communicating the signal from the main thread to the thread running the code above. What do Python programmers that need to write truly robust code do about this problem? Is there a solution that I have missed? If not, would the Powers That Be be amenable to making changes to the language to support signal-safety? One possible fix would be except/finally clauses that blocks signals on entry. For example, if there were a finally_block_signals clause, you could do: # Block signals. sigprocmask(...) try: pipe = os.pipe() except: # Unblock signals. sigprocmask(...) # Reraise the exception. raise try: # Unblock signals. sigprocmask(...) # Do stuff with the pipe. finally_block_signals: # Close the pipe ends. os.close(pipe[0]) os.close(pipe[1]) # Unblock signals. sigprocmask(...) # There needs to be a way of getting the signal # mask on entry to the finally clause. This is not particularly pretty, but it would work. Thoughts? -- Mark Mitchell mark at codesourcery.com CodeSourcery, LLC http://www.codesourcery.com From picodello at yahoo.it Fri Feb 8 06:09:13 2002 From: picodello at yahoo.it (Piero) Date: 8 Feb 2002 03:09:13 -0800 Subject: Problems using calldll library Message-ID: <84323230.0202080309.382bf7f4@posting.google.com> I need to interface with a windows DLL that is declared in C like: getword(&ncard,&nb,&adr,tabl,&status) where the type of parameters are : ncard=16-bit integer nb=16-bit integer adr=32-bit integer tabl= array of 16-bit integer status=16-bit integer where ncard,nb,addr are input parameters and tabl,status are output parameters I try to implement this function, but don't work. I suppose the problem is in the input parameters format. Something can help me ? def getword(self,ncard,nb,adr,tabl): getword =calldll.get_proc_address(self.applicomdll,"getword") p = calldll.membuf(4) px = p.address() pncard = calldll.membuf(2) pncard.write(str(ncard)) pxcard = pncard.address() pnb = calldll.membuf(2) pnb.write(str(nb)) pxnb = pnb.address() padr = calldll.membuf(4) padr.write(str(adr)) pxadr = padr.address() tabll = calldll.membuf(2) ptabll = tabll.address() ret= calldll.call_foreign_function (getword, 'iilii', 'l', (pxcard,pxnb,pxadr,ptabll,px)) res = p.read(0, 2) print struct.unpack('bb', res)[0] ress = tabll.read(0, 2) print struct.unpack('bb', ress)[0] Thank you in advance Piero From usenet at thinkspot.net Sat Feb 23 15:40:52 2002 From: usenet at thinkspot.net (Sheila King) Date: Sat, 23 Feb 2002 12:40:52 -0800 Subject: string substitutions References: Message-ID: [posted and mailed] On 23 Feb 2002 11:52:10 -0800, bobnotbob at byu.edu (Bob Roberts) wrote in comp.lang.python in article : > What would be a good way to replace every one or more spaces (" ") in > a string with just one space? Or replace any number of newlines with > just one? This function, which I'm currently using in an email filter, replaces all '\n' characters with a space, and then replaces all occurrences of more than one space with a single space. def remove_new_lines(searchstring): """ Returns a string without newlines or double spaces. """ newline = '\n' # Replace newlines with spaces newstring = searchstring.replace(newline, ' ') # Replace multiple spaces with single spaces while newstring.find(' ') > -1: newstring = newstring.replace(' ', ' ') return newstring You could also do this with regular expressions, but this method only requires regular string operations. -- Sheila King http://www.thinkspot.net/sheila/ "When introducing your puppy to an adult cat, restrain the puppy, not the cat." -- Gwen Bailey, _The Perfect Puppy: How to Raise a Well-behaved Dog_ From thomas.heller at ion-tof.com Thu Feb 7 15:50:09 2002 From: thomas.heller at ion-tof.com (Thomas Heller) Date: Thu, 7 Feb 2002 21:50:09 +0100 Subject: __class__ for 2.2 types References: <2ec1bc1c.0202071240.44185531@posting.google.com> Message-ID: "Larry" wrote in message news:2ec1bc1c.0202071240.44185531 at posting.google.com... > hi, rookie here, I was hoping someone could explain to me why this happens: > > Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> [].__class__ > > >>> int.__class__ > > > why doesn't the int one return ? int is the *type* of an integer, not an integer itself. See: >>> list.__class__ >>> 2.__class__ File "", line 1 2.__class__ ^ SyntaxError: invalid syntax >>> 2 . __class__ >>> Thomas From martin at v.loewis.de Mon Feb 11 16:58:39 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 11 Feb 2002 22:58:39 +0100 Subject: Is it possible to call a function from a Tkinter widget.bind and include args??? References: Message-ID: "G. Willoughby" writes: > Is it possible to call a function from a Tkinter widget.bind and include > args??? > i.e. i want to do something like this: > > def printButtonAndCoords(event, button): > print "you rolled over %s and coords are %d:%d" % button, event.x, > eventy > > Button1.bind("", printButtonAndCoords("button1")) > Button2.bind("", printButtonAndCoords("button2")) > > is this possible??? The common idiom is Button1.bind("", lambda ev:printButtonAndCoords(ev,"button1")) Button2.bind("", lambda ev:printButtonAndCoords(ev,"button2")) Notice that event.widget will give you the widget that was the source of the event, so you may not need additional parameters at all. Regards, Martin From dalke at dalkescientific.com Sat Feb 16 17:46:10 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Sat, 16 Feb 2002 15:46:10 -0700 Subject: Why Python is like BASIC (and why this is a good thing) References: Message-ID: Dan Bishop: >Everyone should learn BASIC. It's the perfect example of how *not* to >design a programming language :-) Errm, I've used plenty of worse programming languages. Most of the sort of embedded command languages which jest grew. By comparison, BASIC is clean and elegant. But then again, I spent almost a decade programming in BASIC in its various incarnations, so my brain's probably rotted away :) Andrew dalke at dalkescientific.com From emile at fenx.com Thu Feb 21 19:39:09 2002 From: emile at fenx.com (Emile van Sebille) Date: Thu, 21 Feb 2002 16:39:09 -0800 Subject: strings and sort() References: Message-ID: "Delaney, Timothy" replies to: > > I like Python, but the biggest problem I have with the language right > > now is what low code density it has at times. > > Huh? Low code density? Huh? > See the thread on lambdas ;-) Feeling-low-and-dense-ly y'rs, -- Emile van Sebille emile at fenx.com --------- From db3l at fitlinxx.com Fri Feb 1 20:32:22 2002 From: db3l at fitlinxx.com (David Bolen) Date: 01 Feb 2002 20:32:22 -0500 Subject: comparing DateTime instances References: Message-ID: "Mark McEahern" writes: > The documentation for mx.DateTime's cmp seems to assume the reader > understands __cmp__. This is all we find there: > > "cmp(obj1,obj2,accuracy=0.0) > Compares two DateTime[Delta] objects. > If accuracy is given, then equality will result in case the absolute > difference between the two values is less than or equal to accuracy." I think the documentation more assumes that the reader is familiar with the builtin cmp() function (and not necessarily the __cmp__ method, although the former is really just direct access to the latter), which seems fairly reasonable to me. And the documentation for cmp() does detail the <0, 0, >0 result code of the function. But adding some qualification (even if only to note it mirrors cmp()) certainly doesn't seem a bad thing. -- -- David -- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/ From printers at sendme.cz Sat Feb 23 05:21:02 2002 From: printers at sendme.cz (A) Date: Sat, 23 Feb 2002 11:21:02 +0100 Subject: Is it possible in Python too? Message-ID: <3C777B1E.12123.87FDB7@localhost> Hi, Is possible to set up a proxy name (address) in MS Explorer browser from a running Python program? Thank you for your help. Ladislav From msoulier at nortelnetworks.com_.nospam Wed Feb 27 13:34:23 2002 From: msoulier at nortelnetworks.com_.nospam (Michael P. Soulier) Date: 27 Feb 2002 18:34:23 GMT Subject: full closures Message-ID: Hello. While I know about bound methods in Python, I'm wondering if a full closure can be implemented. Can it? Example: I want to pass an arbitrary code reference into a closure and have all of its variables preserved. ie. print "the current count is %d" % counter; counter += 1 Can I pass the above code into a closure, and then simply call it repeatedly and see counter increment itself? If I pass in a function with a local variable, that local will be reset each time, and I don't want to use a global. Thanks, Mike -- Michael P. Soulier, QX41, SKY Tel: 613-765-4699 (ESN: 39-54699) Optical Networks, Nortel Networks, SDE Pegasus "...the word HACK is used as a verb to indicate a massive amount of nerd-like effort." -Harley Hahn, A Student's Guide to Unix From robin at jessikat.fsnet.co.uk Sun Feb 3 19:56:26 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Mon, 4 Feb 2002 00:56:26 +0000 Subject: Autocoding - the resistance to expect from psuedo programmers References: <922.799T2387T11875593threeseas@earthlink.net> Message-ID: In article <922.799T2387T11875593threeseas at earthlink.net>, Timothy Rue writes >In reviewing over many messages in the autocoding and related threads and >seeing the evidence of contridictions, hypocracy, irrational and >illogical responses...... > >Its damn clear that there is a need to remove the sort of people posing to >be professional who are in essence just good liars, abstraction >manipulators, from the industry. > >Who knows, maybe that stench will be enough to motivate me see that it >gets done, gets removed. > >Maybe I should be more appriciative of the stench if it so motivates me. > >Anyone want to add anything to this? > all your ideas are belong to you -- Robin Becker From sab at NOSPAM.freeuk.com Tue Feb 5 10:56:57 2002 From: sab at NOSPAM.freeuk.com (G. Willoughby) Date: Tue, 5 Feb 2002 15:56:57 -0000 Subject: Amount of files on a drive? References: Message-ID: i am using this at the minute: ------------------------------------------------------------------ import win32api import string import os def countFiles(arg, dir, files): for file in files: count=count+1 fileListings=[] driveList=string.split(win32api.GetLogicalDriveStrings(),'\0')[:-1] for drive in driveList: os.path.walk(drive, countFiles, 0) ------------------------------------------------------------------ but its pretty slow any other suggestion how i could speed it up?? G. Willoughby "G. Willoughby" wrote in message news:a3m9d3$mr4$1 at newsg2.svr.pol.co.uk... > Is there a fast an easy way to get the number of files on a drive?? > ta, > G. Willoughby > > From skip at pobox.com Fri Feb 8 13:45:03 2002 From: skip at pobox.com (Skip Montanaro) Date: Fri, 8 Feb 2002 12:45:03 -0600 Subject: What's the equivalent in Python for Perl's CPAN? In-Reply-To: References: Message-ID: <15460.7343.35758.3998@12-248-41-177.client.attbi.com> Mike> So, what's the equivalent in Python for Perl's CPAN? People are working on stuff. Search the list archives for Ciphon. There was a lightning talk presented yesterday about a server called Gideon that's supposed to serve up package metadata to tools like Ciphon I think. -- Skip Montanaro (skip at pobox.com - http://www.mojam.com/) From m.faassen at vet.uu.nl Fri Feb 8 19:00:20 2002 From: m.faassen at vet.uu.nl (Martijn Faassen) Date: 9 Feb 2002 00:00:20 GMT Subject: Please stop responding to Rue References: <3c62a989.3448437947@news> Message-ID: Cliff Wells wrote: > On 8 Feb 2002 22:32:47 GMT > Martijn Faassen wrote: >> Cliff Wells wrote: >> > Arguing with irrational oddballs on usenet is today's equivalent of the >> > Rubik's Cube. >> >> I never managed to solve those either. Is it still equivalent for those > who >> do mananage to solve the cube? > I'm guessing Rue could solve it, if that answers your question ;) I've now lost track of who is the irrational oddball and who they're arguing with. The only thing I still know is that it's happening on usenet -- couldn't be anywhere else. :) Regards, Martijn -- History of the 20th Century: WW1, WW2, WW3? No, WWW -- Could we be going in the right direction? From martin at v.loewis.de Wed Feb 20 17:33:57 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 20 Feb 2002 23:33:57 +0100 Subject: Large integers from C References: <20020220.163039.1504569917.30753@ic.ac.uk> Message-ID: "Phil Mayers" writes: > Any ideas? You could try _PyLong_FromByteArray. It is not official API, but it may still work. Regards, Martin From core.lists.python at core-sdi.com Thu Feb 7 12:56:31 2002 From: core.lists.python at core-sdi.com (Mariano Corsunsky) Date: Thu, 7 Feb 2002 14:56:31 -0300 Subject: Fine Tkinter Question Message-ID: <008401c1b000$c65803b0$8642a8c0@corelabs.coresdi.com> Hi there! I have a Tkinter window which opens a 2nd one in which I want to close it when you hit the <"Return"> key upon the "Close" button. But..... isn't working. Let's see the code: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> from Tkinter import * def show_child (): win=Toplevel() win.focus_set() win.grab_set() Quitter=Button(win,text="Close Me",command=win.destroy) Quitter.pack() Quitter.focus_set() win.bind("",lambda event,myself=win:myself.destroy) root=Tk() Button (root,text="Show",command=show_child).pack() root.mainloop() <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Do you know why this is not working? And do you know what is the elegantly simple way to make it work? I know the problem is in the " win.bind("",lambda event,myself=win:myself.destroy)" line, but I don't know how to make it right. Help me for free ! Tnxs! -------------- next part -------------- An HTML attachment was scrubbed... URL: From nospam at bigfoot.com Tue Feb 5 13:01:26 2002 From: nospam at bigfoot.com (Gillou) Date: Tue, 5 Feb 2002 19:01:26 +0100 Subject: REQ : encoding windows cp1252 => iso latin 1 Message-ID: Hi, This is an emergency ;-) My customers make copy/paste from M$ word docs to forms translated to XML (expecting ISO latin 1 charset). My XML parser (pyexpat) does not accept cp1252 character, and I'm looking for a function that can translate extra cp1252 characters to the closest ISO latin 1 encoding. Thanks in advance for any help. --Gillou PS1: I can't use Unicode facilities cause I'm always running python 1.5.2 (old Zope). PS2: Please reply to glenfant_at_bigfoot.com, the "Freo/Reply-to" headers are antispam. From eppstein at ics.uci.edu Thu Feb 28 20:24:40 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Thu, 28 Feb 2002 17:24:40 -0800 Subject: Status of PEP's? References: Message-ID: In article , James_Althoff at i2.com wrote: > Another issue that I have is that the syntax does not work outside of a > for-loop header. I want to be able to create integer intervals anywhere in > my code, not just in the header of a for-loop. [x for 3 <= x < 10] or, for a slightly more complicated example: yesterday I wanted to iterate over powers of two: [1L << x for 0 <= x < 1000] -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From phd at phd.pp.ru Sun Feb 3 05:55:38 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Sun, 3 Feb 2002 13:55:38 +0300 Subject: curses module In-Reply-To: ; from rhymes@myself.com on Sun, Feb 03, 2002 at 11:11:44AM +0100 References: <953o5u077ruthfqmljnauej8m4v8432qiu@4ax.com> Message-ID: <20020203135538.A12784@phd.pp.ru> On Sun, Feb 03, 2002 at 11:11:44AM +0100, Lawrence Oluyede wrote: > You're right, i use Win2k and the binary distribution.. M$ Ophice GUI is not supposed to run text-mode progrms (though some good guys don't beleive in it and produced pdcurses :) Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From tim_one at email.msn.com Sun Feb 3 17:51:26 2002 From: tim_one at email.msn.com (Tim Peters) Date: Sun, 3 Feb 2002 17:51:26 -0500 Subject: Guido's intuition (was Re: typetesting, adaptation, typeclasses, ...) In-Reply-To: Message-ID: [Tim] > Oddly enough, the more intelligent of us [Python developers] agree with > him [Guido], but nobody can explain why . [Mark Hadfield] > Who *are* the more intelligent of you? Those of us who agree with Guido, of course. leaving-it-a-secret-whether-i-agree-with-him-ly y'rs - tim From wurmy at earthlink.net Mon Feb 25 15:06:19 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Mon, 25 Feb 2002 20:06:19 GMT Subject: All-on, all-off button for checkbuttons? References: Message-ID: <3C7A9975.8D7299BA@earthlink.net> Nick Arnett wrote: > > I'm just bringing myself up to speed with Python, so forgive what I think is > an simple question. I'm building a UI that has a bunch of checkbuttons, > which also includes buttons to turn all the checkbuttons on or off. I see > how to turn them off individually, but it seems to me that there must be a > more elegant way. > > The checkbuttons are created in __init__. I'm thinking that there must be a > way to filter or iterate through the objects in __init__, and for each one, > if it's a button, select or deselect as appropriate. I see how to get the > namespace as a dictionary, but that hasn't helped. Without knowing what GUI (e.g. Tkinter, wxPython, Qt, etc) you are using, I can only give you an example in pseudo-Python... In __init__, keep a list of checkbox instances around: c1 = CheckBox(...) c2 = CheckBox(...) c3 = CheckBox(...) self.checkboxes = [c1, c2, c3] Then, when you want to do something with all these checkboxes, simply loop over the list: for checkbox in self.checkboxes: checkbox.checked = false Again, this is pseudo-Python, the names and method in your program will look different. But you'll get the idea. Depending on the GUI you're using, there should probably be a way to find all objects on a form/frame, and loop over them. That would be another way to do it. HTH, -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From gbreed at cix.compulink.co.uk Tue Feb 26 11:35:08 2002 From: gbreed at cix.compulink.co.uk (gbreed at cix.compulink.co.uk) Date: Tue, 26 Feb 2002 16:35:08 +0000 (UTC) Subject: Python COM -- What is the name of the file? References: Message-ID: Mike Brenner wrote: > Does anybody know how to get the name of the file an Excel Spreadsheet > is in? > > For example, to do a file-save-as in tab-delimited format, > it is necessary to change "C:\data\stuff.xls" > to "C:\data\stuff.txt", but I don't know where to > get the "C:\data\stuff.xls" from in any given spreadsheet. Do you have the "Microsoft Excel Visual Basic Reference" installed? It should be in your help topics list. If not, it's an option when you install Office, and it's what you need to answer questions like this. Anyway, for an object called xl, it looks like these are what you want: >>> xl.Workbooks[0].Path u'C:\\Documents and Settings\\grahamb\\My Documents' >>> xl.Workbooks[0].Name u'Book1.xls' >>> xl.Workbooks[0].FullName u'C:\\Documents and Settings\\grahamb\\My Documents\\Book1.xls' > It would even be okay, if I could just get the name "stuff" from some > part of the COM object. > > (And, of course, hopefully the same technique will work in Microsoft > Project, etc.) I think "Workbooks" is Excel specific. Graham From cliechti at gmx.net Thu Feb 7 16:33:32 2002 From: cliechti at gmx.net (Chris Liechti) Date: 7 Feb 2002 22:33:32 +0100 Subject: Serial port Input/Output conflicts References: Message-ID: [posted and mailed] jwk at mrao.cam.ac.uk (James Keen) wrote in news:ef77152a.0202070729.3a6a5d2a at posting.google.com: ... > The status data gets sent to the port from my Hardware, which I can > read, but the serial port refuses to send any more commands to my > hardware until I close and then reopen the port. > > serial = os.open('/dev/ttyS1', FCNTL.O_RDWR|os.O_NDELAY,0) not much of an initialization... your port could be in processing mode where it interprets control characters, flow controls etc... this initialization is not likely to work with binary data. http://sourceforge.net/project/showfiles.php?group_id=42303 &release_id=67594 (the url above should be one line, here's the project page: http://mspgcc.sourceforge.net/) download pybsl, extract serial* and use the serial.Serial class. i have trimmed it to work with binary data. ... > global serial codesidered writing a class that represents you hardware? would be cleaner that juggling around globals. chris -- Chris From nhodgson at bigpond.net.au Tue Feb 19 18:06:27 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Tue, 19 Feb 2002 23:06:27 GMT Subject: Adding static typing to Python References: Message-ID: Courageous: > Speaking of typedef and the C/C++ languages, I've long thought > that in a statically-typed language, the types should never be > aliased, and should always be distinct. For example, the following > shouldn't compile: > > typedef float F1; > typedef float F2; > ... Some program checkers such as PC-Lint can check for inconsistent use of typedefed types. It is not as good as having the compiler check, but it can be integrated into a build or check in system to ensure a greater degree of type-safety than standard C/C++. http://www.pclint.com/html/strong.htm Neil From dalke at dalkescientific.com Thu Feb 14 17:58:22 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Thu, 14 Feb 2002 15:58:22 -0700 Subject: '/' not allowed in cookie name? References: Message-ID: Oliver Rutherfurd: > I'm ... receiving a cookie.CookieError when a server I am > connecting to sends me a cookie with '/' in the name. ... > After spending a little time reading http://www.faqs.org/rfcs/rfc2109.html > I am still not any closer to understanding whether '/' is a legal value > that the cookie module should accept in a name, or whether the server > is misbehaving. That RFC defines the format for the cookie syntax, in 4.1 av-pairs = av-pair *(";" av-pair) av-pair = attr ["=" value] ; optional value attr = token value = word word = token | quoted-string The "attr" is the name (before the "="), which you want to be 1/2. The specification for token is defined in RFC 2068 as token = 1* where tspecials = "(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\" | <"> | "/" | "[" | "]" | "?" | "=" | "{" | "}" | SP | HT So token cannot contain "/", which means "1/2" is not a valid cookie name. As to if some clients and servers let you use illegal cookie names ... that's a different thing. Andrew dalke at dalkescientific.com From xeno at eskimo.com Sun Feb 17 14:28:26 2002 From: xeno at eskimo.com (Xeno Campanoli) Date: 17 Feb 2002 19:28:26 GMT Subject: chomp equivalents Message-ID: Is there a chomp equivalent in the "string" object? rstrip doesn't seem to take off the newline. Also, I looked up chomp on the Python website search engine, and it said there is a chomp. Am I reading this wrong? I don't show any chomp procedure in my python environment. From stuartn at froggy.com.au Tue Feb 26 23:08:45 2002 From: stuartn at froggy.com.au (Stuart Nettleton) Date: Wed, 27 Feb 2002 15:08:45 +1100 Subject: Topo-Processor Module Message-ID: <004401c1bf44$74414340$560114ac@flow.com.au> Hello, I am looking for an efficient module that applies a list of equation definitions to a database table, where each row in the table represents a variable and fields are assumed to be forward time sequential (i.e. like a financial model in Excel). Does anyone know of such a module? Kind regards, Stuart BTW I wrote a topological processor in Microsoft Access VB but it is very slow! -------------- next part -------------- An HTML attachment was scrubbed... URL: From gerson.kurz at t-online.de Sun Feb 10 03:18:19 2002 From: gerson.kurz at t-online.de (Gerson Kurz) Date: Sun, 10 Feb 2002 08:18:19 GMT Subject: [ANN] pydocgen 0.1 - a windows alternative to pydoc Message-ID: <3c662b40.10617421@news.t-online.de> pydocgen.py generates a HTMLHelp file from the docstrings of the python standard library, offering full-text search and a nice index. As such, it is an alternative to pydoc, which seems to me to be broken (at least on my python22 system it fails when asked to scan all files in /lib recursively.) Note that pydocgen also has problems with some files in the PSL - they simply cannot be imported standalone. Some might also find the "htmlhelpgen.py" source helpful, for generating HTMLHelp files from a python program. "htmlhelptest.py" shows you how to use those classes from your own code. Project Homepage (very little on it right now): http://p-nand-q.com/pydocgen.htm Sourcecode: http://p-nand-q.com/python/pydocgen.zip Helpfile (Warning, 2mb download): http://p-nand-q.com/python/python22.zip From imbaczek at poczta.fm Fri Feb 15 14:46:45 2002 From: imbaczek at poczta.fm (Marek Baczek =?iso-8859-2?Q?Baczy=F1ski?=) Date: Fri, 15 Feb 2002 19:46:45 +0000 (UTC) Subject: Pythonistas? <- Re: OT: Perl programmers? References: Message-ID: Tim Hammerquist wyprodukowa?[ao]?: > OTOH, exceptions in Spanish are much less frequent than in English or > French. Pronunciation is nearly 100% predictable, and there are more > regular verbs than most languages. > > (I have no knowledge of German.) Take a latin alphabet. Take a lot of exceptions. Throw in some weird letters. Take some English words. Change a lot of spelling. Mix in some more spooky letters. Make rules. Make exceptions to these rules. Make even more exceptions. Shuffle. The resulting language will be German :) (I have very little knowledge of German and some of English :) Baczek -- Marek Baczy?ski aka Baczek UIN:57114871 RLU:201791 http://republika.pl/imbaczek There is no pardon FOR Murphy's Law. From gerson.kurz at t-online.de Sat Feb 2 23:08:49 2002 From: gerson.kurz at t-online.de (Gerson Kurz) Date: Sun, 03 Feb 2002 04:08:49 GMT Subject: print statement in lambda expression References: Message-ID: <3c5cb680.312156@news.t-online.de> On Sun, 03 Feb 2002 03:14:53 GMT, "Michael P. Soulier" wrote: > Hello people. > > I just recently found that I couldn't put a print statement in a lambda >expression as a binding in Tk. Could someone explain why? The reason was explained already by other people, here is a hack that makes it work nonetheless: use sys.stdout.write; e.g. import sys lambda x,y: return sys.stdout.write("...") if you need multiple args, make a varargs output function: def out(*x): print " ".join(map(str,x)) f = lambda x,y: out(x,y) f("Hello", 42) From philh at comuno.freeserve.co.uk Thu Feb 7 18:14:33 2002 From: philh at comuno.freeserve.co.uk (phil hunt) Date: Thu, 7 Feb 2002 23:14:33 +0000 Subject: Autocoding evolves from........ References: <972.799T919T11694325threeseas@earthlink.net> <3943.801T1063T14354065threeseas@earthlink.net> <3C616C5A.4D1BBE1C@ccvcorp.com> <2300.802T2206T14055804threeseas@earthlink.net> <3C62190A.A54E9A57@engcorp.com> Message-ID: On 7 Feb 2002 17:23:38 GMT, ameoba wrote: >"Chris Gonnerman" wrote in >news:mailman.1013090595.10717.python-list at python.org: > > >> How the heck to you "enjoy" an idiot like Rue though? > > >With a light chianti? But, grilled or roasted? -- ===== Philip Hunt ===== philh at comuno.freeserve.co.uk ===== Herbivore, a zero-effort email encryption system. Details at: From fperez528 at yahoo.com Fri Feb 22 15:14:09 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Fri, 22 Feb 2002 20:14:09 +0000 Subject: Request for comments: Search and replace script References: Message-ID: VanL wrote: > Sort?of?a?poor?man's?'more'?for?when?this?is?run?on?a?windows?system. > you can take this #---------------------------------------------------------------------------- def page_dumb(strng,start=0,screen_lines=25): """Very dumb 'pager' in Python, for when nothing else works. Only moves forward, same interface as page(), except for pager_cmd and mode.""" ncols = 80 out_ln = strng.splitlines()[start:] out = [] for ln in out_ln: if len(ln) <= ncols: out.append(ln) else: out.extend(chop(ln,ncols)) screens = chop(out,screen_lines-1) #print '\nscreens is:',screens,os.linesep # dbg if len(screens) == 1: print os.linesep.join(screens[0]) else: for scr in screens[0:-1]: print os.linesep.join(scr) ans = raw_input('---Return to continue, q to quit--- ') if ans.lower().startswith('q'): return print os.linesep.join(screens[-1]) If you want its bigger brother, page() (multi-os, with solid fallbacks) go to http://www-hep.colorado.edu/~fperez/ipython/ page() and family are in the genutils.py module (plus lots of other useful stuff). It's LGPL, so feel free to use it. cheers, f. From brown.2053 at osu.edu Tue Feb 26 16:21:20 2002 From: brown.2053 at osu.edu (Locke) Date: Tue, 26 Feb 2002 16:21:20 -0500 Subject: size of socket.recv buffer References: Message-ID: ok, i figured out what i had to do. instead of 'message = s.recv(msg_len)' i did: while len(message) < msg_len: message = message + s.recv(1024) and that seems to work every time. yippee! thanks for help everyone From john_coppola_r_s at yahoo.com Sun Feb 17 22:34:18 2002 From: john_coppola_r_s at yahoo.com (john coppola) Date: Sun, 17 Feb 2002 19:34:18 -0800 (PST) Subject: Why Python is like BASIC ... java "vs" python In-Reply-To: Message-ID: <20020218033418.46493.qmail@web11808.mail.yahoo.com> For all the people following this thread. I think the main point I was trying to make (although rather abstract) is that I think differently depending on which language I am using. If I am using BASIC I don't think like python. If your are, your not using basic correctly. You must use basic like BASIC. And not try to do anything more complicated than basic can describe in a clear way, otherwise you begin to use the language outside the bounds of which it was intended. For instance, it's not very efficient to write xml parsers in pure python. Is this making sense? When I program in C++, I'm not thinking like java. C++ is far more low level and requires more detail. C and C++ are efficiency languages. Good programming practices in C although could be useful in C++, but largely are not since structs and functions have been supplanted by real Object Orientation (well almost real). When I program in C i'm not thinking like C++. Believe it or not, when I program in Jython, I don't think like Python. WHY? When you do advanced programming, you will see the differences. So on basis of that, I feel very strongly that although there are similarities, I seldom consider "print XYZ" to be thinking. When one tackles advanced problems, you see the differences in languages, you see why they are useful, and you see why they are not, and these differences for me out weigh the similarities. Sincerely, John Coppola __________________________________________________ Do You Yahoo!? Yahoo! Sports - Coverage of the 2002 Olympic Games http://sports.yahoo.com From stojek at part-gmbh.de Fri Feb 15 08:53:35 2002 From: stojek at part-gmbh.de (Marcus Stojek) Date: Fri, 15 Feb 2002 13:53:35 GMT Subject: help!: optimization of search problem (example code) References: Message-ID: <3c6d12ba.4348562@news.easynews.net> > > >In Python, access to local variables in functions >is faster than access to global variables. Thanks, I didn't know that. Marcus From sholden at holdenweb.com Mon Feb 4 18:47:57 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 4 Feb 2002 18:47:57 -0500 Subject: Backwards Compatibility of Python versions References: <7x8za8dgle.fsf@ruckus.brouhaha.com> Message-ID: "Paul Rubin" wrote in message news:7x8za8dgle.fsf at ruckus.brouhaha.com... > "Tim Peters" writes: [Paul misunderstands the bugfix process, and wants to produce 1.5.3 and 1.2.1] [2.1.1 / 2.1.2 confusion] > > > If you have messier problems, and you're determined to write code that works > > unchanged back through the first Python ever released, then sure -- slicing > > divmod is clear and works. ... > > No. I'm taking a practical view of this. I use HTML tables in my > webpages even though there's still a few ancient browsers out there > that don't display them. But if 25% of browsers didn't support them, > I'd avoid using them when I didn't need them. I do avoid making my > pages depend on Javascript, for basically that reason. > "When I didn't need them": surely "must run in old browsers" is not a partial requirement. Do you really specify your output format as "must remain compatible with Netscape Navigator 2.0 unless it's really important not to". No wonder you have problems with the meaning of "backward compatibility" <0.9 wink>. > I see publishing Python programs as like publishing web pages. If I > have to tell 2% of my users to upgrade those ridiculous old browsers > to view my pages, I don't mind. If I have to tell 25% of them to > upgrade, I'm causing hassles for a significant population and I > shouldn't do that without a good reason. If I have to tell 80% of > them to upgrade, I'm probably going to lose a lot of them. > > The question is, what percentage of users are using what Python version? > Well, if you want to take a count, add me in to the user population of 1.5.2, 2.0, 2.1.2 and 2.2. And I think there are a few beta copies lying around from pre-2.2. > I bet less than 10% of users have 2.2 right now. I'm curious about > the ratio of 2.1 users to 1.5.2 users. Do you have any idea what it > is? I don't know how I'd measure it. There's no User-agent header > collected at python.org every time someone runs a Python script. > > I go back and forth about whether to code for 1.5.2. I do like 2.1 > features like +=, and I noticed last night that the "continue" > statement works differently. If I had reason to believe that less > than (say) 25% of today's installations are 1.5.2, then I wouldn't > bother with 1.5.2; but I think the percentage may be higher than that. Well, the major problem for most would-be Python software authors right now is that Red Hat are still shipping 1.5.2 without any real attempt to conceal it from a user wanting to install some later version from the RPMs. Building their system so it's hard to upgrade Python without breaking Anaconda was dumb. Defensible, but dumb. And I think it hurts Python more than the benefit of being able to say "Red Hat built Python into their system maintenance software." I appreciate you are keen to distribute "nifty Python programs". If so, you might just have to accept the bloat of building installer versions, untilt someone comes up with a way for installers to determine whether Python is currently available in an appropriate version or not. These engineering issues are what will stand in the way of Python's increasing popularity, which is why I prefer to address them when I see them raised rather than ignore them. If you insist that Python isn't backwards compatible, I have to think what you must think about VB.NET, where they really *have* broken backward compatibility, and in a bug way. Unless VB application authors are really careful (and many VB programmers aren't familiar with the concept of software engineering) we're going to see some really badly broken applications there. By comparison, Python is a hotbed of sanity. So start working on 1.5.3 right now. If you ever produce it I'd like to think it would get a prominent placed on the website. But remember: with very minor exceptions, the rule for bugfix releases is "no new functionality", so don't expect to sneak augmented assignments in there, for example! regards Steve -- Consulting, training, speaking: http://www.holdenweb.com/ Author, Python Web Programming: http://pydish.holdenweb.com/pwp/ From jacek.generowicz at cern.ch Fri Feb 15 03:19:05 2002 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 15 Feb 2002 09:19:05 +0100 Subject: Convert String to Dictionary question References: <3C6C3805.37BD87FB@ccvcorp.com> Message-ID: Jeff Shannon writes: > Gustavo Cordova wrote: > > > > > > > I saved my dictionary {'hello1': [1, 0, 0]} to a file. > > > > > > When I do a readline the I get back a string. > > > > > > How do I convert this string to a dictionary? > > > > > > Thanks. > > > > > > > You eval() it? > > > > >>> d = { "one":1, "two":2, "three":3 } > > >>> print d > > {'three': 3, 'two': 2, 'one': 1} > > >>> S = str(d) > > >>> print S > > {'three': 3, 'two': 2, 'one': 1} > > >>> dd = eval(S) > > >>> print dd > > {'one': 1, 'three': 3, 'two': 2} > > >>> d is dd > > 0 > > >>> > > This works, but is generally a Bad Idea(tm). The problem > with eval/exec on arbitrary strings (and any string you read > in from a file is arbitrary) is that it's hard to be > positive that what you're eval/exec-ing is what you expect. > And if it's *not*, then many, many very bad things can > happen. (Imagine someone "accidentally" replacing that > textfile with one that contains the line "import > os;os.system('rm -s /')" -- suddenly your entire filesystem > is blank....) Writing python scripts works but is generally a Bad Idea(tm). Imagine somone "accidentally" replacing the textfile containing your script with one that contains the line "import os;os.system('rm -s /')" -- suddenly your entire filesystem is blank....) Sic probo. :-) From QnickQm at alum.mit.edu Wed Feb 27 23:46:31 2002 From: QnickQm at alum.mit.edu (Nick Mathewson) Date: Thu, 28 Feb 2002 04:46:31 GMT Subject: Peer review: Python encyphering script References: <3c7c1a91.150875561@menuhin.netfront.net> Message-ID: In article <3c7c1a91.150875561 at menuhin.netfront.net>, A. Jones wrote: > It's my second day Pythoning and I've written this code to encypher > text (or files, ostensibly) into two pieces, neither of which can be > used to determine the message. > > Any problems pointed out, clunky lines spotted, or security problems > would be most appreciated. Also, if you've seen something like this, > if you'd tell me, please. [...] Okay; A code review follows. Not bad for two days of Pythoning! BTW, I would strongly disrecommend using this cipher for real purposes; it is not as secure as you think. See my closing comments below. =================================================================== > #encyphering tool > plaintext = "Isn't it awfully nice to have a penis; isn't it > frightfully good to have it on!" #The variable makes it obvious. #Actually, this won't work: you need to use triple quotes for a string #to span multiple lines. Try it like this: plaintext = '''I would have used the "Bruces' Philosophers Song" myself, but examples are a matter of taste. BTW, the final words are 'a dong'.''' > blarg = [] #To hold translation of ASCII to num > for b in plaintext: > # print b #Was here for development purposes. > blarg.append(ord(b)) #Turn it into a list of ASCII numbers > #nums make sorting easier&append/ord makes a > nice list #Naming your variables 'blarg', 'blurb', and so forth can make your #code harder to read. plaintext = map(ord, plaintext) > plaintext = "Text purged." #It won't do any good to 'purge' the plaintext from memory at this point; #if you're worried about an attacker getting it from RAM, they've already #had an opportunity to have done so. If you're worried about them reading #from swap, your program may have already swapped out. > blurb = {} #To hold 1:1 value/offset references > b = 0 #reuse variable so's to destroy evidence/make my life easier Rather than keeping an index, you might want to use the 'range' or 'xrange' method. > for z in blarg: > if z in blurb: #duplicate key fixer > if type(blurb[z]) == "": #Stops nesting > strings #It's bad style to rely in the string value of a type. Intstead, you #might want to import types, then say # 'if type(blurb[z]) == types.ListType:'. #If you're in Python 2.2, you can say, # 'if type(blurb[z]) == list:' > blurb[z].append(b) > else: > temp = blurb[z] #Used to create first list entry > temp.append(b) > blurb[z] = temp #The two cases above do exactly the same thing; there's no need for the # type check. > else: blurb[z] = [b] #sets dictionary with values as keys, offsets > as objects > b = b+1 #Next step in the offset counter... clunky. # Map from each character to an in-order list of its positions in # the original map. posMap = {} for idx in xrange(len(plaintext)): character = plaintext[idx] if character in posMap: posMap[character].append(idx) else: posMap[character] = [idx] > valuelist = blurb.keys() #extract keys of dictionary > valuelist.sort() #to be randomized later(date) # These lines are reasonable, but see below for thoughts on security. valuelist = posMap.keys() valuelist.sort() > finval = [] #to hold final value list > finoff = [] #to hold fial offset list > for r in valuelist: > z = 0 > while z < len(blurb[r]): #Writes number of values equal to number > of offsets > finval.append(r) > z = z+1 > for q in blurb[r]: #Decomposes my clunky nesting lists/dicts > finoff.append(q) > > blurb = {} #Destroy the evidence! > valuelist = [] # If we use a nested loop, we can eliminate the index variable. finval = [] finoff = [] for val in valuelist: for pos in posMap[val]: finval.append(val) finoff.append(pos) # It's too late to destroy the evidence, but if you'd like, del works # just fine. del posMap, valuelist, plaintext ============================================================ To summarize, and introduce a function: def encipher(plaintext): plaintext = map(ord, plaintext) posMap = {} for idx in xrange(len(plaintext)): character = plaintext[idx] if posMap.has_hey(character): posMap[character].append(idx) else: posMap[character] = [idx] valuelist = posMap.keys() valuelist.sort() finval = [] finoff = [] for val in valuelist: for pos in posMap[val]: finval.append(val) finoff.append(pos) return (finval, finoff) > > -- > #decyphering tool > text = [] #finval > key = [] #finoff > numdict = {} > z = 0 > for r in key: #This here is the heart of the decryption process. > Simply coalates the lists. > numdict[r] = text[z] > z = z + 1 > readlist = numdict.keys() > readlist.sort() #puts the keys/offsets in order > plaintext = "" > for r in readlist: > plaintext = plaintext + chr(numdict[r]) > print plaintext #prints plaintext #This is my first attempt, an the one that changes your approach least: def decipher(text, key): numdict = {} # It's easiest to use range when you want a list of indices for idx in xrange(len(key)): numdict[key[idx]] = text[idx] readlist = numdict.keys() readlist.sort() # Using "+" to build strings can be very slow; it needs to build # a new string every time you use it. plaintext = [ chr(numdict[r]) for r in readlist ] return "".join(plaintext) # This is my second appempt... def decipher(text, key): result = [None]*len(text) for val,pos in zip(text,key): result[pos] = val result = map(chr, result) return "".join(result) # This is my third: def decipher(text, key): temp = zip(key, text) temp.sort() return "".join(map(lambda x: chr(x[1]), temp)) ============================================================ And now, some notes on security. (I'm not trying to be harsh here, and I know this was probably not written for serious use, but it's important to understand that cryptography is a lot harder than it looks, and I wouldn't want you to accidentally leak anything private through trusting inadequate security.) First of all, this cipher is a bit suspicious. It has the undesirable property that the frequency counts of the characters in the ciphertext are the same as in the plaintext. That is to say, if I know you're sending either "attack at dawn" or "run for your lives", it's easy for me to tell which one you sent. Secondly, this cipher doesn't buy you a lot: The key is as long as the plaintext. If you have a secure place to store the key, you would presumably use that place to store the plaintext as well. Third, the scrambling step is more crucial than you think. Without scrambling, if I see the key-portion of a message, I'll have a pretty good idea which parts of the message go where: indices for low letters earlier than indices for high ones. But with scrambling, the quality of your cipher is limited by the power of your random number generator. For a deeper introduction to cryptography, you may want to get a copy of Schneier's _Applied Cryptography_, or read the FAQs from sci.crypt. ============================================================ Well, I hope this that didn't dampen your entusiasm for Python! You're off to a good start (esp. for two days!), and I hope we'll hear more of you in the future! Welcome-to-comp-lang-python-ly Yrs, -- Nick Mathewson Remove Q's to respond. No spam. From joshm at taconic.net Mon Feb 25 22:36:22 2002 From: joshm at taconic.net (Joshua Muskovitz) Date: Mon, 25 Feb 2002 22:36:22 -0500 Subject: size of socket.recv buffer References: Message-ID: <3c7b0051_1@corp.newsgroups.com> No, what he's saying is that the sender and the receiver operate independently. Think of the socket connection as a hose from the sender to you, ending in a huge bucket. You aren't allowed to carry the huge bucket back to your own code, it is attached to the hose. Instead, you have to use your own bucket to scoop stuff out of the huge one, and then carry it off. The value you pass to recv() is the size of your own bucket. When you call recv(), you are going to the huge bucket, scooping out as much as is in there (up to the size of your own bucket), and going back to your own program. If you didn't get all that you needed in that one trip, you have to go back. The other half of it is that the sender of the stuff is pushing it through the hose at its own pace. If it is very busy doing other things, it might not put the stuff through the hose very quickly. So you might get to the huge bucket looking for stuff, but there isn't very much stuff there. So you get what is there, and return. It might not even be enough to fill your own bucket. (There might not even be anything for you on a given trip to the big bucket.) So the purpose of sending you the octet count (and I believe that octet == byte) is so that you'll know whether to expect more stuff to come out of the hose or not. You have to keep track of how much stuff you've gotten so far, to know whether you have to go back and get more. You handle this by calling len() on the returned string, to see how much stuff actually got scooped into your bucket. You keep a running total of how much you've gotten. Does that help? -- # Joshua Muskovitz # joshm at taconic.net def lyyrs(sig): return '-'.join(sig.split()+["ly y'rs"]) lyyrs('Hire me! I need the work!') -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 80,000 Newsgroups - 16 Different Servers! =----- From sab at NOSPAM.freeuk.com Thu Feb 7 14:42:06 2002 From: sab at NOSPAM.freeuk.com (G. Willoughby) Date: Thu, 7 Feb 2002 19:42:06 -0000 Subject: Amount of files on a drive? References: Message-ID: Yep it was trimmed down code and yes i am using a global variable! :) I thought of explaining this when i first posted but i was sure everyone would assume it was a global. he he... G. Willoughby "Robin Munn" wrote in message news:slrna65a5i.1m1.rmunn at rmunn.dyndns.org... > On 6 Feb 2002 04:57:54 GMT, Philip Swartzleonard wrote: > >G. Willoughby || Tue 05 Feb 2002 07:56:57a: > > > >> i am using this at the minute: > >> ------------------------------------------------------------------ > >> import win32api > >> import string > >> import os > >> > >> def countFiles(arg, dir, files): > >> for file in files: > >> count=count+1 > >> > >> fileListings=[] > >> driveList=string.split(win32api.GetLogicalDriveStrings(),'\0')[:-1] > >> > >> for drive in driveList: > >> os.path.walk(drive, countFiles, 0) > >> ------------------------------------------------------------------ > >> but its pretty slow any other suggestion how i could speed it up?? > > > >Well, first determine how long it actually takes (time it), and see how it > >compares to say, selecting everything on the drive and hitting properties > >in the context menu to get a count (i.e. see how good windows itself is at > >it). It took my 800mhz athlon about 35 seconds to tell me that i have 6.15 > >gigs in 101,064 files in 3,930 folders on my C drive. Counting on that > >scale can get slow. > > Also, the bottleneck here is going to be the drive's access time, not > the processor speed. The access time is usually measured in milliseconds > and is the average time for the drive's read/write head to move from one > location to another on the disk surface. This operation is sometimes > called a "seek". Since the drive has to perform at least one seek for > every file, and usually more, the total time spent waiting for the hard > drive far outweighs the time spent by the processor. > > On the other hand, I do see one thing you could do to improve your code. > Chage the countFiles() function thus: > > ------------------------------------------------------------------ > def countFiles(arg, dir, files): > count = count + len(files) > ------------------------------------------------------------------ > > Also, I presume you're using a global variable to hold your count, > unlike the trimmed-down example code you showed us. In the code you > showed us above, the count variable would be a variable local to > countFiles() and would not hold its value across separate invocations of > countFiles(). Instead, you would do: > > ------------------------------------------------------------------ > count = 0 > > def countFiles(arg, dir, files): > global count > count = count + len(files) > ------------------------------------------------------------------ > > The "global count" statement inside countFiles() specifies that from > here on, the name count will refer not to a variable local to > countFiles() but instead to the global variable of that name. > > Gee, this is reminding me of that student blooper (probably an urban > legend) that went, "The Iliad was not written by Homer, but by another > man of that name." :) > > -- > Robin Munn > rmunn at pobox.com From joshm at taconic.net Sat Feb 16 01:09:10 2002 From: joshm at taconic.net (Joshua Muskovitz) Date: Sat, 16 Feb 2002 01:09:10 -0500 Subject: Apology References: <558.804T2090T11654864threeseas@earthlink.net> <3C68274C.F6F702F5@ccvcorp.com> <2320.811T442T11913096threeseas@earthlink.net> Message-ID: <3c6df547_2@corp.newsgroups.com> "Timothy Rue" wrote > Ten years???? it was Feburary 1988 when I identified the nine commands. > > I never claimed to be a programmer and never wanted to make the VIC but > rather someone to use it. But I also don't, and never will want to be > abused by any programmer wanting to take credit and property rights to the > VIC. Well, after 14 years then (happy anniversary!) of ranting about it with NOBODY else even desiring to take credit for it, don't you think you should stop worrying? You're only going to be abused by programmers who see it for what it is. Irrelevent. All you've said, all this time, is that everything boils down to nine things. Yippee. My entire genetic makeup can be done in four. Doesn't mean I find it useful to attempt to function purely on a cellular level. > The computer industry has alot of ethical problems in this area of taking > everything the can from the users, from their ideas, to their debugging > efforts (feedback), to their money in payment for what came from them, and > now rental....and always it is never quite right but lacking always... for > upgrading recycling of consumer entrapment abuse. > > That's what evidence ..... well what is, is what is. You know what you > are. As opposed to the ethical problems in say the energy futures industry, or savings and loans, or any of those other trifling scandals. People of poor moral character exist in all aspects of society. I fail to see any evidence they cluster around the programming profession. Just because there are companies out there who aren't the nicest, doesn't mean that PROGRAMMERS as a group are to blame. You seem to have this amazingly huge and likely malignant chip on your shoulder about something, and I don't think it has anything to do with autocoding. Perhaps we can help you. Tell us more about the bad people who screwed you over so many years ago. You'll feel better. We'll feel better. Programmers learn better by example anyway. Tell us what they did which made you so angry, and we'll promise to try not to do that. We may even apologize. Wouldn't that be nice? > There never will be enough programmers, but there is always exactly the > perfect number of user to do all the things a user needs to do for > themselves. Given the right freedom for the users, creating tools. That's right. Let's all return to the world of hunter/gatherers, where nobody takes advantage of others, and we all struggle to survive. If you despise the evil technology so much, why do you continue to use it? That seems very contradictory. -- # Joshua Muskovitz # joshm at taconic.net def lyyrs(sig): return '-'.join(sig.split()+["ly y'rs"]) lyyrs('Hire me! I need the work!') -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 80,000 Newsgroups - 16 Different Servers! =----- From edcjones at erols.com Thu Feb 28 18:48:56 2002 From: edcjones at erols.com (Edward C. Jones) Date: Thu, 28 Feb 2002 18:48:56 -0500 Subject: Python DB that supports numbers References: Message-ID: <3C7EC1E8.7070001@erols.com> Randall Hopper wrote: > I'm looking for a very simple Python DB which supports: > > 1) ints and floats as keys and values, > 2) performs DB access in the client, and > 3) stores the DB on disk. > > Just a simple DB for quick projects without the setup headache of > server-based database systems. > > For example, on the following table I just want to: "select * where > column_1 is 1". I'm using raw binary files now, but I'd prefer something > more self-describing like an SQL table. > > 1 10 1.814 177.1 13.61 73.2 > 1 5 1.624 182.5 -9999 -9999 > 1 2 1.259 185.9 13.24 73.9 > 2 10 2.672 181.4 13.59 72.5 > 2 5 2.423 183.2 -9999 -9999 > 2 2 1.902 190.7 13.27 73 > 3 10 3.208 181.9 13.46 72.1 > 3 5 2.787 186.6 -9999 -9999 > 3 2 2.17 194.7 13.16 72.3 > > Does anything like this exist in Python? I would use a Python dictionary which I would store to disk using module cPickle. table = {} def AddRow(table, row): key = row[0] if not table.has_key(key): table[key] = [] table[key].append(row) AddRow(table, [1, 10, 1.814, 177.1, 13.61, 73.2]) AddRow(table, [1, 5, 1.624, 182.5, -9999, -9999]) # ... AddRow(table, [3, 2, 2.17, 194.7, 13.16, 72.3]) print table[1] In the C++ Standard Template Library, there is a thing called a Multimap. It is like a Python dictionary except that each key can occur more than once. My Python name for this concept is "MultiDict". A MultiDict can be implemented in Python as a dictionary whose values are lists (like table[1] above). A MultiDict is a natural way to process sets of n-tuples. I have attached MultiDict.py which I use when the approach above is too simple but MySQL is overkill. Thanks, Ed Jones -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: MultiDict.py URL: From phansen at kaval.com Sun Feb 10 20:39:58 2002 From: phansen at kaval.com (Peter Hansen) Date: Sun, 10 Feb 2002 20:39:58 -0500 Subject: Bug or feature? 'abc'.split('') rejects empty separator References: <3C6703F4.8F25BE12@alcyone.com> Message-ID: <3C6720EE.28E0B68B@kaval.com> Erik Max Francis wrote: > > That's what list('abc') would return. But in actuality, for it to be > consistent with the rest of string.split's behavior, 'abc'.split('') > would have to return ['', 'a', 'b', 'c', ''], not ['a', 'b', 'c']. > > Another beautiful example of why string.split('') should raise an error > instead of trying to guess what you mean. And another: >>> ''.join(['ab', 'c']) 'abc' So what should 'abc'.split('') return again? From jason at jvoegele.com Fri Feb 15 08:53:44 2002 From: jason at jvoegele.com (Jason Voegele) Date: 15 Feb 2002 05:53:44 -0800 Subject: Coming of age... References: Message-ID: <91acf731.0202150553.298c1852@posting.google.com> m.faassen at vet.uu.nl (Martijn Faassen) wrote in message news:... > Andrew MacIntyre wrote: > > On 12 Feb 2002, Martijn Faassen wrote: > > >> Another interesting thing the other day is that on comp.object someone > >> was asking which language they should try to experiment with OO, and > >> there came lots of suggestions to use Ruby (Python was in there, but Ruby was > >> mentioned a *lot*). Seems that language has been crossing a barrier > >> as well recently. > > > My take: Ruby turns out to be a language of refuge for escapees from Perl > > who can't cope with white-space significance (more of them than not, I > > expect). > > That doesn't explain the recommendations in comp.object, though. > They use smalltalk, Java, C++ yes, but I don't expect most of the people > there are Perl users at all. Yes, I can attest to the fact that not all Ruby programmers come from Perl. I use Python and Ruby fairly regularly, and my background is Pascal -> C -> C++ -> Java -> Eiffel -> (Smalltalk, Ruby, and Python). I've used Perl in the past, but never considered myself a "Perl guy". I can also attest to the fact that lots of Ruby programmers don't even *like* Perl ;-) The similarities between Ruby and Perl are only skin-deep. A lot of people like it for its semantic similarity with Smalltalk, rather than its syntactic similarity to Perl. In any event, I suspect that popularity of either Ruby or Python will be mutually beneficial to the other. Once one of them "crosses the line", it won't be so hard for the other to do the same. Jason Voegele From jonathan at onegoodidea.com Tue Feb 5 05:56:13 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Tue, 05 Feb 2002 10:56:13 +0000 Subject: Backwards Compatibility of Python versions References: <7x8za8dgle.fsf@ruckus.brouhaha.com> <7xheow3hl2.fsf@ruckus.brouhaha.com> <3C5F3A07.45126DAF@ccvcorp.com> <7xg04gisvz.fsf@ruckus.brouhaha.com> Message-ID: On 5/2/2002 2:06, in article 7xg04gisvz.fsf at ruckus.brouhaha.com, "Paul Rubin" wrote: > OK, that takes care of 1.5.2. I gather that 2.0.* never became very > widespread. So I wonder now, whether more people are using 2.1.* than > 1.5.2, and whether there will still be a significant amount of 2.1 > installations when 3.0 is released. If it sounds like there won't be, > then I'll probably just put > > if 3/2==1: > > at the top of my scripts and then code for 2.1. When 2.1 gets more > displaced by 2.2 and later, I can switch over to import future division. Eh? Sorry, what is the test meant to achieve? This test will succeed and the program will exit in all versions of the interpreter until 3.0 when the semantics of classic division change. Did you mean that to be a '<>' as a test for the introduction of Python 3.0? If you want maximum compatibility then continue to code in forward compatible 1.5.2. Your scripts will be fine for a long time yet. I wouldn't bother switching to using new 2.x features unless you need to. After making such a lot of noise about backwards compatibility, you seem to be remarkably willing to ditch your 1.5.2 users... On a related note, what exactly broke RH Anaconda in Python 2.x? Has someone investigated this. I'd be interested in hearing the actual cause rather than the speculation that has been going on here. Did anyone from the Python "inner circle" contact RedHat to ask them? or discuss solving the problem to allow them to ship a modern version of the interpreter? Jonathan From tdelaney at avaya.com Tue Feb 5 17:45:38 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Wed, 6 Feb 2002 09:45:38 +1100 Subject: My own list object Message-ID: > I made a file mylist.py > > # mylist.py > class MyList: > def __init__(self): > self.list=[] > def append(self, item): > self.list.append(item) > > >>> import mylist > >>> x = mylist() > Traceback (most recent call last): > File "", line 1, in ? > TypeError: object of type 'module' is not call > > Why is this happening? My list object must be a class in its own, > importable file. That statement is incorrect. Read up on Python classes and modules. Basically, a module contains definitions of things, including classes. You can have as many definitions as you want in a module. You can also have code which executes when the module is imported. A module is also a namespace - to get at the definitions within that namespace, you have to qualify them somehow. With your example, you import the module mylist (thus binding the name 'mylist' to the module object). You then try to use the mylist module as a callable - which it is not. However, in the mylist namespace is an object named 'MyList' - which is your class definition. So the call you need to make is x = mylist.MyList() You should now got to http://www.python.org/doc/current/tut/tut.html and work your way through the tutorial. If you have further questions, the FAQ http://www.python.org/cgi-bin/faqw.py should be able to help you. Tim Delaney From thomas.heller at ion-tof.com Fri Feb 1 04:54:38 2002 From: thomas.heller at ion-tof.com (Thomas Heller) Date: Fri, 1 Feb 2002 10:54:38 +0100 Subject: How to change the icon in window header of window developed using python? References: <5d65cf44.0202010126.7b58df35@posting.google.com> Message-ID: "CodeTube" wrote in message news:5d65cf44.0202010126.7b58df35 at posting.google.com... > Hello Everyone, > > Could some one please tell me how to change the icon (a red one saying > TK) in the window title bar of a window generated by python usging > tkinter. > I have developed an application using python and the gui using > Tkinter. However i am not able to change the red 'TK' icon to > something more customized. > Take a look at http://hackicon.sf.net/. HTH, Thomas From peter at engcorp.com Thu Feb 28 19:32:31 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 28 Feb 2002 19:32:31 -0500 Subject: listing threads? References: Message-ID: <3C7ECC1F.F4FD6AFD@engcorp.com> maximilianscherr wrote: > > in the docs theres the information, that i can list all active > threads with threading.enumerate(), but i always just get the > Mainthread displayed in the interpreter console. > > im doing somethin like: [...snip] > then if i do threading.enumerate() i just get the mainthread int he > list. > > so how can i now list all (active) threads? Just as you are trying to do. Does this help? >>> class test(t.Thread): ... def run(self): ... print 'hi' ... self.terminated = 0 ... import time ... while not self.terminated: ... time.sleep(1) ... print 'done' ... >>> te = test() >>> te.start() hi >>> t.enumerate() [, <_MainThread(MainThread, started)>] >>> te.terminated = 1 >>> done >>> t.enumerate() [<_MainThread(MainThread, started)>] >>> Your problem is that (a) you don't have a run() method in your thread class, and that is what gets executed when you call te.start(), and (b) your thread is therefore terminating immediately upon creation, and therefore t.enumerate() is returning only the main thread, because no others are running. -Peter From frederic.giacometti at arakne.com Tue Feb 26 21:18:09 2002 From: frederic.giacometti at arakne.com (Frederic Giacometti) Date: Wed, 27 Feb 2002 02:18:09 GMT Subject: [ANN] JPE 2.0 The Java-Python Extension Message-ID: This is the official announcement of the second version of JPE (CVS release tag jpe_2_0_0). JPE (The Java-Python Extension) is a production-grade seamless integration of Python and Java. JPE lets you call Java objects and classes from Python, and vice-versa, within the same process space. JPE is reentrant (cross-language callbacks), and supports multi-threading concurently in Java and Python. The reference web site for JPE is http://jpe.sourceforge.net As compared to its first release: 1) The build system of JPE has been completely reengineered, and is based on a new build library (libplus). In this new version: - Java and python are auto-detected from the command line, and everything else is derived from there (Java libraries, library paths...). - libplus generated its own makefiles, and runtime environment (env variables) for the build and test phases; so there is no need to set-up anything - everything is now plateform-independant, and the same scripts are used on Win32 and posix (no more GNU make / cygwin make required on windows) - JPE has been ported to posix environments. However, a shared python library is required on these platforms. You can build your onw, or use the branched version of Python 2.1, named 'pythonx', which is provided for these purposes. - JPE is distributed in source form from CVS. Substantial efforts have been invested to provide a config and build environment that makes it straightforward to configure, build from source, and test multi-component, multi-platform software systems. Hopefully, that can be one step ahead from the current autoconf or distutil systems. Easily extensible to support arbitrary software components and tools, libplus currently supports C, C++, Python, Java, and swig wrappers. Libplus generates configuration-specific makefiles that chain software component dependencies together, and provides runtime software/tool configuration information. Litteratly, this is an 'open-source' project :)) 2) New capabilities of JPE, for the 2d release: - Java bean support: Jbean properties are accessed as regular python attributes - Cross-language native array access: JPE integrates the bufarray python extension type; a layer on top of the python buffer interface that provides type-safe access to contiguous fixed-length C arrays (actually, 99% of the situations in scientific C or Fortran libraries). This integration permits to safely access arrays by shared memory reference between Java, Python, and C; while hidding the native memory format. 3) Acknowledgements: Arakn?, and The Molecular Graphics Laboratory at The Scripps Research Institute. Benevolently yours, Fr?d?ric Giacometti fred at arakne.com From gh_pythonlist at gmx.de Mon Feb 11 03:22:20 2002 From: gh_pythonlist at gmx.de (Gerhard =?iso-8859-15?Q?H=E4ring?=) Date: Mon, 11 Feb 2002 09:22:20 +0100 Subject: subclassing tuple In-Reply-To: References: <20020211071605.GA2528@lilith.hqd-internal> Message-ID: <20020211082219.GB3126@lilith.hqd-internal> Le 11/02/02 ? 02:51, Tim Peters ?crivit: > [explanation why __new__ is needed for subclassed immutable types] Thanks for this great explanation, Tim. Guess I'll have to read Guido's Python 2.2 tutorial a few more times. Gerhard -- This sig powered by Python! Au?entemperatur in M?nchen: 8.0 ?C Wind: 6.4 m/s From tbryan at python.net Wed Feb 13 21:21:03 2002 From: tbryan at python.net (Tom Bryan) Date: Thu, 14 Feb 2002 02:21:03 GMT Subject: Using tabs instead of spaces in IDLE? Message-ID: Is there a way to use tabs exclusively for indentation in IDLE? Basically, I'd like tabwidth to equal identwidth while permitting developers to adjust the indentwidth. I see that AutoIndent.py says # indentwidth is the number of characters per logical indent level. # tabwidth is the display width of a literal tab character. # CAUTION: telling Tk to use anything other than its default # tab setting causes it to use an entirely different tabbing algorithm, # treating tab stops as fixed distances from the left margin. # Nobody expects this, so for now tabwidth should never be changed. usetabs = 1 indentwidth = 4 tabwidth = 8 # for IDLE use, must remain 8 until Tk is fixed But I don't quite understand that explanation. The reason I ask is that I'm going to be introducing Jython to a bunch of Java developers at work. I expect to get a lot of complaints about blocks being delimited by whitespace (already got one), and I'd like to be ready with nice editor configurations so that it's never a practical problem for our team. Our group's current coding style (for C++ and Java) includes indentation by tabs. Every developer sets his editor to always insert a tab when the tab key is pressed, but they adjust the visual display of the tab size to be whatever they want it to be. It doesn't look like IDLE is friendly to that type of customization. I know that emacs is. I'm currently investigating the other editors that my team uses, such as CodeWright. Thanks, ---Tom From wolfson at uchicago.edu Sun Feb 3 01:29:36 2002 From: wolfson at uchicago.edu (Ben Wolfson) Date: Sun, 03 Feb 2002 00:29:36 -0600 Subject: Backwards Compatibility of Python versions References: <83sn8peybr.fsf@panacea.canonical.org> <83bsf7z4h2.fsf@panacea.canonical.org> <7x4rkzw9yz.fsf@ruckus.brouhaha.com> <3C5C973E.6080607@sneakemail.com> Message-ID: On Sat, 02 Feb 2002 23:55:38 -0600, Joshua Macy wrote: > try: > from __future__ import division > except ImportError: > pass This construct is illegal, as __future__ imports must be the first statements in a module. ##tmp.py: try: from __future__ import division except ImportError: pass ##interpreter: Python 2.2 (#1, Dec 22 2001, 14:06:34) [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-81)] on linux2 Type "copyright", "credits" or "license" for more information. IDLE 0.8 -- press F1 for help >>> import tmp Traceback (most recent call last): File "", line 1, in ? import tmp SyntaxError: from __future__ imports must occur at the beginning of the file (tmp.py, line 2) >>> -- BTR BEN WOLFSON HAS RUINED ROCK MUSIC FOR A GENERATION -- Crgre Jvyyneq From jeff at ccvcorp.com Mon Feb 18 21:04:02 2002 From: jeff at ccvcorp.com (Jeff Shannon) Date: Mon, 18 Feb 2002 18:04:02 -0800 Subject: Adding static typing to Python References: <24c39b2c.0202181531.187fad4c@posting.google.com> Message-ID: <3C71B291.B8574221@ccvcorp.com> Peter Milliken wrote: > > There are regular discussions on the usefulness of Python for "larger" > projects. Many claim that they use it without any problems - I suspect that > it is from a background of ignorance and lack of metrics ... ................ > Of course, it takes me longer to write > up front but overall development effort (in my subjective opinion - since I > have no metrics :-)) is that it is much lower. So, you're just as guilty of the subjectiveness as those Python-supporters, yet you feel justified in telling them that they're wrong? :) Standard disclaimer: I don't have any metrics either, nor am I familiar with Ada at all, so I'm not making any specific claims either way. However, there seems to be enough people making the claim in Python's favor, that I'm inclined to believe it until such time as I see real (objective) evidence that it's false. I freely admit that I've never worked on a large (or even midsized) coding project, in Python or otherwise, but in my year of using Python I can't recall a single instance of a grueling debugging session finding a name- or type- error as the cause. When I compare this to how much time it took me to get C/C++ programs to compile at all, and *then* verify that they worked *correctly*, Python is a clear win. Again, perhaps Ada is easier than C++ (I'm sure that *you* think so >wink< ), but all of my (limited) personal experience supports the Pythonic claims. (And please note, I'm intending this as a friendly discussion, not a personal attack. I'm *not* trying to flame you, by any means -- I know I don't know enough to get away with that. I just find it interesting that you are always advocating Ada....) Jeff Shannon Technician/Programmer Credit International From cfelling at iae.nl Thu Feb 28 08:21:33 2002 From: cfelling at iae.nl (Carel Fellinger) Date: 28 Feb 2002 14:21:33 +0100 Subject: PEP 263 comments References: <87g03lhm3p.fsf@tleepslib.sk.tsukuba.ac.jp> Message-ID: Stephen J. Turnbull wrote: > Hi, I'm Steve Turnbull, I do XEmacs. Mostly Mule. Barry asked me to > step up to bat on this. ... lots of interesting experiences snipped Thanks for sharing, hope this helps us to do the right thing. Now that we have your attention, what's your personal opinion on using something else but ascii (in whatever encoding:) for the code itself (things like keywords and variable names). My Western centered view would be that it would make reading code harder, but that's probably what the rest of the world already experiences. I personally use English even for my privat code and I even try to stick to English in my comments, just in case some foreignor might have to look at it:) -- groetjes, carel From sabren at manifestation.com Sat Feb 23 09:16:49 2002 From: sabren at manifestation.com (Michal Wallace) Date: Sat, 23 Feb 2002 09:16:49 -0500 (EST) Subject: help: Problem with cgi form In-Reply-To: Message-ID: On 23 Feb 2002, Flavian Hardcastle wrote: > I know when it's undeclared ... whenever a user first > tries to access the form, it is undeclared. What I want to > know is how to get the script to check whether this value > has not been declared yet. Um. Why don't you just declare it, and assign a default value? Failing that: locals().get("varname", "defaultvalue") or: is_declared = locals().has_key("varname") Cheers, - Michal http://www.sabren.net/ sabren at manifestation.com ------------------------------------------------------------ Give your ideas the perfect home: http://www.cornerhost.com/ cvs - weblogs - php - linux shell - perl/python/cgi - java ------------------------------------------------------------ From philh at comuno.freeserve.co.uk Tue Feb 12 10:46:49 2002 From: philh at comuno.freeserve.co.uk (phil hunt) Date: Tue, 12 Feb 2002 15:46:49 +0000 Subject: Apology References: <558.804T2090T11654864threeseas@earthlink.net> <3C68274C.F6F702F5@ccvcorp.com> Message-ID: On Mon, 11 Feb 2002 18:37:51 -0600, Chris Gonnerman wrote: > >Indeed. He uses a nonstandard definition of "language" and applies >"physics" >to programming. He can't program, you know; ten years on this project and >nothing to show for it. If I had tried to develop something like this for >ten years and had nothing to show for it but a website, I'd give up. At least his code is all neatly lined up! -- ===== Philip Hunt ===== philh at comuno.freeserve.co.uk ===== Herbivore, a zero-effort email encryption system. Details at: From phr-n2002a at nightsong.com Wed Feb 20 23:21:18 2002 From: phr-n2002a at nightsong.com (Paul Rubin) Date: 20 Feb 2002 20:21:18 -0800 Subject: strings and sort() References: <3C747268.6C756B9D@earthlink.net> Message-ID: <7xvgcrfosh.fsf@ruckus.brouhaha.com> Hans Nowak writes: > > Why doesn't sort() return the sorted list. I would like to chain it > > to other operations: > > b=[x for x in a].sort() > > The other replies told you why list.sort() doesn't return > the sorted list. You can easily roll your own function, > though: > > >>> def sort2(lst): > z = lst[:] > z.sort() > return z > ... > This sort2() function returns a new, sorted list > without affecting the original one. Don't use this > when performance is an issue, though... it's not > very efficient because it copies the original > list first. Just write it like this: def sort3(lst): lst.sort() return lst The list comprehension already makes a temporary list. You don't need to copy it around again. From phd at phd.pp.ru Fri Feb 1 05:34:30 2002 From: phd at phd.pp.ru (Oleg Broytmann) Date: Fri, 1 Feb 2002 13:34:30 +0300 Subject: locale on cygwin In-Reply-To: <3C5A6BC1.6080009@halfcooked.com>; from andy47@halfcooked.com on Fri, Feb 01, 2002 at 09:19:45PM +1100 References: <20020125140805.GC1252@dothill.com> <3C5A607F.6060107@halfcooked.com> <20020201123241.H10316@phd.pp.ru> <3C5A6BC1.6080009@halfcooked.com> Message-ID: <20020201133430.M10316@phd.pp.ru> On Fri, Feb 01, 2002 at 09:19:45PM +1100, Andy Todd wrote: > Thanks for that, but this is what happens if I don't force it; > > """ > $ echo $LANG > C > $ python > Python 2.1.1+ (#1, Jan 8 2002, 00:37:12) > [GCC 2.95.4 20011006 (Debian prerelease)] on linux2 > Type "copyright", "credits" or "license" for more information. > >>> import locale > >>> locale.getdefaultlocale() > Traceback (most recent call last): > File "", line1, in ? > File "/usr/lib/python2.1/locale.py", line 339, in getdefaultlocale > return _parse_localename(localename) > File "/usr/lib/python2.1/locale.py", line 272, in _parse_localename > raise ValueError, 'unknown locale: %s' % localename > ValueError: unknown locale: > """ Strange. It works perfectly for my. On LNAG=C it returns (None, None), on LANG=ru_RU it returns ("ru_RU", "ISO-8859-5"). Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From jimmy at retzlaff.com Fri Feb 15 11:45:42 2002 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Fri, 15 Feb 2002 08:45:42 -0800 Subject: VB code -> Python Message-ID: > Set oContext = GetObjectContext > Err.Clear > Set oUser = GetObject("WinNT://" & CStr(Domain) & "/" & CStr(UserID)) > If Err = 0 Then > For Each oGroup In oUser.Groups > If UCase(Groupname) = UCase(oGroup.Name) Then > MemberofGroup = True > 'Exit Function > Exit For > End If > Next > oContext.SetComplete > Else > oContext.SetAbort > MemberofGroup = False > End If > >So my questin is how do I translate the GetObject(...) thing in to >Python code. Here is a version in Python, using your same variable names, etc.: import win32com.client def MemberofGroup(Domain, UserID, Groupname): try: oUser = win32com.client.GetObject(r'WinNT://%s/%s' % (Domain, UserID)) except: return 0 for oGroup in oUser.Groups(): if Groupname.upper() == oGroup.Name.upper(): return 1 print MemberofGroup(Domain='CoolDomain', UserID='Cool Guy', Groupname='Domain Users') Jimmy From fredrik at pythonware.com Mon Feb 11 17:05:22 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 11 Feb 2002 22:05:22 GMT Subject: Fear of autocoding! References: <7934d084.0202101718.404404d1@posting.google.com> <7643.807T2626T856092threeseas@earthlink.net> <3C67C369.597E3517@optonline.net> <3C67D328.985269AC@optonline.net> Message-ID: Frederick wrote: > Whoops! He's ... Herr Professor Doktor Gerhard Wuensch. a quick googling revealed the following quotation: "I always try to write music which is accessible to the widest possible audience, reasonably well crafted and economical, in that it requires a minimum of rehearsal time." sounds like he would have been a great python developer, had he picked up computing instead of music ;-) From jriveramerla at yahoo.com Fri Feb 1 11:58:23 2002 From: jriveramerla at yahoo.com (Jose Rivera) Date: 1 Feb 2002 08:58:23 -0800 Subject: Is there a Metakit release for python 2.2? Message-ID: <11e94203.0202010858.17a6bce7@posting.google.com> Hi.. I just Installed Python 2.2 and I am getting the followin error: Traceback (most recent call last): File "D:\scripts\Rev_Si_Hay_Archivos_En_BCKS_Sin_Procesar.py", line 2, in ? import metakit File "D:\TOOLS\Python22\lib\metakit.py", line 12, in ? from Mk4py import * ImportError: Module use of python21.dll conflicts with this version of Python. It worked with Python 2.1, and I searched on the WEB and did not found a comment about a new release. Thanks for your help. From teddrain at earthlink.net Tue Feb 26 15:31:01 2002 From: teddrain at earthlink.net (Ted Drain) Date: Tue, 26 Feb 2002 20:31:01 GMT Subject: Building 2.2 with the Intel icc compiler Message-ID: <9gSe8.18435$ZC3.1526281@newsread2.prod.itd.earthlink.net> Has anyone built Python 2.2 with the new Intel C/C++ compiler icc? I configured Python and then edited the Makefile by hand to use icc and icc options. Python builds but the modules all report errors (and then remove themselves). This compiler generates code that is roughly 30% faster than gcc. Check out: http://www.open-mag.com/754088105111.htm Any thoughts? Ted From tismer at tismer.com Tue Feb 26 06:48:17 2002 From: tismer at tismer.com (Christian Tismer) Date: Tue, 26 Feb 2002 12:48:17 +0100 Subject: Time to rename Stackless? References: Message-ID: <3C7B7601.70906@tismer.com> Christopher Browne wrote: ... > If it gets to the point of supporting billions of threads, it would > _certainly_ make sense to call it "NanoThreading Python." Or > "NanoTech Python." :-) I doubt that we can easily have a million of threads, so even the microthread name is a bit optimistic. MilliThreading is more accurate. Esspecially since a typical thread takes 1 MB of memory, and tasklets use a thousandth of that. > There have got to be some puns heading in the direction of "seriously > stacked." Hmm... Ok, here what "Stackless" really means: I didn't earn haystacks of money with it yet. When that happens, I might rename it :) Pythonlet -- yes, thousands of little snakelets squirreling around me -- huh! I need a nap -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Kaunstr. 26 : *Starship* http://starship.python.net/ 14163 Berlin : PGP key -> http://wwwkeys.pgp.net/ PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF where do you want to jump today? http://www.stackless.com/ From jason at jorendorff.com Tue Feb 5 20:31:00 2002 From: jason at jorendorff.com (Jason Orendorff) Date: Tue, 5 Feb 2002 19:31:00 -0600 Subject: My own list object In-Reply-To: Message-ID: MDK writes: > I am trying to create my own special type of list object. > > However, when I do x.append('yo') it uses Python's append instead > of the one from my class. > > If this is not easy can someone at least point me to an example of what I > want to do? It is very easy. But it requires Python 2.2. class X(list): def append(self, something): print "Hello, world!" >>> x = X() >>> x.append(14) Hello, world! ## Jason Orendorff http://www.jorendorff.com/ From martin at v.loewis.de Tue Feb 26 12:52:03 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 26 Feb 2002 18:52:03 +0100 Subject: Python 2.2 on SunOS5.7 install errors References: Message-ID: Alex Chavez writes: > I'm getting the error msg below when I attempt to install python 2.2 on > a sun solaris 7 os5.7 sparc box, using gcc 3.0.3 > > > *** Error code 1 > make: Fatal error: Command failed for target `Parser/tokenizer.o' > > > > I hope I'm not duplicating the Jeff Bauer's post. I read the thread but > I cant make heads or tails of it. It's certainly different, but we need to know more details. What was the command that failed, and did that give any indication how it failed? Regards, Martin From hmartires at cultalg.pt Mon Feb 25 07:32:40 2002 From: hmartires at cultalg.pt (Hugo Martires) Date: Mon, 25 Feb 2002 12:32:40 -0000 Subject: Counting bytes Message-ID: How can i count the number of bytes of: --> List [] --> array('d',[]) There is any function that return's the number of bytes ? Tanks in advance From jason at jorendorff.com Sun Feb 10 22:51:34 2002 From: jason at jorendorff.com (Jason Orendorff) Date: Sun, 10 Feb 2002 21:51:34 -0600 Subject: FixedPoint In-Reply-To: Message-ID: Mark McEahern wrote: > [Jason Orendorff] > > How about: > > > > def __cmp__(self, other): > > try: > > xn, yn, p = _norm(self, other) > > return cmp(xn, yn) > > except: > > return cmp(float(self), other) > > I like that! Would it be better style to trap only the specific error I > know about? Yep. If you know what's in _norm() you can do better than I can. :) Also, you might pull the first return statement out of the try. ## Jason Orendorff http://www.jorendorff.com/ From python at dejazzd.com Thu Feb 28 14:08:22 2002 From: python at dejazzd.com (Glenn Stauffer) Date: Thu, 28 Feb 2002 14:08:22 -0500 Subject: mime multipart messages Message-ID: <20020228190909.E03C117E8C@juniper.its.swarthmore.edu> I'm using the MimeWriter module to attach a file, submitted through an html form, to an email message. When I do this and send mail to a unix machine and read the mail with mutt or kmail, the file is attached to the message as I would expect. However, when the message is opened on a Mac or Windows machine, the file is mixed into the body of the message. This is the code I use to construct the message: ------------------------------------------------------------------------------- message = StringIO.StringIO() writer = MimeWriter.MimeWriter(message) writer.addheader('Subject', mail_subject) writer.startmultipartbody('mixed') part=writer.nextpart() body = part.startbody('text/plain') body.write(msgbody) part=writer.nextpart() part.addheader('Content-Type','application/mixed') part.addheader('Content-Transfer-Encoding', 'base64') part.addheader('Content-Disposition','attachment; filename=%s' % form['file'].filename) body = part.startbody('application/binary') base64.encode(open(tmpfile,'rb'), body) writer.lastpart() ------------------------------------------------------------------------------- This is how the file looks when someone opens it with Eudora on a Windows PC: --130.58.64.30.99.29450.1014921136.814.11340 Content-Type: text/plain --130.58.64.30.99.29450.1014921136.814.11340 Content-Type: application/binary Content-Type: application/mixed Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=README PT09PT09PT09PT09PT09PT09PT0NClRoZSB4bWxycGNsaWIgbW9kdWxlDQo9PT09PT09PT09PT09 PT09PT09PQ0KDQpUaGlzIGtpdCBjb250YWlucyBhIFB5dGhvbiBpbXBsZW1lbnRhdGlvbiBmb3Ig ------------------------------------------------------------------------------- Anyone have any thoughts on what I'm doing wrong or where to look to figured this problem out? Thanks, Glenn From ryan.phillips at csus.edu Tue Feb 12 12:49:19 2002 From: ryan.phillips at csus.edu (Ryan Phillips) Date: 12 Feb 2002 17:49:19 GMT Subject: Help with Installer. References: Message-ID: Did you set the file's attributes to be executable? chmod +x some_file_name -ryan "Maciej Starzyk" wrote in message news:Xns91B3A738AD5C1maccetipl at 149.156.4.11... > Gordon McMillan wrote in > news:Xns91B36755D3F49gmcmhypernetcom at 199.171.54.214: > > > The only way I know of (and boy, I hope I've > > missed something!) is to install the executable > > on the user's PATH. It should be able to find > > itself, at the expense of some hunting and pecking. > > > > -- Gordon > > http://www.mcmillan-inc.com/ > > > > Thanks for your reply. > Unfortunately, I cannot put it in PATH. > It is executed as a CGI script, and I have no > write access to any directory in the apache's PATH. > > Maciek From quinn at hurl.ugcs.caltech.edu Mon Feb 11 18:05:07 2002 From: quinn at hurl.ugcs.caltech.edu (Quinn Dunkan) Date: 11 Feb 2002 23:05:07 GMT Subject: why i love python... References: Message-ID: On Wed, 6 Feb 2002 17:34:52 -0800, Mark McEahern wrote: >python comes with a slew of special methods for objects that you can >leverage to do some really neat things. consider __str__, which is called >on your objects when you print them. if you don't define __str__, >that's ok, you'll get something like this: Of course, just about every object oriented language has this, from haskell's 'show' to CLOS's 'print-object' to eiffel's 'out', so python doesn't have a monopoly :) >obviously, i should return something more meaningful than that. for >instance, it might be nice to return an xml representation of the object. >again, with python this is unbelievably easy: I'd assert that this is a misuse of __str__. __str__ is supposed to be something all objects use to present human readable output. I would only use it to make XML if a) I was prepared to make *all* objects' __str__s return XML (already too late for that :) and b) I thought XML was human-readable (way too late for that). I'd go with a 'to_xml()'. __str__ is just overloading the built in function str(). There's nothing special about it except that the REPL invokes it automatically. You wouldn't overload '+' to print strings, would you (sather notwithstanding)? Or, you wouldn't overload bit-shift to... err... pay no attention to those other languages. >this snippet shows: > >
    >
  • how you can use self.__dict__ to access an object's attributes.
  • >
  • how you can iterate over the keys of a dictionary (i believe that's >new with python 2.2).
  • >
  • how you can use self.__class__ to access an instance's class; and >__class__.__name__ to access the name of the class as a string.
  • >
Yep, python's introspection is nice. >i think this shows some of the power of python. particularly, how special >methods can save you an amazing amount of time. to me, the natural next There's nothing special about most __special__ methods except some simple syntax transformation (str(o) -> o.__str__()). And if you overload a widely used, general purpose method to do something different from its usual meaning you might spend an amazing amount of time debugging why some objects aren't getting XML-ified properly (they're actually the wrong type, but that's hidden by the fact that they already have a working __str__ method). >